| 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 | 67073c6 | 2021-03-01 09:18:21 -0800 | [diff] [blame] | 4 | * Copyright (C) 2017-2021 Broadcom. All Rights Reserved. The term * |
| 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 | 840a470 | 2020-11-15 11:26:40 -0800 | [diff] [blame] | 93 | union lpfc_wqe128 lpfc_iread_cmd_template; |
| 94 | union lpfc_wqe128 lpfc_iwrite_cmd_template; |
| 95 | union lpfc_wqe128 lpfc_icmnd_cmd_template; |
| 96 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 97 | static IOCB_t * |
| 98 | lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) |
| 99 | { |
| 100 | return &iocbq->iocb; |
| 101 | } |
| 102 | |
James Smart | 840a470 | 2020-11-15 11:26:40 -0800 | [diff] [blame] | 103 | /* Setup WQE templates for IOs */ |
| 104 | void lpfc_wqe_cmd_template(void) |
| 105 | { |
| 106 | union lpfc_wqe128 *wqe; |
| 107 | |
| 108 | /* IREAD template */ |
| 109 | wqe = &lpfc_iread_cmd_template; |
| 110 | memset(wqe, 0, sizeof(union lpfc_wqe128)); |
| 111 | |
| 112 | /* Word 0, 1, 2 - BDE is variable */ |
| 113 | |
| 114 | /* Word 3 - cmd_buff_len, payload_offset_len is zero */ |
| 115 | |
| 116 | /* Word 4 - total_xfer_len is variable */ |
| 117 | |
| 118 | /* Word 5 - is zero */ |
| 119 | |
| 120 | /* Word 6 - ctxt_tag, xri_tag is variable */ |
| 121 | |
| 122 | /* Word 7 */ |
| 123 | bf_set(wqe_cmnd, &wqe->fcp_iread.wqe_com, CMD_FCP_IREAD64_WQE); |
| 124 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, PARM_READ_CHECK); |
| 125 | bf_set(wqe_class, &wqe->fcp_iread.wqe_com, CLASS3); |
| 126 | bf_set(wqe_ct, &wqe->fcp_iread.wqe_com, SLI4_CT_RPI); |
| 127 | |
| 128 | /* Word 8 - abort_tag is variable */ |
| 129 | |
| 130 | /* Word 9 - reqtag is variable */ |
| 131 | |
| 132 | /* Word 10 - dbde, wqes is variable */ |
| 133 | bf_set(wqe_qosd, &wqe->fcp_iread.wqe_com, 0); |
| 134 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
| 135 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, LPFC_WQE_LENLOC_WORD4); |
| 136 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 0); |
| 137 | bf_set(wqe_wqes, &wqe->fcp_iread.wqe_com, 1); |
| 138 | |
| 139 | /* Word 11 - pbde is variable */ |
| 140 | bf_set(wqe_cmd_type, &wqe->fcp_iread.wqe_com, COMMAND_DATA_IN); |
| 141 | bf_set(wqe_cqid, &wqe->fcp_iread.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); |
| 142 | bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 0); |
| 143 | |
| 144 | /* Word 12 - is zero */ |
| 145 | |
| 146 | /* Word 13, 14, 15 - PBDE is variable */ |
| 147 | |
| 148 | /* IWRITE template */ |
| 149 | wqe = &lpfc_iwrite_cmd_template; |
| 150 | memset(wqe, 0, sizeof(union lpfc_wqe128)); |
| 151 | |
| 152 | /* Word 0, 1, 2 - BDE is variable */ |
| 153 | |
| 154 | /* Word 3 - cmd_buff_len, payload_offset_len is zero */ |
| 155 | |
| 156 | /* Word 4 - total_xfer_len is variable */ |
| 157 | |
| 158 | /* Word 5 - initial_xfer_len is variable */ |
| 159 | |
| 160 | /* Word 6 - ctxt_tag, xri_tag is variable */ |
| 161 | |
| 162 | /* Word 7 */ |
| 163 | bf_set(wqe_cmnd, &wqe->fcp_iwrite.wqe_com, CMD_FCP_IWRITE64_WQE); |
| 164 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, PARM_READ_CHECK); |
| 165 | bf_set(wqe_class, &wqe->fcp_iwrite.wqe_com, CLASS3); |
| 166 | bf_set(wqe_ct, &wqe->fcp_iwrite.wqe_com, SLI4_CT_RPI); |
| 167 | |
| 168 | /* Word 8 - abort_tag is variable */ |
| 169 | |
| 170 | /* Word 9 - reqtag is variable */ |
| 171 | |
| 172 | /* Word 10 - dbde, wqes is variable */ |
| 173 | bf_set(wqe_qosd, &wqe->fcp_iwrite.wqe_com, 0); |
| 174 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
| 175 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_LENLOC_WORD4); |
| 176 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0); |
| 177 | bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1); |
| 178 | |
| 179 | /* Word 11 - pbde is variable */ |
| 180 | bf_set(wqe_cmd_type, &wqe->fcp_iwrite.wqe_com, COMMAND_DATA_OUT); |
| 181 | bf_set(wqe_cqid, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); |
| 182 | bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 0); |
| 183 | |
| 184 | /* Word 12 - is zero */ |
| 185 | |
| 186 | /* Word 13, 14, 15 - PBDE is variable */ |
| 187 | |
| 188 | /* ICMND template */ |
| 189 | wqe = &lpfc_icmnd_cmd_template; |
| 190 | memset(wqe, 0, sizeof(union lpfc_wqe128)); |
| 191 | |
| 192 | /* Word 0, 1, 2 - BDE is variable */ |
| 193 | |
| 194 | /* Word 3 - payload_offset_len is variable */ |
| 195 | |
| 196 | /* Word 4, 5 - is zero */ |
| 197 | |
| 198 | /* Word 6 - ctxt_tag, xri_tag is variable */ |
| 199 | |
| 200 | /* Word 7 */ |
| 201 | bf_set(wqe_cmnd, &wqe->fcp_icmd.wqe_com, CMD_FCP_ICMND64_WQE); |
| 202 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
| 203 | bf_set(wqe_class, &wqe->fcp_icmd.wqe_com, CLASS3); |
| 204 | bf_set(wqe_ct, &wqe->fcp_icmd.wqe_com, SLI4_CT_RPI); |
| 205 | |
| 206 | /* Word 8 - abort_tag is variable */ |
| 207 | |
| 208 | /* Word 9 - reqtag is variable */ |
| 209 | |
| 210 | /* Word 10 - dbde, wqes is variable */ |
| 211 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); |
| 212 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_NONE); |
| 213 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 214 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 0); |
| 215 | bf_set(wqe_wqes, &wqe->fcp_icmd.wqe_com, 1); |
| 216 | |
| 217 | /* Word 11 */ |
| 218 | bf_set(wqe_cmd_type, &wqe->fcp_icmd.wqe_com, COMMAND_DATA_IN); |
| 219 | bf_set(wqe_cqid, &wqe->fcp_icmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); |
| 220 | bf_set(wqe_pbde, &wqe->fcp_icmd.wqe_com, 0); |
| 221 | |
| 222 | /* Word 12, 13, 14, 15 - is zero */ |
| 223 | } |
| 224 | |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 225 | #if defined(CONFIG_64BIT) && defined(__LITTLE_ENDIAN) |
| 226 | /** |
| 227 | * lpfc_sli4_pcimem_bcopy - SLI4 memory copy function |
| 228 | * @srcp: Source memory pointer. |
| 229 | * @destp: Destination memory pointer. |
| 230 | * @cnt: Number of words required to be copied. |
| 231 | * Must be a multiple of sizeof(uint64_t) |
| 232 | * |
| 233 | * This function is used for copying data between driver memory |
| 234 | * and the SLI WQ. This function also changes the endianness |
| 235 | * of each word if native endianness is different from SLI |
| 236 | * endianness. This function can be called with or without |
| 237 | * lock. |
| 238 | **/ |
YueHaibing | d7b761b | 2019-05-31 23:28:41 +0800 | [diff] [blame] | 239 | static void |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 240 | lpfc_sli4_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 241 | { |
| 242 | uint64_t *src = srcp; |
| 243 | uint64_t *dest = destp; |
| 244 | int i; |
| 245 | |
| 246 | for (i = 0; i < (int)cnt; i += sizeof(uint64_t)) |
| 247 | *dest++ = *src++; |
| 248 | } |
| 249 | #else |
| 250 | #define lpfc_sli4_pcimem_bcopy(a, b, c) lpfc_sli_pcimem_bcopy(a, b, c) |
| 251 | #endif |
| 252 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 253 | /** |
| 254 | * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue |
| 255 | * @q: The Work Queue to operate on. |
| 256 | * @wqe: The work Queue Entry to put on the Work queue. |
| 257 | * |
| 258 | * This routine will copy the contents of @wqe to the next available entry on |
| 259 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 260 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 261 | * successful. If no entries are available on @q then this function will return |
| 262 | * -ENOMEM. |
| 263 | * The caller is expected to hold the hbalock when calling this routine. |
| 264 | **/ |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 265 | static int |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 266 | lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe128 *wqe) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 267 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 268 | union lpfc_wqe *temp_wqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 269 | struct lpfc_register doorbell; |
| 270 | uint32_t host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 271 | uint32_t idx; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 272 | uint32_t i = 0; |
| 273 | uint8_t *tmp; |
James Smart | 5cc167d | 2018-06-26 08:24:23 -0700 | [diff] [blame] | 274 | u32 if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 275 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 276 | /* sanity check on queue memory */ |
| 277 | if (unlikely(!q)) |
| 278 | return -ENOMEM; |
James Smart | 47ff4c5 | 2020-11-15 11:26:41 -0800 | [diff] [blame] | 279 | |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 280 | temp_wqe = lpfc_sli4_qe(q, q->host_index); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 281 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 282 | /* 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] | 283 | idx = ((q->host_index + 1) % q->entry_count); |
| 284 | if (idx == q->hba_index) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 285 | q->WQ_overflow++; |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 286 | return -EBUSY; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 287 | } |
| 288 | q->WQ_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 289 | /* set consumption flag every once in a while */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 290 | if (!((q->host_index + 1) % q->notify_interval)) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 291 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
James Smart | 04673e3 | 2018-01-30 15:58:45 -0800 | [diff] [blame] | 292 | else |
| 293 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 0); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 294 | if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED) |
| 295 | bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id); |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 296 | lpfc_sli4_pcimem_bcopy(wqe, temp_wqe, q->entry_size); |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 297 | if (q->dpp_enable && q->phba->cfg_enable_dpp) { |
| 298 | /* write to DPP aperture taking advatage of Combined Writes */ |
James Smart | 4c06619 | 2018-03-05 10:29:03 -0800 | [diff] [blame] | 299 | tmp = (uint8_t *)temp_wqe; |
| 300 | #ifdef __raw_writeq |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 301 | for (i = 0; i < q->entry_size; i += sizeof(uint64_t)) |
James Smart | 4c06619 | 2018-03-05 10:29:03 -0800 | [diff] [blame] | 302 | __raw_writeq(*((uint64_t *)(tmp + i)), |
| 303 | q->dpp_regaddr + i); |
| 304 | #else |
| 305 | for (i = 0; i < q->entry_size; i += sizeof(uint32_t)) |
| 306 | __raw_writel(*((uint32_t *)(tmp + i)), |
| 307 | q->dpp_regaddr + i); |
| 308 | #endif |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 309 | } |
| 310 | /* ensure WQE bcopy and DPP flushed before doorbell write */ |
James Smart | 6b3b3bd | 2016-12-19 15:07:30 -0800 | [diff] [blame] | 311 | wmb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 312 | |
| 313 | /* Update the host index before invoking device */ |
| 314 | host_index = q->host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 315 | |
| 316 | q->host_index = idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 317 | |
| 318 | /* Ring Doorbell */ |
| 319 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 320 | if (q->db_format == LPFC_DB_LIST_FORMAT) { |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 321 | if (q->dpp_enable && q->phba->cfg_enable_dpp) { |
| 322 | bf_set(lpfc_if6_wq_db_list_fm_num_posted, &doorbell, 1); |
| 323 | bf_set(lpfc_if6_wq_db_list_fm_dpp, &doorbell, 1); |
| 324 | bf_set(lpfc_if6_wq_db_list_fm_dpp_id, &doorbell, |
| 325 | q->dpp_id); |
| 326 | bf_set(lpfc_if6_wq_db_list_fm_id, &doorbell, |
| 327 | q->queue_id); |
| 328 | } else { |
| 329 | bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1); |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 330 | bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id); |
James Smart | 5cc167d | 2018-06-26 08:24:23 -0700 | [diff] [blame] | 331 | |
| 332 | /* Leave bits <23:16> clear for if_type 6 dpp */ |
| 333 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 334 | &q->phba->sli4_hba.sli_intf); |
| 335 | if (if_type != LPFC_SLI_INTF_IF_TYPE_6) |
| 336 | bf_set(lpfc_wq_db_list_fm_index, &doorbell, |
| 337 | host_index); |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 338 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 339 | } else if (q->db_format == LPFC_DB_RING_FORMAT) { |
| 340 | bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1); |
| 341 | bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id); |
| 342 | } else { |
| 343 | return -EINVAL; |
| 344 | } |
| 345 | writel(doorbell.word0, q->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 346 | |
| 347 | return 0; |
| 348 | } |
| 349 | |
| 350 | /** |
| 351 | * lpfc_sli4_wq_release - Updates internal hba index for WQ |
| 352 | * @q: The Work Queue to operate on. |
| 353 | * @index: The index to advance the hba index to. |
| 354 | * |
| 355 | * This routine will update the HBA index of a queue to reflect consumption of |
| 356 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed |
| 357 | * 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] | 358 | * pointers. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 359 | **/ |
James Smart | 1543af3 | 2020-03-22 11:12:58 -0700 | [diff] [blame] | 360 | static void |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 361 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) |
| 362 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 363 | /* sanity check on queue memory */ |
| 364 | if (unlikely(!q)) |
James Smart | 1543af3 | 2020-03-22 11:12:58 -0700 | [diff] [blame] | 365 | return; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 366 | |
James Smart | 1543af3 | 2020-03-22 11:12:58 -0700 | [diff] [blame] | 367 | q->hba_index = index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | /** |
| 371 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue |
| 372 | * @q: The Mailbox Queue to operate on. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 373 | * @mqe: The Mailbox Queue Entry to put on the Work queue. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 374 | * |
| 375 | * This routine will copy the contents of @mqe to the next available entry on |
| 376 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 377 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 378 | * successful. If no entries are available on @q then this function will return |
| 379 | * -ENOMEM. |
| 380 | * The caller is expected to hold the hbalock when calling this routine. |
| 381 | **/ |
| 382 | static uint32_t |
| 383 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) |
| 384 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 385 | struct lpfc_mqe *temp_mqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 386 | struct lpfc_register doorbell; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 387 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 388 | /* sanity check on queue memory */ |
| 389 | if (unlikely(!q)) |
| 390 | return -ENOMEM; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 391 | temp_mqe = lpfc_sli4_qe(q, q->host_index); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 392 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 393 | /* If the host has not yet processed the next entry then we are done */ |
| 394 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) |
| 395 | return -ENOMEM; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 396 | lpfc_sli4_pcimem_bcopy(mqe, temp_mqe, q->entry_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 397 | /* Save off the mailbox pointer for completion */ |
| 398 | q->phba->mbox = (MAILBOX_t *)temp_mqe; |
| 399 | |
| 400 | /* Update the host index before invoking device */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 401 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 402 | |
| 403 | /* Ring Doorbell */ |
| 404 | doorbell.word0 = 0; |
| 405 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); |
| 406 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); |
| 407 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 408 | return 0; |
| 409 | } |
| 410 | |
| 411 | /** |
| 412 | * lpfc_sli4_mq_release - Updates internal hba index for MQ |
| 413 | * @q: The Mailbox Queue to operate on. |
| 414 | * |
| 415 | * This routine will update the HBA index of a queue to reflect consumption of |
| 416 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed |
| 417 | * an entry the host calls this function to update the queue's internal |
| 418 | * pointers. This routine returns the number of entries that were consumed by |
| 419 | * the HBA. |
| 420 | **/ |
| 421 | static uint32_t |
| 422 | lpfc_sli4_mq_release(struct lpfc_queue *q) |
| 423 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 424 | /* sanity check on queue memory */ |
| 425 | if (unlikely(!q)) |
| 426 | return 0; |
| 427 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 428 | /* Clear the mailbox pointer for completion */ |
| 429 | q->phba->mbox = NULL; |
| 430 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 431 | return 1; |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ |
| 436 | * @q: The Event Queue to get the first valid EQE from |
| 437 | * |
| 438 | * This routine will get the first valid Event Queue Entry from @q, update |
| 439 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in |
| 440 | * the Queue (no more work to do), or the Queue is full of EQEs that have been |
| 441 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 442 | **/ |
| 443 | static struct lpfc_eqe * |
| 444 | lpfc_sli4_eq_get(struct lpfc_queue *q) |
| 445 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 446 | struct lpfc_eqe *eqe; |
| 447 | |
| 448 | /* sanity check on queue memory */ |
| 449 | if (unlikely(!q)) |
| 450 | return NULL; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 451 | eqe = lpfc_sli4_qe(q, q->host_index); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 452 | |
| 453 | /* If the next EQE is not valid then we are done */ |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 454 | if (bf_get_le32(lpfc_eqe_valid, eqe) != q->qe_valid) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 455 | return NULL; |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 456 | |
| 457 | /* |
| 458 | * insert barrier for instruction interlock : data from the hardware |
| 459 | * 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] | 460 | * upon. Speculative instructions were allowing a bcopy at the start |
| 461 | * of lpfc_sli4_fp_handle_wcqe(), which is called immediately |
| 462 | * after our return, to copy data before the valid bit check above |
| 463 | * was done. As such, some of the copied data was stale. The barrier |
| 464 | * ensures the check is before any data is copied. |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 465 | */ |
| 466 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 467 | return eqe; |
| 468 | } |
| 469 | |
| 470 | /** |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 471 | * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ |
| 472 | * @q: The Event Queue to disable interrupts |
| 473 | * |
| 474 | **/ |
James Smart | 92f3b32 | 2019-03-20 10:44:22 -0700 | [diff] [blame] | 475 | void |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 476 | lpfc_sli4_eq_clr_intr(struct lpfc_queue *q) |
| 477 | { |
| 478 | struct lpfc_register doorbell; |
| 479 | |
| 480 | doorbell.word0 = 0; |
| 481 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 482 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
| 483 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 484 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 485 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 486 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | /** |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 490 | * lpfc_sli4_if6_eq_clr_intr - Turn off interrupts from this EQ |
| 491 | * @q: The Event Queue to disable interrupts |
| 492 | * |
| 493 | **/ |
James Smart | 92f3b32 | 2019-03-20 10:44:22 -0700 | [diff] [blame] | 494 | void |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 495 | lpfc_sli4_if6_eq_clr_intr(struct lpfc_queue *q) |
| 496 | { |
| 497 | struct lpfc_register doorbell; |
| 498 | |
| 499 | doorbell.word0 = 0; |
James Smart | aad59d5 | 2018-09-10 10:30:47 -0700 | [diff] [blame] | 500 | bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 501 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
| 502 | } |
| 503 | |
| 504 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 505 | * lpfc_sli4_write_eq_db - write EQ DB for eqe's consumed or arm state |
| 506 | * @phba: adapter with EQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 507 | * @q: The Event Queue that the host has completed processing for. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 508 | * @count: Number of elements that have been consumed |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 509 | * @arm: Indicates whether the host wants to arms this CQ. |
| 510 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 511 | * This routine will notify the HBA, by ringing the doorbell, that count |
| 512 | * number of EQEs have been processed. The @arm parameter indicates whether |
| 513 | * the queue should be rearmed when ringing the doorbell. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 514 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 515 | void |
| 516 | lpfc_sli4_write_eq_db(struct lpfc_hba *phba, struct lpfc_queue *q, |
| 517 | uint32_t count, bool arm) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 518 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 519 | struct lpfc_register doorbell; |
| 520 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 521 | /* sanity check on queue memory */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 522 | if (unlikely(!q || (count == 0 && !arm))) |
| 523 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 524 | |
| 525 | /* ring doorbell for number popped */ |
| 526 | doorbell.word0 = 0; |
| 527 | if (arm) { |
| 528 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 529 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 530 | } |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 531 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 532 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 533 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 534 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 535 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 536 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 537 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 538 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 539 | readl(q->phba->sli4_hba.EQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 543 | * lpfc_sli4_if6_write_eq_db - write EQ DB for eqe's consumed or arm state |
| 544 | * @phba: adapter with EQ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 545 | * @q: The Event Queue that the host has completed processing for. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 546 | * @count: Number of elements that have been consumed |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 547 | * @arm: Indicates whether the host wants to arms this CQ. |
| 548 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 549 | * This routine will notify the HBA, by ringing the doorbell, that count |
| 550 | * number of EQEs have been processed. The @arm parameter indicates whether |
| 551 | * the queue should be rearmed when ringing the doorbell. |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 552 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 553 | void |
| 554 | lpfc_sli4_if6_write_eq_db(struct lpfc_hba *phba, struct lpfc_queue *q, |
| 555 | uint32_t count, bool arm) |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 556 | { |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 557 | struct lpfc_register doorbell; |
| 558 | |
| 559 | /* sanity check on queue memory */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 560 | if (unlikely(!q || (count == 0 && !arm))) |
| 561 | return; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 562 | |
| 563 | /* ring doorbell for number popped */ |
| 564 | doorbell.word0 = 0; |
| 565 | if (arm) |
| 566 | bf_set(lpfc_if6_eq_doorbell_arm, &doorbell, 1); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 567 | bf_set(lpfc_if6_eq_doorbell_num_released, &doorbell, count); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 568 | bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id); |
| 569 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
| 570 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 571 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
| 572 | readl(q->phba->sli4_hba.EQDBregaddr); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | static void |
| 576 | __lpfc_sli4_consume_eqe(struct lpfc_hba *phba, struct lpfc_queue *eq, |
| 577 | struct lpfc_eqe *eqe) |
| 578 | { |
| 579 | if (!phba->sli4_hba.pc_sli4_params.eqav) |
| 580 | bf_set_le32(lpfc_eqe_valid, eqe, 0); |
| 581 | |
| 582 | eq->host_index = ((eq->host_index + 1) % eq->entry_count); |
| 583 | |
| 584 | /* if the index wrapped around, toggle the valid bit */ |
| 585 | if (phba->sli4_hba.pc_sli4_params.eqav && !eq->host_index) |
| 586 | eq->qe_valid = (eq->qe_valid) ? 0 : 1; |
| 587 | } |
| 588 | |
| 589 | static void |
James Smart | 24c7c0a | 2019-09-21 20:58:58 -0700 | [diff] [blame] | 590 | lpfc_sli4_eqcq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 591 | { |
James Smart | 24c7c0a | 2019-09-21 20:58:58 -0700 | [diff] [blame] | 592 | struct lpfc_eqe *eqe = NULL; |
| 593 | u32 eq_count = 0, cq_count = 0; |
| 594 | struct lpfc_cqe *cqe = NULL; |
| 595 | struct lpfc_queue *cq = NULL, *childq = NULL; |
| 596 | int cqid = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 597 | |
| 598 | /* walk all the EQ entries and drop on the floor */ |
| 599 | eqe = lpfc_sli4_eq_get(eq); |
| 600 | while (eqe) { |
James Smart | 24c7c0a | 2019-09-21 20:58:58 -0700 | [diff] [blame] | 601 | /* Get the reference to the corresponding CQ */ |
| 602 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 603 | cq = NULL; |
| 604 | |
| 605 | list_for_each_entry(childq, &eq->child_list, list) { |
| 606 | if (childq->queue_id == cqid) { |
| 607 | cq = childq; |
| 608 | break; |
| 609 | } |
| 610 | } |
| 611 | /* If CQ is valid, iterate through it and drop all the CQEs */ |
| 612 | if (cq) { |
| 613 | cqe = lpfc_sli4_cq_get(cq); |
| 614 | while (cqe) { |
| 615 | __lpfc_sli4_consume_cqe(phba, cq, cqe); |
| 616 | cq_count++; |
| 617 | cqe = lpfc_sli4_cq_get(cq); |
| 618 | } |
| 619 | /* Clear and re-arm the CQ */ |
| 620 | phba->sli4_hba.sli4_write_cq_db(phba, cq, cq_count, |
| 621 | LPFC_QUEUE_REARM); |
| 622 | cq_count = 0; |
| 623 | } |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 624 | __lpfc_sli4_consume_eqe(phba, eq, eqe); |
James Smart | 24c7c0a | 2019-09-21 20:58:58 -0700 | [diff] [blame] | 625 | eq_count++; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 626 | eqe = lpfc_sli4_eq_get(eq); |
| 627 | } |
| 628 | |
| 629 | /* Clear and re-arm the EQ */ |
James Smart | 24c7c0a | 2019-09-21 20:58:58 -0700 | [diff] [blame] | 630 | 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] | 631 | } |
| 632 | |
| 633 | static int |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 634 | lpfc_sli4_process_eq(struct lpfc_hba *phba, struct lpfc_queue *eq, |
| 635 | uint8_t rearm) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 636 | { |
| 637 | struct lpfc_eqe *eqe; |
| 638 | int count = 0, consumed = 0; |
| 639 | |
| 640 | if (cmpxchg(&eq->queue_claimed, 0, 1) != 0) |
| 641 | goto rearm_and_exit; |
| 642 | |
| 643 | eqe = lpfc_sli4_eq_get(eq); |
| 644 | while (eqe) { |
| 645 | lpfc_sli4_hba_handle_eqe(phba, eq, eqe); |
| 646 | __lpfc_sli4_consume_eqe(phba, eq, eqe); |
| 647 | |
| 648 | consumed++; |
| 649 | if (!(++count % eq->max_proc_limit)) |
| 650 | break; |
| 651 | |
| 652 | if (!(count % eq->notify_interval)) { |
| 653 | phba->sli4_hba.sli4_write_eq_db(phba, eq, consumed, |
| 654 | LPFC_QUEUE_NOARM); |
| 655 | consumed = 0; |
| 656 | } |
| 657 | |
| 658 | eqe = lpfc_sli4_eq_get(eq); |
| 659 | } |
| 660 | eq->EQ_processed += count; |
| 661 | |
| 662 | /* Track the max number of EQEs processed in 1 intr */ |
| 663 | if (count > eq->EQ_max_eqe) |
| 664 | eq->EQ_max_eqe = count; |
| 665 | |
Dick Kennedy | 164ba8d | 2020-05-01 14:43:03 -0700 | [diff] [blame] | 666 | xchg(&eq->queue_claimed, 0); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 667 | |
| 668 | rearm_and_exit: |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 669 | /* Always clear the EQ. */ |
| 670 | phba->sli4_hba.sli4_write_eq_db(phba, eq, consumed, rearm); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 671 | |
| 672 | return count; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 676 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ |
| 677 | * @q: The Completion Queue to get the first valid CQE from |
| 678 | * |
| 679 | * This routine will get the first valid Completion Queue Entry from @q, update |
| 680 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in |
| 681 | * the Queue (no more work to do), or the Queue is full of CQEs that have been |
| 682 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 683 | **/ |
| 684 | static struct lpfc_cqe * |
| 685 | lpfc_sli4_cq_get(struct lpfc_queue *q) |
| 686 | { |
| 687 | struct lpfc_cqe *cqe; |
| 688 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 689 | /* sanity check on queue memory */ |
| 690 | if (unlikely(!q)) |
| 691 | return NULL; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 692 | cqe = lpfc_sli4_qe(q, q->host_index); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 693 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 694 | /* If the next CQE is not valid then we are done */ |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 695 | if (bf_get_le32(lpfc_cqe_valid, cqe) != q->qe_valid) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 696 | return NULL; |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 697 | |
| 698 | /* |
| 699 | * insert barrier for instruction interlock : data from the hardware |
| 700 | * 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] | 701 | * upon. Given what was seen in lpfc_sli4_cq_get() of speculative |
| 702 | * instructions allowing action on content before valid bit checked, |
| 703 | * add barrier here as well. May not be needed as "content" is a |
| 704 | * single 32-bit entity here (vs multi word structure for cq's). |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 705 | */ |
| 706 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 707 | return cqe; |
| 708 | } |
| 709 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 710 | static void |
| 711 | __lpfc_sli4_consume_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 712 | struct lpfc_cqe *cqe) |
| 713 | { |
| 714 | if (!phba->sli4_hba.pc_sli4_params.cqav) |
| 715 | bf_set_le32(lpfc_cqe_valid, cqe, 0); |
| 716 | |
| 717 | cq->host_index = ((cq->host_index + 1) % cq->entry_count); |
| 718 | |
| 719 | /* if the index wrapped around, toggle the valid bit */ |
| 720 | if (phba->sli4_hba.pc_sli4_params.cqav && !cq->host_index) |
| 721 | cq->qe_valid = (cq->qe_valid) ? 0 : 1; |
| 722 | } |
| 723 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 724 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 725 | * lpfc_sli4_write_cq_db - write cq DB for entries consumed or arm state. |
| 726 | * @phba: the adapter with the CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 727 | * @q: The Completion Queue that the host has completed processing for. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 728 | * @count: the number of elements that were consumed |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 729 | * @arm: Indicates whether the host wants to arms this CQ. |
| 730 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 731 | * This routine will notify the HBA, by ringing the doorbell, that the |
| 732 | * CQEs have been processed. The @arm parameter specifies whether the |
| 733 | * queue should be rearmed when ringing the doorbell. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 734 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 735 | void |
| 736 | lpfc_sli4_write_cq_db(struct lpfc_hba *phba, struct lpfc_queue *q, |
| 737 | uint32_t count, bool arm) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 738 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 739 | struct lpfc_register doorbell; |
| 740 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 741 | /* sanity check on queue memory */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 742 | if (unlikely(!q || (count == 0 && !arm))) |
| 743 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 744 | |
| 745 | /* ring doorbell for number popped */ |
| 746 | doorbell.word0 = 0; |
| 747 | if (arm) |
| 748 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 749 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 750 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 751 | bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell, |
| 752 | (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT)); |
| 753 | bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 754 | writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 758 | * lpfc_sli4_if6_write_cq_db - write cq DB for entries consumed or arm state. |
| 759 | * @phba: the adapter with the CQ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 760 | * @q: The Completion Queue that the host has completed processing for. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 761 | * @count: the number of elements that were consumed |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 762 | * @arm: Indicates whether the host wants to arms this CQ. |
| 763 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 764 | * This routine will notify the HBA, by ringing the doorbell, that the |
| 765 | * CQEs have been processed. The @arm parameter specifies whether the |
| 766 | * queue should be rearmed when ringing the doorbell. |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 767 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 768 | void |
| 769 | lpfc_sli4_if6_write_cq_db(struct lpfc_hba *phba, struct lpfc_queue *q, |
| 770 | uint32_t count, bool arm) |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 771 | { |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 772 | struct lpfc_register doorbell; |
| 773 | |
| 774 | /* sanity check on queue memory */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 775 | if (unlikely(!q || (count == 0 && !arm))) |
| 776 | return; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 777 | |
| 778 | /* ring doorbell for number popped */ |
| 779 | doorbell.word0 = 0; |
| 780 | if (arm) |
| 781 | bf_set(lpfc_if6_cq_doorbell_arm, &doorbell, 1); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 782 | bf_set(lpfc_if6_cq_doorbell_num_released, &doorbell, count); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 783 | bf_set(lpfc_if6_cq_doorbell_cqid, &doorbell, q->queue_id); |
| 784 | writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 785 | } |
| 786 | |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 787 | /* |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 788 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 789 | * |
| 790 | * This routine will copy the contents of @wqe to the next available entry on |
| 791 | * the @q. This function will then ring the Receive Queue Doorbell to signal the |
| 792 | * HBA to start processing the Receive Queue Entry. This function returns the |
| 793 | * index that the rqe was copied to if successful. If no entries are available |
| 794 | * on @q then this function will return -ENOMEM. |
| 795 | * The caller is expected to hold the hbalock when calling this routine. |
| 796 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 797 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 798 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, |
| 799 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) |
| 800 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 801 | struct lpfc_rqe *temp_hrqe; |
| 802 | struct lpfc_rqe *temp_drqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 803 | struct lpfc_register doorbell; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 804 | int hq_put_index; |
| 805 | int dq_put_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 806 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 807 | /* sanity check on queue memory */ |
| 808 | if (unlikely(!hq) || unlikely(!dq)) |
| 809 | return -ENOMEM; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 810 | hq_put_index = hq->host_index; |
| 811 | dq_put_index = dq->host_index; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 812 | temp_hrqe = lpfc_sli4_qe(hq, hq_put_index); |
| 813 | temp_drqe = lpfc_sli4_qe(dq, dq_put_index); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 814 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 815 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) |
| 816 | return -EINVAL; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 817 | if (hq_put_index != dq_put_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 818 | return -EINVAL; |
| 819 | /* 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] | 820 | if (((hq_put_index + 1) % hq->entry_count) == hq->hba_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 821 | return -EBUSY; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 822 | lpfc_sli4_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); |
| 823 | lpfc_sli4_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 824 | |
| 825 | /* Update the host index to point to the next slot */ |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 826 | hq->host_index = ((hq_put_index + 1) % hq->entry_count); |
| 827 | dq->host_index = ((dq_put_index + 1) % dq->entry_count); |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 828 | hq->RQ_buf_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 829 | |
| 830 | /* Ring The Header Receive Queue Doorbell */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 831 | if (!(hq->host_index % hq->notify_interval)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 832 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 833 | if (hq->db_format == LPFC_DB_RING_FORMAT) { |
| 834 | bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell, |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 835 | hq->notify_interval); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 836 | bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id); |
| 837 | } else if (hq->db_format == LPFC_DB_LIST_FORMAT) { |
| 838 | bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell, |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 839 | hq->notify_interval); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 840 | bf_set(lpfc_rq_db_list_fm_index, &doorbell, |
| 841 | hq->host_index); |
| 842 | bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id); |
| 843 | } else { |
| 844 | return -EINVAL; |
| 845 | } |
| 846 | writel(doorbell.word0, hq->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 847 | } |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 848 | return hq_put_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 849 | } |
| 850 | |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 851 | /* |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 852 | * lpfc_sli4_rq_release - Updates internal hba index for RQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 853 | * |
| 854 | * This routine will update the HBA index of a queue to reflect consumption of |
| 855 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has |
| 856 | * consumed an entry the host calls this function to update the queue's |
| 857 | * internal pointers. This routine returns the number of entries that were |
| 858 | * consumed by the HBA. |
| 859 | **/ |
| 860 | static uint32_t |
| 861 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) |
| 862 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 863 | /* sanity check on queue memory */ |
| 864 | if (unlikely(!hq) || unlikely(!dq)) |
| 865 | return 0; |
| 866 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 867 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) |
| 868 | return 0; |
| 869 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); |
| 870 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); |
| 871 | return 1; |
| 872 | } |
| 873 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 874 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 875 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 876 | * @phba: Pointer to HBA context object. |
| 877 | * @pring: Pointer to driver SLI ring object. |
| 878 | * |
| 879 | * This function returns pointer to next command iocb entry |
| 880 | * in the command ring. The caller must hold hbalock to prevent |
| 881 | * other threads consume the next command iocb. |
| 882 | * SLI-2/SLI-3 provide different sized iocbs. |
| 883 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 884 | static inline IOCB_t * |
| 885 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 886 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 887 | return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) + |
| 888 | pring->sli.sli3.cmdidx * phba->iocb_cmd_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 889 | } |
| 890 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 891 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 892 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 893 | * @phba: Pointer to HBA context object. |
| 894 | * @pring: Pointer to driver SLI ring object. |
| 895 | * |
| 896 | * This function returns pointer to next response iocb entry |
| 897 | * in the response ring. The caller must hold hbalock to make sure |
| 898 | * that no other thread consume the next response iocb. |
| 899 | * SLI-2/SLI-3 provide different sized iocbs. |
| 900 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 901 | static inline IOCB_t * |
| 902 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 903 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 904 | return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) + |
| 905 | pring->sli.sli3.rspidx * phba->iocb_rsp_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 906 | } |
| 907 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 908 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 909 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 910 | * @phba: Pointer to HBA context object. |
| 911 | * |
| 912 | * This function is called with hbalock held. This function |
| 913 | * allocates a new driver iocb object from the iocb pool. If the |
| 914 | * allocation is successful, it returns pointer to the newly |
| 915 | * allocated iocb object else it returns NULL. |
| 916 | **/ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 917 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 918 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 919 | { |
| 920 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 921 | struct lpfc_iocbq * iocbq = NULL; |
| 922 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 923 | lockdep_assert_held(&phba->hbalock); |
| 924 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 925 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 926 | if (iocbq) |
| 927 | phba->iocb_cnt++; |
| 928 | if (phba->iocb_cnt > phba->iocb_max) |
| 929 | phba->iocb_max = phba->iocb_cnt; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 930 | return iocbq; |
| 931 | } |
| 932 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 933 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 934 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. |
| 935 | * @phba: Pointer to HBA context object. |
| 936 | * @xritag: XRI value. |
| 937 | * |
James Smart | 3bfab8a | 2021-04-11 18:31:23 -0700 | [diff] [blame] | 938 | * This function clears the sglq pointer from the array of active |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 939 | * sglq's. The xritag that is passed in is used to index into the |
| 940 | * array. Before the xritag can be used it needs to be adjusted |
| 941 | * by subtracting the xribase. |
| 942 | * |
| 943 | * Returns sglq ponter = success, NULL = Failure. |
| 944 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 945 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 946 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 947 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 948 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 949 | |
| 950 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
| 951 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 952 | return sglq; |
| 953 | } |
| 954 | |
| 955 | /** |
| 956 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. |
| 957 | * @phba: Pointer to HBA context object. |
| 958 | * @xritag: XRI value. |
| 959 | * |
James Smart | 3bfab8a | 2021-04-11 18:31:23 -0700 | [diff] [blame] | 960 | * This function returns the sglq pointer from the array of active |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 961 | * sglq's. The xritag that is passed in is used to index into the |
| 962 | * array. Before the xritag can be used it needs to be adjusted |
| 963 | * by subtracting the xribase. |
| 964 | * |
| 965 | * Returns sglq ponter = success, NULL = Failure. |
| 966 | **/ |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 967 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 968 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 969 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 970 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 971 | |
| 972 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 973 | return sglq; |
| 974 | } |
| 975 | |
| 976 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 977 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 978 | * @phba: Pointer to HBA context object. |
| 979 | * @xritag: xri used in this exchange. |
| 980 | * @rrq: The RRQ to be cleared. |
| 981 | * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 982 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 983 | void |
| 984 | lpfc_clr_rrq_active(struct lpfc_hba *phba, |
| 985 | uint16_t xritag, |
| 986 | struct lpfc_node_rrq *rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 987 | { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 988 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 989 | |
James Smart | 2693f5d | 2021-03-01 09:18:03 -0800 | [diff] [blame] | 990 | /* Lookup did to verify if did is still active on this vport */ |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 991 | if (rrq->vport) |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 992 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 993 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 994 | if (!ndlp) |
| 995 | goto out; |
| 996 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 997 | if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 998 | rrq->send_rrq = 0; |
| 999 | rrq->xritag = 0; |
| 1000 | rrq->rrq_stop_time = 0; |
| 1001 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1002 | out: |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1003 | mempool_free(rrq, phba->rrq_pool); |
| 1004 | } |
| 1005 | |
| 1006 | /** |
| 1007 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. |
| 1008 | * @phba: Pointer to HBA context object. |
| 1009 | * |
| 1010 | * This function is called with hbalock held. This function |
| 1011 | * Checks if stop_time (ratov from setting rrq active) has |
| 1012 | * been reached, if it has and the send_rrq flag is set then |
| 1013 | * it will call lpfc_send_rrq. If the send_rrq flag is not set |
| 1014 | * then it will just call the routine to clear the rrq and |
| 1015 | * free the rrq resource. |
| 1016 | * The timer is set to the next rrq that is going to expire before |
| 1017 | * leaving the routine. |
| 1018 | * |
| 1019 | **/ |
| 1020 | void |
| 1021 | lpfc_handle_rrq_active(struct lpfc_hba *phba) |
| 1022 | { |
| 1023 | struct lpfc_node_rrq *rrq; |
| 1024 | struct lpfc_node_rrq *nextrrq; |
| 1025 | unsigned long next_time; |
| 1026 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1027 | LIST_HEAD(send_rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1028 | |
| 1029 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1030 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1031 | next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1032 | list_for_each_entry_safe(rrq, nextrrq, |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1033 | &phba->active_rrq_list, list) { |
| 1034 | if (time_after(jiffies, rrq->rrq_stop_time)) |
| 1035 | list_move(&rrq->list, &send_rrq); |
| 1036 | else if (time_before(rrq->rrq_stop_time, next_time)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1037 | next_time = rrq->rrq_stop_time; |
| 1038 | } |
| 1039 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 1040 | if ((!list_empty(&phba->active_rrq_list)) && |
| 1041 | (!(phba->pport->load_flag & FC_UNLOADING))) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1042 | mod_timer(&phba->rrq_tmr, next_time); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1043 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
| 1044 | list_del(&rrq->list); |
Bart Van Assche | ffd4381 | 2019-03-28 11:06:17 -0700 | [diff] [blame] | 1045 | if (!rrq->send_rrq) { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1046 | /* this call will free the rrq */ |
Bart Van Assche | ffd4381 | 2019-03-28 11:06:17 -0700 | [diff] [blame] | 1047 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 1048 | } else if (lpfc_send_rrq(phba, rrq)) { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1049 | /* if we send the rrq then the completion handler |
| 1050 | * will clear the bit in the xribitmap. |
| 1051 | */ |
| 1052 | lpfc_clr_rrq_active(phba, rrq->xritag, |
| 1053 | rrq); |
| 1054 | } |
| 1055 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | /** |
| 1059 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. |
| 1060 | * @vport: Pointer to vport context object. |
| 1061 | * @xri: The xri used in the exchange. |
| 1062 | * @did: The targets DID for this exchange. |
| 1063 | * |
| 1064 | * returns NULL = rrq not found in the phba->active_rrq_list. |
| 1065 | * rrq = rrq for this xri and target. |
| 1066 | **/ |
| 1067 | struct lpfc_node_rrq * |
| 1068 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) |
| 1069 | { |
| 1070 | struct lpfc_hba *phba = vport->phba; |
| 1071 | struct lpfc_node_rrq *rrq; |
| 1072 | struct lpfc_node_rrq *nextrrq; |
| 1073 | unsigned long iflags; |
| 1074 | |
| 1075 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 1076 | return NULL; |
| 1077 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1078 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { |
| 1079 | if (rrq->vport == vport && rrq->xritag == xri && |
| 1080 | rrq->nlp_DID == did){ |
| 1081 | list_del(&rrq->list); |
| 1082 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1083 | return rrq; |
| 1084 | } |
| 1085 | } |
| 1086 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1087 | return NULL; |
| 1088 | } |
| 1089 | |
| 1090 | /** |
| 1091 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. |
| 1092 | * @vport: Pointer to vport context object. |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1093 | * @ndlp: Pointer to the lpfc_node_list structure. |
| 1094 | * If ndlp is NULL Remove all active RRQs for this vport from the |
| 1095 | * phba->active_rrq_list and clear the rrq. |
| 1096 | * 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] | 1097 | **/ |
| 1098 | void |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1099 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1100 | |
| 1101 | { |
| 1102 | struct lpfc_hba *phba = vport->phba; |
| 1103 | struct lpfc_node_rrq *rrq; |
| 1104 | struct lpfc_node_rrq *nextrrq; |
| 1105 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1106 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1107 | |
| 1108 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 1109 | return; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1110 | if (!ndlp) { |
| 1111 | lpfc_sli4_vport_delete_els_xri_aborted(vport); |
| 1112 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1113 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1114 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 2693f5d | 2021-03-01 09:18:03 -0800 | [diff] [blame] | 1115 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { |
| 1116 | if (rrq->vport != vport) |
| 1117 | continue; |
| 1118 | |
| 1119 | if (!ndlp || ndlp == lpfc_findnode_did(vport, rrq->nlp_DID)) |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1120 | list_move(&rrq->list, &rrq_list); |
James Smart | 2693f5d | 2021-03-01 09:18:03 -0800 | [diff] [blame] | 1121 | |
| 1122 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1123 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1124 | |
| 1125 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 1126 | list_del(&rrq->list); |
| 1127 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 1128 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1132 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1133 | * @phba: Pointer to HBA context object. |
| 1134 | * @ndlp: Targets nodelist pointer for this exchange. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 1135 | * @xritag: the xri in the bitmap to test. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1136 | * |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1137 | * This function returns: |
| 1138 | * 0 = rrq not active for this xri |
| 1139 | * 1 = rrq is valid for this xri. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1140 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1141 | int |
| 1142 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1143 | uint16_t xritag) |
| 1144 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1145 | if (!ndlp) |
| 1146 | return 0; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1147 | if (!ndlp->active_rrqs_xri_bitmap) |
| 1148 | return 0; |
| 1149 | if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
Colin Ian King | 258f84f | 2019-02-12 15:29:45 +0000 | [diff] [blame] | 1150 | return 1; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1151 | else |
| 1152 | return 0; |
| 1153 | } |
| 1154 | |
| 1155 | /** |
| 1156 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. |
| 1157 | * @phba: Pointer to HBA context object. |
| 1158 | * @ndlp: nodelist pointer for this target. |
| 1159 | * @xritag: xri used in this exchange. |
| 1160 | * @rxid: Remote Exchange ID. |
| 1161 | * @send_rrq: Flag used to determine if we should send rrq els cmd. |
| 1162 | * |
| 1163 | * This function takes the hbalock. |
| 1164 | * The active bit is always set in the active rrq xri_bitmap even |
| 1165 | * if there is no slot avaiable for the other rrq information. |
| 1166 | * |
| 1167 | * returns 0 rrq actived for this xri |
| 1168 | * < 0 No memory or invalid ndlp. |
| 1169 | **/ |
| 1170 | int |
| 1171 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1172 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1173 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1174 | unsigned long iflags; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1175 | struct lpfc_node_rrq *rrq; |
| 1176 | int empty; |
| 1177 | |
| 1178 | if (!ndlp) |
| 1179 | return -EINVAL; |
| 1180 | |
| 1181 | if (!phba->cfg_enable_rrq) |
| 1182 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1183 | |
| 1184 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1185 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 1186 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 1187 | goto out; |
| 1188 | } |
| 1189 | |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1190 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) |
| 1191 | goto out; |
| 1192 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1193 | if (!ndlp->active_rrqs_xri_bitmap) |
| 1194 | goto out; |
| 1195 | |
| 1196 | if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1197 | goto out; |
| 1198 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1199 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
Dick Kennedy | 9dace1f | 2020-06-30 14:49:53 -0700 | [diff] [blame] | 1200 | rrq = mempool_alloc(phba->rrq_pool, GFP_ATOMIC); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1201 | if (!rrq) { |
| 1202 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 1203 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" |
| 1204 | " DID:0x%x Send:%d\n", |
| 1205 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 1206 | return -EINVAL; |
| 1207 | } |
James Smart | e5771b4 | 2013-03-01 16:37:14 -0500 | [diff] [blame] | 1208 | if (phba->cfg_enable_rrq == 1) |
| 1209 | rrq->send_rrq = send_rrq; |
| 1210 | else |
| 1211 | rrq->send_rrq = 0; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1212 | rrq->xritag = xritag; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1213 | rrq->rrq_stop_time = jiffies + |
| 1214 | msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1215 | rrq->nlp_DID = ndlp->nlp_DID; |
| 1216 | rrq->vport = ndlp->vport; |
| 1217 | rrq->rxid = rxid; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1218 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1219 | empty = list_empty(&phba->active_rrq_list); |
| 1220 | list_add_tail(&rrq->list, &phba->active_rrq_list); |
| 1221 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 1222 | if (empty) |
| 1223 | lpfc_worker_wake_up(phba); |
| 1224 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1225 | return 0; |
| 1226 | out: |
| 1227 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1228 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 1229 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" |
| 1230 | " DID:0x%x Send:%d\n", |
| 1231 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 1232 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1236 | * __lpfc_sli_get_els_sglq - Allocates an iocb object from sgl pool |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1237 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 1238 | * @piocbq: Pointer to the iocbq. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1239 | * |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1240 | * The driver calls this function with either the nvme ls ring lock |
| 1241 | * or the fc els ring lock held depending on the iocb usage. This function |
| 1242 | * gets a new driver sglq object from the sglq list. If the list is not empty |
| 1243 | * then it is successful, it returns pointer to the newly allocated sglq |
| 1244 | * object else it returns NULL. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1245 | **/ |
| 1246 | static struct lpfc_sglq * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1247 | __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] | 1248 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1249 | 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] | 1250 | struct lpfc_sglq *sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1251 | struct lpfc_sglq *start_sglq = NULL; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1252 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1253 | struct lpfc_nodelist *ndlp; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1254 | struct lpfc_sli_ring *pring = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1255 | int found = 0; |
| 1256 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1257 | if (piocbq->iocb_flag & LPFC_IO_NVME_LS) |
| 1258 | pring = phba->sli4_hba.nvmels_wq->pring; |
| 1259 | else |
| 1260 | pring = lpfc_phba_elsring(phba); |
| 1261 | |
| 1262 | lockdep_assert_held(&pring->ring_lock); |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1263 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1264 | if (piocbq->iocb_flag & LPFC_IO_FCP) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1265 | lpfc_cmd = (struct lpfc_io_buf *) piocbq->context1; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1266 | ndlp = lpfc_cmd->rdata->pnode; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 1267 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1268 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1269 | ndlp = piocbq->context_un.ndlp; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1270 | } else if (piocbq->iocb_flag & LPFC_IO_LIBDFC) { |
| 1271 | if (piocbq->iocb_flag & LPFC_IO_LOOPBACK) |
| 1272 | ndlp = NULL; |
| 1273 | else |
| 1274 | ndlp = piocbq->context_un.ndlp; |
| 1275 | } else { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1276 | ndlp = piocbq->context1; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1277 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1278 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1279 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 1280 | list_remove_head(lpfc_els_sgl_list, sglq, struct lpfc_sglq, list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1281 | start_sglq = sglq; |
| 1282 | while (!found) { |
| 1283 | if (!sglq) |
James Smart | d11f54b | 2017-03-04 09:30:24 -0800 | [diff] [blame] | 1284 | break; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1285 | if (ndlp && ndlp->active_rrqs_xri_bitmap && |
| 1286 | test_bit(sglq->sli4_lxritag, |
| 1287 | ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1288 | /* This xri has an rrq outstanding for this DID. |
| 1289 | * put it back in the list and get another xri. |
| 1290 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1291 | list_add_tail(&sglq->list, lpfc_els_sgl_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1292 | sglq = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1293 | list_remove_head(lpfc_els_sgl_list, sglq, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1294 | struct lpfc_sglq, list); |
| 1295 | if (sglq == start_sglq) { |
James Smart | 14041bd | 2017-06-01 21:07:01 -0700 | [diff] [blame] | 1296 | list_add_tail(&sglq->list, lpfc_els_sgl_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1297 | sglq = NULL; |
| 1298 | break; |
| 1299 | } else |
| 1300 | continue; |
| 1301 | } |
| 1302 | sglq->ndlp = ndlp; |
| 1303 | found = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1304 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1305 | sglq->state = SGL_ALLOCATED; |
| 1306 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1307 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1308 | return sglq; |
| 1309 | } |
| 1310 | |
| 1311 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1312 | * __lpfc_sli_get_nvmet_sglq - Allocates an iocb object from sgl pool |
| 1313 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 1314 | * @piocbq: Pointer to the iocbq. |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1315 | * |
| 1316 | * This function is called with the sgl_list lock held. This function |
| 1317 | * gets a new driver sglq object from the sglq list. If the |
| 1318 | * list is not empty then it is successful, it returns pointer to the newly |
| 1319 | * allocated sglq object else it returns NULL. |
| 1320 | **/ |
| 1321 | struct lpfc_sglq * |
| 1322 | __lpfc_sli_get_nvmet_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
| 1323 | { |
| 1324 | struct list_head *lpfc_nvmet_sgl_list; |
| 1325 | struct lpfc_sglq *sglq = NULL; |
| 1326 | |
| 1327 | lpfc_nvmet_sgl_list = &phba->sli4_hba.lpfc_nvmet_sgl_list; |
| 1328 | |
| 1329 | lockdep_assert_held(&phba->sli4_hba.sgl_list_lock); |
| 1330 | |
| 1331 | list_remove_head(lpfc_nvmet_sgl_list, sglq, struct lpfc_sglq, list); |
| 1332 | if (!sglq) |
| 1333 | return NULL; |
| 1334 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
| 1335 | sglq->state = SGL_ALLOCATED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1336 | return sglq; |
| 1337 | } |
| 1338 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1339 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1340 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1341 | * @phba: Pointer to HBA context object. |
| 1342 | * |
| 1343 | * This function is called with no lock held. This function |
| 1344 | * allocates a new driver iocb object from the iocb pool. If the |
| 1345 | * allocation is successful, it returns pointer to the newly |
| 1346 | * allocated iocb object else it returns NULL. |
| 1347 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1348 | struct lpfc_iocbq * |
| 1349 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1350 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1351 | struct lpfc_iocbq * iocbq = NULL; |
| 1352 | unsigned long iflags; |
| 1353 | |
| 1354 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1355 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 1356 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1357 | return iocbq; |
| 1358 | } |
| 1359 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1360 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1361 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool |
| 1362 | * @phba: Pointer to HBA context object. |
| 1363 | * @iocbq: Pointer to driver iocb object. |
| 1364 | * |
Dick Kennedy | 88acb4d | 2020-05-01 14:43:07 -0700 | [diff] [blame] | 1365 | * This function is called to release the driver iocb object |
| 1366 | * to the iocb pool. The iotag in the iocb object |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1367 | * does not change for each use of the iocb object. This function |
| 1368 | * clears all other fields of the iocb object when it is freed. |
| 1369 | * The sqlq structure that holds the xritag and phys and virtual |
| 1370 | * mappings for the scatter gather list is retrieved from the |
| 1371 | * active array of sglq. The get of the sglq pointer also clears |
| 1372 | * the entry in the array. If the status of the IO indiactes that |
| 1373 | * this IO was aborted then the sglq entry it put on the |
| 1374 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the |
| 1375 | * 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] | 1376 | * entry is added to the free list (lpfc_els_sgl_list). The hbalock is |
| 1377 | * asserted held in the code path calling this routine. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1378 | **/ |
| 1379 | static void |
| 1380 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1381 | { |
| 1382 | struct lpfc_sglq *sglq; |
| 1383 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1384 | unsigned long iflag = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1385 | struct lpfc_sli_ring *pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1386 | |
| 1387 | if (iocbq->sli4_xritag == NO_XRI) |
| 1388 | sglq = NULL; |
| 1389 | else |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1390 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
| 1391 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1392 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1393 | if (sglq) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1394 | if (iocbq->iocb_flag & LPFC_IO_NVMET) { |
| 1395 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1396 | iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1397 | sglq->state = SGL_FREED; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1398 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1399 | list_add_tail(&sglq->list, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1400 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 1401 | spin_unlock_irqrestore( |
| 1402 | &phba->sli4_hba.sgl_list_lock, iflag); |
| 1403 | goto out; |
| 1404 | } |
| 1405 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1406 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
| 1407 | (sglq->state != SGL_XRI_ABORTED)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1408 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1409 | iflag); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 1410 | |
| 1411 | /* Check if we can get a reference on ndlp */ |
| 1412 | if (sglq->ndlp && !lpfc_nlp_get(sglq->ndlp)) |
| 1413 | sglq->ndlp = NULL; |
| 1414 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 1415 | list_add(&sglq->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1416 | &phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1417 | spin_unlock_irqrestore( |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1418 | &phba->sli4_hba.sgl_list_lock, iflag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1419 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1420 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1421 | iflag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1422 | sglq->state = SGL_FREED; |
| 1423 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1424 | list_add_tail(&sglq->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1425 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 1426 | spin_unlock_irqrestore( |
| 1427 | &phba->sli4_hba.sgl_list_lock, iflag); |
James Smart | 9628aac | 2021-03-01 09:18:16 -0800 | [diff] [blame] | 1428 | pring = lpfc_phba_elsring(phba); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1429 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 9628aac | 2021-03-01 09:18:16 -0800 | [diff] [blame] | 1430 | if (pring && (!list_empty(&pring->txq))) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1431 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1432 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1433 | } |
| 1434 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1435 | out: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1436 | /* |
| 1437 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1438 | */ |
| 1439 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1440 | iocbq->sli4_lxritag = NO_XRI; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1441 | iocbq->sli4_xritag = NO_XRI; |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 1442 | iocbq->iocb_flag &= ~(LPFC_IO_NVME | LPFC_IO_NVMET | LPFC_IO_CMF | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1443 | LPFC_IO_NVME_LS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1444 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1445 | } |
| 1446 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1447 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1448 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1449 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
| 1450 | * @phba: Pointer to HBA context object. |
| 1451 | * @iocbq: Pointer to driver iocb object. |
| 1452 | * |
Dick Kennedy | 88acb4d | 2020-05-01 14:43:07 -0700 | [diff] [blame] | 1453 | * This function is called to release the driver iocb object to the |
| 1454 | * iocb pool. The iotag in the iocb object does not change for each |
| 1455 | * use of the iocb object. This function clears all other fields of |
| 1456 | * the iocb object when it is freed. The hbalock is asserted held in |
| 1457 | * the code path calling this routine. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1458 | **/ |
| 1459 | static void |
| 1460 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1461 | { |
| 1462 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
| 1463 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1464 | /* |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1465 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1466 | */ |
| 1467 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 1468 | iocbq->sli4_xritag = NO_XRI; |
| 1469 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1470 | } |
| 1471 | |
| 1472 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1473 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1474 | * @phba: Pointer to HBA context object. |
| 1475 | * @iocbq: Pointer to driver iocb object. |
| 1476 | * |
| 1477 | * This function is called with hbalock held to release driver |
| 1478 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1479 | * does not change for each use of the iocb object. This function |
| 1480 | * clears all other fields of the iocb object when it is freed. |
| 1481 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1482 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1483 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1484 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1485 | lockdep_assert_held(&phba->hbalock); |
| 1486 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1487 | phba->__lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1488 | phba->iocb_cnt--; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1489 | } |
| 1490 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1491 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1492 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1493 | * @phba: Pointer to HBA context object. |
| 1494 | * @iocbq: Pointer to driver iocb object. |
| 1495 | * |
| 1496 | * This function is called with no lock held to release the iocb to |
| 1497 | * iocb pool. |
| 1498 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1499 | void |
| 1500 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1501 | { |
| 1502 | unsigned long iflags; |
| 1503 | |
| 1504 | /* |
| 1505 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1506 | */ |
| 1507 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1508 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 1509 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1510 | } |
| 1511 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1512 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1513 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. |
| 1514 | * @phba: Pointer to HBA context object. |
| 1515 | * @iocblist: List of IOCBs. |
| 1516 | * @ulpstatus: ULP status in IOCB command field. |
| 1517 | * @ulpWord4: ULP word-4 in IOCB command field. |
| 1518 | * |
| 1519 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB |
| 1520 | * on the list by invoking the complete callback function associated with the |
| 1521 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond |
| 1522 | * fields. |
| 1523 | **/ |
| 1524 | void |
| 1525 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, |
| 1526 | uint32_t ulpstatus, uint32_t ulpWord4) |
| 1527 | { |
| 1528 | struct lpfc_iocbq *piocb; |
| 1529 | |
| 1530 | while (!list_empty(iocblist)) { |
| 1531 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); |
James Smart | 9ec58ec | 2021-01-04 10:02:35 -0800 | [diff] [blame] | 1532 | if (piocb->wqe_cmpl) { |
James Smart | 84f2ddf | 2019-08-14 16:56:55 -0700 | [diff] [blame] | 1533 | if (piocb->iocb_flag & LPFC_IO_NVME) |
James Smart | 9ec58ec | 2021-01-04 10:02:35 -0800 | [diff] [blame] | 1534 | lpfc_nvme_cancel_iocb(phba, piocb, |
| 1535 | ulpstatus, ulpWord4); |
James Smart | 84f2ddf | 2019-08-14 16:56:55 -0700 | [diff] [blame] | 1536 | else |
| 1537 | lpfc_sli_release_iocbq(phba, piocb); |
James Smart | 9ec58ec | 2021-01-04 10:02:35 -0800 | [diff] [blame] | 1538 | |
| 1539 | } else if (piocb->iocb_cmpl) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1540 | piocb->iocb.ulpStatus = ulpstatus; |
| 1541 | piocb->iocb.un.ulpWord[4] = ulpWord4; |
| 1542 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
James Smart | 9ec58ec | 2021-01-04 10:02:35 -0800 | [diff] [blame] | 1543 | } else { |
| 1544 | lpfc_sli_release_iocbq(phba, piocb); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1545 | } |
| 1546 | } |
| 1547 | return; |
| 1548 | } |
| 1549 | |
| 1550 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1551 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
| 1552 | * @iocb_cmnd: iocb command code. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1553 | * |
| 1554 | * This function is called by ring event handler function to get the iocb type. |
| 1555 | * This function translates the iocb command to an iocb command type used to |
| 1556 | * decide the final disposition of each completed IOCB. |
| 1557 | * The function returns |
| 1558 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 1559 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 1560 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 1561 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 1562 | * |
| 1563 | * The caller is not required to hold any lock. |
| 1564 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1565 | static lpfc_iocb_type |
| 1566 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 1567 | { |
| 1568 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 1569 | |
| 1570 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 1571 | return 0; |
| 1572 | |
| 1573 | switch (iocb_cmnd) { |
| 1574 | case CMD_XMIT_SEQUENCE_CR: |
| 1575 | case CMD_XMIT_SEQUENCE_CX: |
| 1576 | case CMD_XMIT_BCAST_CN: |
| 1577 | case CMD_XMIT_BCAST_CX: |
| 1578 | case CMD_ELS_REQUEST_CR: |
| 1579 | case CMD_ELS_REQUEST_CX: |
| 1580 | case CMD_CREATE_XRI_CR: |
| 1581 | case CMD_CREATE_XRI_CX: |
| 1582 | case CMD_GET_RPI_CN: |
| 1583 | case CMD_XMIT_ELS_RSP_CX: |
| 1584 | case CMD_GET_RPI_CR: |
| 1585 | case CMD_FCP_IWRITE_CR: |
| 1586 | case CMD_FCP_IWRITE_CX: |
| 1587 | case CMD_FCP_IREAD_CR: |
| 1588 | case CMD_FCP_IREAD_CX: |
| 1589 | case CMD_FCP_ICMND_CR: |
| 1590 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1591 | case CMD_FCP_TSEND_CX: |
| 1592 | case CMD_FCP_TRSP_CX: |
| 1593 | case CMD_FCP_TRECEIVE_CX: |
| 1594 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1595 | case CMD_ADAPTER_MSG: |
| 1596 | case CMD_ADAPTER_DUMP: |
| 1597 | case CMD_XMIT_SEQUENCE64_CR: |
| 1598 | case CMD_XMIT_SEQUENCE64_CX: |
| 1599 | case CMD_XMIT_BCAST64_CN: |
| 1600 | case CMD_XMIT_BCAST64_CX: |
| 1601 | case CMD_ELS_REQUEST64_CR: |
| 1602 | case CMD_ELS_REQUEST64_CX: |
| 1603 | case CMD_FCP_IWRITE64_CR: |
| 1604 | case CMD_FCP_IWRITE64_CX: |
| 1605 | case CMD_FCP_IREAD64_CR: |
| 1606 | case CMD_FCP_IREAD64_CX: |
| 1607 | case CMD_FCP_ICMND64_CR: |
| 1608 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1609 | case CMD_FCP_TSEND64_CX: |
| 1610 | case CMD_FCP_TRSP64_CX: |
| 1611 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1612 | case CMD_GEN_REQUEST64_CR: |
| 1613 | case CMD_GEN_REQUEST64_CX: |
| 1614 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1615 | case DSSCMD_IWRITE64_CR: |
| 1616 | case DSSCMD_IWRITE64_CX: |
| 1617 | case DSSCMD_IREAD64_CR: |
| 1618 | case DSSCMD_IREAD64_CX: |
Dick Kennedy | c93764a | 2020-06-30 14:49:49 -0700 | [diff] [blame] | 1619 | case CMD_SEND_FRAME: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1620 | type = LPFC_SOL_IOCB; |
| 1621 | break; |
| 1622 | case CMD_ABORT_XRI_CN: |
| 1623 | case CMD_ABORT_XRI_CX: |
| 1624 | case CMD_CLOSE_XRI_CN: |
| 1625 | case CMD_CLOSE_XRI_CX: |
| 1626 | case CMD_XRI_ABORTED_CX: |
| 1627 | case CMD_ABORT_MXRI64_CN: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 1628 | case CMD_XMIT_BLS_RSP64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1629 | type = LPFC_ABORT_IOCB; |
| 1630 | break; |
| 1631 | case CMD_RCV_SEQUENCE_CX: |
| 1632 | case CMD_RCV_ELS_REQ_CX: |
| 1633 | case CMD_RCV_SEQUENCE64_CX: |
| 1634 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1635 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1636 | case CMD_IOCB_RCV_SEQ64_CX: |
| 1637 | case CMD_IOCB_RCV_ELS64_CX: |
| 1638 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1639 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1640 | type = LPFC_UNSOL_IOCB; |
| 1641 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1642 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 1643 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 1644 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 1645 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 1646 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 1647 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 1648 | case CMD_IOCB_RET_HBQE64_CN: |
| 1649 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 1650 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 1651 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 1652 | case CMD_IOCB_LOGENTRY_CN: |
| 1653 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 1654 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1655 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1656 | type = LPFC_UNKNOWN_IOCB; |
| 1657 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1658 | default: |
| 1659 | type = LPFC_UNKNOWN_IOCB; |
| 1660 | break; |
| 1661 | } |
| 1662 | |
| 1663 | return type; |
| 1664 | } |
| 1665 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1666 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1667 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1668 | * @phba: Pointer to HBA context object. |
| 1669 | * |
| 1670 | * This function is called from SLI initialization code |
| 1671 | * to configure every ring of the HBA's SLI interface. The |
| 1672 | * caller is not required to hold any lock. This function issues |
| 1673 | * a config_ring mailbox command for each ring. |
| 1674 | * This function returns zero if successful else returns a negative |
| 1675 | * error code. |
| 1676 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1677 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1678 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1679 | { |
| 1680 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1681 | LPFC_MBOXQ_t *pmb; |
| 1682 | MAILBOX_t *pmbox; |
| 1683 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1684 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1685 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1686 | if (!pmb) |
| 1687 | return -ENOMEM; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1688 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1689 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1690 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1691 | lpfc_config_ring(phba, i, pmb); |
| 1692 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 1693 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1694 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1695 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1696 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 1697 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1698 | rc, pmbox->mbxCommand, |
| 1699 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1700 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1701 | ret = -ENXIO; |
| 1702 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1703 | } |
| 1704 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1705 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1706 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1707 | } |
| 1708 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1709 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1710 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1711 | * @phba: Pointer to HBA context object. |
| 1712 | * @pring: Pointer to driver SLI ring object. |
| 1713 | * @piocb: Pointer to the driver iocb object. |
| 1714 | * |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1715 | * The driver calls this function with the hbalock held for SLI3 ports or |
| 1716 | * the ring lock held for SLI4 ports. The function adds the |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1717 | * new iocb to txcmplq of the given ring. This function always returns |
| 1718 | * 0. If this function is called for ELS ring, this function checks if |
| 1719 | * there is a vport associated with the ELS command. This function also |
| 1720 | * starts els_tmofunc timer if this is an ELS command. |
| 1721 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1722 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1723 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1724 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1725 | { |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1726 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1727 | lockdep_assert_held(&pring->ring_lock); |
| 1728 | else |
| 1729 | lockdep_assert_held(&phba->hbalock); |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1730 | |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1731 | BUG_ON(!piocb); |
Johannes Thumshirn | 22466da | 2016-07-29 15:30:56 +0200 | [diff] [blame] | 1732 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1733 | list_add_tail(&piocb->list, &pring->txcmplq); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 1734 | piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1735 | pring->txcmplq_cnt++; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1736 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1737 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 1738 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1739 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 1740 | BUG_ON(!piocb->vport); |
| 1741 | if (!(piocb->vport->load_flag & FC_UNLOADING)) |
| 1742 | mod_timer(&piocb->vport->els_tmofunc, |
| 1743 | jiffies + |
| 1744 | msecs_to_jiffies(1000 * (phba->fc_ratov << 1))); |
| 1745 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1746 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1747 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1748 | } |
| 1749 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1750 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1751 | * lpfc_sli_ringtx_get - Get first element of the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1752 | * @phba: Pointer to HBA context object. |
| 1753 | * @pring: Pointer to driver SLI ring object. |
| 1754 | * |
| 1755 | * This function is called with hbalock held to get next |
| 1756 | * iocb in txq of the given ring. If there is any iocb in |
| 1757 | * the txq, the function returns first iocb in the list after |
| 1758 | * removing the iocb from the list, else it returns NULL. |
| 1759 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1760 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1761 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1762 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1763 | struct lpfc_iocbq *cmd_iocb; |
| 1764 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1765 | lockdep_assert_held(&phba->hbalock); |
| 1766 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1767 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1768 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1769 | } |
| 1770 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1771 | /** |
James Smart | daebf93 | 2021-08-16 09:28:53 -0700 | [diff] [blame] | 1772 | * lpfc_cmf_sync_cmpl - Process a CMF_SYNC_WQE cmpl |
| 1773 | * @phba: Pointer to HBA context object. |
| 1774 | * @cmdiocb: Pointer to driver command iocb object. |
| 1775 | * @cmf_cmpl: Pointer to completed WCQE. |
| 1776 | * |
| 1777 | * This routine will inform the driver of any BW adjustments we need |
| 1778 | * to make. These changes will be picked up during the next CMF |
| 1779 | * timer interrupt. In addition, any BW changes will be logged |
| 1780 | * with LOG_CGN_MGMT. |
| 1781 | **/ |
| 1782 | static void |
| 1783 | lpfc_cmf_sync_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1784 | struct lpfc_wcqe_complete *cmf_cmpl) |
| 1785 | { |
| 1786 | union lpfc_wqe128 *wqe; |
| 1787 | uint32_t status, info; |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 1788 | uint64_t bw, bwdif, slop; |
| 1789 | uint64_t pcent, bwpcent; |
James Smart | daebf93 | 2021-08-16 09:28:53 -0700 | [diff] [blame] | 1790 | int asig, afpin, sigcnt, fpincnt; |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 1791 | int wsigmax, wfpinmax, cg, tdp; |
| 1792 | char *s; |
James Smart | daebf93 | 2021-08-16 09:28:53 -0700 | [diff] [blame] | 1793 | |
| 1794 | /* First check for error */ |
| 1795 | status = bf_get(lpfc_wcqe_c_status, cmf_cmpl); |
| 1796 | if (status) { |
| 1797 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT, |
| 1798 | "6211 CMF_SYNC_WQE Error " |
| 1799 | "req_tag x%x status x%x hwstatus x%x " |
| 1800 | "tdatap x%x parm x%x\n", |
| 1801 | bf_get(lpfc_wcqe_c_request_tag, cmf_cmpl), |
| 1802 | bf_get(lpfc_wcqe_c_status, cmf_cmpl), |
| 1803 | bf_get(lpfc_wcqe_c_hw_status, cmf_cmpl), |
| 1804 | cmf_cmpl->total_data_placed, |
| 1805 | cmf_cmpl->parameter); |
| 1806 | goto out; |
| 1807 | } |
| 1808 | |
| 1809 | /* Gather congestion information on a successful cmpl */ |
| 1810 | info = cmf_cmpl->parameter; |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 1811 | phba->cmf_active_info = info; |
| 1812 | |
| 1813 | /* See if firmware info count is valid or has changed */ |
| 1814 | if (info > LPFC_MAX_CMF_INFO || phba->cmf_info_per_interval == info) |
| 1815 | info = 0; |
| 1816 | else |
| 1817 | phba->cmf_info_per_interval = info; |
| 1818 | |
James Smart | daebf93 | 2021-08-16 09:28:53 -0700 | [diff] [blame] | 1819 | tdp = bf_get(lpfc_wcqe_c_cmf_bw, cmf_cmpl); |
| 1820 | cg = bf_get(lpfc_wcqe_c_cmf_cg, cmf_cmpl); |
| 1821 | |
| 1822 | /* Get BW requirement from firmware */ |
| 1823 | bw = (uint64_t)tdp * LPFC_CMF_BLK_SIZE; |
| 1824 | if (!bw) { |
| 1825 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT, |
| 1826 | "6212 CMF_SYNC_WQE x%x: NULL bw\n", |
| 1827 | bf_get(lpfc_wcqe_c_request_tag, cmf_cmpl)); |
| 1828 | goto out; |
| 1829 | } |
| 1830 | |
| 1831 | /* Gather information needed for logging if a BW change is required */ |
| 1832 | wqe = &cmdiocb->wqe; |
| 1833 | asig = bf_get(cmf_sync_asig, &wqe->cmf_sync); |
| 1834 | afpin = bf_get(cmf_sync_afpin, &wqe->cmf_sync); |
| 1835 | fpincnt = bf_get(cmf_sync_wfpincnt, &wqe->cmf_sync); |
| 1836 | sigcnt = bf_get(cmf_sync_wsigcnt, &wqe->cmf_sync); |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 1837 | if (phba->cmf_max_bytes_per_interval != bw || |
| 1838 | (asig || afpin || sigcnt || fpincnt)) { |
| 1839 | /* Are we increasing or decreasing BW */ |
| 1840 | if (phba->cmf_max_bytes_per_interval < bw) { |
| 1841 | bwdif = bw - phba->cmf_max_bytes_per_interval; |
| 1842 | s = "Increase"; |
| 1843 | } else { |
| 1844 | bwdif = phba->cmf_max_bytes_per_interval - bw; |
| 1845 | s = "Decrease"; |
| 1846 | } |
James Smart | daebf93 | 2021-08-16 09:28:53 -0700 | [diff] [blame] | 1847 | |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 1848 | /* What is the change percentage */ |
| 1849 | slop = div_u64(phba->cmf_link_byte_count, 200); /*For rounding*/ |
| 1850 | pcent = div64_u64(bwdif * 100 + slop, |
| 1851 | phba->cmf_link_byte_count); |
| 1852 | bwpcent = div64_u64(bw * 100 + slop, |
| 1853 | phba->cmf_link_byte_count); |
| 1854 | if (asig) { |
| 1855 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT, |
| 1856 | "6237 BW Threshold %lld%% (%lld): " |
| 1857 | "%lld%% %s: Signal Alarm: cg:%d " |
| 1858 | "Info:%u\n", |
| 1859 | bwpcent, bw, pcent, s, cg, |
| 1860 | phba->cmf_active_info); |
| 1861 | } else if (afpin) { |
| 1862 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT, |
| 1863 | "6238 BW Threshold %lld%% (%lld): " |
| 1864 | "%lld%% %s: FPIN Alarm: cg:%d " |
| 1865 | "Info:%u\n", |
| 1866 | bwpcent, bw, pcent, s, cg, |
| 1867 | phba->cmf_active_info); |
| 1868 | } else if (sigcnt) { |
| 1869 | wsigmax = bf_get(cmf_sync_wsigmax, &wqe->cmf_sync); |
| 1870 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT, |
| 1871 | "6239 BW Threshold %lld%% (%lld): " |
| 1872 | "%lld%% %s: Signal Warning: " |
| 1873 | "Cnt %d Max %d: cg:%d Info:%u\n", |
| 1874 | bwpcent, bw, pcent, s, sigcnt, |
| 1875 | wsigmax, cg, phba->cmf_active_info); |
| 1876 | } else if (fpincnt) { |
| 1877 | wfpinmax = bf_get(cmf_sync_wfpinmax, &wqe->cmf_sync); |
| 1878 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT, |
| 1879 | "6240 BW Threshold %lld%% (%lld): " |
| 1880 | "%lld%% %s: FPIN Warning: " |
| 1881 | "Cnt %d Max %d: cg:%d Info:%u\n", |
| 1882 | bwpcent, bw, pcent, s, fpincnt, |
| 1883 | wfpinmax, cg, phba->cmf_active_info); |
| 1884 | } else { |
| 1885 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT, |
| 1886 | "6241 BW Threshold %lld%% (%lld): " |
| 1887 | "CMF %lld%% %s: cg:%d Info:%u\n", |
| 1888 | bwpcent, bw, pcent, s, cg, |
| 1889 | phba->cmf_active_info); |
| 1890 | } |
| 1891 | } else if (info) { |
| 1892 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT, |
| 1893 | "6246 Info Threshold %u\n", info); |
| 1894 | } |
| 1895 | |
| 1896 | /* Save BW change to be picked up during next timer interrupt */ |
| 1897 | phba->cmf_last_sync_bw = bw; |
James Smart | daebf93 | 2021-08-16 09:28:53 -0700 | [diff] [blame] | 1898 | out: |
| 1899 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| 1900 | } |
| 1901 | |
| 1902 | /** |
| 1903 | * lpfc_issue_cmf_sync_wqe - Issue a CMF_SYNC_WQE |
| 1904 | * @phba: Pointer to HBA context object. |
| 1905 | * @ms: ms to set in WQE interval, 0 means use init op |
| 1906 | * @total: Total rcv bytes for this interval |
| 1907 | * |
| 1908 | * This routine is called every CMF timer interrupt. Its purpose is |
| 1909 | * to issue a CMF_SYNC_WQE to the firmware to inform it of any events |
| 1910 | * that may indicate we have congestion (FPINs or Signals). Upon |
| 1911 | * completion, the firmware will indicate any BW restrictions the |
| 1912 | * driver may need to take. |
| 1913 | **/ |
| 1914 | int |
| 1915 | lpfc_issue_cmf_sync_wqe(struct lpfc_hba *phba, u32 ms, u64 total) |
| 1916 | { |
| 1917 | union lpfc_wqe128 *wqe; |
| 1918 | struct lpfc_iocbq *sync_buf; |
| 1919 | unsigned long iflags; |
| 1920 | u32 ret_val; |
| 1921 | u32 atot, wtot, max; |
| 1922 | |
| 1923 | /* First address any alarm / warning activity */ |
| 1924 | atot = atomic_xchg(&phba->cgn_sync_alarm_cnt, 0); |
| 1925 | wtot = atomic_xchg(&phba->cgn_sync_warn_cnt, 0); |
| 1926 | |
| 1927 | /* ONLY Managed mode will send the CMF_SYNC_WQE to the HBA */ |
| 1928 | if (phba->cmf_active_mode != LPFC_CFG_MANAGED || |
| 1929 | phba->link_state == LPFC_LINK_DOWN) |
| 1930 | return 0; |
| 1931 | |
| 1932 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1933 | sync_buf = __lpfc_sli_get_iocbq(phba); |
| 1934 | if (!sync_buf) { |
| 1935 | lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT, |
| 1936 | "6213 No available WQEs for CMF_SYNC_WQE\n"); |
| 1937 | ret_val = ENOMEM; |
| 1938 | goto out_unlock; |
| 1939 | } |
| 1940 | |
| 1941 | wqe = &sync_buf->wqe; |
| 1942 | |
| 1943 | /* WQEs are reused. Clear stale data and set key fields to zero */ |
| 1944 | memset(wqe, 0, sizeof(*wqe)); |
| 1945 | |
| 1946 | /* If this is the very first CMF_SYNC_WQE, issue an init operation */ |
| 1947 | if (!ms) { |
| 1948 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT, |
| 1949 | "6441 CMF Init %d - CMF_SYNC_WQE\n", |
| 1950 | phba->fc_eventTag); |
| 1951 | bf_set(cmf_sync_op, &wqe->cmf_sync, 1); /* 1=init */ |
| 1952 | bf_set(cmf_sync_interval, &wqe->cmf_sync, LPFC_CMF_INTERVAL); |
| 1953 | goto initpath; |
| 1954 | } |
| 1955 | |
| 1956 | bf_set(cmf_sync_op, &wqe->cmf_sync, 0); /* 0=recalc */ |
| 1957 | bf_set(cmf_sync_interval, &wqe->cmf_sync, ms); |
| 1958 | |
| 1959 | /* Check for alarms / warnings */ |
| 1960 | if (atot) { |
| 1961 | if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) { |
| 1962 | /* We hit an Signal alarm condition */ |
| 1963 | bf_set(cmf_sync_asig, &wqe->cmf_sync, 1); |
| 1964 | } else { |
| 1965 | /* We hit a FPIN alarm condition */ |
| 1966 | bf_set(cmf_sync_afpin, &wqe->cmf_sync, 1); |
| 1967 | } |
| 1968 | } else if (wtot) { |
| 1969 | if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY || |
| 1970 | phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) { |
| 1971 | /* We hit an Signal warning condition */ |
| 1972 | max = LPFC_SEC_TO_MSEC / lpfc_fabric_cgn_frequency * |
| 1973 | lpfc_acqe_cgn_frequency; |
| 1974 | bf_set(cmf_sync_wsigmax, &wqe->cmf_sync, max); |
| 1975 | bf_set(cmf_sync_wsigcnt, &wqe->cmf_sync, wtot); |
| 1976 | } else { |
| 1977 | /* We hit a FPIN warning condition */ |
| 1978 | bf_set(cmf_sync_wfpinmax, &wqe->cmf_sync, 1); |
| 1979 | bf_set(cmf_sync_wfpincnt, &wqe->cmf_sync, 1); |
| 1980 | } |
| 1981 | } |
| 1982 | |
| 1983 | /* Update total read blocks during previous timer interval */ |
| 1984 | wqe->cmf_sync.read_bytes = (u32)(total / LPFC_CMF_BLK_SIZE); |
| 1985 | |
| 1986 | initpath: |
| 1987 | bf_set(cmf_sync_ver, &wqe->cmf_sync, LPFC_CMF_SYNC_VER); |
| 1988 | wqe->cmf_sync.event_tag = phba->fc_eventTag; |
| 1989 | bf_set(cmf_sync_cmnd, &wqe->cmf_sync, CMD_CMF_SYNC_WQE); |
| 1990 | |
| 1991 | /* Setup reqtag to match the wqe completion. */ |
| 1992 | bf_set(cmf_sync_reqtag, &wqe->cmf_sync, sync_buf->iotag); |
| 1993 | |
| 1994 | bf_set(cmf_sync_qosd, &wqe->cmf_sync, 1); |
| 1995 | |
| 1996 | bf_set(cmf_sync_cmd_type, &wqe->cmf_sync, CMF_SYNC_COMMAND); |
| 1997 | bf_set(cmf_sync_wqec, &wqe->cmf_sync, 1); |
| 1998 | bf_set(cmf_sync_cqid, &wqe->cmf_sync, LPFC_WQE_CQ_ID_DEFAULT); |
| 1999 | |
| 2000 | sync_buf->vport = phba->pport; |
| 2001 | sync_buf->wqe_cmpl = lpfc_cmf_sync_cmpl; |
| 2002 | sync_buf->iocb_cmpl = NULL; |
| 2003 | sync_buf->context1 = NULL; |
| 2004 | sync_buf->context2 = NULL; |
| 2005 | sync_buf->context3 = NULL; |
| 2006 | sync_buf->sli4_xritag = NO_XRI; |
| 2007 | |
| 2008 | sync_buf->iocb_flag |= LPFC_IO_CMF; |
| 2009 | ret_val = lpfc_sli4_issue_wqe(phba, &phba->sli4_hba.hdwq[0], sync_buf); |
| 2010 | if (ret_val) |
| 2011 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT, |
| 2012 | "6214 Cannot issue CMF_SYNC_WQE: x%x\n", |
| 2013 | ret_val); |
| 2014 | out_unlock: |
| 2015 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 2016 | return ret_val; |
| 2017 | } |
| 2018 | |
| 2019 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2020 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2021 | * @phba: Pointer to HBA context object. |
| 2022 | * @pring: Pointer to driver SLI ring object. |
| 2023 | * |
| 2024 | * This function is called with hbalock held and the caller must post the |
| 2025 | * iocb without releasing the lock. If the caller releases the lock, |
| 2026 | * iocb slot returned by the function is not guaranteed to be available. |
| 2027 | * The function returns pointer to the next available iocb slot if there |
| 2028 | * is available slot in the ring, else it returns NULL. |
| 2029 | * If the get index of the ring is ahead of the put index, the function |
| 2030 | * will post an error attention event to the worker thread to take the |
| 2031 | * HBA to offline state. |
| 2032 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2033 | static IOCB_t * |
| 2034 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 2035 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2036 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2037 | uint32_t max_cmd_idx = pring->sli.sli3.numCiocb; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2038 | |
| 2039 | lockdep_assert_held(&phba->hbalock); |
| 2040 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2041 | if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) && |
| 2042 | (++pring->sli.sli3.next_cmdidx >= max_cmd_idx)) |
| 2043 | pring->sli.sli3.next_cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2044 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2045 | if (unlikely(pring->sli.sli3.local_getidx == |
| 2046 | pring->sli.sli3.next_cmdidx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2047 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2048 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2049 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2050 | if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2051 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2052 | "0315 Ring %d issue: portCmdGet %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2053 | "is bigger than cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2054 | pring->ringno, |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2055 | pring->sli.sli3.local_getidx, |
| 2056 | max_cmd_idx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2057 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2058 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2059 | /* |
| 2060 | * All error attention handlers are posted to |
| 2061 | * worker thread |
| 2062 | */ |
| 2063 | phba->work_ha |= HA_ERATT; |
| 2064 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2065 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2066 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2067 | |
| 2068 | return NULL; |
| 2069 | } |
| 2070 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2071 | if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2072 | return NULL; |
| 2073 | } |
| 2074 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2075 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2076 | } |
| 2077 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2078 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2079 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2080 | * @phba: Pointer to HBA context object. |
| 2081 | * @iocbq: Pointer to driver iocb object. |
| 2082 | * |
| 2083 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 2084 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 2085 | * array and assigns a new iotag. |
| 2086 | * The function returns the allocated iotag if successful, else returns zero. |
| 2087 | * Zero is not a valid iotag. |
| 2088 | * The caller is not required to hold any lock. |
| 2089 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2090 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2091 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2092 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2093 | struct lpfc_iocbq **new_arr; |
| 2094 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2095 | size_t new_len; |
| 2096 | struct lpfc_sli *psli = &phba->sli; |
| 2097 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2098 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2099 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2100 | iotag = psli->last_iotag; |
| 2101 | if(++iotag < psli->iocbq_lookup_len) { |
| 2102 | psli->last_iotag = iotag; |
| 2103 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2104 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2105 | iocbq->iotag = iotag; |
| 2106 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2107 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2108 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 2109 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2110 | spin_unlock_irq(&phba->hbalock); |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 2111 | new_arr = kcalloc(new_len, sizeof(struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2112 | GFP_KERNEL); |
| 2113 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2114 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2115 | old_arr = psli->iocbq_lookup; |
| 2116 | if (new_len <= psli->iocbq_lookup_len) { |
| 2117 | /* highly unprobable case */ |
| 2118 | kfree(new_arr); |
| 2119 | iotag = psli->last_iotag; |
| 2120 | if(++iotag < psli->iocbq_lookup_len) { |
| 2121 | psli->last_iotag = iotag; |
| 2122 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2123 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2124 | iocbq->iotag = iotag; |
| 2125 | return iotag; |
| 2126 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2127 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2128 | return 0; |
| 2129 | } |
| 2130 | if (psli->iocbq_lookup) |
| 2131 | memcpy(new_arr, old_arr, |
| 2132 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 2133 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2134 | psli->iocbq_lookup = new_arr; |
| 2135 | psli->iocbq_lookup_len = new_len; |
| 2136 | psli->last_iotag = iotag; |
| 2137 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2138 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2139 | iocbq->iotag = iotag; |
| 2140 | kfree(old_arr); |
| 2141 | return iotag; |
| 2142 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 2143 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2144 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2145 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 2146 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2147 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 2148 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2149 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2150 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2151 | } |
| 2152 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2153 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2154 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2155 | * @phba: Pointer to HBA context object. |
| 2156 | * @pring: Pointer to driver SLI ring object. |
| 2157 | * @iocb: Pointer to iocb slot in the ring. |
| 2158 | * @nextiocb: Pointer to driver iocb object which need to be |
| 2159 | * posted to firmware. |
| 2160 | * |
Dick Kennedy | 88acb4d | 2020-05-01 14:43:07 -0700 | [diff] [blame] | 2161 | * This function is called to post a new iocb to the firmware. This |
| 2162 | * function copies the new iocb to ring iocb slot and updates the |
| 2163 | * ring pointers. It adds the new iocb to txcmplq if there is |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2164 | * 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] | 2165 | * iocb object. The hbalock is asserted held in the code path calling |
| 2166 | * this routine. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2167 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2168 | static void |
| 2169 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2170 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 2171 | { |
| 2172 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2173 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2174 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2175 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2176 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2177 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2178 | if (pring->ringno == LPFC_ELS_RING) { |
| 2179 | lpfc_debugfs_slow_ring_trc(phba, |
| 2180 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 2181 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 2182 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 2183 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 2184 | } |
| 2185 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2186 | /* |
| 2187 | * Issue iocb command to adapter |
| 2188 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2189 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2190 | wmb(); |
| 2191 | pring->stats.iocb_cmd++; |
| 2192 | |
| 2193 | /* |
| 2194 | * If there is no completion routine to call, we can release the |
| 2195 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 2196 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 2197 | */ |
| 2198 | if (nextiocb->iocb_cmpl) |
| 2199 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2200 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2201 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2202 | |
| 2203 | /* |
| 2204 | * Let the HBA know what IOCB slot will be the next one the |
| 2205 | * driver will put a command into. |
| 2206 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2207 | pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx; |
| 2208 | writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2209 | } |
| 2210 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2211 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2212 | * lpfc_sli_update_full_ring - Update the chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2213 | * @phba: Pointer to HBA context object. |
| 2214 | * @pring: Pointer to driver SLI ring object. |
| 2215 | * |
| 2216 | * The caller is not required to hold any lock for calling this function. |
| 2217 | * This function updates the chip attention bits for the ring to inform firmware |
| 2218 | * that there are pending work to be done for this ring and requests an |
| 2219 | * interrupt when there is space available in the ring. This function is |
| 2220 | * called when the driver is unable to post more iocbs to the ring due |
| 2221 | * to unavailability of space in the ring. |
| 2222 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2223 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2224 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2225 | { |
| 2226 | int ringno = pring->ringno; |
| 2227 | |
| 2228 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 2229 | |
| 2230 | wmb(); |
| 2231 | |
| 2232 | /* |
| 2233 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 2234 | * The HBA will tell us when an IOCB entry is available. |
| 2235 | */ |
| 2236 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 2237 | readl(phba->CAregaddr); /* flush */ |
| 2238 | |
| 2239 | pring->stats.iocb_cmd_full++; |
| 2240 | } |
| 2241 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2242 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2243 | * lpfc_sli_update_ring - Update chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2244 | * @phba: Pointer to HBA context object. |
| 2245 | * @pring: Pointer to driver SLI ring object. |
| 2246 | * |
| 2247 | * This function updates the chip attention register bit for the |
| 2248 | * given ring to inform HBA that there is more work to be done |
| 2249 | * in this ring. The caller is not required to hold any lock. |
| 2250 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2251 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2252 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2253 | { |
| 2254 | int ringno = pring->ringno; |
| 2255 | |
| 2256 | /* |
| 2257 | * Tell the HBA that there is work to do in this ring. |
| 2258 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2259 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 2260 | wmb(); |
| 2261 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 2262 | readl(phba->CAregaddr); /* flush */ |
| 2263 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2264 | } |
| 2265 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2266 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2267 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2268 | * @phba: Pointer to HBA context object. |
| 2269 | * @pring: Pointer to driver SLI ring object. |
| 2270 | * |
| 2271 | * This function is called with hbalock held to post pending iocbs |
| 2272 | * in the txq to the firmware. This function is called when driver |
| 2273 | * detects space available in the ring. |
| 2274 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2275 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2276 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2277 | { |
| 2278 | IOCB_t *iocb; |
| 2279 | struct lpfc_iocbq *nextiocb; |
| 2280 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2281 | lockdep_assert_held(&phba->hbalock); |
| 2282 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2283 | /* |
| 2284 | * Check to see if: |
| 2285 | * (a) there is anything on the txq to send |
| 2286 | * (b) link is up |
| 2287 | * (c) link attention events can be processed (fcp ring only) |
| 2288 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 2289 | */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 2290 | |
| 2291 | if (lpfc_is_link_up(phba) && |
| 2292 | (!list_empty(&pring->txq)) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2293 | (pring->ringno != LPFC_FCP_RING || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2294 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2295 | |
| 2296 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 2297 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 2298 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 2299 | |
| 2300 | if (iocb) |
| 2301 | lpfc_sli_update_ring(phba, pring); |
| 2302 | else |
| 2303 | lpfc_sli_update_full_ring(phba, pring); |
| 2304 | } |
| 2305 | |
| 2306 | return; |
| 2307 | } |
| 2308 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2309 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2310 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2311 | * @phba: Pointer to HBA context object. |
| 2312 | * @hbqno: HBQ number. |
| 2313 | * |
| 2314 | * This function is called with hbalock held to get the next |
| 2315 | * available slot for the given HBQ. If there is free slot |
| 2316 | * available for the HBQ it will return pointer to the next available |
| 2317 | * HBQ entry else it will return NULL. |
| 2318 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2319 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2320 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 2321 | { |
| 2322 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 2323 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2324 | lockdep_assert_held(&phba->hbalock); |
| 2325 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2326 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 2327 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 2328 | hbqp->next_hbqPutIdx = 0; |
| 2329 | |
| 2330 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2331 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2332 | uint32_t getidx = le32_to_cpu(raw_index); |
| 2333 | |
| 2334 | hbqp->local_hbqGetIdx = getidx; |
| 2335 | |
| 2336 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2337 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2338 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2339 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2340 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2341 | hbqp->entry_count); |
| 2342 | |
| 2343 | phba->link_state = LPFC_HBA_ERROR; |
| 2344 | return NULL; |
| 2345 | } |
| 2346 | |
| 2347 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 2348 | return NULL; |
| 2349 | } |
| 2350 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2351 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 2352 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2353 | } |
| 2354 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2355 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2356 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2357 | * @phba: Pointer to HBA context object. |
| 2358 | * |
| 2359 | * This function is called with no lock held to free all the |
| 2360 | * hbq buffers while uninitializing the SLI interface. It also |
| 2361 | * frees the HBQ buffers returned by the firmware but not yet |
| 2362 | * processed by the upper layers. |
| 2363 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2364 | void |
| 2365 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 2366 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2367 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 2368 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2369 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2370 | int i, hbq_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2371 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2372 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2373 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2374 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2375 | for (i = 0; i < hbq_count; ++i) { |
| 2376 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 2377 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 2378 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 2379 | list_del(&hbq_buf->dbuf.list); |
| 2380 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 2381 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2382 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2383 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2384 | |
| 2385 | /* Mark the HBQs not in use */ |
| 2386 | phba->hbq_in_use = 0; |
| 2387 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2388 | } |
| 2389 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2390 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2391 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2392 | * @phba: Pointer to HBA context object. |
| 2393 | * @hbqno: HBQ number. |
| 2394 | * @hbq_buf: Pointer to HBQ buffer. |
| 2395 | * |
| 2396 | * This function is called with the hbalock held to post a |
| 2397 | * hbq buffer to the firmware. If the function finds an empty |
| 2398 | * slot in the HBQ, it will post the buffer. The function will return |
| 2399 | * pointer to the hbq entry if it successfully post the buffer |
| 2400 | * else it will return NULL. |
| 2401 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2402 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2403 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2404 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2405 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2406 | lockdep_assert_held(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2407 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); |
| 2408 | } |
| 2409 | |
| 2410 | /** |
| 2411 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware |
| 2412 | * @phba: Pointer to HBA context object. |
| 2413 | * @hbqno: HBQ number. |
| 2414 | * @hbq_buf: Pointer to HBQ buffer. |
| 2415 | * |
| 2416 | * This function is called with the hbalock held to post a hbq buffer to the |
| 2417 | * firmware. If the function finds an empty slot in the HBQ, it will post the |
| 2418 | * buffer and place it on the hbq_buffer_list. The function will return zero if |
| 2419 | * it successfully post the buffer else it will return an error. |
| 2420 | **/ |
| 2421 | static int |
| 2422 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, |
| 2423 | struct hbq_dmabuf *hbq_buf) |
| 2424 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2425 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2426 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2427 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2428 | lockdep_assert_held(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2429 | /* Get next HBQ entry slot to use */ |
| 2430 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 2431 | if (hbqe) { |
| 2432 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 2433 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2434 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 2435 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2436 | hbqe->bde.tus.f.bdeSize = hbq_buf->total_size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2437 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2438 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 2439 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 2440 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2441 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 2442 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2443 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2444 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2445 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2446 | return 0; |
| 2447 | } else |
| 2448 | return -ENOMEM; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2449 | } |
| 2450 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2451 | /** |
| 2452 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware |
| 2453 | * @phba: Pointer to HBA context object. |
| 2454 | * @hbqno: HBQ number. |
| 2455 | * @hbq_buf: Pointer to HBQ buffer. |
| 2456 | * |
| 2457 | * This function is called with the hbalock held to post an RQE to the SLI4 |
| 2458 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to |
| 2459 | * the hbq_buffer_list and return zero, otherwise it will return an error. |
| 2460 | **/ |
| 2461 | static int |
| 2462 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, |
| 2463 | struct hbq_dmabuf *hbq_buf) |
| 2464 | { |
| 2465 | int rc; |
| 2466 | struct lpfc_rqe hrqe; |
| 2467 | struct lpfc_rqe drqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2468 | struct lpfc_queue *hrq; |
| 2469 | struct lpfc_queue *drq; |
| 2470 | |
| 2471 | if (hbqno != LPFC_ELS_HBQ) |
| 2472 | return 1; |
| 2473 | hrq = phba->sli4_hba.hdr_rq; |
| 2474 | drq = phba->sli4_hba.dat_rq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2475 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2476 | lockdep_assert_held(&phba->hbalock); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2477 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); |
| 2478 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); |
| 2479 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); |
| 2480 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2481 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2482 | if (rc < 0) |
| 2483 | return rc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2484 | hbq_buf->tag = (rc | (hbqno << 16)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2485 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); |
| 2486 | return 0; |
| 2487 | } |
| 2488 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2489 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2490 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 2491 | .rn = 1, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2492 | .entry_count = 256, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2493 | .mask_count = 0, |
| 2494 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2495 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2496 | .buffer_count = 0, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2497 | .init_count = 40, |
| 2498 | .add_count = 40, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2499 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2500 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2501 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 2502 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2503 | &lpfc_els_hbq, |
| 2504 | }; |
| 2505 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2506 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2507 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2508 | * @phba: Pointer to HBA context object. |
| 2509 | * @hbqno: HBQ number. |
| 2510 | * @count: Number of HBQ buffers to be posted. |
| 2511 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2512 | * This function is called with no lock held to post more hbq buffers to the |
| 2513 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 2514 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2515 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 2516 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2517 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 2518 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2519 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2520 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2521 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2522 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 2523 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2524 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2525 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2526 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 2527 | lpfc_hbq_defs[hbqno]->entry_count) |
| 2528 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 2529 | phba->hbqs[hbqno].buffer_count; |
| 2530 | if (!count) |
| 2531 | return 0; |
| 2532 | /* Allocate HBQ entries */ |
| 2533 | for (i = 0; i < count; i++) { |
| 2534 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 2535 | if (!hbq_buffer) |
| 2536 | break; |
| 2537 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 2538 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2539 | /* Check whether HBQ is still in use */ |
| 2540 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 2541 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2542 | goto err; |
| 2543 | while (!list_empty(&hbq_buf_list)) { |
| 2544 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 2545 | dbuf.list); |
| 2546 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 2547 | (hbqno << 16)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2548 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2549 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2550 | posted++; |
| 2551 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2552 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2553 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2554 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2555 | return posted; |
| 2556 | err: |
| 2557 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 2558 | while (!list_empty(&hbq_buf_list)) { |
| 2559 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 2560 | dbuf.list); |
| 2561 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 2562 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2563 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2564 | } |
| 2565 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2566 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2567 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2568 | * @phba: Pointer to HBA context object. |
| 2569 | * @qno: HBQ number. |
| 2570 | * |
| 2571 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2572 | * is called with no lock held. The function returns the number of HBQ entries |
| 2573 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2574 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2575 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2576 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2577 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2578 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2579 | return 0; |
| 2580 | else |
| 2581 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 2582 | lpfc_hbq_defs[qno]->add_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2583 | } |
| 2584 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2585 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2586 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2587 | * @phba: Pointer to HBA context object. |
| 2588 | * @qno: HBQ queue number. |
| 2589 | * |
| 2590 | * This function is called from SLI initialization code path with |
| 2591 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2592 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2593 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2594 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2595 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2596 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2597 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2598 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 2599 | lpfc_hbq_defs[qno]->entry_count); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2600 | else |
| 2601 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 2602 | lpfc_hbq_defs[qno]->init_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2603 | } |
| 2604 | |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 2605 | /* |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2606 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2607 | * |
| 2608 | * This function removes the first hbq buffer on an hbq list and returns a |
| 2609 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 2610 | **/ |
| 2611 | static struct hbq_dmabuf * |
| 2612 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) |
| 2613 | { |
| 2614 | struct lpfc_dmabuf *d_buf; |
| 2615 | |
| 2616 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); |
| 2617 | if (!d_buf) |
| 2618 | return NULL; |
| 2619 | return container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 2620 | } |
| 2621 | |
| 2622 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 2623 | * lpfc_sli_rqbuf_get - Remove the first dma buffer off of an RQ list |
| 2624 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 2625 | * @hrq: HBQ number. |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 2626 | * |
| 2627 | * This function removes the first RQ buffer on an RQ buffer list and returns a |
| 2628 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 2629 | **/ |
| 2630 | static struct rqb_dmabuf * |
| 2631 | lpfc_sli_rqbuf_get(struct lpfc_hba *phba, struct lpfc_queue *hrq) |
| 2632 | { |
| 2633 | struct lpfc_dmabuf *h_buf; |
| 2634 | struct lpfc_rqb *rqbp; |
| 2635 | |
| 2636 | rqbp = hrq->rqbp; |
| 2637 | list_remove_head(&rqbp->rqb_buffer_list, h_buf, |
| 2638 | struct lpfc_dmabuf, list); |
| 2639 | if (!h_buf) |
| 2640 | return NULL; |
| 2641 | rqbp->buffer_count--; |
| 2642 | return container_of(h_buf, struct rqb_dmabuf, hbuf); |
| 2643 | } |
| 2644 | |
| 2645 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2646 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2647 | * @phba: Pointer to HBA context object. |
| 2648 | * @tag: Tag of the hbq buffer. |
| 2649 | * |
Sebastian Herbszt | 7189241 | 2016-04-17 13:27:27 +0200 | [diff] [blame] | 2650 | * This function searches for the hbq buffer associated with the given tag in |
| 2651 | * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer |
| 2652 | * otherwise it returns NULL. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2653 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2654 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2655 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 2656 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2657 | struct lpfc_dmabuf *d_buf; |
| 2658 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2659 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2660 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2661 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 2662 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2663 | return NULL; |
| 2664 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2665 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2666 | 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] | 2667 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2668 | if (hbq_buf->tag == tag) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2669 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2670 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2671 | } |
| 2672 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2673 | spin_unlock_irq(&phba->hbalock); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2674 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2675 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2676 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2677 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2678 | } |
| 2679 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2680 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2681 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2682 | * @phba: Pointer to HBA context object. |
| 2683 | * @hbq_buffer: Pointer to HBQ buffer. |
| 2684 | * |
| 2685 | * This function is called with hbalock. This function gives back |
| 2686 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 2687 | * post the buffer, it will free the buffer. |
| 2688 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2689 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2690 | 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] | 2691 | { |
| 2692 | uint32_t hbqno; |
| 2693 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2694 | if (hbq_buffer) { |
| 2695 | hbqno = hbq_buffer->tag >> 16; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2696 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2697 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2698 | } |
| 2699 | } |
| 2700 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2701 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2702 | * 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] | 2703 | * @mbxCommand: mailbox command code. |
| 2704 | * |
| 2705 | * This function is called by the mailbox event handler function to verify |
| 2706 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 2707 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 2708 | * and the mailbox event handler will take the HBA offline. |
| 2709 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2710 | static int |
| 2711 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 2712 | { |
| 2713 | uint8_t ret; |
| 2714 | |
| 2715 | switch (mbxCommand) { |
| 2716 | case MBX_LOAD_SM: |
| 2717 | case MBX_READ_NV: |
| 2718 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2719 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2720 | case MBX_RUN_BIU_DIAG: |
| 2721 | case MBX_INIT_LINK: |
| 2722 | case MBX_DOWN_LINK: |
| 2723 | case MBX_CONFIG_LINK: |
| 2724 | case MBX_CONFIG_RING: |
| 2725 | case MBX_RESET_RING: |
| 2726 | case MBX_READ_CONFIG: |
| 2727 | case MBX_READ_RCONFIG: |
| 2728 | case MBX_READ_SPARM: |
| 2729 | case MBX_READ_STATUS: |
| 2730 | case MBX_READ_RPI: |
| 2731 | case MBX_READ_XRI: |
| 2732 | case MBX_READ_REV: |
| 2733 | case MBX_READ_LNK_STAT: |
| 2734 | case MBX_REG_LOGIN: |
| 2735 | case MBX_UNREG_LOGIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2736 | case MBX_CLEAR_LA: |
| 2737 | case MBX_DUMP_MEMORY: |
| 2738 | case MBX_DUMP_CONTEXT: |
| 2739 | case MBX_RUN_DIAGS: |
| 2740 | case MBX_RESTART: |
| 2741 | case MBX_UPDATE_CFG: |
| 2742 | case MBX_DOWN_LOAD: |
| 2743 | case MBX_DEL_LD_ENTRY: |
| 2744 | case MBX_RUN_PROGRAM: |
| 2745 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2746 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2747 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2748 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2749 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2750 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2751 | case MBX_LOAD_AREA: |
| 2752 | case MBX_RUN_BIU_DIAG64: |
| 2753 | case MBX_CONFIG_PORT: |
| 2754 | case MBX_READ_SPARM64: |
| 2755 | case MBX_READ_RPI64: |
| 2756 | case MBX_REG_LOGIN64: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2757 | case MBX_READ_TOPOLOGY: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2758 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2759 | case MBX_SET_DEBUG: |
| 2760 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2761 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2762 | case MBX_REG_VPI: |
| 2763 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2764 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2765 | case MBX_PORT_CAPABILITIES: |
| 2766 | case MBX_PORT_IOV_CONTROL: |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2767 | case MBX_SLI4_CONFIG: |
| 2768 | case MBX_SLI4_REQ_FTRS: |
| 2769 | case MBX_REG_FCFI: |
| 2770 | case MBX_UNREG_FCFI: |
| 2771 | case MBX_REG_VFI: |
| 2772 | case MBX_UNREG_VFI: |
| 2773 | case MBX_INIT_VPI: |
| 2774 | case MBX_INIT_VFI: |
| 2775 | case MBX_RESUME_RPI: |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 2776 | case MBX_READ_EVENT_LOG_STATUS: |
| 2777 | case MBX_READ_EVENT_LOG: |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2778 | case MBX_SECURITY_MGMT: |
| 2779 | case MBX_AUTH_PORT: |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 2780 | case MBX_ACCESS_VDATA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2781 | ret = mbxCommand; |
| 2782 | break; |
| 2783 | default: |
| 2784 | ret = MBX_SHUTDOWN; |
| 2785 | break; |
| 2786 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2787 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2788 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2789 | |
| 2790 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2791 | * 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] | 2792 | * @phba: Pointer to HBA context object. |
| 2793 | * @pmboxq: Pointer to mailbox command. |
| 2794 | * |
| 2795 | * This is completion handler function for mailbox commands issued from |
| 2796 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 2797 | * mailbox event handler function with no lock held. This function |
| 2798 | * will wake up thread waiting on the wait queue pointed by context1 |
| 2799 | * of the mailbox. |
| 2800 | **/ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2801 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2802 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2803 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2804 | unsigned long drvr_flag; |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2805 | struct completion *pmbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2806 | |
| 2807 | /* |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2808 | * If pmbox_done is empty, the driver thread gave up waiting and |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2809 | * continued running. |
| 2810 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2811 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2812 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2813 | pmbox_done = (struct completion *)pmboxq->context3; |
| 2814 | if (pmbox_done) |
| 2815 | complete(pmbox_done); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2816 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2817 | return; |
| 2818 | } |
| 2819 | |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 2820 | static void |
| 2821 | __lpfc_sli_rpi_release(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 2822 | { |
| 2823 | unsigned long iflags; |
| 2824 | |
| 2825 | if (ndlp->nlp_flag & NLP_RELEASE_RPI) { |
| 2826 | lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi); |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2827 | spin_lock_irqsave(&ndlp->lock, iflags); |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 2828 | ndlp->nlp_flag &= ~NLP_RELEASE_RPI; |
| 2829 | ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2830 | spin_unlock_irqrestore(&ndlp->lock, iflags); |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 2831 | } |
| 2832 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
| 2833 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2834 | |
| 2835 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2836 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2837 | * @phba: Pointer to HBA context object. |
| 2838 | * @pmb: Pointer to mailbox object. |
| 2839 | * |
| 2840 | * This function is the default mailbox completion handler. It |
| 2841 | * frees the memory resources associated with the completed mailbox |
| 2842 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 2843 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 2844 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2845 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2846 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2847 | { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2848 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2849 | struct lpfc_dmabuf *mp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2850 | struct lpfc_nodelist *ndlp; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2851 | struct Scsi_Host *shost; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2852 | uint16_t rpi, vpi; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2853 | int rc; |
| 2854 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2855 | mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2856 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2857 | if (mp) { |
| 2858 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2859 | kfree(mp); |
| 2860 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2861 | |
| 2862 | /* |
| 2863 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 2864 | * is in re-discovery driver need to cleanup the RPI. |
| 2865 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2866 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2867 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
| 2868 | !pmb->u.mb.mbxStatus) { |
| 2869 | rpi = pmb->u.mb.un.varWords[0]; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2870 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
James Smart | 3850394 | 2020-03-22 11:12:53 -0700 | [diff] [blame] | 2871 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2872 | vpi -= phba->sli4_hba.max_cfg_param.vpi_base; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2873 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
James Smart | de96e9c | 2016-03-31 14:12:27 -0700 | [diff] [blame] | 2874 | pmb->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2875 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2876 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2877 | if (rc != MBX_NOT_FINISHED) |
| 2878 | return; |
| 2879 | } |
| 2880 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2881 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
| 2882 | !(phba->pport->load_flag & FC_UNLOADING) && |
| 2883 | !pmb->u.mb.mbxStatus) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2884 | shost = lpfc_shost_from_vport(vport); |
| 2885 | spin_lock_irq(shost->host_lock); |
| 2886 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
| 2887 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 2888 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2889 | } |
| 2890 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2891 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2892 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2893 | lpfc_nlp_put(ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2894 | pmb->ctx_buf = NULL; |
| 2895 | pmb->ctx_ndlp = NULL; |
| 2896 | } |
| 2897 | |
| 2898 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { |
| 2899 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
| 2900 | |
| 2901 | /* Check to see if there are any deferred events to process */ |
| 2902 | if (ndlp) { |
| 2903 | lpfc_printf_vlog( |
| 2904 | vport, |
| 2905 | KERN_INFO, LOG_MBOX | LOG_DISCOVERY, |
| 2906 | "1438 UNREG cmpl deferred mbox x%x " |
James Smart | f115612 | 2021-04-11 18:31:24 -0700 | [diff] [blame] | 2907 | "on NPort x%x Data: x%x x%x x%px x%x x%x\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2908 | ndlp->nlp_rpi, ndlp->nlp_DID, |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 2909 | ndlp->nlp_flag, ndlp->nlp_defer_did, |
| 2910 | ndlp, vport->load_flag, kref_read(&ndlp->kref)); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2911 | |
| 2912 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && |
| 2913 | (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) { |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2914 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2915 | ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING; |
| 2916 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2917 | } else { |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 2918 | __lpfc_sli_rpi_release(vport, ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2919 | } |
James Smart | a70e63e | 2020-11-15 11:26:38 -0800 | [diff] [blame] | 2920 | |
| 2921 | /* The unreg_login mailbox is complete and had a |
| 2922 | * reference that has to be released. The PLOGI |
| 2923 | * got its own ref. |
| 2924 | */ |
| 2925 | lpfc_nlp_put(ndlp); |
James Smart | 9b16406 | 2019-03-12 16:30:06 -0700 | [diff] [blame] | 2926 | pmb->ctx_ndlp = NULL; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2927 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2928 | } |
| 2929 | |
James Smart | 1037e4b | 2021-05-14 12:55:52 -0700 | [diff] [blame] | 2930 | /* This nlp_put pairs with lpfc_sli4_resume_rpi */ |
| 2931 | if (pmb->u.mb.mbxCommand == MBX_RESUME_RPI) { |
| 2932 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
| 2933 | lpfc_nlp_put(ndlp); |
| 2934 | } |
| 2935 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2936 | /* Check security permission status on INIT_LINK mailbox command */ |
| 2937 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && |
| 2938 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2939 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2940 | "2860 SLI authentication is required " |
| 2941 | "for INIT_LINK but has not done yet\n"); |
| 2942 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2943 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
| 2944 | lpfc_sli4_mbox_cmd_free(phba, pmb); |
| 2945 | else |
| 2946 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2947 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2948 | /** |
| 2949 | * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler |
| 2950 | * @phba: Pointer to HBA context object. |
| 2951 | * @pmb: Pointer to mailbox object. |
| 2952 | * |
| 2953 | * This function is the unreg rpi mailbox completion handler. It |
| 2954 | * frees the memory resources associated with the completed mailbox |
James Smart | a70e63e | 2020-11-15 11:26:38 -0800 | [diff] [blame] | 2955 | * command. An additional reference is put on the ndlp to prevent |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2956 | * lpfc_nlp_release from freeing the rpi bit in the bitmask before |
| 2957 | * the unreg mailbox command completes, this routine puts the |
| 2958 | * reference back. |
| 2959 | * |
| 2960 | **/ |
| 2961 | void |
| 2962 | lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2963 | { |
| 2964 | struct lpfc_vport *vport = pmb->vport; |
| 2965 | struct lpfc_nodelist *ndlp; |
| 2966 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2967 | ndlp = pmb->ctx_ndlp; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2968 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { |
| 2969 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 2970 | (bf_get(lpfc_sli_intf_if_type, |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 2971 | &phba->sli4_hba.sli_intf) >= |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2972 | LPFC_SLI_INTF_IF_TYPE_2)) { |
| 2973 | if (ndlp) { |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2974 | lpfc_printf_vlog( |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 2975 | vport, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2976 | "0010 UNREG_LOGIN vpi:%x " |
| 2977 | "rpi:%x DID:%x defer x%x flg x%x " |
James Smart | f115612 | 2021-04-11 18:31:24 -0700 | [diff] [blame] | 2978 | "x%px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2979 | vport->vpi, ndlp->nlp_rpi, |
| 2980 | ndlp->nlp_DID, ndlp->nlp_defer_did, |
| 2981 | ndlp->nlp_flag, |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 2982 | ndlp); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 2983 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2984 | |
| 2985 | /* Check to see if there are any deferred |
| 2986 | * events to process |
| 2987 | */ |
| 2988 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && |
| 2989 | (ndlp->nlp_defer_did != |
| 2990 | NLP_EVT_NOTHING_PENDING)) { |
| 2991 | lpfc_printf_vlog( |
| 2992 | vport, KERN_INFO, LOG_DISCOVERY, |
| 2993 | "4111 UNREG cmpl deferred " |
| 2994 | "clr x%x on " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 2995 | "NPort x%x Data: x%x x%px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2996 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 2997 | ndlp->nlp_defer_did, ndlp); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2998 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2999 | ndlp->nlp_defer_did = |
| 3000 | NLP_EVT_NOTHING_PENDING; |
| 3001 | lpfc_issue_els_plogi( |
| 3002 | vport, ndlp->nlp_DID, 0); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 3003 | } else { |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 3004 | __lpfc_sli_rpi_release(vport, ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 3005 | } |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 3006 | lpfc_nlp_put(ndlp); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3007 | } |
| 3008 | } |
| 3009 | } |
| 3010 | |
| 3011 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3012 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3013 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3014 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3015 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3016 | * @phba: Pointer to HBA context object. |
| 3017 | * |
| 3018 | * This function is called with no lock held. This function processes all |
| 3019 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 3020 | * service routine processes mailbox completion interrupt and adds completed |
| 3021 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 3022 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 3023 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 3024 | * function returns the mailbox commands to the upper layer by calling the |
| 3025 | * completion handler function of each mailbox. |
| 3026 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3027 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3028 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3029 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3030 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3031 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3032 | int rc; |
| 3033 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3034 | |
| 3035 | phba->sli.slistat.mbox_event++; |
| 3036 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3037 | /* Get all completed mailboxe buffers into the cmplq */ |
| 3038 | spin_lock_irq(&phba->hbalock); |
| 3039 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 3040 | spin_unlock_irq(&phba->hbalock); |
| 3041 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3042 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3043 | do { |
| 3044 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 3045 | if (pmb == NULL) |
| 3046 | break; |
| 3047 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3048 | pmbox = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3049 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3050 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 3051 | if (pmb->vport) { |
| 3052 | lpfc_debugfs_disc_trc(pmb->vport, |
| 3053 | LPFC_DISC_TRC_MBOX_VPORT, |
| 3054 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 3055 | (uint32_t)pmbox->mbxCommand, |
| 3056 | pmbox->un.varWords[0], |
| 3057 | pmbox->un.varWords[1]); |
| 3058 | } |
| 3059 | else { |
| 3060 | lpfc_debugfs_disc_trc(phba->pport, |
| 3061 | LPFC_DISC_TRC_MBOX, |
| 3062 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 3063 | (uint32_t)pmbox->mbxCommand, |
| 3064 | pmbox->un.varWords[0], |
| 3065 | pmbox->un.varWords[1]); |
| 3066 | } |
| 3067 | } |
| 3068 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3069 | /* |
| 3070 | * It is a fatal error if unknown mbox command completion. |
| 3071 | */ |
| 3072 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 3073 | MBX_SHUTDOWN) { |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 3074 | /* Unknown mailbox command compl */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3075 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3076 | "(%d):0323 Unknown Mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 3077 | "x%x (x%x/x%x) Cmpl\n", |
James Smart | 43bfea1 | 2019-09-21 20:58:57 -0700 | [diff] [blame] | 3078 | pmb->vport ? pmb->vport->vpi : |
| 3079 | LPFC_VPORT_UNKNOWN, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3080 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 3081 | lpfc_sli_config_mbox_subsys_get(phba, |
| 3082 | pmb), |
| 3083 | lpfc_sli_config_mbox_opcode_get(phba, |
| 3084 | pmb)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3085 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3086 | phba->work_hs = HS_FFER3; |
| 3087 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3088 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3089 | } |
| 3090 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3091 | if (pmbox->mbxStatus) { |
| 3092 | phba->sli.slistat.mbox_stat_err++; |
| 3093 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 3094 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3095 | lpfc_printf_log(phba, KERN_INFO, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 3096 | LOG_MBOX | LOG_SLI, |
| 3097 | "(%d):0305 Mbox cmd cmpl " |
| 3098 | "error - RETRYing Data: x%x " |
| 3099 | "(x%x/x%x) x%x x%x x%x\n", |
James Smart | 43bfea1 | 2019-09-21 20:58:57 -0700 | [diff] [blame] | 3100 | pmb->vport ? pmb->vport->vpi : |
| 3101 | LPFC_VPORT_UNKNOWN, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 3102 | pmbox->mbxCommand, |
| 3103 | lpfc_sli_config_mbox_subsys_get(phba, |
| 3104 | pmb), |
| 3105 | lpfc_sli_config_mbox_opcode_get(phba, |
| 3106 | pmb), |
| 3107 | pmbox->mbxStatus, |
| 3108 | pmbox->un.varWords[0], |
James Smart | 43bfea1 | 2019-09-21 20:58:57 -0700 | [diff] [blame] | 3109 | pmb->vport ? pmb->vport->port_state : |
| 3110 | LPFC_VPORT_UNKNOWN); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3111 | pmbox->mbxStatus = 0; |
| 3112 | pmbox->mbxOwner = OWN_HOST; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3113 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3114 | if (rc != MBX_NOT_FINISHED) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3115 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3116 | } |
| 3117 | } |
| 3118 | |
| 3119 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3120 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
Sakari Ailus | 2d44d16 | 2019-09-04 19:04:23 +0300 | [diff] [blame] | 3121 | "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl %ps " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 3122 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 3123 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3124 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3125 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 3126 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
| 3127 | lpfc_sli_config_mbox_opcode_get(phba, pmb), |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3128 | pmb->mbox_cmpl, |
| 3129 | *((uint32_t *) pmbox), |
| 3130 | pmbox->un.varWords[0], |
| 3131 | pmbox->un.varWords[1], |
| 3132 | pmbox->un.varWords[2], |
| 3133 | pmbox->un.varWords[3], |
| 3134 | pmbox->un.varWords[4], |
| 3135 | pmbox->un.varWords[5], |
| 3136 | pmbox->un.varWords[6], |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 3137 | pmbox->un.varWords[7], |
| 3138 | pmbox->un.varWords[8], |
| 3139 | pmbox->un.varWords[9], |
| 3140 | pmbox->un.varWords[10]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3141 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3142 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3143 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3144 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3145 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3146 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3147 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3148 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3149 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3150 | * @phba: Pointer to HBA context object. |
| 3151 | * @pring: Pointer to driver SLI ring object. |
| 3152 | * @tag: buffer tag. |
| 3153 | * |
| 3154 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 3155 | * is set in the tag the buffer is posted for a particular exchange, |
| 3156 | * the function will return the buffer without replacing the buffer. |
| 3157 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 3158 | * returns the buffer and also posts another buffer to the firmware. |
| 3159 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3160 | static struct lpfc_dmabuf * |
| 3161 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 3162 | struct lpfc_sli_ring *pring, |
| 3163 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3164 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 3165 | struct hbq_dmabuf *hbq_entry; |
| 3166 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3167 | if (tag & QUE_BUFTAG_BIT) |
| 3168 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 3169 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 3170 | if (!hbq_entry) |
| 3171 | return NULL; |
| 3172 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3173 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3174 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3175 | /** |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 3176 | * lpfc_nvme_unsol_ls_handler - Process an unsolicited event data buffer |
| 3177 | * containing a NVME LS request. |
| 3178 | * @phba: pointer to lpfc hba data structure. |
| 3179 | * @piocb: pointer to the iocbq struct representing the sequence starting |
| 3180 | * frame. |
| 3181 | * |
| 3182 | * This routine initially validates the NVME LS, validates there is a login |
| 3183 | * with the port that sent the LS, and then calls the appropriate nvme host |
| 3184 | * or target LS request handler. |
| 3185 | **/ |
| 3186 | static void |
| 3187 | lpfc_nvme_unsol_ls_handler(struct lpfc_hba *phba, struct lpfc_iocbq *piocb) |
| 3188 | { |
| 3189 | struct lpfc_nodelist *ndlp; |
| 3190 | struct lpfc_dmabuf *d_buf; |
| 3191 | struct hbq_dmabuf *nvmebuf; |
| 3192 | struct fc_frame_header *fc_hdr; |
| 3193 | struct lpfc_async_xchg_ctx *axchg = NULL; |
| 3194 | char *failwhy = NULL; |
| 3195 | uint32_t oxid, sid, did, fctl, size; |
James Smart | 4e57e0b | 2020-05-20 11:59:28 -0700 | [diff] [blame] | 3196 | int ret = 1; |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 3197 | |
| 3198 | d_buf = piocb->context2; |
| 3199 | |
| 3200 | nvmebuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 3201 | fc_hdr = nvmebuf->hbuf.virt; |
| 3202 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
| 3203 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 3204 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 3205 | fctl = (fc_hdr->fh_f_ctl[0] << 16 | |
| 3206 | fc_hdr->fh_f_ctl[1] << 8 | |
| 3207 | fc_hdr->fh_f_ctl[2]); |
| 3208 | size = bf_get(lpfc_rcqe_length, &nvmebuf->cq_event.cqe.rcqe_cmpl); |
| 3209 | |
| 3210 | lpfc_nvmeio_data(phba, "NVME LS RCV: xri x%x sz %d from %06x\n", |
| 3211 | oxid, size, sid); |
| 3212 | |
| 3213 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 3214 | failwhy = "Driver Unloading"; |
| 3215 | } else if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) { |
| 3216 | failwhy = "NVME FC4 Disabled"; |
| 3217 | } else if (!phba->nvmet_support && !phba->pport->localport) { |
| 3218 | failwhy = "No Localport"; |
| 3219 | } else if (phba->nvmet_support && !phba->targetport) { |
| 3220 | failwhy = "No Targetport"; |
| 3221 | } else if (unlikely(fc_hdr->fh_r_ctl != FC_RCTL_ELS4_REQ)) { |
| 3222 | failwhy = "Bad NVME LS R_CTL"; |
| 3223 | } else if (unlikely((fctl & 0x00FF0000) != |
| 3224 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT))) { |
| 3225 | failwhy = "Bad NVME LS F_CTL"; |
| 3226 | } else { |
| 3227 | axchg = kzalloc(sizeof(*axchg), GFP_ATOMIC); |
| 3228 | if (!axchg) |
| 3229 | failwhy = "No CTX memory"; |
| 3230 | } |
| 3231 | |
| 3232 | if (unlikely(failwhy)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3233 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 3234 | "6154 Drop NVME LS: SID %06X OXID x%X: %s\n", |
| 3235 | sid, oxid, failwhy); |
| 3236 | goto out_fail; |
| 3237 | } |
| 3238 | |
| 3239 | /* validate the source of the LS is logged in */ |
| 3240 | ndlp = lpfc_findnode_did(phba->pport, sid); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3241 | if (!ndlp || |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 3242 | ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 3243 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) { |
| 3244 | lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC, |
| 3245 | "6216 NVME Unsol rcv: No ndlp: " |
| 3246 | "NPort_ID x%x oxid x%x\n", |
| 3247 | sid, oxid); |
| 3248 | goto out_fail; |
| 3249 | } |
| 3250 | |
| 3251 | axchg->phba = phba; |
| 3252 | axchg->ndlp = ndlp; |
| 3253 | axchg->size = size; |
| 3254 | axchg->oxid = oxid; |
| 3255 | axchg->sid = sid; |
| 3256 | axchg->wqeq = NULL; |
| 3257 | axchg->state = LPFC_NVME_STE_LS_RCV; |
| 3258 | axchg->entry_cnt = 1; |
| 3259 | axchg->rqb_buffer = (void *)nvmebuf; |
| 3260 | axchg->hdwq = &phba->sli4_hba.hdwq[0]; |
| 3261 | axchg->payload = nvmebuf->dbuf.virt; |
| 3262 | INIT_LIST_HEAD(&axchg->list); |
| 3263 | |
James Smart | 243156c | 2021-01-04 10:02:37 -0800 | [diff] [blame] | 3264 | if (phba->nvmet_support) { |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 3265 | ret = lpfc_nvmet_handle_lsreq(phba, axchg); |
James Smart | 243156c | 2021-01-04 10:02:37 -0800 | [diff] [blame] | 3266 | spin_lock_irq(&ndlp->lock); |
| 3267 | if (!ret && !(ndlp->fc4_xpt_flags & NLP_XPT_HAS_HH)) { |
| 3268 | ndlp->fc4_xpt_flags |= NLP_XPT_HAS_HH; |
| 3269 | spin_unlock_irq(&ndlp->lock); |
| 3270 | |
| 3271 | /* This reference is a single occurrence to hold the |
| 3272 | * node valid until the nvmet transport calls |
| 3273 | * host_release. |
| 3274 | */ |
| 3275 | if (!lpfc_nlp_get(ndlp)) |
| 3276 | goto out_fail; |
| 3277 | |
| 3278 | lpfc_printf_log(phba, KERN_ERR, LOG_NODE, |
James Smart | f115612 | 2021-04-11 18:31:24 -0700 | [diff] [blame] | 3279 | "6206 NVMET unsol ls_req ndlp x%px " |
James Smart | 243156c | 2021-01-04 10:02:37 -0800 | [diff] [blame] | 3280 | "DID x%x xflags x%x refcnt %d\n", |
| 3281 | ndlp, ndlp->nlp_DID, |
| 3282 | ndlp->fc4_xpt_flags, |
| 3283 | kref_read(&ndlp->kref)); |
| 3284 | } else { |
| 3285 | spin_unlock_irq(&ndlp->lock); |
| 3286 | } |
| 3287 | } else { |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 3288 | ret = lpfc_nvme_handle_lsreq(phba, axchg); |
James Smart | 243156c | 2021-01-04 10:02:37 -0800 | [diff] [blame] | 3289 | } |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 3290 | |
| 3291 | /* if zero, LS was successfully handled. If non-zero, LS not handled */ |
| 3292 | if (!ret) |
| 3293 | return; |
| 3294 | |
James Smart | 243156c | 2021-01-04 10:02:37 -0800 | [diff] [blame] | 3295 | out_fail: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3296 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 3297 | "6155 Drop NVME LS from DID %06X: SID %06X OXID x%X " |
| 3298 | "NVMe%s handler failed %d\n", |
| 3299 | did, sid, oxid, |
| 3300 | (phba->nvmet_support) ? "T" : "I", ret); |
| 3301 | |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 3302 | /* recycle receive buffer */ |
| 3303 | lpfc_in_buf_free(phba, &nvmebuf->dbuf); |
| 3304 | |
| 3305 | /* If start of new exchange, abort it */ |
James Smart | 4e57e0b | 2020-05-20 11:59:28 -0700 | [diff] [blame] | 3306 | if (axchg && (fctl & FC_FC_FIRST_SEQ && !(fctl & FC_FC_EX_CTX))) |
| 3307 | ret = lpfc_nvme_unsol_ls_issue_abort(phba, axchg, sid, oxid); |
| 3308 | |
| 3309 | if (ret) |
| 3310 | kfree(axchg); |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 3311 | } |
| 3312 | |
| 3313 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3314 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence |
| 3315 | * @phba: Pointer to HBA context object. |
| 3316 | * @pring: Pointer to driver SLI ring object. |
| 3317 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. |
| 3318 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. |
| 3319 | * @fch_type: the type for the first frame of the sequence. |
| 3320 | * |
| 3321 | * This function is called with no lock held. This function uses the r_ctl and |
| 3322 | * type of the received sequence to find the correct callback function to call |
| 3323 | * to process the sequence. |
| 3324 | **/ |
| 3325 | static int |
| 3326 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3327 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, |
| 3328 | uint32_t fch_type) |
| 3329 | { |
| 3330 | int i; |
| 3331 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3332 | switch (fch_type) { |
| 3333 | case FC_TYPE_NVME: |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 3334 | lpfc_nvme_unsol_ls_handler(phba, saveq); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3335 | return 1; |
| 3336 | default: |
| 3337 | break; |
| 3338 | } |
| 3339 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3340 | /* unSolicited Responses */ |
| 3341 | if (pring->prt[0].profile) { |
| 3342 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 3343 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 3344 | saveq); |
| 3345 | return 1; |
| 3346 | } |
| 3347 | /* We must search, based on rctl / type |
| 3348 | for the right routine */ |
| 3349 | for (i = 0; i < pring->num_mask; i++) { |
| 3350 | if ((pring->prt[i].rctl == fch_r_ctl) && |
| 3351 | (pring->prt[i].type == fch_type)) { |
| 3352 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 3353 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 3354 | (phba, pring, saveq); |
| 3355 | return 1; |
| 3356 | } |
| 3357 | } |
| 3358 | return 0; |
| 3359 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3360 | |
| 3361 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3362 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3363 | * @phba: Pointer to HBA context object. |
| 3364 | * @pring: Pointer to driver SLI ring object. |
| 3365 | * @saveq: Pointer to the unsolicited iocb. |
| 3366 | * |
| 3367 | * This function is called with no lock held by the ring event handler |
| 3368 | * when there is an unsolicited iocb posted to the response ring by the |
| 3369 | * firmware. This function gets the buffer associated with the iocbs |
| 3370 | * and calls the event handler for the ring. This function handles both |
| 3371 | * qring buffers and hbq buffers. |
| 3372 | * When the function returns 1 the caller can free the iocb object otherwise |
| 3373 | * upper layer functions will free the iocb objects. |
| 3374 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3375 | static int |
| 3376 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3377 | struct lpfc_iocbq *saveq) |
| 3378 | { |
| 3379 | IOCB_t * irsp; |
| 3380 | WORD5 * w5p; |
| 3381 | uint32_t Rctl, Type; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3382 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3383 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3384 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3385 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3386 | |
| 3387 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 3388 | if (pring->lpfc_sli_rcv_async_status) |
| 3389 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 3390 | else |
| 3391 | lpfc_printf_log(phba, |
| 3392 | KERN_WARNING, |
| 3393 | LOG_SLI, |
| 3394 | "0316 Ring %d handler: unexpected " |
| 3395 | "ASYNC_STATUS iocb received evt_code " |
| 3396 | "0x%x\n", |
| 3397 | pring->ringno, |
| 3398 | irsp->un.asyncstat.evt_code); |
| 3399 | return 1; |
| 3400 | } |
| 3401 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3402 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 3403 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 3404 | if (irsp->ulpBdeCount > 0) { |
| 3405 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 3406 | irsp->un.ulpWord[3]); |
| 3407 | lpfc_in_buf_free(phba, dmzbuf); |
| 3408 | } |
| 3409 | |
| 3410 | if (irsp->ulpBdeCount > 1) { |
| 3411 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 3412 | irsp->unsli3.sli3Words[3]); |
| 3413 | lpfc_in_buf_free(phba, dmzbuf); |
| 3414 | } |
| 3415 | |
| 3416 | if (irsp->ulpBdeCount > 2) { |
| 3417 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 3418 | irsp->unsli3.sli3Words[7]); |
| 3419 | lpfc_in_buf_free(phba, dmzbuf); |
| 3420 | } |
| 3421 | |
| 3422 | return 1; |
| 3423 | } |
| 3424 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3425 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3426 | if (irsp->ulpBdeCount != 0) { |
| 3427 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3428 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3429 | if (!saveq->context2) |
| 3430 | lpfc_printf_log(phba, |
| 3431 | KERN_ERR, |
| 3432 | LOG_SLI, |
| 3433 | "0341 Ring %d Cannot find buffer for " |
| 3434 | "an unsolicited iocb. tag 0x%x\n", |
| 3435 | pring->ringno, |
| 3436 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3437 | } |
| 3438 | if (irsp->ulpBdeCount == 2) { |
| 3439 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3440 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3441 | if (!saveq->context3) |
| 3442 | lpfc_printf_log(phba, |
| 3443 | KERN_ERR, |
| 3444 | LOG_SLI, |
| 3445 | "0342 Ring %d Cannot find buffer for an" |
| 3446 | " unsolicited iocb. tag 0x%x\n", |
| 3447 | pring->ringno, |
| 3448 | irsp->unsli3.sli3Words[7]); |
| 3449 | } |
| 3450 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3451 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3452 | if (irsp->ulpBdeCount != 0) { |
| 3453 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 3454 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 3455 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3456 | lpfc_printf_log(phba, |
| 3457 | KERN_ERR, |
| 3458 | LOG_SLI, |
| 3459 | "0343 Ring %d Cannot find " |
| 3460 | "buffer for an unsolicited iocb" |
| 3461 | ". tag 0x%x\n", pring->ringno, |
| 3462 | irsp->un.ulpWord[3]); |
| 3463 | } |
| 3464 | if (irsp->ulpBdeCount == 2) { |
| 3465 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 3466 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 3467 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3468 | lpfc_printf_log(phba, |
| 3469 | KERN_ERR, |
| 3470 | LOG_SLI, |
| 3471 | "0344 Ring %d Cannot find " |
| 3472 | "buffer for an unsolicited " |
| 3473 | "iocb. tag 0x%x\n", |
| 3474 | pring->ringno, |
| 3475 | irsp->unsli3.sli3Words[7]); |
| 3476 | } |
| 3477 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3478 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 3479 | if (irsp->ulpBdeCount != 0 && |
| 3480 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 3481 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 3482 | int found = 0; |
| 3483 | |
| 3484 | /* search continue save q for same XRI */ |
| 3485 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3486 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
| 3487 | saveq->iocb.unsli3.rcvsli3.ox_id) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 3488 | list_add_tail(&saveq->list, &iocbq->list); |
| 3489 | found = 1; |
| 3490 | break; |
| 3491 | } |
| 3492 | } |
| 3493 | if (!found) |
| 3494 | list_add_tail(&saveq->clist, |
| 3495 | &pring->iocb_continue_saveq); |
| 3496 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 3497 | list_del_init(&iocbq->clist); |
| 3498 | saveq = iocbq; |
| 3499 | irsp = &(saveq->iocb); |
| 3500 | } else |
| 3501 | return 0; |
| 3502 | } |
| 3503 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 3504 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 3505 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3506 | Rctl = FC_RCTL_ELS_REQ; |
| 3507 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 3508 | } else { |
| 3509 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 3510 | Rctl = w5p->hcsw.Rctl; |
| 3511 | Type = w5p->hcsw.Type; |
| 3512 | |
| 3513 | /* Firmware Workaround */ |
| 3514 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 3515 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 3516 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3517 | Rctl = FC_RCTL_ELS_REQ; |
| 3518 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 3519 | w5p->hcsw.Rctl = Rctl; |
| 3520 | w5p->hcsw.Type = Type; |
| 3521 | } |
| 3522 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3523 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3524 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3525 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3526 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3527 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3528 | pring->ringno, Rctl, Type); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3529 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3530 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3531 | } |
| 3532 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3533 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3534 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3535 | * @phba: Pointer to HBA context object. |
| 3536 | * @pring: Pointer to driver SLI ring object. |
| 3537 | * @prspiocb: Pointer to response iocb object. |
| 3538 | * |
| 3539 | * This function looks up the iocb_lookup table to get the command iocb |
| 3540 | * corresponding to the given response iocb using the iotag of the |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3541 | * response iocb. The driver calls this function with the hbalock held |
| 3542 | * for SLI3 ports or the ring lock held for SLI4 ports. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3543 | * This function returns the command iocb object if it finds the command |
| 3544 | * iocb else returns NULL. |
| 3545 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3546 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3547 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 3548 | struct lpfc_sli_ring *pring, |
| 3549 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3550 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3551 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 3552 | uint16_t iotag; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3553 | spinlock_t *temp_lock = NULL; |
| 3554 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3555 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3556 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3557 | temp_lock = &pring->ring_lock; |
| 3558 | else |
| 3559 | temp_lock = &phba->hbalock; |
| 3560 | |
| 3561 | spin_lock_irqsave(temp_lock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3562 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3563 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3564 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 3565 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3566 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3567 | /* remove from txcmpl queue list */ |
| 3568 | list_del_init(&cmd_iocb->list); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3569 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3570 | pring->txcmplq_cnt--; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3571 | spin_unlock_irqrestore(temp_lock, iflag); |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3572 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 3573 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3574 | } |
| 3575 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3576 | spin_unlock_irqrestore(temp_lock, iflag); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3577 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3578 | "0317 iotag x%x is out of " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3579 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3580 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3581 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3582 | return NULL; |
| 3583 | } |
| 3584 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3585 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3586 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag |
| 3587 | * @phba: Pointer to HBA context object. |
| 3588 | * @pring: Pointer to driver SLI ring object. |
| 3589 | * @iotag: IOCB tag. |
| 3590 | * |
| 3591 | * 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] | 3592 | * corresponding to the given iotag. The driver calls this function with |
| 3593 | * 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] | 3594 | * This function returns the command iocb object if it finds the command |
| 3595 | * iocb else returns NULL. |
| 3596 | **/ |
| 3597 | static struct lpfc_iocbq * |
| 3598 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, |
| 3599 | struct lpfc_sli_ring *pring, uint16_t iotag) |
| 3600 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3601 | struct lpfc_iocbq *cmd_iocb = NULL; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3602 | spinlock_t *temp_lock = NULL; |
| 3603 | unsigned long iflag = 0; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3604 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3605 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3606 | temp_lock = &pring->ring_lock; |
| 3607 | else |
| 3608 | temp_lock = &phba->hbalock; |
| 3609 | |
| 3610 | spin_lock_irqsave(temp_lock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3611 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 3612 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3613 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
| 3614 | /* remove from txcmpl queue list */ |
| 3615 | list_del_init(&cmd_iocb->list); |
| 3616 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3617 | pring->txcmplq_cnt--; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3618 | spin_unlock_irqrestore(temp_lock, iflag); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3619 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 3620 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3621 | } |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3622 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3623 | spin_unlock_irqrestore(temp_lock, iflag); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3624 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3625 | "0372 iotag x%x lookup error: max iotag (x%x) " |
| 3626 | "iocb_flag x%x\n", |
| 3627 | iotag, phba->sli.last_iotag, |
| 3628 | cmd_iocb ? cmd_iocb->iocb_flag : 0xffff); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3629 | return NULL; |
| 3630 | } |
| 3631 | |
| 3632 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3633 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3634 | * @phba: Pointer to HBA context object. |
| 3635 | * @pring: Pointer to driver SLI ring object. |
| 3636 | * @saveq: Pointer to the response iocb to be processed. |
| 3637 | * |
| 3638 | * This function is called by the ring event handler for non-fcp |
| 3639 | * rings when there is a new response iocb in the response ring. |
| 3640 | * The caller is not required to hold any locks. This function |
| 3641 | * gets the command iocb associated with the response iocb and |
| 3642 | * calls the completion handler for the command iocb. If there |
| 3643 | * is no completion handler, the function will free the resources |
| 3644 | * associated with command iocb. If the response iocb is for |
| 3645 | * an already aborted command iocb, the status of the completion |
| 3646 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 3647 | * This function always returns 1. |
| 3648 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3649 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3650 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3651 | struct lpfc_iocbq *saveq) |
| 3652 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3653 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3654 | int rc = 1; |
| 3655 | unsigned long iflag; |
| 3656 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3657 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3658 | if (cmdiocbp) { |
| 3659 | if (cmdiocbp->iocb_cmpl) { |
| 3660 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3661 | * If an ELS command failed send an event to mgmt |
| 3662 | * application. |
| 3663 | */ |
| 3664 | if (saveq->iocb.ulpStatus && |
| 3665 | (pring->ringno == LPFC_ELS_RING) && |
| 3666 | (cmdiocbp->iocb.ulpCommand == |
| 3667 | CMD_ELS_REQUEST64_CR)) |
| 3668 | lpfc_send_els_failure_event(phba, |
| 3669 | cmdiocbp, saveq); |
| 3670 | |
| 3671 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3672 | * Post all ELS completions to the worker thread. |
| 3673 | * All other are passed to the completion callback. |
| 3674 | */ |
| 3675 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3676 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 3677 | (cmdiocbp->iocb_flag & |
| 3678 | LPFC_DRIVER_ABORTED)) { |
| 3679 | spin_lock_irqsave(&phba->hbalock, |
| 3680 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3681 | cmdiocbp->iocb_flag &= |
| 3682 | ~LPFC_DRIVER_ABORTED; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3683 | spin_unlock_irqrestore(&phba->hbalock, |
| 3684 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3685 | saveq->iocb.ulpStatus = |
| 3686 | IOSTAT_LOCAL_REJECT; |
| 3687 | saveq->iocb.un.ulpWord[4] = |
| 3688 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3689 | |
| 3690 | /* Firmware could still be in progress |
| 3691 | * of DMAing payload, so don't free data |
| 3692 | * buffer till after a hbeat. |
| 3693 | */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3694 | spin_lock_irqsave(&phba->hbalock, |
| 3695 | iflag); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3696 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3697 | spin_unlock_irqrestore(&phba->hbalock, |
| 3698 | iflag); |
| 3699 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3700 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3701 | if (saveq->iocb_flag & |
| 3702 | LPFC_EXCHANGE_BUSY) { |
| 3703 | /* Set cmdiocb flag for the |
| 3704 | * exchange busy so sgl (xri) |
| 3705 | * will not be released until |
| 3706 | * the abort xri is received |
| 3707 | * from hba. |
| 3708 | */ |
| 3709 | spin_lock_irqsave( |
| 3710 | &phba->hbalock, iflag); |
| 3711 | cmdiocbp->iocb_flag |= |
| 3712 | LPFC_EXCHANGE_BUSY; |
| 3713 | spin_unlock_irqrestore( |
| 3714 | &phba->hbalock, iflag); |
| 3715 | } |
| 3716 | if (cmdiocbp->iocb_flag & |
| 3717 | LPFC_DRIVER_ABORTED) { |
| 3718 | /* |
| 3719 | * Clear LPFC_DRIVER_ABORTED |
| 3720 | * bit in case it was driver |
| 3721 | * initiated abort. |
| 3722 | */ |
| 3723 | spin_lock_irqsave( |
| 3724 | &phba->hbalock, iflag); |
| 3725 | cmdiocbp->iocb_flag &= |
| 3726 | ~LPFC_DRIVER_ABORTED; |
| 3727 | spin_unlock_irqrestore( |
| 3728 | &phba->hbalock, iflag); |
| 3729 | cmdiocbp->iocb.ulpStatus = |
| 3730 | IOSTAT_LOCAL_REJECT; |
| 3731 | cmdiocbp->iocb.un.ulpWord[4] = |
| 3732 | IOERR_ABORT_REQUESTED; |
| 3733 | /* |
| 3734 | * For SLI4, irsiocb contains |
| 3735 | * NO_XRI in sli_xritag, it |
| 3736 | * shall not affect releasing |
| 3737 | * sgl (xri) process. |
| 3738 | */ |
| 3739 | saveq->iocb.ulpStatus = |
| 3740 | IOSTAT_LOCAL_REJECT; |
| 3741 | saveq->iocb.un.ulpWord[4] = |
| 3742 | IOERR_SLI_ABORTED; |
| 3743 | spin_lock_irqsave( |
| 3744 | &phba->hbalock, iflag); |
| 3745 | saveq->iocb_flag |= |
| 3746 | LPFC_DELAY_MEM_FREE; |
| 3747 | spin_unlock_irqrestore( |
| 3748 | &phba->hbalock, iflag); |
| 3749 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3750 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3751 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3752 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3753 | } else |
| 3754 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3755 | } else { |
| 3756 | /* |
| 3757 | * Unknown initiating command based on the response iotag. |
| 3758 | * This could be the case on the ELS ring because of |
| 3759 | * lpfc_els_abort(). |
| 3760 | */ |
| 3761 | if (pring->ringno != LPFC_ELS_RING) { |
| 3762 | /* |
| 3763 | * Ring <ringno> handler: unexpected completion IoTag |
| 3764 | * <IoTag> |
| 3765 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3766 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3767 | "0322 Ring %d handler: " |
| 3768 | "unexpected completion IoTag x%x " |
| 3769 | "Data: x%x x%x x%x x%x\n", |
| 3770 | pring->ringno, |
| 3771 | saveq->iocb.ulpIoTag, |
| 3772 | saveq->iocb.ulpStatus, |
| 3773 | saveq->iocb.un.ulpWord[4], |
| 3774 | saveq->iocb.ulpCommand, |
| 3775 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3776 | } |
| 3777 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3778 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3779 | return rc; |
| 3780 | } |
| 3781 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3782 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3783 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3784 | * @phba: Pointer to HBA context object. |
| 3785 | * @pring: Pointer to driver SLI ring object. |
| 3786 | * |
| 3787 | * This function is called from the iocb ring event handlers when |
| 3788 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 3789 | * an error attention condition to the worker thread and the worker |
| 3790 | * thread will transition the HBA to offline state. |
| 3791 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3792 | static void |
| 3793 | 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] | 3794 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3795 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3796 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3797 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3798 | * rsp ring <portRspMax> |
| 3799 | */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3800 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3801 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3802 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3803 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3804 | pring->sli.sli3.numRiocb); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3805 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3806 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3807 | |
| 3808 | /* |
| 3809 | * All error attention handlers are posted to |
| 3810 | * worker thread |
| 3811 | */ |
| 3812 | phba->work_ha |= HA_ERATT; |
| 3813 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3814 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3815 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3816 | |
| 3817 | return; |
| 3818 | } |
| 3819 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3820 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3821 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 3822 | * @t: Context to fetch pointer to address of HBA context object from. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3823 | * |
| 3824 | * This function is invoked by the Error Attention polling timer when the |
| 3825 | * timer times out. It will check the SLI Error Attention register for |
| 3826 | * possible attention events. If so, it will post an Error Attention event |
| 3827 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 3828 | * Error Attention polling timer for the next poll. |
| 3829 | **/ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3830 | void lpfc_poll_eratt(struct timer_list *t) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3831 | { |
| 3832 | struct lpfc_hba *phba; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 3833 | uint32_t eratt = 0; |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3834 | uint64_t sli_intr, cnt; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3835 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3836 | phba = from_timer(phba, t, eratt_poll); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3837 | |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3838 | /* Here we will also keep track of interrupts per sec of the hba */ |
| 3839 | sli_intr = phba->sli.slistat.sli_intr; |
| 3840 | |
| 3841 | if (phba->sli.slistat.sli_prev_intr > sli_intr) |
| 3842 | cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) + |
| 3843 | sli_intr); |
| 3844 | else |
| 3845 | cnt = (sli_intr - phba->sli.slistat.sli_prev_intr); |
| 3846 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 3847 | /* 64-bit integer division not supported on 32-bit x86 - use do_div */ |
| 3848 | do_div(cnt, phba->eratt_poll_interval); |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3849 | phba->sli.slistat.sli_ips = cnt; |
| 3850 | |
| 3851 | phba->sli.slistat.sli_prev_intr = sli_intr; |
| 3852 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3853 | /* Check chip HA register for error event */ |
| 3854 | eratt = lpfc_sli_check_eratt(phba); |
| 3855 | |
| 3856 | if (eratt) |
| 3857 | /* Tell the worker thread there is work to do */ |
| 3858 | lpfc_worker_wake_up(phba); |
| 3859 | else |
| 3860 | /* Restart the timer for next eratt poll */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3861 | mod_timer(&phba->eratt_poll, |
| 3862 | jiffies + |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 3863 | msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3864 | return; |
| 3865 | } |
| 3866 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3867 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3868 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3869 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3870 | * @phba: Pointer to HBA context object. |
| 3871 | * @pring: Pointer to driver SLI ring object. |
| 3872 | * @mask: Host attention register mask for this ring. |
| 3873 | * |
| 3874 | * This function is called from the interrupt context when there is a ring |
| 3875 | * event for the fcp ring. The caller does not hold any lock. |
| 3876 | * 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] | 3877 | * 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] | 3878 | * LE bit set. The function will call the completion handler of the command iocb |
| 3879 | * if the response iocb indicates a completion for a command iocb or it is |
| 3880 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 3881 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3882 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3883 | * to check it explicitly. |
| 3884 | */ |
| 3885 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3886 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 3887 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3888 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3889 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3890 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3891 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3892 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 3893 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3894 | uint32_t status; |
| 3895 | uint32_t portRspPut, portRspMax; |
| 3896 | int rc = 1; |
| 3897 | lpfc_iocb_type type; |
| 3898 | unsigned long iflag; |
| 3899 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3900 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3901 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3902 | pring->stats.iocb_event++; |
| 3903 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3904 | /* |
| 3905 | * The next available response entry should never exceed the maximum |
| 3906 | * entries. If it does, treat it as an adapter hardware error. |
| 3907 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3908 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3909 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3910 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3911 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3912 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3913 | return 1; |
| 3914 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3915 | if (phba->fcp_ring_in_use) { |
| 3916 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3917 | return 1; |
| 3918 | } else |
| 3919 | phba->fcp_ring_in_use = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3920 | |
| 3921 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3922 | while (pring->sli.sli3.rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3923 | /* |
| 3924 | * Fetch an entry off the ring and copy it into a local data |
| 3925 | * structure. The copy involves a byte-swap since the |
| 3926 | * network byte order and pci byte orders are different. |
| 3927 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3928 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3929 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3930 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3931 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3932 | pring->sli.sli3.rspidx = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3933 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3934 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 3935 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3936 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3937 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3938 | irsp = &rspiocbq.iocb; |
| 3939 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3940 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 3941 | pring->stats.iocb_rsp++; |
| 3942 | rsp_cmpl++; |
| 3943 | |
| 3944 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3945 | /* |
| 3946 | * If resource errors reported from HBA, reduce |
| 3947 | * queuedepths of the SCSI device. |
| 3948 | */ |
| 3949 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3950 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3951 | IOERR_NO_RESOURCES)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3952 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3953 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3954 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3955 | } |
| 3956 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3957 | /* Rsp ring <ringno> error: IOCB */ |
| 3958 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3959 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3960 | "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] | 3961 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3962 | irsp->un.ulpWord[0], |
| 3963 | irsp->un.ulpWord[1], |
| 3964 | irsp->un.ulpWord[2], |
| 3965 | irsp->un.ulpWord[3], |
| 3966 | irsp->un.ulpWord[4], |
| 3967 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3968 | *(uint32_t *)&irsp->un1, |
| 3969 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3970 | } |
| 3971 | |
| 3972 | switch (type) { |
| 3973 | case LPFC_ABORT_IOCB: |
| 3974 | case LPFC_SOL_IOCB: |
| 3975 | /* |
| 3976 | * Idle exchange closed via ABTS from port. No iocb |
| 3977 | * resources need to be recovered. |
| 3978 | */ |
| 3979 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3980 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3981 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3982 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3983 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3984 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3985 | break; |
| 3986 | } |
| 3987 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3988 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3989 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 3990 | &rspiocbq); |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3991 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3992 | if (unlikely(!cmdiocbq)) |
| 3993 | break; |
| 3994 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 3995 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 3996 | if (cmdiocbq->iocb_cmpl) { |
| 3997 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3998 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 3999 | &rspiocbq); |
| 4000 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 4001 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4002 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 4003 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4004 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 4005 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4006 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 4007 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4008 | default: |
| 4009 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 4010 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 4011 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 4012 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 4013 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 4014 | dev_warn(&((phba->pcidev)->dev), |
| 4015 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4016 | phba->brd_no, adaptermsg); |
| 4017 | } else { |
| 4018 | /* Unknown IOCB command */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4019 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4020 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4021 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4022 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4023 | irsp->ulpStatus, |
| 4024 | irsp->ulpIoTag, |
| 4025 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4026 | } |
| 4027 | break; |
| 4028 | } |
| 4029 | |
| 4030 | /* |
| 4031 | * The response IOCB has been processed. Update the ring |
| 4032 | * pointer in SLIM. If the port response put pointer has not |
| 4033 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 4034 | * response put pointer. |
| 4035 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4036 | writel(pring->sli.sli3.rspidx, |
| 4037 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4038 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4039 | if (pring->sli.sli3.rspidx == portRspPut) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4040 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 4041 | } |
| 4042 | |
| 4043 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 4044 | pring->stats.iocb_rsp_full++; |
| 4045 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 4046 | writel(status, phba->CAregaddr); |
| 4047 | readl(phba->CAregaddr); |
| 4048 | } |
| 4049 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 4050 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 4051 | pring->stats.iocb_cmd_empty++; |
| 4052 | |
| 4053 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4054 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4055 | lpfc_sli_resume_iocb(phba, pring); |
| 4056 | |
| 4057 | if ((pring->lpfc_sli_cmd_available)) |
| 4058 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 4059 | |
| 4060 | } |
| 4061 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4062 | phba->fcp_ring_in_use = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4063 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4064 | return rc; |
| 4065 | } |
| 4066 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4067 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4068 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
| 4069 | * @phba: Pointer to HBA context object. |
| 4070 | * @pring: Pointer to driver SLI ring object. |
| 4071 | * @rspiocbp: Pointer to driver response IOCB object. |
| 4072 | * |
| 4073 | * This function is called from the worker thread when there is a slow-path |
| 4074 | * response IOCB to process. This function chains all the response iocbs until |
| 4075 | * seeing the iocb with the LE bit set. The function will call |
| 4076 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a |
| 4077 | * completion of a command iocb. The function will call the |
| 4078 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. |
| 4079 | * The function frees the resources or calls the completion handler if this |
| 4080 | * iocb is an abort completion. The function returns NULL when the response |
| 4081 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise |
| 4082 | * this function shall chain the iocb on to the iocb_continueq and return the |
| 4083 | * response iocb passed in. |
| 4084 | **/ |
| 4085 | static struct lpfc_iocbq * |
| 4086 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4087 | struct lpfc_iocbq *rspiocbp) |
| 4088 | { |
| 4089 | struct lpfc_iocbq *saveq; |
| 4090 | struct lpfc_iocbq *cmdiocbp; |
| 4091 | struct lpfc_iocbq *next_iocb; |
| 4092 | IOCB_t *irsp = NULL; |
| 4093 | uint32_t free_saveq; |
| 4094 | uint8_t iocb_cmd_type; |
| 4095 | lpfc_iocb_type type; |
| 4096 | unsigned long iflag; |
| 4097 | int rc; |
| 4098 | |
| 4099 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 4100 | /* First add the response iocb to the countinueq list */ |
| 4101 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| 4102 | pring->iocb_continueq_cnt++; |
| 4103 | |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 4104 | /* Now, determine whether the list is completed for processing */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4105 | irsp = &rspiocbp->iocb; |
| 4106 | if (irsp->ulpLe) { |
| 4107 | /* |
| 4108 | * By default, the driver expects to free all resources |
| 4109 | * associated with this iocb completion. |
| 4110 | */ |
| 4111 | free_saveq = 1; |
| 4112 | saveq = list_get_first(&pring->iocb_continueq, |
| 4113 | struct lpfc_iocbq, list); |
| 4114 | irsp = &(saveq->iocb); |
| 4115 | list_del_init(&pring->iocb_continueq); |
| 4116 | pring->iocb_continueq_cnt = 0; |
| 4117 | |
| 4118 | pring->stats.iocb_rsp++; |
| 4119 | |
| 4120 | /* |
| 4121 | * If resource errors reported from HBA, reduce |
| 4122 | * queuedepths of the SCSI device. |
| 4123 | */ |
| 4124 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 4125 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 4126 | IOERR_NO_RESOURCES)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4127 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 4128 | phba->lpfc_rampdown_queue_depth(phba); |
| 4129 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 4130 | } |
| 4131 | |
| 4132 | if (irsp->ulpStatus) { |
| 4133 | /* Rsp ring <ringno> error: IOCB */ |
| 4134 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 4135 | "0328 Rsp Ring %d error: " |
| 4136 | "IOCB Data: " |
| 4137 | "x%x x%x x%x x%x " |
| 4138 | "x%x x%x x%x x%x " |
| 4139 | "x%x x%x x%x x%x " |
| 4140 | "x%x x%x x%x x%x\n", |
| 4141 | pring->ringno, |
| 4142 | irsp->un.ulpWord[0], |
| 4143 | irsp->un.ulpWord[1], |
| 4144 | irsp->un.ulpWord[2], |
| 4145 | irsp->un.ulpWord[3], |
| 4146 | irsp->un.ulpWord[4], |
| 4147 | irsp->un.ulpWord[5], |
| 4148 | *(((uint32_t *) irsp) + 6), |
| 4149 | *(((uint32_t *) irsp) + 7), |
| 4150 | *(((uint32_t *) irsp) + 8), |
| 4151 | *(((uint32_t *) irsp) + 9), |
| 4152 | *(((uint32_t *) irsp) + 10), |
| 4153 | *(((uint32_t *) irsp) + 11), |
| 4154 | *(((uint32_t *) irsp) + 12), |
| 4155 | *(((uint32_t *) irsp) + 13), |
| 4156 | *(((uint32_t *) irsp) + 14), |
| 4157 | *(((uint32_t *) irsp) + 15)); |
| 4158 | } |
| 4159 | |
| 4160 | /* |
| 4161 | * Fetch the IOCB command type and call the correct completion |
| 4162 | * routine. Solicited and Unsolicited IOCBs on the ELS ring |
| 4163 | * get freed back to the lpfc_iocb_list by the discovery |
| 4164 | * kernel thread. |
| 4165 | */ |
| 4166 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 4167 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 4168 | switch (type) { |
| 4169 | case LPFC_SOL_IOCB: |
| 4170 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 4171 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); |
| 4172 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 4173 | break; |
| 4174 | |
| 4175 | case LPFC_UNSOL_IOCB: |
| 4176 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 4177 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); |
| 4178 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 4179 | if (!rc) |
| 4180 | free_saveq = 0; |
| 4181 | break; |
| 4182 | |
| 4183 | case LPFC_ABORT_IOCB: |
| 4184 | cmdiocbp = NULL; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 4185 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) { |
| 4186 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4187 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, |
| 4188 | saveq); |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 4189 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 4190 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4191 | if (cmdiocbp) { |
| 4192 | /* Call the specified completion routine */ |
| 4193 | if (cmdiocbp->iocb_cmpl) { |
| 4194 | spin_unlock_irqrestore(&phba->hbalock, |
| 4195 | iflag); |
| 4196 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, |
| 4197 | saveq); |
| 4198 | spin_lock_irqsave(&phba->hbalock, |
| 4199 | iflag); |
| 4200 | } else |
| 4201 | __lpfc_sli_release_iocbq(phba, |
| 4202 | cmdiocbp); |
| 4203 | } |
| 4204 | break; |
| 4205 | |
| 4206 | case LPFC_UNKNOWN_IOCB: |
| 4207 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 4208 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 4209 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 4210 | memcpy(&adaptermsg[0], (uint8_t *)irsp, |
| 4211 | MAX_MSG_DATA); |
| 4212 | dev_warn(&((phba->pcidev)->dev), |
| 4213 | "lpfc%d: %s\n", |
| 4214 | phba->brd_no, adaptermsg); |
| 4215 | } else { |
| 4216 | /* Unknown IOCB command */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4217 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4218 | "0335 Unknown IOCB " |
| 4219 | "command Data: x%x " |
| 4220 | "x%x x%x x%x\n", |
| 4221 | irsp->ulpCommand, |
| 4222 | irsp->ulpStatus, |
| 4223 | irsp->ulpIoTag, |
| 4224 | irsp->ulpContext); |
| 4225 | } |
| 4226 | break; |
| 4227 | } |
| 4228 | |
| 4229 | if (free_saveq) { |
| 4230 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 4231 | &saveq->list, list) { |
James Smart | 61f35bf | 2013-05-31 17:03:48 -0400 | [diff] [blame] | 4232 | list_del_init(&rspiocbp->list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4233 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
| 4234 | } |
| 4235 | __lpfc_sli_release_iocbq(phba, saveq); |
| 4236 | } |
| 4237 | rspiocbp = NULL; |
| 4238 | } |
| 4239 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 4240 | return rspiocbp; |
| 4241 | } |
| 4242 | |
| 4243 | /** |
| 4244 | * 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] | 4245 | * @phba: Pointer to HBA context object. |
| 4246 | * @pring: Pointer to driver SLI ring object. |
| 4247 | * @mask: Host attention register mask for this ring. |
| 4248 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4249 | * This routine wraps the actual slow_ring event process routine from the |
| 4250 | * API jump table function pointer from the lpfc_hba struct. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4251 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4252 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4253 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 4254 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4255 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4256 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); |
| 4257 | } |
| 4258 | |
| 4259 | /** |
| 4260 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings |
| 4261 | * @phba: Pointer to HBA context object. |
| 4262 | * @pring: Pointer to driver SLI ring object. |
| 4263 | * @mask: Host attention register mask for this ring. |
| 4264 | * |
| 4265 | * This function is called from the worker thread when there is a ring event |
| 4266 | * for non-fcp rings. The caller does not hold any lock. The function will |
| 4267 | * remove each response iocb in the response ring and calls the handle |
| 4268 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 4269 | **/ |
| 4270 | static void |
| 4271 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, |
| 4272 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 4273 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4274 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4275 | IOCB_t *entry; |
| 4276 | IOCB_t *irsp = NULL; |
| 4277 | struct lpfc_iocbq *rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4278 | uint32_t portRspPut, portRspMax; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4279 | unsigned long iflag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4280 | uint32_t status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4281 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4282 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4283 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4284 | pring->stats.iocb_event++; |
| 4285 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4286 | /* |
| 4287 | * The next available response entry should never exceed the maximum |
| 4288 | * entries. If it does, treat it as an adapter hardware error. |
| 4289 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4290 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4291 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 4292 | if (portRspPut >= portRspMax) { |
| 4293 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4294 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4295 | * rsp ring <portRspMax> |
| 4296 | */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4297 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4298 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4299 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4300 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4301 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4302 | phba->link_state = LPFC_HBA_ERROR; |
| 4303 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4304 | |
| 4305 | phba->work_hs = HS_FFER3; |
| 4306 | lpfc_handle_eratt(phba); |
| 4307 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4308 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4309 | } |
| 4310 | |
| 4311 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4312 | while (pring->sli.sli3.rspidx != portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4313 | /* |
| 4314 | * Build a completion list and call the appropriate handler. |
| 4315 | * The process is to get the next available response iocb, get |
| 4316 | * a free iocb from the list, copy the response data into the |
| 4317 | * free iocb, insert to the continuation list, and update the |
| 4318 | * next response index to slim. This process makes response |
| 4319 | * iocb's in the ring available to DMA as fast as possible but |
| 4320 | * pays a penalty for a copy operation. Since the iocb is |
| 4321 | * only 32 bytes, this penalty is considered small relative to |
| 4322 | * the PCI reads for register values and a slim write. When |
| 4323 | * the ulpLe field is set, the entire Command has been |
| 4324 | * received. |
| 4325 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4326 | entry = lpfc_resp_iocb(phba, pring); |
| 4327 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4328 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4329 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4330 | if (rspiocbp == NULL) { |
| 4331 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 4332 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4333 | break; |
| 4334 | } |
| 4335 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4336 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 4337 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4338 | irsp = &rspiocbp->iocb; |
| 4339 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4340 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 4341 | pring->sli.sli3.rspidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4342 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 4343 | if (pring->ringno == LPFC_ELS_RING) { |
| 4344 | lpfc_debugfs_slow_ring_trc(phba, |
| 4345 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 4346 | *(((uint32_t *) irsp) + 4), |
| 4347 | *(((uint32_t *) irsp) + 6), |
| 4348 | *(((uint32_t *) irsp) + 7)); |
| 4349 | } |
| 4350 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4351 | writel(pring->sli.sli3.rspidx, |
| 4352 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4353 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4354 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 4355 | /* Handle the response IOCB */ |
| 4356 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); |
| 4357 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4358 | |
| 4359 | /* |
| 4360 | * If the port response put pointer has not been updated, sync |
| 4361 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 4362 | * response put pointer. |
| 4363 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4364 | if (pring->sli.sli3.rspidx == portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4365 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 4366 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4367 | } /* while (pring->sli.sli3.rspidx != portRspPut) */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4368 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4369 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4370 | /* At least one response entry has been freed */ |
| 4371 | pring->stats.iocb_rsp_full++; |
| 4372 | /* SET RxRE_RSP in Chip Att register */ |
| 4373 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 4374 | writel(status, phba->CAregaddr); |
| 4375 | readl(phba->CAregaddr); /* flush */ |
| 4376 | } |
| 4377 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 4378 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 4379 | pring->stats.iocb_cmd_empty++; |
| 4380 | |
| 4381 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4382 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4383 | lpfc_sli_resume_iocb(phba, pring); |
| 4384 | |
| 4385 | if ((pring->lpfc_sli_cmd_available)) |
| 4386 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 4387 | |
| 4388 | } |
| 4389 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4390 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4391 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4392 | } |
| 4393 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4394 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4395 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events |
| 4396 | * @phba: Pointer to HBA context object. |
| 4397 | * @pring: Pointer to driver SLI ring object. |
| 4398 | * @mask: Host attention register mask for this ring. |
| 4399 | * |
| 4400 | * This function is called from the worker thread when there is a pending |
| 4401 | * ELS response iocb on the driver internal slow-path response iocb worker |
| 4402 | * queue. The caller does not hold any lock. The function will remove each |
| 4403 | * response iocb from the response worker queue and calls the handle |
| 4404 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 4405 | **/ |
| 4406 | static void |
| 4407 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, |
| 4408 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 4409 | { |
| 4410 | struct lpfc_iocbq *irspiocbq; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4411 | struct hbq_dmabuf *dmabuf; |
| 4412 | struct lpfc_cq_event *cq_event; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4413 | unsigned long iflag; |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 4414 | int count = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4415 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4416 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 4417 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 4418 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 4419 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4420 | /* Get the response iocb from the head of work queue */ |
| 4421 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4422 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4423 | cq_event, struct lpfc_cq_event, list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4424 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4425 | |
| 4426 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 4427 | case CQE_CODE_COMPL_WQE: |
| 4428 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 4429 | cq_event); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4430 | /* Translate ELS WCQE to response IOCBQ */ |
| 4431 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, |
| 4432 | irspiocbq); |
| 4433 | if (irspiocbq) |
| 4434 | lpfc_sli_sp_handle_rspiocb(phba, pring, |
| 4435 | irspiocbq); |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 4436 | count++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4437 | break; |
| 4438 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4439 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4440 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 4441 | cq_event); |
| 4442 | lpfc_sli4_handle_received_buffer(phba, dmabuf); |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 4443 | count++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4444 | break; |
| 4445 | default: |
| 4446 | break; |
| 4447 | } |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 4448 | |
| 4449 | /* Limit the number of events to 64 to avoid soft lockups */ |
| 4450 | if (count == 64) |
| 4451 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4452 | } |
| 4453 | } |
| 4454 | |
| 4455 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4456 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4457 | * @phba: Pointer to HBA context object. |
| 4458 | * @pring: Pointer to driver SLI ring object. |
| 4459 | * |
| 4460 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 4461 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 4462 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 4463 | * the return of this function. The caller is not required to hold any locks. |
| 4464 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4465 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4466 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 4467 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4468 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4469 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4470 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4471 | if (pring->ringno == LPFC_ELS_RING) { |
| 4472 | lpfc_fabric_abort_hba(phba); |
| 4473 | } |
| 4474 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4475 | /* Error everything on txq and txcmplq |
| 4476 | * First do the txq. |
| 4477 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4478 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 4479 | spin_lock_irq(&pring->ring_lock); |
| 4480 | list_splice_init(&pring->txq, &completions); |
| 4481 | pring->txq_cnt = 0; |
| 4482 | spin_unlock_irq(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4483 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4484 | spin_lock_irq(&phba->hbalock); |
| 4485 | /* Next issue ABTS for everything on the txcmplq */ |
| 4486 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 4487 | lpfc_sli_issue_abort_iotag(phba, pring, iocb, NULL); |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4488 | spin_unlock_irq(&phba->hbalock); |
| 4489 | } else { |
| 4490 | spin_lock_irq(&phba->hbalock); |
| 4491 | list_splice_init(&pring->txq, &completions); |
| 4492 | pring->txq_cnt = 0; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4493 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4494 | /* Next issue ABTS for everything on the txcmplq */ |
| 4495 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 4496 | lpfc_sli_issue_abort_iotag(phba, pring, iocb, NULL); |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4497 | spin_unlock_irq(&phba->hbalock); |
| 4498 | } |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 4499 | /* Make sure HBA is alive */ |
| 4500 | lpfc_issue_hb_tmo(phba); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4501 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4502 | /* Cancel all the IOCBs from the completions list */ |
| 4503 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 4504 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4505 | } |
| 4506 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4507 | /** |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4508 | * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings |
| 4509 | * @phba: Pointer to HBA context object. |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4510 | * |
| 4511 | * This function aborts all iocbs in FCP rings and frees all the iocb |
| 4512 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 4513 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 4514 | * the return of this function. The caller is not required to hold any locks. |
| 4515 | **/ |
| 4516 | void |
| 4517 | lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba) |
| 4518 | { |
| 4519 | struct lpfc_sli *psli = &phba->sli; |
| 4520 | struct lpfc_sli_ring *pring; |
| 4521 | uint32_t i; |
| 4522 | |
| 4523 | /* Look on all the FCP Rings for the iotag */ |
| 4524 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4525 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4526 | pring = phba->sli4_hba.hdwq[i].io_wq->pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4527 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 4528 | } |
| 4529 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4530 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4531 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 4532 | } |
| 4533 | } |
| 4534 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4535 | /** |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4536 | * lpfc_sli_flush_io_rings - flush all iocbs in the IO ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4537 | * @phba: Pointer to HBA context object. |
| 4538 | * |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4539 | * 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] | 4540 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 4541 | * for all the iocb commands in txcmplq, they will just be returned with |
| 4542 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 4543 | * slot has been permanently disabled. |
| 4544 | **/ |
| 4545 | void |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4546 | lpfc_sli_flush_io_rings(struct lpfc_hba *phba) |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4547 | { |
| 4548 | LIST_HEAD(txq); |
| 4549 | LIST_HEAD(txcmplq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4550 | struct lpfc_sli *psli = &phba->sli; |
| 4551 | struct lpfc_sli_ring *pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4552 | uint32_t i; |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4553 | struct lpfc_iocbq *piocb, *next_iocb; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4554 | |
| 4555 | spin_lock_irq(&phba->hbalock); |
James Smart | 4cd7089 | 2020-03-22 11:12:57 -0700 | [diff] [blame] | 4556 | if (phba->hba_flag & HBA_IOQ_FLUSH || |
| 4557 | !phba->sli4_hba.hdwq) { |
| 4558 | spin_unlock_irq(&phba->hbalock); |
| 4559 | return; |
| 4560 | } |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4561 | /* Indicate the I/O queues are flushed */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4562 | phba->hba_flag |= HBA_IOQ_FLUSH; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4563 | spin_unlock_irq(&phba->hbalock); |
| 4564 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4565 | /* Look on all the FCP Rings for the iotag */ |
| 4566 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4567 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4568 | pring = phba->sli4_hba.hdwq[i].io_wq->pring; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4569 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4570 | spin_lock_irq(&pring->ring_lock); |
| 4571 | /* Retrieve everything on txq */ |
| 4572 | list_splice_init(&pring->txq, &txq); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4573 | list_for_each_entry_safe(piocb, next_iocb, |
| 4574 | &pring->txcmplq, list) |
| 4575 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4576 | /* Retrieve everything on the txcmplq */ |
| 4577 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 4578 | pring->txq_cnt = 0; |
| 4579 | pring->txcmplq_cnt = 0; |
| 4580 | spin_unlock_irq(&pring->ring_lock); |
| 4581 | |
| 4582 | /* Flush the txq */ |
| 4583 | lpfc_sli_cancel_iocbs(phba, &txq, |
| 4584 | IOSTAT_LOCAL_REJECT, |
| 4585 | IOERR_SLI_DOWN); |
| 4586 | /* Flush the txcmpq */ |
| 4587 | lpfc_sli_cancel_iocbs(phba, &txcmplq, |
| 4588 | IOSTAT_LOCAL_REJECT, |
| 4589 | IOERR_SLI_DOWN); |
| 4590 | } |
| 4591 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4592 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4593 | |
| 4594 | spin_lock_irq(&phba->hbalock); |
| 4595 | /* Retrieve everything on txq */ |
| 4596 | list_splice_init(&pring->txq, &txq); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4597 | list_for_each_entry_safe(piocb, next_iocb, |
| 4598 | &pring->txcmplq, list) |
| 4599 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4600 | /* Retrieve everything on the txcmplq */ |
| 4601 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 4602 | pring->txq_cnt = 0; |
| 4603 | pring->txcmplq_cnt = 0; |
| 4604 | spin_unlock_irq(&phba->hbalock); |
| 4605 | |
| 4606 | /* Flush the txq */ |
| 4607 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
| 4608 | IOERR_SLI_DOWN); |
| 4609 | /* Flush the txcmpq */ |
| 4610 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
| 4611 | IOERR_SLI_DOWN); |
| 4612 | } |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4613 | } |
| 4614 | |
| 4615 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4616 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4617 | * @phba: Pointer to HBA context object. |
| 4618 | * @mask: Bit mask to be checked. |
| 4619 | * |
| 4620 | * This function reads the host status register and compares |
| 4621 | * with the provided bit mask to check if HBA completed |
| 4622 | * the restart. This function will wait in a loop for the |
| 4623 | * HBA to complete restart. If the HBA does not restart within |
| 4624 | * 15 iterations, the function will reset the HBA again. The |
| 4625 | * function returns 1 when HBA fail to restart otherwise returns |
| 4626 | * zero. |
| 4627 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4628 | static int |
| 4629 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4630 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4631 | uint32_t status; |
| 4632 | int i = 0; |
| 4633 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4634 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4635 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4636 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4637 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4638 | |
James Smart | d2f2547 | 2021-01-04 10:02:27 -0800 | [diff] [blame] | 4639 | phba->hba_flag |= HBA_NEEDS_CFG_PORT; |
| 4640 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4641 | /* |
| 4642 | * Check status register every 100ms for 5 retries, then every |
| 4643 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 4644 | * every 2.5 sec for 4. |
| 4645 | * Break our of the loop if errors occurred during init. |
| 4646 | */ |
| 4647 | while (((status & mask) != mask) && |
| 4648 | !(status & HS_FFERM) && |
| 4649 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4650 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4651 | if (i <= 5) |
| 4652 | msleep(10); |
| 4653 | else if (i <= 10) |
| 4654 | msleep(500); |
| 4655 | else |
| 4656 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4657 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4658 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4659 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4660 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4661 | lpfc_sli_brdrestart(phba); |
| 4662 | } |
| 4663 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4664 | if (lpfc_readl(phba->HSregaddr, &status)) { |
| 4665 | retval = 1; |
| 4666 | break; |
| 4667 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4668 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4669 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4670 | /* Check to see if any errors occurred during init */ |
| 4671 | if ((status & HS_FFERM) || (i >= 20)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4672 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4673 | "2751 Adapter failed to restart, " |
| 4674 | "status reg x%x, FW Data: A8 x%x AC x%x\n", |
| 4675 | status, |
| 4676 | readl(phba->MBslimaddr + 0xa8), |
| 4677 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4678 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4679 | retval = 1; |
| 4680 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4681 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4682 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4683 | } |
| 4684 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4685 | /** |
| 4686 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status |
| 4687 | * @phba: Pointer to HBA context object. |
| 4688 | * @mask: Bit mask to be checked. |
| 4689 | * |
| 4690 | * This function checks the host status register to check if HBA is |
| 4691 | * ready. This function will wait in a loop for the HBA to be ready |
| 4692 | * If the HBA is not ready , the function will will reset the HBA PCI |
| 4693 | * function again. The function returns 1 when HBA fail to be ready |
| 4694 | * otherwise returns zero. |
| 4695 | **/ |
| 4696 | static int |
| 4697 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) |
| 4698 | { |
| 4699 | uint32_t status; |
| 4700 | int retval = 0; |
| 4701 | |
| 4702 | /* Read the HBA Host Status Register */ |
| 4703 | status = lpfc_sli4_post_status_check(phba); |
| 4704 | |
| 4705 | if (status) { |
| 4706 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 4707 | lpfc_sli_brdrestart(phba); |
| 4708 | status = lpfc_sli4_post_status_check(phba); |
| 4709 | } |
| 4710 | |
| 4711 | /* Check to see if any errors occurred during init */ |
| 4712 | if (status) { |
| 4713 | phba->link_state = LPFC_HBA_ERROR; |
| 4714 | retval = 1; |
| 4715 | } else |
| 4716 | phba->sli4_hba.intr_enable = 0; |
| 4717 | |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 4718 | phba->hba_flag &= ~HBA_SETUP; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4719 | return retval; |
| 4720 | } |
| 4721 | |
| 4722 | /** |
| 4723 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness |
| 4724 | * @phba: Pointer to HBA context object. |
| 4725 | * @mask: Bit mask to be checked. |
| 4726 | * |
| 4727 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine |
| 4728 | * from the API jump table function pointer from the lpfc_hba struct. |
| 4729 | **/ |
| 4730 | int |
| 4731 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| 4732 | { |
| 4733 | return phba->lpfc_sli_brdready(phba, mask); |
| 4734 | } |
| 4735 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4736 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 4737 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4738 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4739 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4740 | * @phba: Pointer to HBA context object. |
| 4741 | * |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 4742 | * This function is called before resetting an HBA. This function is called |
| 4743 | * with hbalock held and requests HBA to quiesce DMAs before a reset. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4744 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4745 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4746 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4747 | uint32_t __iomem *resp_buf; |
| 4748 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4749 | volatile uint32_t mbox; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4750 | uint32_t hc_copy, ha_copy, resp_data; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4751 | int i; |
| 4752 | uint8_t hdrtype; |
| 4753 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 4754 | lockdep_assert_held(&phba->hbalock); |
| 4755 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4756 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 4757 | if (hdrtype != 0x80 || |
| 4758 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 4759 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 4760 | return; |
| 4761 | |
| 4762 | /* |
| 4763 | * Tell the other part of the chip to suspend temporarily all |
| 4764 | * its DMA activity. |
| 4765 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4766 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4767 | |
| 4768 | /* Disable the error attention */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4769 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 4770 | return; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4771 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 4772 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4773 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4774 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4775 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4776 | return; |
| 4777 | if (ha_copy & HA_ERATT) { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4778 | /* Clear Chip error bit */ |
| 4779 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4780 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4781 | } |
| 4782 | |
| 4783 | mbox = 0; |
| 4784 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 4785 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 4786 | |
| 4787 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4788 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4789 | writel(mbox, mbox_buf); |
| 4790 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4791 | for (i = 0; i < 50; i++) { |
| 4792 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 4793 | return; |
| 4794 | if (resp_data != ~(BARRIER_TEST_PATTERN)) |
| 4795 | mdelay(1); |
| 4796 | else |
| 4797 | break; |
| 4798 | } |
| 4799 | resp_data = 0; |
| 4800 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 4801 | return; |
| 4802 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4803 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4804 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4805 | goto restore_hc; |
| 4806 | else |
| 4807 | goto clear_errat; |
| 4808 | } |
| 4809 | |
| 4810 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4811 | resp_data = 0; |
| 4812 | for (i = 0; i < 500; i++) { |
| 4813 | if (lpfc_readl(resp_buf, &resp_data)) |
| 4814 | return; |
| 4815 | if (resp_data != mbox) |
| 4816 | mdelay(1); |
| 4817 | else |
| 4818 | break; |
| 4819 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4820 | |
| 4821 | clear_errat: |
| 4822 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4823 | while (++i < 500) { |
| 4824 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4825 | return; |
| 4826 | if (!(ha_copy & HA_ERATT)) |
| 4827 | mdelay(1); |
| 4828 | else |
| 4829 | break; |
| 4830 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4831 | |
| 4832 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 4833 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4834 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4835 | } |
| 4836 | |
| 4837 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4838 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4839 | writel(hc_copy, phba->HCregaddr); |
| 4840 | readl(phba->HCregaddr); /* flush */ |
| 4841 | } |
| 4842 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4843 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4844 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4845 | * @phba: Pointer to HBA context object. |
| 4846 | * |
| 4847 | * This function issues a kill_board mailbox command and waits for |
| 4848 | * the error attention interrupt. This function is called for stopping |
| 4849 | * the firmware processing. The caller is not required to hold any |
| 4850 | * locks. This function calls lpfc_hba_down_post function to free |
| 4851 | * any pending commands after the kill. The function will return 1 when it |
| 4852 | * fails to kill the board else will return 0. |
| 4853 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4854 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4855 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4856 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4857 | struct lpfc_sli *psli; |
| 4858 | LPFC_MBOXQ_t *pmb; |
| 4859 | uint32_t status; |
| 4860 | uint32_t ha_copy; |
| 4861 | int retval; |
| 4862 | int i = 0; |
| 4863 | |
| 4864 | psli = &phba->sli; |
| 4865 | |
| 4866 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4867 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4868 | "0329 Kill HBA Data: x%x x%x\n", |
| 4869 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4870 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4871 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4872 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4873 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4874 | |
| 4875 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4876 | spin_lock_irq(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4877 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 4878 | spin_unlock_irq(&phba->hbalock); |
| 4879 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4880 | return 1; |
| 4881 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4882 | status &= ~HC_ERINT_ENA; |
| 4883 | writel(status, phba->HCregaddr); |
| 4884 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4885 | phba->link_flag |= LS_IGNORE_ERATT; |
| 4886 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4887 | |
| 4888 | lpfc_kill_board(phba, pmb); |
| 4889 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4890 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 4891 | |
| 4892 | if (retval != MBX_SUCCESS) { |
| 4893 | if (retval != MBX_BUSY) |
| 4894 | mempool_free(pmb, phba->mbox_mem_pool); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4895 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4896 | "2752 KILL_BOARD command failed retval %d\n", |
| 4897 | retval); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4898 | spin_lock_irq(&phba->hbalock); |
| 4899 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4900 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4901 | return 1; |
| 4902 | } |
| 4903 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4904 | spin_lock_irq(&phba->hbalock); |
| 4905 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 4906 | spin_unlock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4907 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4908 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4909 | |
| 4910 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 4911 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 4912 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 4913 | * board is now undefined. |
| 4914 | */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4915 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4916 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4917 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 4918 | mdelay(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4919 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4920 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4921 | } |
| 4922 | |
| 4923 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4924 | if (ha_copy & HA_ERATT) { |
| 4925 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4926 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4927 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4928 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4929 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4930 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4931 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4932 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4933 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4934 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4935 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4936 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4937 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4938 | } |
| 4939 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4940 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4941 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4942 | * @phba: Pointer to HBA context object. |
| 4943 | * |
| 4944 | * This function resets the HBA by writing HC_INITFF to the control |
| 4945 | * register. After the HBA resets, this function resets all the iocb ring |
| 4946 | * indices. This function disables PCI layer parity checking during |
| 4947 | * the reset. |
| 4948 | * This function returns 0 always. |
| 4949 | * The caller is not required to hold any locks. |
| 4950 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4951 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4952 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4953 | { |
| 4954 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4955 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4956 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4957 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4958 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4959 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4960 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4961 | /* Reset HBA */ |
| 4962 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4963 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4964 | (phba->pport) ? phba->pport->port_state : 0, |
| 4965 | psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4966 | |
| 4967 | /* perform board reset */ |
| 4968 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4969 | phba->link_events = 0; |
James Smart | d2f2547 | 2021-01-04 10:02:27 -0800 | [diff] [blame] | 4970 | phba->hba_flag |= HBA_NEEDS_CFG_PORT; |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4971 | if (phba->pport) { |
| 4972 | phba->pport->fc_myDID = 0; |
| 4973 | phba->pport->fc_prevDID = 0; |
| 4974 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4975 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4976 | /* Turn off parity checking and serr during the physical reset */ |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 4977 | if (pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value)) |
| 4978 | return -EIO; |
| 4979 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4980 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 4981 | (cfg_value & |
| 4982 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4983 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4984 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
| 4985 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4986 | /* Now toggle INITFF bit in the Host Control Register */ |
| 4987 | writel(HC_INITFF, phba->HCregaddr); |
| 4988 | mdelay(1); |
| 4989 | readl(phba->HCregaddr); /* flush */ |
| 4990 | writel(0, phba->HCregaddr); |
| 4991 | readl(phba->HCregaddr); /* flush */ |
| 4992 | |
| 4993 | /* Restore PCI cmd register */ |
| 4994 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4995 | |
| 4996 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4997 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4998 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4999 | pring->flag = 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 5000 | pring->sli.sli3.rspidx = 0; |
| 5001 | pring->sli.sli3.next_cmdidx = 0; |
| 5002 | pring->sli.sli3.local_getidx = 0; |
| 5003 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5004 | pring->missbufcnt = 0; |
| 5005 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5006 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5007 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 5008 | return 0; |
| 5009 | } |
| 5010 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5011 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5012 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
| 5013 | * @phba: Pointer to HBA context object. |
| 5014 | * |
| 5015 | * This function resets a SLI4 HBA. This function disables PCI layer parity |
| 5016 | * checking during resets the device. The caller is not required to hold |
| 5017 | * any locks. |
| 5018 | * |
James Smart | 8c24a4f | 2019-08-14 16:56:53 -0700 | [diff] [blame] | 5019 | * This function returns 0 on success else returns negative error code. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5020 | **/ |
| 5021 | int |
| 5022 | lpfc_sli4_brdreset(struct lpfc_hba *phba) |
| 5023 | { |
| 5024 | struct lpfc_sli *psli = &phba->sli; |
| 5025 | uint16_t cfg_value; |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 5026 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5027 | |
| 5028 | /* Reset HBA */ |
| 5029 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 5030 | "0295 Reset HBA Data: x%x x%x x%x\n", |
| 5031 | phba->pport->port_state, psli->sli_flag, |
| 5032 | phba->hba_flag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5033 | |
| 5034 | /* perform board reset */ |
| 5035 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5036 | phba->link_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5037 | phba->pport->fc_myDID = 0; |
| 5038 | phba->pport->fc_prevDID = 0; |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 5039 | phba->hba_flag &= ~HBA_SETUP; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5040 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5041 | spin_lock_irq(&phba->hbalock); |
| 5042 | psli->sli_flag &= ~(LPFC_PROCESS_LA); |
| 5043 | phba->fcf.fcf_flag = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5044 | spin_unlock_irq(&phba->hbalock); |
| 5045 | |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 5046 | /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */ |
| 5047 | if (phba->hba_flag & HBA_FW_DUMP_OP) { |
| 5048 | phba->hba_flag &= ~HBA_FW_DUMP_OP; |
| 5049 | return rc; |
| 5050 | } |
| 5051 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5052 | /* Now physically reset the device */ |
| 5053 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5054 | "0389 Performing PCI function reset!\n"); |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 5055 | |
| 5056 | /* Turn off parity checking and serr during the physical reset */ |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 5057 | if (pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value)) { |
| 5058 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5059 | "3205 PCI read Config failed\n"); |
| 5060 | return -EIO; |
| 5061 | } |
| 5062 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 5063 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & |
| 5064 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 5065 | |
James Smart | 8831881 | 2012-09-29 11:29:29 -0400 | [diff] [blame] | 5066 | /* Perform FCoE PCI function reset before freeing queue memory */ |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5067 | rc = lpfc_pci_function_reset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5068 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 5069 | /* Restore PCI cmd register */ |
| 5070 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| 5071 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5072 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5073 | } |
| 5074 | |
| 5075 | /** |
| 5076 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5077 | * @phba: Pointer to HBA context object. |
| 5078 | * |
| 5079 | * This function is called in the SLI initialization code path to |
| 5080 | * restart the HBA. The caller is not required to hold any lock. |
| 5081 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 5082 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 5083 | * function to free any pending commands. The function enables |
| 5084 | * POST only during the first initialization. The function returns zero. |
| 5085 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 5086 | * command before the return of this function. |
| 5087 | **/ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5088 | static int |
| 5089 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 5090 | { |
| 5091 | MAILBOX_t *mb; |
| 5092 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 5093 | volatile uint32_t word0; |
| 5094 | void __iomem *to_slim; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 5095 | uint32_t hba_aer_enabled; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 5096 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5097 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 5098 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 5099 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 5100 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 5101 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 5102 | psli = &phba->sli; |
| 5103 | |
| 5104 | /* Restart HBA */ |
| 5105 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5106 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 5107 | (phba->pport) ? phba->pport->port_state : 0, |
| 5108 | psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 5109 | |
| 5110 | word0 = 0; |
| 5111 | mb = (MAILBOX_t *) &word0; |
| 5112 | mb->mbxCommand = MBX_RESTART; |
| 5113 | mb->mbxHc = 1; |
| 5114 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 5115 | lpfc_reset_barrier(phba); |
| 5116 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 5117 | to_slim = phba->MBslimaddr; |
| 5118 | writel(*(uint32_t *) mb, to_slim); |
| 5119 | readl(to_slim); /* flush */ |
| 5120 | |
| 5121 | /* Only skip post after fc_ffinit is completed */ |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 5122 | if (phba->pport && phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 5123 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5124 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 5125 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 5126 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 5127 | writel(*(uint32_t *) mb, to_slim); |
| 5128 | readl(to_slim); /* flush */ |
| 5129 | |
| 5130 | lpfc_sli_brdreset(phba); |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 5131 | if (phba->pport) |
| 5132 | phba->pport->stopped = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5133 | phba->link_state = LPFC_INIT_START; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5134 | phba->hba_flag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5135 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 5136 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 5137 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
Arnd Bergmann | c4d6204d | 2018-06-18 17:28:23 +0200 | [diff] [blame] | 5138 | psli->stats_start = ktime_get_seconds(); |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 5139 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5140 | /* Give the INITFF and Post time to settle. */ |
| 5141 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5142 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 5143 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 5144 | if (hba_aer_enabled) |
| 5145 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 5146 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 5147 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5148 | |
| 5149 | return 0; |
| 5150 | } |
| 5151 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5152 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5153 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba |
| 5154 | * @phba: Pointer to HBA context object. |
| 5155 | * |
| 5156 | * This function is called in the SLI initialization code path to restart |
| 5157 | * a SLI4 HBA. The caller is not required to hold any lock. |
| 5158 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 5159 | * free any pending commands. |
| 5160 | **/ |
| 5161 | static int |
| 5162 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) |
| 5163 | { |
| 5164 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 5165 | uint32_t hba_aer_enabled; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5166 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5167 | |
| 5168 | /* Restart HBA */ |
| 5169 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5170 | "0296 Restart HBA Data: x%x x%x\n", |
| 5171 | phba->pport->port_state, psli->sli_flag); |
| 5172 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 5173 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 5174 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 5175 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5176 | rc = lpfc_sli4_brdreset(phba); |
James Smart | 4fb86a6 | 2019-09-03 14:54:41 -0700 | [diff] [blame] | 5177 | if (rc) { |
| 5178 | phba->link_state = LPFC_HBA_ERROR; |
| 5179 | goto hba_down_queue; |
| 5180 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5181 | |
| 5182 | spin_lock_irq(&phba->hbalock); |
| 5183 | phba->pport->stopped = 0; |
| 5184 | phba->link_state = LPFC_INIT_START; |
| 5185 | phba->hba_flag = 0; |
| 5186 | spin_unlock_irq(&phba->hbalock); |
| 5187 | |
| 5188 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
Arnd Bergmann | c4d6204d | 2018-06-18 17:28:23 +0200 | [diff] [blame] | 5189 | psli->stats_start = ktime_get_seconds(); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5190 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 5191 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 5192 | if (hba_aer_enabled) |
| 5193 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 5194 | |
James Smart | 4fb86a6 | 2019-09-03 14:54:41 -0700 | [diff] [blame] | 5195 | hba_down_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5196 | lpfc_hba_down_post(phba); |
James Smart | 569dbe8 | 2017-06-15 22:56:47 -0700 | [diff] [blame] | 5197 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5198 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5199 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5200 | } |
| 5201 | |
| 5202 | /** |
| 5203 | * lpfc_sli_brdrestart - Wrapper func for restarting hba |
| 5204 | * @phba: Pointer to HBA context object. |
| 5205 | * |
| 5206 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the |
| 5207 | * API jump table function pointer from the lpfc_hba struct. |
| 5208 | **/ |
| 5209 | int |
| 5210 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
| 5211 | { |
| 5212 | return phba->lpfc_sli_brdrestart(phba); |
| 5213 | } |
| 5214 | |
| 5215 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5216 | * 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] | 5217 | * @phba: Pointer to HBA context object. |
| 5218 | * |
| 5219 | * This function is called after a HBA restart to wait for successful |
| 5220 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 5221 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 5222 | * iteration, the function will restart the HBA again. The function returns |
| 5223 | * zero if HBA successfully restarted else returns negative error code. |
| 5224 | **/ |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 5225 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5226 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 5227 | { |
| 5228 | uint32_t status, i = 0; |
| 5229 | |
| 5230 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 5231 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 5232 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5233 | |
| 5234 | /* Check status register to see what current state is */ |
| 5235 | i = 0; |
| 5236 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 5237 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 5238 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
| 5239 | * retries, then every 1 sec for 50 retires for a total of |
| 5240 | * ~60 seconds before reset the board again and check every |
| 5241 | * 1 sec for 50 retries. The up to 60 seconds before the |
| 5242 | * board ready is required by the Falcon FIPS zeroization |
| 5243 | * complete, and any reset the board in between shall cause |
| 5244 | * restart of zeroization, further delay the board ready. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5245 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 5246 | if (i++ >= 200) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5247 | /* Adapter failed to init, timeout, status reg |
| 5248 | <status> */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5249 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5250 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5251 | "timeout, status reg x%x, " |
| 5252 | "FW Data: A8 x%x AC x%x\n", status, |
| 5253 | readl(phba->MBslimaddr + 0xa8), |
| 5254 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5255 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5256 | return -ETIMEDOUT; |
| 5257 | } |
| 5258 | |
| 5259 | /* Check to see if any errors occurred during init */ |
| 5260 | if (status & HS_FFERM) { |
| 5261 | /* ERROR: During chipset initialization */ |
| 5262 | /* Adapter failed to init, chipset, status reg |
| 5263 | <status> */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5264 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5265 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5266 | "chipset, status reg x%x, " |
| 5267 | "FW Data: A8 x%x AC x%x\n", status, |
| 5268 | readl(phba->MBslimaddr + 0xa8), |
| 5269 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5270 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5271 | return -EIO; |
| 5272 | } |
| 5273 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 5274 | if (i <= 10) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5275 | msleep(10); |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 5276 | else if (i <= 100) |
| 5277 | msleep(100); |
| 5278 | else |
| 5279 | msleep(1000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5280 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 5281 | if (i == 150) { |
| 5282 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5283 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 5284 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5285 | } |
| 5286 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 5287 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 5288 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5289 | } |
| 5290 | |
| 5291 | /* Check to see if any errors occurred during init */ |
| 5292 | if (status & HS_FFERM) { |
| 5293 | /* ERROR: During chipset initialization */ |
| 5294 | /* Adapter failed to init, chipset, status reg <status> */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5295 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5296 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5297 | "status reg x%x, " |
| 5298 | "FW Data: A8 x%x AC x%x\n", status, |
| 5299 | readl(phba->MBslimaddr + 0xa8), |
| 5300 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5301 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5302 | return -EIO; |
| 5303 | } |
| 5304 | |
James Smart | d2f2547 | 2021-01-04 10:02:27 -0800 | [diff] [blame] | 5305 | phba->hba_flag |= HBA_NEEDS_CFG_PORT; |
| 5306 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5307 | /* Clear all interrupt enable conditions */ |
| 5308 | writel(0, phba->HCregaddr); |
| 5309 | readl(phba->HCregaddr); /* flush */ |
| 5310 | |
| 5311 | /* setup host attn register */ |
| 5312 | writel(0xffffffff, phba->HAregaddr); |
| 5313 | readl(phba->HAregaddr); /* flush */ |
| 5314 | return 0; |
| 5315 | } |
| 5316 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5317 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5318 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5319 | * |
| 5320 | * This function calculates and returns the number of HBQs required to be |
| 5321 | * configured. |
| 5322 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 5323 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5324 | lpfc_sli_hbq_count(void) |
| 5325 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5326 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5327 | } |
| 5328 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5329 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5330 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5331 | * |
| 5332 | * This function adds the number of hbq entries in every HBQ to get |
| 5333 | * the total number of hbq entries required for the HBA and returns |
| 5334 | * the total count. |
| 5335 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5336 | static int |
| 5337 | lpfc_sli_hbq_entry_count(void) |
| 5338 | { |
| 5339 | int hbq_count = lpfc_sli_hbq_count(); |
| 5340 | int count = 0; |
| 5341 | int i; |
| 5342 | |
| 5343 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5344 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5345 | return count; |
| 5346 | } |
| 5347 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5348 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5349 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5350 | * |
| 5351 | * This function calculates amount of memory required for all hbq entries |
| 5352 | * to be configured and returns the total memory required. |
| 5353 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5354 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5355 | lpfc_sli_hbq_size(void) |
| 5356 | { |
| 5357 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 5358 | } |
| 5359 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5360 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5361 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5362 | * @phba: Pointer to HBA context object. |
| 5363 | * |
| 5364 | * This function is called during the SLI initialization to configure |
| 5365 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 5366 | * required to hold any locks. This function will return zero if successful |
| 5367 | * else it will return negative error code. |
| 5368 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5369 | static int |
| 5370 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 5371 | { |
| 5372 | int hbq_count = lpfc_sli_hbq_count(); |
| 5373 | LPFC_MBOXQ_t *pmb; |
| 5374 | MAILBOX_t *pmbox; |
| 5375 | uint32_t hbqno; |
| 5376 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5377 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5378 | /* Get a Mailbox buffer to setup mailbox |
| 5379 | * commands for HBA initialization |
| 5380 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5381 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5382 | |
| 5383 | if (!pmb) |
| 5384 | return -ENOMEM; |
| 5385 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5386 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5387 | |
| 5388 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 5389 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 5390 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5391 | |
| 5392 | hbq_entry_index = 0; |
| 5393 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 5394 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 5395 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 5396 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 5397 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5398 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5399 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 5400 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5401 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 5402 | |
| 5403 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 5404 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 5405 | mbxStatus <status>, ring <num> */ |
| 5406 | |
| 5407 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5408 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5409 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5410 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5411 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5412 | pmbox->mbxStatus, hbqno); |
| 5413 | |
| 5414 | phba->link_state = LPFC_HBA_ERROR; |
| 5415 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 5416 | return -ENXIO; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5417 | } |
| 5418 | } |
| 5419 | phba->hbq_count = hbq_count; |
| 5420 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5421 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5422 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5423 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5424 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 5425 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5426 | return 0; |
| 5427 | } |
| 5428 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5429 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 5430 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA |
| 5431 | * @phba: Pointer to HBA context object. |
| 5432 | * |
| 5433 | * This function is called during the SLI initialization to configure |
| 5434 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 5435 | * required to hold any locks. This function will return zero if successful |
| 5436 | * else it will return negative error code. |
| 5437 | **/ |
| 5438 | static int |
| 5439 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) |
| 5440 | { |
| 5441 | phba->hbq_in_use = 1; |
James Smart | 999fbbc | 2019-12-18 15:58:06 -0800 | [diff] [blame] | 5442 | /** |
| 5443 | * Specific case when the MDS diagnostics is enabled and supported. |
| 5444 | * The receive buffer count is truncated to manage the incoming |
| 5445 | * traffic. |
| 5446 | **/ |
| 5447 | if (phba->cfg_enable_mds_diags && phba->mds_diags_support) |
| 5448 | phba->hbqs[LPFC_ELS_HBQ].entry_count = |
| 5449 | lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count >> 1; |
| 5450 | else |
| 5451 | phba->hbqs[LPFC_ELS_HBQ].entry_count = |
| 5452 | lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 5453 | phba->hbq_count = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5454 | lpfc_sli_hbqbuf_init_hbqs(phba, LPFC_ELS_HBQ); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 5455 | /* Initially populate or replenish the HBQs */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 5456 | return 0; |
| 5457 | } |
| 5458 | |
| 5459 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5460 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5461 | * @phba: Pointer to HBA context object. |
| 5462 | * @sli_mode: sli mode - 2/3 |
| 5463 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 5464 | * This function is called by the sli initialization code path |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5465 | * to issue config_port mailbox command. This function restarts the |
| 5466 | * HBA firmware and issues a config_port mailbox command to configure |
| 5467 | * the SLI interface in the sli mode specified by sli_mode |
| 5468 | * variable. The caller is not required to hold any locks. |
| 5469 | * The function returns 0 if successful, else returns negative error |
| 5470 | * code. |
| 5471 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5472 | int |
| 5473 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5474 | { |
| 5475 | LPFC_MBOXQ_t *pmb; |
| 5476 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 5477 | |
| 5478 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5479 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5480 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5481 | return -ENOMEM; |
| 5482 | } |
| 5483 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5484 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5485 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5486 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 5487 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5488 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5489 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 5490 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5491 | rc = lpfc_sli_chipset_init(phba); |
| 5492 | if (rc) |
| 5493 | break; |
| 5494 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5495 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 5496 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5497 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5498 | resetcount++; |
| 5499 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5500 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 5501 | * value of 0 means the call was successful. Any other |
| 5502 | * nonzero value is a failure, but if ERESTART is returned, |
| 5503 | * the driver may reset the HBA and try again. |
| 5504 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5505 | rc = lpfc_config_port_prep(phba); |
| 5506 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5507 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5508 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5509 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5510 | break; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5511 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5512 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5513 | lpfc_config_port(phba, pmb); |
| 5514 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5515 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 5516 | LPFC_SLI3_HBQ_ENABLED | |
| 5517 | LPFC_SLI3_CRP_ENABLED | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 5518 | LPFC_SLI3_DSS_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5519 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5520 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5521 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5522 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5523 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5524 | spin_lock_irq(&phba->hbalock); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5525 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5526 | spin_unlock_irq(&phba->hbalock); |
| 5527 | rc = -ENXIO; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5528 | } else { |
| 5529 | /* Allow asynchronous mailbox command to go through */ |
| 5530 | spin_lock_irq(&phba->hbalock); |
| 5531 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 5532 | spin_unlock_irq(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5533 | done = 1; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 5534 | |
| 5535 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && |
| 5536 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) |
| 5537 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 5538 | "3110 Port did not grant ASABT\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5539 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5540 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5541 | if (!done) { |
| 5542 | rc = -EINVAL; |
| 5543 | goto do_prep_failed; |
| 5544 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5545 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
| 5546 | if (!pmb->u.mb.un.varCfgPort.cMA) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5547 | rc = -ENXIO; |
| 5548 | goto do_prep_failed; |
| 5549 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5550 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5551 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5552 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
| 5553 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? |
| 5554 | phba->max_vpi : phba->max_vports; |
| 5555 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5556 | } else |
| 5557 | phba->max_vpi = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5558 | if (pmb->u.mb.un.varCfgPort.gerbm) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5559 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5560 | if (pmb->u.mb.un.varCfgPort.gcrp) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5561 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 5562 | |
| 5563 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
| 5564 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5565 | |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 5566 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
| 5567 | if (pmb->u.mb.un.varCfgPort.gbg == 0) { |
| 5568 | phba->cfg_enable_bg = 0; |
| 5569 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5570 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5571 | "0443 Adapter did not grant " |
| 5572 | "BlockGuard\n"); |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 5573 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5574 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5575 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 5576 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5577 | phba->port_gp = phba->mbox->us.s2.port; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5578 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5579 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5580 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5581 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5582 | return rc; |
| 5583 | } |
| 5584 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5585 | |
| 5586 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 5587 | * lpfc_sli_hba_setup - SLI initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5588 | * @phba: Pointer to HBA context object. |
| 5589 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 5590 | * This function is the main SLI initialization function. This function |
| 5591 | * is called by the HBA initialization code, HBA reset code and HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5592 | * error attention handler code. Caller is not required to hold any |
| 5593 | * locks. This function issues config_port mailbox command to configure |
| 5594 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 5595 | * calls the config_port_post function to issue init_link mailbox |
| 5596 | * command and to start the discovery. The function will return zero |
| 5597 | * if successful, else it will return negative error code. |
| 5598 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5599 | int |
| 5600 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 5601 | { |
| 5602 | uint32_t rc; |
James Smart | d2f2547 | 2021-01-04 10:02:27 -0800 | [diff] [blame] | 5603 | int i; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5604 | int longs; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5605 | |
James Smart | d2f2547 | 2021-01-04 10:02:27 -0800 | [diff] [blame] | 5606 | /* Enable ISR already does config_port because of config_msi mbx */ |
| 5607 | if (phba->hba_flag & HBA_NEEDS_CFG_PORT) { |
| 5608 | rc = lpfc_sli_config_port(phba, LPFC_SLI_REV3); |
| 5609 | if (rc) |
| 5610 | return -EIO; |
| 5611 | phba->hba_flag &= ~HBA_NEEDS_CFG_PORT; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5612 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 5613 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5614 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 5615 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 5616 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 5617 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 5618 | if (!rc) { |
| 5619 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5620 | "2709 This device supports " |
| 5621 | "Advanced Error Reporting (AER)\n"); |
| 5622 | spin_lock_irq(&phba->hbalock); |
| 5623 | phba->hba_flag |= HBA_AER_ENABLED; |
| 5624 | spin_unlock_irq(&phba->hbalock); |
| 5625 | } else { |
| 5626 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5627 | "2708 This device does not support " |
James Smart | b069d7e | 2013-05-31 17:04:36 -0400 | [diff] [blame] | 5628 | "Advanced Error Reporting (AER): %d\n", |
| 5629 | rc); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 5630 | phba->cfg_aer_support = 0; |
| 5631 | } |
| 5632 | } |
| 5633 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5634 | if (phba->sli_rev == 3) { |
| 5635 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 5636 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5637 | } else { |
| 5638 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 5639 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5640 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5641 | } |
| 5642 | |
| 5643 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5644 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 5645 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5646 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5647 | |
| 5648 | if (rc) |
| 5649 | goto lpfc_sli_hba_setup_error; |
| 5650 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5651 | /* Initialize VPIs. */ |
| 5652 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 5653 | /* |
| 5654 | * The VPI bitmask and physical ID array are allocated |
| 5655 | * and initialized once only - at driver load. A port |
| 5656 | * reset doesn't need to reinitialize this memory. |
| 5657 | */ |
| 5658 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { |
| 5659 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5660 | phba->vpi_bmask = kcalloc(longs, |
| 5661 | sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5662 | GFP_KERNEL); |
| 5663 | if (!phba->vpi_bmask) { |
| 5664 | rc = -ENOMEM; |
| 5665 | goto lpfc_sli_hba_setup_error; |
| 5666 | } |
| 5667 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5668 | phba->vpi_ids = kcalloc(phba->max_vpi + 1, |
| 5669 | sizeof(uint16_t), |
| 5670 | GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5671 | if (!phba->vpi_ids) { |
| 5672 | kfree(phba->vpi_bmask); |
| 5673 | rc = -ENOMEM; |
| 5674 | goto lpfc_sli_hba_setup_error; |
| 5675 | } |
| 5676 | for (i = 0; i < phba->max_vpi; i++) |
| 5677 | phba->vpi_ids[i] = i; |
| 5678 | } |
| 5679 | } |
| 5680 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5681 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5682 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 5683 | rc = lpfc_sli_hbq_setup(phba); |
| 5684 | if (rc) |
| 5685 | goto lpfc_sli_hba_setup_error; |
| 5686 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5687 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5688 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5689 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5690 | |
| 5691 | rc = lpfc_config_port_post(phba); |
| 5692 | if (rc) |
| 5693 | goto lpfc_sli_hba_setup_error; |
| 5694 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5695 | return rc; |
| 5696 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5697 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5698 | phba->link_state = LPFC_HBA_ERROR; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5699 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5700 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5701 | return rc; |
| 5702 | } |
| 5703 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5704 | /** |
| 5705 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
| 5706 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 5707 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5708 | * This function issue a dump mailbox command to read config region |
| 5709 | * 23 and parse the records in the region and populate driver |
| 5710 | * data structure. |
| 5711 | **/ |
| 5712 | static int |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5713 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5714 | { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5715 | LPFC_MBOXQ_t *mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5716 | struct lpfc_dmabuf *mp; |
| 5717 | struct lpfc_mqe *mqe; |
| 5718 | uint32_t data_length; |
| 5719 | int rc; |
| 5720 | |
| 5721 | /* Program the default value of vlan_id and fc_map */ |
| 5722 | phba->valid_vlan = 0; |
| 5723 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 5724 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 5725 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 5726 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5727 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5728 | if (!mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5729 | return -ENOMEM; |
| 5730 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5731 | mqe = &mboxq->u.mqe; |
| 5732 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { |
| 5733 | rc = -ENOMEM; |
| 5734 | goto out_free_mboxq; |
| 5735 | } |
| 5736 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5737 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5738 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5739 | |
| 5740 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 5741 | "(%d):2571 Mailbox cmd x%x Status x%x " |
| 5742 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 5743 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 5744 | "CQ: x%x x%x x%x x%x\n", |
| 5745 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 5746 | bf_get(lpfc_mqe_command, mqe), |
| 5747 | bf_get(lpfc_mqe_status, mqe), |
| 5748 | mqe->un.mb_words[0], mqe->un.mb_words[1], |
| 5749 | mqe->un.mb_words[2], mqe->un.mb_words[3], |
| 5750 | mqe->un.mb_words[4], mqe->un.mb_words[5], |
| 5751 | mqe->un.mb_words[6], mqe->un.mb_words[7], |
| 5752 | mqe->un.mb_words[8], mqe->un.mb_words[9], |
| 5753 | mqe->un.mb_words[10], mqe->un.mb_words[11], |
| 5754 | mqe->un.mb_words[12], mqe->un.mb_words[13], |
| 5755 | mqe->un.mb_words[14], mqe->un.mb_words[15], |
| 5756 | mqe->un.mb_words[16], mqe->un.mb_words[50], |
| 5757 | mboxq->mcqe.word0, |
| 5758 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 5759 | mboxq->mcqe.trailer); |
| 5760 | |
| 5761 | if (rc) { |
| 5762 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5763 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5764 | rc = -EIO; |
| 5765 | goto out_free_mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5766 | } |
| 5767 | data_length = mqe->un.mb_words[5]; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 5768 | if (data_length > DMP_RGN23_SIZE) { |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5769 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5770 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5771 | rc = -EIO; |
| 5772 | goto out_free_mboxq; |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5773 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5774 | |
| 5775 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
| 5776 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5777 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5778 | rc = 0; |
| 5779 | |
| 5780 | out_free_mboxq: |
| 5781 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5782 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5783 | } |
| 5784 | |
| 5785 | /** |
| 5786 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
| 5787 | * @phba: pointer to lpfc hba data structure. |
| 5788 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. |
| 5789 | * @vpd: pointer to the memory to hold resulting port vpd data. |
| 5790 | * @vpd_size: On input, the number of bytes allocated to @vpd. |
| 5791 | * On output, the number of data bytes in @vpd. |
| 5792 | * |
| 5793 | * This routine executes a READ_REV SLI4 mailbox command. In |
| 5794 | * addition, this routine gets the port vpd data. |
| 5795 | * |
| 5796 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5797 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 5798 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5799 | **/ |
| 5800 | static int |
| 5801 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 5802 | uint8_t *vpd, uint32_t *vpd_size) |
| 5803 | { |
| 5804 | int rc = 0; |
| 5805 | uint32_t dma_size; |
| 5806 | struct lpfc_dmabuf *dmabuf; |
| 5807 | struct lpfc_mqe *mqe; |
| 5808 | |
| 5809 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5810 | if (!dmabuf) |
| 5811 | return -ENOMEM; |
| 5812 | |
| 5813 | /* |
| 5814 | * Get a DMA buffer for the vpd data resulting from the READ_REV |
| 5815 | * mailbox command. |
| 5816 | */ |
| 5817 | dma_size = *vpd_size; |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 5818 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, dma_size, |
| 5819 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5820 | if (!dmabuf->virt) { |
| 5821 | kfree(dmabuf); |
| 5822 | return -ENOMEM; |
| 5823 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5824 | |
| 5825 | /* |
| 5826 | * The SLI4 implementation of READ_REV conflicts at word1, |
| 5827 | * bits 31:16 and SLI4 adds vpd functionality not present |
| 5828 | * in SLI3. This code corrects the conflicts. |
| 5829 | */ |
| 5830 | lpfc_read_rev(phba, mboxq); |
| 5831 | mqe = &mboxq->u.mqe; |
| 5832 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); |
| 5833 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); |
| 5834 | mqe->un.read_rev.word1 &= 0x0000FFFF; |
| 5835 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); |
| 5836 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); |
| 5837 | |
| 5838 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5839 | if (rc) { |
| 5840 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 5841 | dmabuf->virt, dmabuf->phys); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 5842 | kfree(dmabuf); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5843 | return -EIO; |
| 5844 | } |
| 5845 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5846 | /* |
| 5847 | * The available vpd length cannot be bigger than the |
| 5848 | * DMA buffer passed to the port. Catch the less than |
| 5849 | * case and update the caller's size. |
| 5850 | */ |
| 5851 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) |
| 5852 | *vpd_size = mqe->un.read_rev.avail_vpd_len; |
| 5853 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5854 | memcpy(vpd, dmabuf->virt, *vpd_size); |
| 5855 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5856 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 5857 | dmabuf->virt, dmabuf->phys); |
| 5858 | kfree(dmabuf); |
| 5859 | return 0; |
| 5860 | } |
| 5861 | |
| 5862 | /** |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5863 | * lpfc_sli4_get_ctl_attr - Retrieve SLI4 device controller attributes |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5864 | * @phba: pointer to lpfc hba data structure. |
| 5865 | * |
| 5866 | * This routine retrieves SLI4 device physical port name this PCI function |
| 5867 | * is attached to. |
| 5868 | * |
| 5869 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 5870 | * 0 - successful |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5871 | * otherwise - failed to retrieve controller attributes |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5872 | **/ |
| 5873 | static int |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5874 | lpfc_sli4_get_ctl_attr(struct lpfc_hba *phba) |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5875 | { |
| 5876 | LPFC_MBOXQ_t *mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5877 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
| 5878 | struct lpfc_controller_attribute *cntl_attr; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5879 | void *virtaddr = NULL; |
| 5880 | uint32_t alloclen, reqlen; |
| 5881 | uint32_t shdr_status, shdr_add_status; |
| 5882 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5883 | int rc; |
| 5884 | |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5885 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5886 | if (!mboxq) |
| 5887 | return -ENOMEM; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5888 | |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5889 | /* Send COMMON_GET_CNTL_ATTRIBUTES mbox cmd */ |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5890 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); |
| 5891 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5892 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, |
| 5893 | LPFC_SLI4_MBX_NEMBED); |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5894 | |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5895 | if (alloclen < reqlen) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5896 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5897 | "3084 Allocated DMA memory size (%d) is " |
| 5898 | "less than the requested DMA memory size " |
| 5899 | "(%d)\n", alloclen, reqlen); |
| 5900 | rc = -ENOMEM; |
| 5901 | goto out_free_mboxq; |
| 5902 | } |
| 5903 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5904 | virtaddr = mboxq->sge_array->addr[0]; |
| 5905 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; |
| 5906 | shdr = &mbx_cntl_attr->cfg_shdr; |
| 5907 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5908 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5909 | if (shdr_status || shdr_add_status || rc) { |
| 5910 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5911 | "3085 Mailbox x%x (x%x/x%x) failed, " |
| 5912 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5913 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5914 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5915 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5916 | rc, shdr_status, shdr_add_status); |
| 5917 | rc = -ENXIO; |
| 5918 | goto out_free_mboxq; |
| 5919 | } |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5920 | |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5921 | cntl_attr = &mbx_cntl_attr->cntl_attr; |
| 5922 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 5923 | phba->sli4_hba.lnk_info.lnk_tp = |
| 5924 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); |
| 5925 | phba->sli4_hba.lnk_info.lnk_no = |
| 5926 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); |
James Smart | 16a93e8 | 2021-07-07 11:43:34 -0700 | [diff] [blame] | 5927 | phba->sli4_hba.flash_id = bf_get(lpfc_cntl_attr_flash_id, cntl_attr); |
| 5928 | phba->sli4_hba.asic_rev = bf_get(lpfc_cntl_attr_asic_rev, cntl_attr); |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5929 | |
| 5930 | memset(phba->BIOSVersion, 0, sizeof(phba->BIOSVersion)); |
| 5931 | strlcat(phba->BIOSVersion, (char *)cntl_attr->bios_ver_str, |
| 5932 | sizeof(phba->BIOSVersion)); |
| 5933 | |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5934 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 16a93e8 | 2021-07-07 11:43:34 -0700 | [diff] [blame] | 5935 | "3086 lnk_type:%d, lnk_numb:%d, bios_ver:%s, " |
| 5936 | "flash_id: x%02x, asic_rev: x%02x\n", |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5937 | phba->sli4_hba.lnk_info.lnk_tp, |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5938 | phba->sli4_hba.lnk_info.lnk_no, |
James Smart | 16a93e8 | 2021-07-07 11:43:34 -0700 | [diff] [blame] | 5939 | phba->BIOSVersion, phba->sli4_hba.flash_id, |
| 5940 | phba->sli4_hba.asic_rev); |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5941 | out_free_mboxq: |
James Smart | 304ee43 | 2021-04-11 18:31:17 -0700 | [diff] [blame] | 5942 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 5943 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 5944 | else |
| 5945 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5946 | return rc; |
| 5947 | } |
| 5948 | |
| 5949 | /** |
| 5950 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name |
| 5951 | * @phba: pointer to lpfc hba data structure. |
| 5952 | * |
| 5953 | * This routine retrieves SLI4 device physical port name this PCI function |
| 5954 | * is attached to. |
| 5955 | * |
| 5956 | * Return codes |
| 5957 | * 0 - successful |
| 5958 | * otherwise - failed to retrieve physical port name |
| 5959 | **/ |
| 5960 | static int |
| 5961 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) |
| 5962 | { |
| 5963 | LPFC_MBOXQ_t *mboxq; |
| 5964 | struct lpfc_mbx_get_port_name *get_port_name; |
| 5965 | uint32_t shdr_status, shdr_add_status; |
| 5966 | union lpfc_sli4_cfg_shdr *shdr; |
| 5967 | char cport_name = 0; |
| 5968 | int rc; |
| 5969 | |
| 5970 | /* We assume nothing at this point */ |
| 5971 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 5972 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; |
| 5973 | |
| 5974 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5975 | if (!mboxq) |
| 5976 | return -ENOMEM; |
| 5977 | /* obtain link type and link number via READ_CONFIG */ |
| 5978 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 5979 | lpfc_sli4_read_config(phba); |
| 5980 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) |
| 5981 | goto retrieve_ppname; |
| 5982 | |
| 5983 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ |
| 5984 | rc = lpfc_sli4_get_ctl_attr(phba); |
| 5985 | if (rc) |
| 5986 | goto out_free_mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5987 | |
| 5988 | retrieve_ppname: |
| 5989 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5990 | LPFC_MBOX_OPCODE_GET_PORT_NAME, |
| 5991 | sizeof(struct lpfc_mbx_get_port_name) - |
| 5992 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 5993 | LPFC_SLI4_MBX_EMBED); |
| 5994 | get_port_name = &mboxq->u.mqe.un.get_port_name; |
| 5995 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; |
| 5996 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); |
| 5997 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, |
| 5998 | phba->sli4_hba.lnk_info.lnk_tp); |
| 5999 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6000 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 6001 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 6002 | if (shdr_status || shdr_add_status || rc) { |
| 6003 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 6004 | "3087 Mailbox x%x (x%x/x%x) failed: " |
| 6005 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 6006 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 6007 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 6008 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 6009 | rc, shdr_status, shdr_add_status); |
| 6010 | rc = -ENXIO; |
| 6011 | goto out_free_mboxq; |
| 6012 | } |
| 6013 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 6014 | case LPFC_LINK_NUMBER_0: |
| 6015 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, |
| 6016 | &get_port_name->u.response); |
| 6017 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 6018 | break; |
| 6019 | case LPFC_LINK_NUMBER_1: |
| 6020 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, |
| 6021 | &get_port_name->u.response); |
| 6022 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 6023 | break; |
| 6024 | case LPFC_LINK_NUMBER_2: |
| 6025 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, |
| 6026 | &get_port_name->u.response); |
| 6027 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 6028 | break; |
| 6029 | case LPFC_LINK_NUMBER_3: |
| 6030 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, |
| 6031 | &get_port_name->u.response); |
| 6032 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 6033 | break; |
| 6034 | default: |
| 6035 | break; |
| 6036 | } |
| 6037 | |
| 6038 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { |
| 6039 | phba->Port[0] = cport_name; |
| 6040 | phba->Port[1] = '\0'; |
| 6041 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 6042 | "3091 SLI get port name: %s\n", phba->Port); |
| 6043 | } |
| 6044 | |
| 6045 | out_free_mboxq: |
James Smart | 304ee43 | 2021-04-11 18:31:17 -0700 | [diff] [blame] | 6046 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 6047 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 6048 | else |
| 6049 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6050 | return rc; |
| 6051 | } |
| 6052 | |
| 6053 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6054 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
| 6055 | * @phba: pointer to lpfc hba data structure. |
| 6056 | * |
| 6057 | * This routine is called to explicitly arm the SLI4 device's completion and |
| 6058 | * event queues |
| 6059 | **/ |
| 6060 | static void |
| 6061 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) |
| 6062 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6063 | int qidx; |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 6064 | struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 6065 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 6066 | struct lpfc_queue *eq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6067 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 6068 | sli4_hba->sli4_write_cq_db(phba, sli4_hba->mbx_cq, 0, LPFC_QUEUE_REARM); |
| 6069 | 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] | 6070 | if (sli4_hba->nvmels_cq) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 6071 | sli4_hba->sli4_write_cq_db(phba, sli4_hba->nvmels_cq, 0, |
| 6072 | LPFC_QUEUE_REARM); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6073 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 6074 | if (sli4_hba->hdwq) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 6075 | /* Loop thru all Hardware Queues */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 6076 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 6077 | qp = &sli4_hba->hdwq[qidx]; |
| 6078 | /* ARM the corresponding CQ */ |
James Smart | 01f2ef6 | 2019-08-28 16:19:11 -0700 | [diff] [blame] | 6079 | sli4_hba->sli4_write_cq_db(phba, qp->io_cq, 0, |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 6080 | LPFC_QUEUE_REARM); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 6081 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6082 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 6083 | /* Loop thru all IRQ vectors */ |
| 6084 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
| 6085 | eq = sli4_hba->hba_eq_hdl[qidx].eq; |
| 6086 | /* ARM the corresponding EQ */ |
| 6087 | sli4_hba->sli4_write_eq_db(phba, eq, |
| 6088 | 0, LPFC_QUEUE_REARM); |
| 6089 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 6090 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6091 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 6092 | if (phba->nvmet_support) { |
| 6093 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 6094 | sli4_hba->sli4_write_cq_db(phba, |
| 6095 | sli4_hba->nvmet_cqset[qidx], 0, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 6096 | LPFC_QUEUE_REARM); |
| 6097 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 6098 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6099 | } |
| 6100 | |
| 6101 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6102 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. |
| 6103 | * @phba: Pointer to HBA context object. |
| 6104 | * @type: The resource extent type. |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6105 | * @extnt_count: buffer to hold port available extent count. |
| 6106 | * @extnt_size: buffer to hold element count per extent. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6107 | * |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6108 | * This function calls the port and retrievs the number of available |
| 6109 | * extents and their size for a particular extent type. |
| 6110 | * |
| 6111 | * Returns: 0 if successful. Nonzero otherwise. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6112 | **/ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6113 | int |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6114 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
| 6115 | uint16_t *extnt_count, uint16_t *extnt_size) |
| 6116 | { |
| 6117 | int rc = 0; |
| 6118 | uint32_t length; |
| 6119 | uint32_t mbox_tmo; |
| 6120 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; |
| 6121 | LPFC_MBOXQ_t *mbox; |
| 6122 | |
| 6123 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6124 | if (!mbox) |
| 6125 | return -ENOMEM; |
| 6126 | |
| 6127 | /* Find out how many extents are available for this resource type */ |
| 6128 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - |
| 6129 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6130 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6131 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, |
| 6132 | length, LPFC_SLI4_MBX_EMBED); |
| 6133 | |
| 6134 | /* Send an extents count of 0 - the GET doesn't use it. */ |
| 6135 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 6136 | LPFC_SLI4_MBX_EMBED); |
| 6137 | if (unlikely(rc)) { |
| 6138 | rc = -EIO; |
| 6139 | goto err_exit; |
| 6140 | } |
| 6141 | |
| 6142 | if (!phba->sli4_hba.intr_enable) |
| 6143 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 6144 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6145 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6146 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 6147 | } |
| 6148 | if (unlikely(rc)) { |
| 6149 | rc = -EIO; |
| 6150 | goto err_exit; |
| 6151 | } |
| 6152 | |
| 6153 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; |
| 6154 | if (bf_get(lpfc_mbox_hdr_status, |
| 6155 | &rsrc_info->header.cfg_shdr.response)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6156 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6157 | "2930 Failed to get resource extents " |
| 6158 | "Status 0x%x Add'l Status 0x%x\n", |
| 6159 | bf_get(lpfc_mbox_hdr_status, |
| 6160 | &rsrc_info->header.cfg_shdr.response), |
| 6161 | bf_get(lpfc_mbox_hdr_add_status, |
| 6162 | &rsrc_info->header.cfg_shdr.response)); |
| 6163 | rc = -EIO; |
| 6164 | goto err_exit; |
| 6165 | } |
| 6166 | |
| 6167 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, |
| 6168 | &rsrc_info->u.rsp); |
| 6169 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, |
| 6170 | &rsrc_info->u.rsp); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6171 | |
| 6172 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 6173 | "3162 Retrieved extents type-%d from port: count:%d, " |
| 6174 | "size:%d\n", type, *extnt_count, *extnt_size); |
| 6175 | |
| 6176 | err_exit: |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6177 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6178 | return rc; |
| 6179 | } |
| 6180 | |
| 6181 | /** |
| 6182 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. |
| 6183 | * @phba: Pointer to HBA context object. |
| 6184 | * @type: The extent type to check. |
| 6185 | * |
| 6186 | * This function reads the current available extents from the port and checks |
| 6187 | * if the extent count or extent size has changed since the last access. |
| 6188 | * Callers use this routine post port reset to understand if there is a |
| 6189 | * extent reprovisioning requirement. |
| 6190 | * |
| 6191 | * Returns: |
| 6192 | * -Error: error indicates problem. |
| 6193 | * 1: Extent count or size has changed. |
| 6194 | * 0: No changes. |
| 6195 | **/ |
| 6196 | static int |
| 6197 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) |
| 6198 | { |
| 6199 | uint16_t curr_ext_cnt, rsrc_ext_cnt; |
| 6200 | uint16_t size_diff, rsrc_ext_size; |
| 6201 | int rc = 0; |
| 6202 | struct lpfc_rsrc_blks *rsrc_entry; |
| 6203 | struct list_head *rsrc_blk_list = NULL; |
| 6204 | |
| 6205 | size_diff = 0; |
| 6206 | curr_ext_cnt = 0; |
| 6207 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 6208 | &rsrc_ext_cnt, |
| 6209 | &rsrc_ext_size); |
| 6210 | if (unlikely(rc)) |
| 6211 | return -EIO; |
| 6212 | |
| 6213 | switch (type) { |
| 6214 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 6215 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 6216 | break; |
| 6217 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 6218 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; |
| 6219 | break; |
| 6220 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 6221 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 6222 | break; |
| 6223 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 6224 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 6225 | break; |
| 6226 | default: |
| 6227 | break; |
| 6228 | } |
| 6229 | |
| 6230 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { |
| 6231 | curr_ext_cnt++; |
| 6232 | if (rsrc_entry->rsrc_size != rsrc_ext_size) |
| 6233 | size_diff++; |
| 6234 | } |
| 6235 | |
| 6236 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) |
| 6237 | rc = 1; |
| 6238 | |
| 6239 | return rc; |
| 6240 | } |
| 6241 | |
| 6242 | /** |
| 6243 | * lpfc_sli4_cfg_post_extnts - |
| 6244 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 6245 | * @extnt_cnt: number of available extents. |
| 6246 | * @type: the extent type (rpi, xri, vfi, vpi). |
| 6247 | * @emb: buffer to hold either MBX_EMBED or MBX_NEMBED operation. |
| 6248 | * @mbox: pointer to the caller's allocated mailbox structure. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6249 | * |
| 6250 | * This function executes the extents allocation request. It also |
| 6251 | * takes care of the amount of memory needed to allocate or get the |
| 6252 | * allocated extents. It is the caller's responsibility to evaluate |
| 6253 | * the response. |
| 6254 | * |
| 6255 | * Returns: |
| 6256 | * -Error: Error value describes the condition found. |
| 6257 | * 0: if successful |
| 6258 | **/ |
| 6259 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6260 | 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] | 6261 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
| 6262 | { |
| 6263 | int rc = 0; |
| 6264 | uint32_t req_len; |
| 6265 | uint32_t emb_len; |
| 6266 | uint32_t alloc_len, mbox_tmo; |
| 6267 | |
| 6268 | /* Calculate the total requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6269 | req_len = extnt_cnt * sizeof(uint16_t); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6270 | |
| 6271 | /* |
| 6272 | * Calculate the size of an embedded mailbox. The uint32_t |
| 6273 | * accounts for extents-specific word. |
| 6274 | */ |
| 6275 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 6276 | sizeof(uint32_t); |
| 6277 | |
| 6278 | /* |
| 6279 | * Presume the allocation and response will fit into an embedded |
| 6280 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 6281 | */ |
| 6282 | *emb = LPFC_SLI4_MBX_EMBED; |
| 6283 | if (req_len > emb_len) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6284 | req_len = extnt_cnt * sizeof(uint16_t) + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6285 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 6286 | sizeof(uint32_t); |
| 6287 | *emb = LPFC_SLI4_MBX_NEMBED; |
| 6288 | } |
| 6289 | |
| 6290 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6291 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, |
| 6292 | req_len, *emb); |
| 6293 | if (alloc_len < req_len) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6294 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6295 | "2982 Allocated DMA memory size (x%x) is " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6296 | "less than the requested DMA memory " |
| 6297 | "size (x%x)\n", alloc_len, req_len); |
| 6298 | return -ENOMEM; |
| 6299 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6300 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6301 | if (unlikely(rc)) |
| 6302 | return -EIO; |
| 6303 | |
| 6304 | if (!phba->sli4_hba.intr_enable) |
| 6305 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 6306 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6307 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6308 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 6309 | } |
| 6310 | |
| 6311 | if (unlikely(rc)) |
| 6312 | rc = -EIO; |
| 6313 | return rc; |
| 6314 | } |
| 6315 | |
| 6316 | /** |
| 6317 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. |
| 6318 | * @phba: Pointer to HBA context object. |
| 6319 | * @type: The resource extent type to allocate. |
| 6320 | * |
| 6321 | * This function allocates the number of elements for the specified |
| 6322 | * resource type. |
| 6323 | **/ |
| 6324 | static int |
| 6325 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 6326 | { |
| 6327 | bool emb = false; |
| 6328 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; |
| 6329 | uint16_t rsrc_id, rsrc_start, j, k; |
| 6330 | uint16_t *ids; |
| 6331 | int i, rc; |
| 6332 | unsigned long longs; |
| 6333 | unsigned long *bmask; |
| 6334 | struct lpfc_rsrc_blks *rsrc_blks; |
| 6335 | LPFC_MBOXQ_t *mbox; |
| 6336 | uint32_t length; |
| 6337 | struct lpfc_id_range *id_array = NULL; |
| 6338 | void *virtaddr = NULL; |
| 6339 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 6340 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 6341 | struct list_head *ext_blk_list; |
| 6342 | |
| 6343 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 6344 | &rsrc_cnt, |
| 6345 | &rsrc_size); |
| 6346 | if (unlikely(rc)) |
| 6347 | return -EIO; |
| 6348 | |
| 6349 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6350 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6351 | "3009 No available Resource Extents " |
| 6352 | "for resource type 0x%x: Count: 0x%x, " |
| 6353 | "Size 0x%x\n", type, rsrc_cnt, |
| 6354 | rsrc_size); |
| 6355 | return -ENOMEM; |
| 6356 | } |
| 6357 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6358 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
| 6359 | "2903 Post resource extents type-0x%x: " |
| 6360 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6361 | |
| 6362 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6363 | if (!mbox) |
| 6364 | return -ENOMEM; |
| 6365 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6366 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6367 | if (unlikely(rc)) { |
| 6368 | rc = -EIO; |
| 6369 | goto err_exit; |
| 6370 | } |
| 6371 | |
| 6372 | /* |
| 6373 | * Figure out where the response is located. Then get local pointers |
| 6374 | * to the response data. The port does not guarantee to respond to |
| 6375 | * all extents counts request so update the local variable with the |
| 6376 | * allocated count from the port. |
| 6377 | */ |
| 6378 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 6379 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 6380 | id_array = &rsrc_ext->u.rsp.id[0]; |
| 6381 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 6382 | } else { |
| 6383 | virtaddr = mbox->sge_array->addr[0]; |
| 6384 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 6385 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 6386 | id_array = &n_rsrc->id; |
| 6387 | } |
| 6388 | |
| 6389 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 6390 | rsrc_id_cnt = rsrc_cnt * rsrc_size; |
| 6391 | |
| 6392 | /* |
| 6393 | * Based on the resource size and count, correct the base and max |
| 6394 | * resource values. |
| 6395 | */ |
| 6396 | length = sizeof(struct lpfc_rsrc_blks); |
| 6397 | switch (type) { |
| 6398 | case LPFC_RSC_TYPE_FCOE_RPI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6399 | phba->sli4_hba.rpi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6400 | sizeof(unsigned long), |
| 6401 | GFP_KERNEL); |
| 6402 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 6403 | rc = -ENOMEM; |
| 6404 | goto err_exit; |
| 6405 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6406 | phba->sli4_hba.rpi_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6407 | sizeof(uint16_t), |
| 6408 | GFP_KERNEL); |
| 6409 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 6410 | kfree(phba->sli4_hba.rpi_bmask); |
| 6411 | rc = -ENOMEM; |
| 6412 | goto err_exit; |
| 6413 | } |
| 6414 | |
| 6415 | /* |
| 6416 | * The next_rpi was initialized with the maximum available |
| 6417 | * count but the port may allocate a smaller number. Catch |
| 6418 | * that case and update the next_rpi. |
| 6419 | */ |
| 6420 | phba->sli4_hba.next_rpi = rsrc_id_cnt; |
| 6421 | |
| 6422 | /* Initialize local ptrs for common extent processing later. */ |
| 6423 | bmask = phba->sli4_hba.rpi_bmask; |
| 6424 | ids = phba->sli4_hba.rpi_ids; |
| 6425 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 6426 | break; |
| 6427 | case LPFC_RSC_TYPE_FCOE_VPI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6428 | phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6429 | GFP_KERNEL); |
| 6430 | if (unlikely(!phba->vpi_bmask)) { |
| 6431 | rc = -ENOMEM; |
| 6432 | goto err_exit; |
| 6433 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6434 | phba->vpi_ids = kcalloc(rsrc_id_cnt, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6435 | GFP_KERNEL); |
| 6436 | if (unlikely(!phba->vpi_ids)) { |
| 6437 | kfree(phba->vpi_bmask); |
| 6438 | rc = -ENOMEM; |
| 6439 | goto err_exit; |
| 6440 | } |
| 6441 | |
| 6442 | /* Initialize local ptrs for common extent processing later. */ |
| 6443 | bmask = phba->vpi_bmask; |
| 6444 | ids = phba->vpi_ids; |
| 6445 | ext_blk_list = &phba->lpfc_vpi_blk_list; |
| 6446 | break; |
| 6447 | case LPFC_RSC_TYPE_FCOE_XRI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6448 | phba->sli4_hba.xri_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6449 | sizeof(unsigned long), |
| 6450 | GFP_KERNEL); |
| 6451 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 6452 | rc = -ENOMEM; |
| 6453 | goto err_exit; |
| 6454 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6455 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6456 | phba->sli4_hba.xri_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6457 | sizeof(uint16_t), |
| 6458 | GFP_KERNEL); |
| 6459 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 6460 | kfree(phba->sli4_hba.xri_bmask); |
| 6461 | rc = -ENOMEM; |
| 6462 | goto err_exit; |
| 6463 | } |
| 6464 | |
| 6465 | /* Initialize local ptrs for common extent processing later. */ |
| 6466 | bmask = phba->sli4_hba.xri_bmask; |
| 6467 | ids = phba->sli4_hba.xri_ids; |
| 6468 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 6469 | break; |
| 6470 | case LPFC_RSC_TYPE_FCOE_VFI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6471 | phba->sli4_hba.vfi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6472 | sizeof(unsigned long), |
| 6473 | GFP_KERNEL); |
| 6474 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 6475 | rc = -ENOMEM; |
| 6476 | goto err_exit; |
| 6477 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6478 | phba->sli4_hba.vfi_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6479 | sizeof(uint16_t), |
| 6480 | GFP_KERNEL); |
| 6481 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 6482 | kfree(phba->sli4_hba.vfi_bmask); |
| 6483 | rc = -ENOMEM; |
| 6484 | goto err_exit; |
| 6485 | } |
| 6486 | |
| 6487 | /* Initialize local ptrs for common extent processing later. */ |
| 6488 | bmask = phba->sli4_hba.vfi_bmask; |
| 6489 | ids = phba->sli4_hba.vfi_ids; |
| 6490 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 6491 | break; |
| 6492 | default: |
| 6493 | /* Unsupported Opcode. Fail call. */ |
| 6494 | id_array = NULL; |
| 6495 | bmask = NULL; |
| 6496 | ids = NULL; |
| 6497 | ext_blk_list = NULL; |
| 6498 | goto err_exit; |
| 6499 | } |
| 6500 | |
| 6501 | /* |
| 6502 | * Complete initializing the extent configuration with the |
| 6503 | * allocated ids assigned to this function. The bitmask serves |
| 6504 | * as an index into the array and manages the available ids. The |
| 6505 | * array just stores the ids communicated to the port via the wqes. |
| 6506 | */ |
| 6507 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { |
| 6508 | if ((i % 2) == 0) |
| 6509 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, |
| 6510 | &id_array[k]); |
| 6511 | else |
| 6512 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, |
| 6513 | &id_array[k]); |
| 6514 | |
| 6515 | rsrc_blks = kzalloc(length, GFP_KERNEL); |
| 6516 | if (unlikely(!rsrc_blks)) { |
| 6517 | rc = -ENOMEM; |
| 6518 | kfree(bmask); |
| 6519 | kfree(ids); |
| 6520 | goto err_exit; |
| 6521 | } |
| 6522 | rsrc_blks->rsrc_start = rsrc_id; |
| 6523 | rsrc_blks->rsrc_size = rsrc_size; |
| 6524 | list_add_tail(&rsrc_blks->list, ext_blk_list); |
| 6525 | rsrc_start = rsrc_id; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6526 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 6527 | phba->sli4_hba.io_xri_start = rsrc_start + |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6528 | lpfc_sli4_get_iocb_cnt(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6529 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6530 | |
| 6531 | while (rsrc_id < (rsrc_start + rsrc_size)) { |
| 6532 | ids[j] = rsrc_id; |
| 6533 | rsrc_id++; |
| 6534 | j++; |
| 6535 | } |
| 6536 | /* Entire word processed. Get next word.*/ |
| 6537 | if ((i % 2) == 1) |
| 6538 | k++; |
| 6539 | } |
| 6540 | err_exit: |
| 6541 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 6542 | return rc; |
| 6543 | } |
| 6544 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6545 | |
| 6546 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6547 | /** |
| 6548 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. |
| 6549 | * @phba: Pointer to HBA context object. |
| 6550 | * @type: the extent's type. |
| 6551 | * |
| 6552 | * This function deallocates all extents of a particular resource type. |
| 6553 | * SLI4 does not allow for deallocating a particular extent range. It |
| 6554 | * is the caller's responsibility to release all kernel memory resources. |
| 6555 | **/ |
| 6556 | static int |
| 6557 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 6558 | { |
| 6559 | int rc; |
| 6560 | uint32_t length, mbox_tmo = 0; |
| 6561 | LPFC_MBOXQ_t *mbox; |
| 6562 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; |
| 6563 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; |
| 6564 | |
| 6565 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6566 | if (!mbox) |
| 6567 | return -ENOMEM; |
| 6568 | |
| 6569 | /* |
| 6570 | * This function sends an embedded mailbox because it only sends the |
| 6571 | * the resource type. All extents of this type are released by the |
| 6572 | * port. |
| 6573 | */ |
| 6574 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - |
| 6575 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6576 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6577 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, |
| 6578 | length, LPFC_SLI4_MBX_EMBED); |
| 6579 | |
| 6580 | /* Send an extents count of 0 - the dealloc doesn't use it. */ |
| 6581 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 6582 | LPFC_SLI4_MBX_EMBED); |
| 6583 | if (unlikely(rc)) { |
| 6584 | rc = -EIO; |
| 6585 | goto out_free_mbox; |
| 6586 | } |
| 6587 | if (!phba->sli4_hba.intr_enable) |
| 6588 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 6589 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6590 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6591 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 6592 | } |
| 6593 | if (unlikely(rc)) { |
| 6594 | rc = -EIO; |
| 6595 | goto out_free_mbox; |
| 6596 | } |
| 6597 | |
| 6598 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; |
| 6599 | if (bf_get(lpfc_mbox_hdr_status, |
| 6600 | &dealloc_rsrc->header.cfg_shdr.response)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6601 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6602 | "2919 Failed to release resource extents " |
| 6603 | "for type %d - Status 0x%x Add'l Status 0x%x. " |
| 6604 | "Resource memory not released.\n", |
| 6605 | type, |
| 6606 | bf_get(lpfc_mbox_hdr_status, |
| 6607 | &dealloc_rsrc->header.cfg_shdr.response), |
| 6608 | bf_get(lpfc_mbox_hdr_add_status, |
| 6609 | &dealloc_rsrc->header.cfg_shdr.response)); |
| 6610 | rc = -EIO; |
| 6611 | goto out_free_mbox; |
| 6612 | } |
| 6613 | |
| 6614 | /* Release kernel memory resources for the specific type. */ |
| 6615 | switch (type) { |
| 6616 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 6617 | kfree(phba->vpi_bmask); |
| 6618 | kfree(phba->vpi_ids); |
| 6619 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6620 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6621 | &phba->lpfc_vpi_blk_list, list) { |
| 6622 | list_del_init(&rsrc_blk->list); |
| 6623 | kfree(rsrc_blk); |
| 6624 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 6625 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6626 | break; |
| 6627 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 6628 | kfree(phba->sli4_hba.xri_bmask); |
| 6629 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6630 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6631 | &phba->sli4_hba.lpfc_xri_blk_list, list) { |
| 6632 | list_del_init(&rsrc_blk->list); |
| 6633 | kfree(rsrc_blk); |
| 6634 | } |
| 6635 | break; |
| 6636 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 6637 | kfree(phba->sli4_hba.vfi_bmask); |
| 6638 | kfree(phba->sli4_hba.vfi_ids); |
| 6639 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6640 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6641 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { |
| 6642 | list_del_init(&rsrc_blk->list); |
| 6643 | kfree(rsrc_blk); |
| 6644 | } |
| 6645 | break; |
| 6646 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 6647 | /* RPI bitmask and physical id array are cleaned up earlier. */ |
| 6648 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6649 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { |
| 6650 | list_del_init(&rsrc_blk->list); |
| 6651 | kfree(rsrc_blk); |
| 6652 | } |
| 6653 | break; |
| 6654 | default: |
| 6655 | break; |
| 6656 | } |
| 6657 | |
| 6658 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6659 | |
| 6660 | out_free_mbox: |
| 6661 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6662 | return rc; |
| 6663 | } |
| 6664 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 6665 | static void |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6666 | lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox, |
| 6667 | uint32_t feature) |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6668 | { |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6669 | uint32_t len; |
James Smart | 9064aeb | 2021-08-16 09:28:50 -0700 | [diff] [blame] | 6670 | u32 sig_freq = 0; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6671 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6672 | len = sizeof(struct lpfc_mbx_set_feature) - |
| 6673 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 6674 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6675 | LPFC_MBOX_OPCODE_SET_FEATURES, len, |
| 6676 | LPFC_SLI4_MBX_EMBED); |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6677 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6678 | switch (feature) { |
| 6679 | case LPFC_SET_UE_RECOVERY: |
| 6680 | bf_set(lpfc_mbx_set_feature_UER, |
| 6681 | &mbox->u.mqe.un.set_feature, 1); |
| 6682 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY; |
| 6683 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 6684 | break; |
| 6685 | case LPFC_SET_MDS_DIAGS: |
| 6686 | bf_set(lpfc_mbx_set_feature_mds, |
| 6687 | &mbox->u.mqe.un.set_feature, 1); |
| 6688 | bf_set(lpfc_mbx_set_feature_mds_deep_loopbk, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 6689 | &mbox->u.mqe.un.set_feature, 1); |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6690 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS; |
| 6691 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 6692 | break; |
James Smart | 9064aeb | 2021-08-16 09:28:50 -0700 | [diff] [blame] | 6693 | case LPFC_SET_CGN_SIGNAL: |
| 6694 | if (phba->cmf_active_mode == LPFC_CFG_OFF) |
| 6695 | sig_freq = 0; |
| 6696 | else |
| 6697 | sig_freq = phba->cgn_sig_freq; |
| 6698 | |
| 6699 | if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) { |
| 6700 | bf_set(lpfc_mbx_set_feature_CGN_alarm_freq, |
| 6701 | &mbox->u.mqe.un.set_feature, sig_freq); |
| 6702 | bf_set(lpfc_mbx_set_feature_CGN_warn_freq, |
| 6703 | &mbox->u.mqe.un.set_feature, sig_freq); |
| 6704 | } |
| 6705 | |
| 6706 | if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY) |
| 6707 | bf_set(lpfc_mbx_set_feature_CGN_warn_freq, |
| 6708 | &mbox->u.mqe.un.set_feature, sig_freq); |
| 6709 | |
| 6710 | if (phba->cmf_active_mode == LPFC_CFG_OFF || |
| 6711 | phba->cgn_reg_signal == EDC_CG_SIG_NOTSUPPORTED) |
| 6712 | sig_freq = 0; |
| 6713 | else |
| 6714 | sig_freq = lpfc_acqe_cgn_frequency; |
| 6715 | |
| 6716 | bf_set(lpfc_mbx_set_feature_CGN_acqe_freq, |
| 6717 | &mbox->u.mqe.un.set_feature, sig_freq); |
| 6718 | |
| 6719 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_CGN_SIGNAL; |
| 6720 | mbox->u.mqe.un.set_feature.param_len = 12; |
| 6721 | break; |
James Smart | 171f6c4 | 2019-11-04 16:57:07 -0800 | [diff] [blame] | 6722 | case LPFC_SET_DUAL_DUMP: |
| 6723 | bf_set(lpfc_mbx_set_feature_dd, |
| 6724 | &mbox->u.mqe.un.set_feature, LPFC_ENABLE_DUAL_DUMP); |
| 6725 | bf_set(lpfc_mbx_set_feature_ddquery, |
| 6726 | &mbox->u.mqe.un.set_feature, 0); |
| 6727 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_DUAL_DUMP; |
| 6728 | mbox->u.mqe.un.set_feature.param_len = 4; |
| 6729 | break; |
James Smart | c6a5c747 | 2021-08-16 09:28:48 -0700 | [diff] [blame] | 6730 | case LPFC_SET_ENABLE_MI: |
| 6731 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_ENABLE_MI; |
| 6732 | mbox->u.mqe.un.set_feature.param_len = 4; |
| 6733 | bf_set(lpfc_mbx_set_feature_milunq, &mbox->u.mqe.un.set_feature, |
| 6734 | phba->pport->cfg_lun_queue_depth); |
| 6735 | bf_set(lpfc_mbx_set_feature_mi, &mbox->u.mqe.un.set_feature, |
| 6736 | phba->sli4_hba.pc_sli4_params.mi_ver); |
| 6737 | break; |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 6738 | case LPFC_SET_ENABLE_CMF: |
| 6739 | bf_set(lpfc_mbx_set_feature_dd, &mbox->u.mqe.un.set_feature, 1); |
| 6740 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_ENABLE_CMF; |
| 6741 | mbox->u.mqe.un.set_feature.param_len = 4; |
| 6742 | bf_set(lpfc_mbx_set_feature_cmf, |
| 6743 | &mbox->u.mqe.un.set_feature, 1); |
| 6744 | break; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6745 | } |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6746 | return; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6747 | } |
| 6748 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6749 | /** |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 6750 | * lpfc_ras_stop_fwlog: Disable FW logging by the adapter |
| 6751 | * @phba: Pointer to HBA context object. |
| 6752 | * |
| 6753 | * Disable FW logging into host memory on the adapter. To |
| 6754 | * be done before reading logs from the host memory. |
| 6755 | **/ |
| 6756 | void |
| 6757 | lpfc_ras_stop_fwlog(struct lpfc_hba *phba) |
| 6758 | { |
| 6759 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6760 | |
James Smart | 95bfc6d | 2019-10-18 14:18:27 -0700 | [diff] [blame] | 6761 | spin_lock_irq(&phba->hbalock); |
| 6762 | ras_fwlog->state = INACTIVE; |
| 6763 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 6764 | |
| 6765 | /* Disable FW logging to host memory */ |
| 6766 | writel(LPFC_CTL_PDEV_CTL_DDL_RAS, |
| 6767 | phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET); |
James Smart | 95bfc6d | 2019-10-18 14:18:27 -0700 | [diff] [blame] | 6768 | |
| 6769 | /* Wait 10ms for firmware to stop using DMA buffer */ |
| 6770 | usleep_range(10 * 1000, 20 * 1000); |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 6771 | } |
| 6772 | |
| 6773 | /** |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6774 | * lpfc_sli4_ras_dma_free - Free memory allocated for FW logging. |
| 6775 | * @phba: Pointer to HBA context object. |
| 6776 | * |
| 6777 | * This function is called to free memory allocated for RAS FW logging |
| 6778 | * support in the driver. |
| 6779 | **/ |
| 6780 | void |
| 6781 | lpfc_sli4_ras_dma_free(struct lpfc_hba *phba) |
| 6782 | { |
| 6783 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6784 | struct lpfc_dmabuf *dmabuf, *next; |
| 6785 | |
| 6786 | if (!list_empty(&ras_fwlog->fwlog_buff_list)) { |
| 6787 | list_for_each_entry_safe(dmabuf, next, |
| 6788 | &ras_fwlog->fwlog_buff_list, |
| 6789 | list) { |
| 6790 | list_del(&dmabuf->list); |
| 6791 | dma_free_coherent(&phba->pcidev->dev, |
| 6792 | LPFC_RAS_MAX_ENTRY_SIZE, |
| 6793 | dmabuf->virt, dmabuf->phys); |
| 6794 | kfree(dmabuf); |
| 6795 | } |
| 6796 | } |
| 6797 | |
| 6798 | if (ras_fwlog->lwpd.virt) { |
| 6799 | dma_free_coherent(&phba->pcidev->dev, |
| 6800 | sizeof(uint32_t) * 2, |
| 6801 | ras_fwlog->lwpd.virt, |
| 6802 | ras_fwlog->lwpd.phys); |
| 6803 | ras_fwlog->lwpd.virt = NULL; |
| 6804 | } |
| 6805 | |
James Smart | 95bfc6d | 2019-10-18 14:18:27 -0700 | [diff] [blame] | 6806 | spin_lock_irq(&phba->hbalock); |
| 6807 | ras_fwlog->state = INACTIVE; |
| 6808 | spin_unlock_irq(&phba->hbalock); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6809 | } |
| 6810 | |
| 6811 | /** |
| 6812 | * lpfc_sli4_ras_dma_alloc: Allocate memory for FW support |
| 6813 | * @phba: Pointer to HBA context object. |
| 6814 | * @fwlog_buff_count: Count of buffers to be created. |
| 6815 | * |
| 6816 | * This routine DMA memory for Log Write Position Data[LPWD] and buffer |
| 6817 | * to update FW log is posted to the adapter. |
| 6818 | * Buffer count is calculated based on module param ras_fwlog_buffsize |
| 6819 | * Size of each buffer posted to FW is 64K. |
| 6820 | **/ |
| 6821 | |
| 6822 | static int |
| 6823 | lpfc_sli4_ras_dma_alloc(struct lpfc_hba *phba, |
| 6824 | uint32_t fwlog_buff_count) |
| 6825 | { |
| 6826 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6827 | struct lpfc_dmabuf *dmabuf; |
| 6828 | int rc = 0, i = 0; |
| 6829 | |
| 6830 | /* Initialize List */ |
| 6831 | INIT_LIST_HEAD(&ras_fwlog->fwlog_buff_list); |
| 6832 | |
| 6833 | /* Allocate memory for the LWPD */ |
| 6834 | ras_fwlog->lwpd.virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 6835 | sizeof(uint32_t) * 2, |
| 6836 | &ras_fwlog->lwpd.phys, |
| 6837 | GFP_KERNEL); |
| 6838 | if (!ras_fwlog->lwpd.virt) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6839 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6840 | "6185 LWPD Memory Alloc Failed\n"); |
| 6841 | |
| 6842 | return -ENOMEM; |
| 6843 | } |
| 6844 | |
| 6845 | ras_fwlog->fw_buffcount = fwlog_buff_count; |
| 6846 | for (i = 0; i < ras_fwlog->fw_buffcount; i++) { |
| 6847 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 6848 | GFP_KERNEL); |
| 6849 | if (!dmabuf) { |
| 6850 | rc = -ENOMEM; |
| 6851 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6852 | "6186 Memory Alloc failed FW logging"); |
| 6853 | goto free_mem; |
| 6854 | } |
| 6855 | |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 6856 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6857 | LPFC_RAS_MAX_ENTRY_SIZE, |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 6858 | &dmabuf->phys, GFP_KERNEL); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6859 | if (!dmabuf->virt) { |
| 6860 | kfree(dmabuf); |
| 6861 | rc = -ENOMEM; |
| 6862 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6863 | "6187 DMA Alloc Failed FW logging"); |
| 6864 | goto free_mem; |
| 6865 | } |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6866 | dmabuf->buffer_tag = i; |
| 6867 | list_add_tail(&dmabuf->list, &ras_fwlog->fwlog_buff_list); |
| 6868 | } |
| 6869 | |
| 6870 | free_mem: |
| 6871 | if (rc) |
| 6872 | lpfc_sli4_ras_dma_free(phba); |
| 6873 | |
| 6874 | return rc; |
| 6875 | } |
| 6876 | |
| 6877 | /** |
| 6878 | * lpfc_sli4_ras_mbox_cmpl: Completion handler for RAS MBX command |
| 6879 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 6880 | * @pmb: pointer to the driver internal queue element for mailbox command. |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6881 | * |
| 6882 | * Completion handler for driver's RAS MBX command to the device. |
| 6883 | **/ |
| 6884 | static void |
| 6885 | lpfc_sli4_ras_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6886 | { |
| 6887 | MAILBOX_t *mb; |
| 6888 | union lpfc_sli4_cfg_shdr *shdr; |
| 6889 | uint32_t shdr_status, shdr_add_status; |
| 6890 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6891 | |
| 6892 | mb = &pmb->u.mb; |
| 6893 | |
| 6894 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 6895 | &pmb->u.mqe.un.ras_fwlog.header.cfg_shdr; |
| 6896 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 6897 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 6898 | |
| 6899 | if (mb->mbxStatus != MBX_SUCCESS || shdr_status) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6900 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6901 | "6188 FW LOG mailbox " |
| 6902 | "completed with status x%x add_status x%x," |
| 6903 | " mbx status x%x\n", |
| 6904 | shdr_status, shdr_add_status, mb->mbxStatus); |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6905 | |
| 6906 | ras_fwlog->ras_hwsupport = false; |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6907 | goto disable_ras; |
| 6908 | } |
| 6909 | |
James Smart | 95bfc6d | 2019-10-18 14:18:27 -0700 | [diff] [blame] | 6910 | spin_lock_irq(&phba->hbalock); |
| 6911 | ras_fwlog->state = ACTIVE; |
| 6912 | spin_unlock_irq(&phba->hbalock); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6913 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6914 | |
| 6915 | return; |
| 6916 | |
| 6917 | disable_ras: |
| 6918 | /* Free RAS DMA memory */ |
| 6919 | lpfc_sli4_ras_dma_free(phba); |
| 6920 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6921 | } |
| 6922 | |
| 6923 | /** |
| 6924 | * lpfc_sli4_ras_fwlog_init: Initialize memory and post RAS MBX command |
| 6925 | * @phba: pointer to lpfc hba data structure. |
| 6926 | * @fwlog_level: Logging verbosity level. |
| 6927 | * @fwlog_enable: Enable/Disable logging. |
| 6928 | * |
| 6929 | * Initialize memory and post mailbox command to enable FW logging in host |
| 6930 | * memory. |
| 6931 | **/ |
| 6932 | int |
| 6933 | lpfc_sli4_ras_fwlog_init(struct lpfc_hba *phba, |
| 6934 | uint32_t fwlog_level, |
| 6935 | uint32_t fwlog_enable) |
| 6936 | { |
| 6937 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6938 | struct lpfc_mbx_set_ras_fwlog *mbx_fwlog = NULL; |
| 6939 | struct lpfc_dmabuf *dmabuf; |
| 6940 | LPFC_MBOXQ_t *mbox; |
| 6941 | uint32_t len = 0, fwlog_buffsize, fwlog_entry_count; |
| 6942 | int rc = 0; |
| 6943 | |
James Smart | 95bfc6d | 2019-10-18 14:18:27 -0700 | [diff] [blame] | 6944 | spin_lock_irq(&phba->hbalock); |
| 6945 | ras_fwlog->state = INACTIVE; |
| 6946 | spin_unlock_irq(&phba->hbalock); |
| 6947 | |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6948 | fwlog_buffsize = (LPFC_RAS_MIN_BUFF_POST_SIZE * |
| 6949 | phba->cfg_ras_fwlog_buffsize); |
| 6950 | fwlog_entry_count = (fwlog_buffsize/LPFC_RAS_MAX_ENTRY_SIZE); |
| 6951 | |
| 6952 | /* |
| 6953 | * If re-enabling FW logging support use earlier allocated |
| 6954 | * DMA buffers while posting MBX command. |
| 6955 | **/ |
| 6956 | if (!ras_fwlog->lwpd.virt) { |
| 6957 | rc = lpfc_sli4_ras_dma_alloc(phba, fwlog_entry_count); |
| 6958 | if (rc) { |
| 6959 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6960 | "6189 FW Log Memory Allocation Failed"); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6961 | return rc; |
| 6962 | } |
| 6963 | } |
| 6964 | |
| 6965 | /* Setup Mailbox command */ |
| 6966 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6967 | if (!mbox) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6968 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6969 | "6190 RAS MBX Alloc Failed"); |
| 6970 | rc = -ENOMEM; |
| 6971 | goto mem_free; |
| 6972 | } |
| 6973 | |
| 6974 | ras_fwlog->fw_loglevel = fwlog_level; |
| 6975 | len = (sizeof(struct lpfc_mbx_set_ras_fwlog) - |
| 6976 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6977 | |
| 6978 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_LOWLEVEL, |
| 6979 | LPFC_MBOX_OPCODE_SET_DIAG_LOG_OPTION, |
| 6980 | len, LPFC_SLI4_MBX_EMBED); |
| 6981 | |
| 6982 | mbx_fwlog = (struct lpfc_mbx_set_ras_fwlog *)&mbox->u.mqe.un.ras_fwlog; |
| 6983 | bf_set(lpfc_fwlog_enable, &mbx_fwlog->u.request, |
| 6984 | fwlog_enable); |
| 6985 | bf_set(lpfc_fwlog_loglvl, &mbx_fwlog->u.request, |
| 6986 | ras_fwlog->fw_loglevel); |
| 6987 | bf_set(lpfc_fwlog_buffcnt, &mbx_fwlog->u.request, |
| 6988 | ras_fwlog->fw_buffcount); |
| 6989 | bf_set(lpfc_fwlog_buffsz, &mbx_fwlog->u.request, |
| 6990 | LPFC_RAS_MAX_ENTRY_SIZE/SLI4_PAGE_SIZE); |
| 6991 | |
| 6992 | /* Update DMA buffer address */ |
| 6993 | list_for_each_entry(dmabuf, &ras_fwlog->fwlog_buff_list, list) { |
| 6994 | memset(dmabuf->virt, 0, LPFC_RAS_MAX_ENTRY_SIZE); |
| 6995 | |
| 6996 | mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_lo = |
| 6997 | putPaddrLow(dmabuf->phys); |
| 6998 | |
| 6999 | mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_hi = |
| 7000 | putPaddrHigh(dmabuf->phys); |
| 7001 | } |
| 7002 | |
| 7003 | /* Update LPWD address */ |
| 7004 | mbx_fwlog->u.request.lwpd.addr_lo = putPaddrLow(ras_fwlog->lwpd.phys); |
| 7005 | mbx_fwlog->u.request.lwpd.addr_hi = putPaddrHigh(ras_fwlog->lwpd.phys); |
| 7006 | |
James Smart | 95bfc6d | 2019-10-18 14:18:27 -0700 | [diff] [blame] | 7007 | spin_lock_irq(&phba->hbalock); |
| 7008 | ras_fwlog->state = REG_INPROGRESS; |
| 7009 | spin_unlock_irq(&phba->hbalock); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 7010 | mbox->vport = phba->pport; |
| 7011 | mbox->mbox_cmpl = lpfc_sli4_ras_mbox_cmpl; |
| 7012 | |
| 7013 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 7014 | |
| 7015 | if (rc == MBX_NOT_FINISHED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7016 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 7017 | "6191 FW-Log Mailbox failed. " |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 7018 | "status %d mbxStatus : x%x", rc, |
| 7019 | bf_get(lpfc_mqe_status, &mbox->u.mqe)); |
| 7020 | mempool_free(mbox, phba->mbox_mem_pool); |
| 7021 | rc = -EIO; |
| 7022 | goto mem_free; |
| 7023 | } else |
| 7024 | rc = 0; |
| 7025 | mem_free: |
| 7026 | if (rc) |
| 7027 | lpfc_sli4_ras_dma_free(phba); |
| 7028 | |
| 7029 | return rc; |
| 7030 | } |
| 7031 | |
| 7032 | /** |
| 7033 | * lpfc_sli4_ras_setup - Check if RAS supported on the adapter |
| 7034 | * @phba: Pointer to HBA context object. |
| 7035 | * |
| 7036 | * Check if RAS is supported on the adapter and initialize it. |
| 7037 | **/ |
| 7038 | void |
| 7039 | lpfc_sli4_ras_setup(struct lpfc_hba *phba) |
| 7040 | { |
| 7041 | /* Check RAS FW Log needs to be enabled or not */ |
| 7042 | if (lpfc_check_fwlog_support(phba)) |
| 7043 | return; |
| 7044 | |
| 7045 | lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level, |
| 7046 | LPFC_RAS_ENABLE_LOGGING); |
| 7047 | } |
| 7048 | |
| 7049 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7050 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. |
| 7051 | * @phba: Pointer to HBA context object. |
| 7052 | * |
| 7053 | * This function allocates all SLI4 resource identifiers. |
| 7054 | **/ |
| 7055 | int |
| 7056 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) |
| 7057 | { |
| 7058 | int i, rc, error = 0; |
| 7059 | uint16_t count, base; |
| 7060 | unsigned long longs; |
| 7061 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7062 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 7063 | 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] | 7064 | if (phba->sli4_hba.extents_in_use) { |
| 7065 | /* |
| 7066 | * The port supports resource extents. The XRI, VPI, VFI, RPI |
| 7067 | * resource extent count must be read and allocated before |
| 7068 | * provisioning the resource id arrays. |
| 7069 | */ |
| 7070 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
| 7071 | LPFC_IDX_RSRC_RDY) { |
| 7072 | /* |
| 7073 | * Extent-based resources are set - the driver could |
| 7074 | * be in a port reset. Figure out if any corrective |
| 7075 | * actions need to be taken. |
| 7076 | */ |
| 7077 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 7078 | LPFC_RSC_TYPE_FCOE_VFI); |
| 7079 | if (rc != 0) |
| 7080 | error++; |
| 7081 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 7082 | LPFC_RSC_TYPE_FCOE_VPI); |
| 7083 | if (rc != 0) |
| 7084 | error++; |
| 7085 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 7086 | LPFC_RSC_TYPE_FCOE_XRI); |
| 7087 | if (rc != 0) |
| 7088 | error++; |
| 7089 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 7090 | LPFC_RSC_TYPE_FCOE_RPI); |
| 7091 | if (rc != 0) |
| 7092 | error++; |
| 7093 | |
| 7094 | /* |
| 7095 | * It's possible that the number of resources |
| 7096 | * provided to this port instance changed between |
| 7097 | * resets. Detect this condition and reallocate |
| 7098 | * resources. Otherwise, there is no action. |
| 7099 | */ |
| 7100 | if (error) { |
| 7101 | lpfc_printf_log(phba, KERN_INFO, |
| 7102 | LOG_MBOX | LOG_INIT, |
| 7103 | "2931 Detected extent resource " |
| 7104 | "change. Reallocating all " |
| 7105 | "extents.\n"); |
| 7106 | rc = lpfc_sli4_dealloc_extent(phba, |
| 7107 | LPFC_RSC_TYPE_FCOE_VFI); |
| 7108 | rc = lpfc_sli4_dealloc_extent(phba, |
| 7109 | LPFC_RSC_TYPE_FCOE_VPI); |
| 7110 | rc = lpfc_sli4_dealloc_extent(phba, |
| 7111 | LPFC_RSC_TYPE_FCOE_XRI); |
| 7112 | rc = lpfc_sli4_dealloc_extent(phba, |
| 7113 | LPFC_RSC_TYPE_FCOE_RPI); |
| 7114 | } else |
| 7115 | return 0; |
| 7116 | } |
| 7117 | |
| 7118 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 7119 | if (unlikely(rc)) |
| 7120 | goto err_exit; |
| 7121 | |
| 7122 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 7123 | if (unlikely(rc)) |
| 7124 | goto err_exit; |
| 7125 | |
| 7126 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 7127 | if (unlikely(rc)) |
| 7128 | goto err_exit; |
| 7129 | |
| 7130 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 7131 | if (unlikely(rc)) |
| 7132 | goto err_exit; |
| 7133 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 7134 | LPFC_IDX_RSRC_RDY); |
| 7135 | return rc; |
| 7136 | } else { |
| 7137 | /* |
| 7138 | * The port does not support resource extents. The XRI, VPI, |
| 7139 | * VFI, RPI resource ids were determined from READ_CONFIG. |
| 7140 | * Just allocate the bitmasks and provision the resource id |
| 7141 | * arrays. If a port reset is active, the resources don't |
| 7142 | * need any action - just exit. |
| 7143 | */ |
| 7144 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7145 | LPFC_IDX_RSRC_RDY) { |
| 7146 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 7147 | lpfc_sli4_remove_rpis(phba); |
| 7148 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7149 | /* RPIs. */ |
| 7150 | count = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 7151 | if (count <= 0) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7152 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 7153 | "3279 Invalid provisioning of " |
| 7154 | "rpi:%d\n", count); |
| 7155 | rc = -EINVAL; |
| 7156 | goto err_exit; |
| 7157 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7158 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
| 7159 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 7160 | phba->sli4_hba.rpi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7161 | sizeof(unsigned long), |
| 7162 | GFP_KERNEL); |
| 7163 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 7164 | rc = -ENOMEM; |
| 7165 | goto err_exit; |
| 7166 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 7167 | phba->sli4_hba.rpi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7168 | GFP_KERNEL); |
| 7169 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 7170 | rc = -ENOMEM; |
| 7171 | goto free_rpi_bmask; |
| 7172 | } |
| 7173 | |
| 7174 | for (i = 0; i < count; i++) |
| 7175 | phba->sli4_hba.rpi_ids[i] = base + i; |
| 7176 | |
| 7177 | /* VPIs. */ |
| 7178 | count = phba->sli4_hba.max_cfg_param.max_vpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 7179 | if (count <= 0) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7180 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 7181 | "3280 Invalid provisioning of " |
| 7182 | "vpi:%d\n", count); |
| 7183 | rc = -EINVAL; |
| 7184 | goto free_rpi_ids; |
| 7185 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7186 | base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 7187 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 7188 | phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7189 | GFP_KERNEL); |
| 7190 | if (unlikely(!phba->vpi_bmask)) { |
| 7191 | rc = -ENOMEM; |
| 7192 | goto free_rpi_ids; |
| 7193 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 7194 | phba->vpi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7195 | GFP_KERNEL); |
| 7196 | if (unlikely(!phba->vpi_ids)) { |
| 7197 | rc = -ENOMEM; |
| 7198 | goto free_vpi_bmask; |
| 7199 | } |
| 7200 | |
| 7201 | for (i = 0; i < count; i++) |
| 7202 | phba->vpi_ids[i] = base + i; |
| 7203 | |
| 7204 | /* XRIs. */ |
| 7205 | count = phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 7206 | if (count <= 0) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7207 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 7208 | "3281 Invalid provisioning of " |
| 7209 | "xri:%d\n", count); |
| 7210 | rc = -EINVAL; |
| 7211 | goto free_vpi_ids; |
| 7212 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7213 | base = phba->sli4_hba.max_cfg_param.xri_base; |
| 7214 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 7215 | phba->sli4_hba.xri_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7216 | sizeof(unsigned long), |
| 7217 | GFP_KERNEL); |
| 7218 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 7219 | rc = -ENOMEM; |
| 7220 | goto free_vpi_ids; |
| 7221 | } |
James Smart | 41899be | 2012-03-01 22:34:19 -0500 | [diff] [blame] | 7222 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 7223 | phba->sli4_hba.xri_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7224 | GFP_KERNEL); |
| 7225 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 7226 | rc = -ENOMEM; |
| 7227 | goto free_xri_bmask; |
| 7228 | } |
| 7229 | |
| 7230 | for (i = 0; i < count; i++) |
| 7231 | phba->sli4_hba.xri_ids[i] = base + i; |
| 7232 | |
| 7233 | /* VFIs. */ |
| 7234 | count = phba->sli4_hba.max_cfg_param.max_vfi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 7235 | if (count <= 0) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7236 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 7237 | "3282 Invalid provisioning of " |
| 7238 | "vfi:%d\n", count); |
| 7239 | rc = -EINVAL; |
| 7240 | goto free_xri_ids; |
| 7241 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7242 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
| 7243 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 7244 | phba->sli4_hba.vfi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7245 | sizeof(unsigned long), |
| 7246 | GFP_KERNEL); |
| 7247 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 7248 | rc = -ENOMEM; |
| 7249 | goto free_xri_ids; |
| 7250 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 7251 | phba->sli4_hba.vfi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7252 | GFP_KERNEL); |
| 7253 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 7254 | rc = -ENOMEM; |
| 7255 | goto free_vfi_bmask; |
| 7256 | } |
| 7257 | |
| 7258 | for (i = 0; i < count; i++) |
| 7259 | phba->sli4_hba.vfi_ids[i] = base + i; |
| 7260 | |
| 7261 | /* |
| 7262 | * Mark all resources ready. An HBA reset doesn't need |
| 7263 | * to reset the initialization. |
| 7264 | */ |
| 7265 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 7266 | LPFC_IDX_RSRC_RDY); |
| 7267 | return 0; |
| 7268 | } |
| 7269 | |
| 7270 | free_vfi_bmask: |
| 7271 | kfree(phba->sli4_hba.vfi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 7272 | phba->sli4_hba.vfi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7273 | free_xri_ids: |
| 7274 | kfree(phba->sli4_hba.xri_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 7275 | phba->sli4_hba.xri_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7276 | free_xri_bmask: |
| 7277 | kfree(phba->sli4_hba.xri_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 7278 | phba->sli4_hba.xri_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7279 | free_vpi_ids: |
| 7280 | kfree(phba->vpi_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 7281 | phba->vpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7282 | free_vpi_bmask: |
| 7283 | kfree(phba->vpi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 7284 | phba->vpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7285 | free_rpi_ids: |
| 7286 | kfree(phba->sli4_hba.rpi_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 7287 | phba->sli4_hba.rpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7288 | free_rpi_bmask: |
| 7289 | kfree(phba->sli4_hba.rpi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 7290 | phba->sli4_hba.rpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7291 | err_exit: |
| 7292 | return rc; |
| 7293 | } |
| 7294 | |
| 7295 | /** |
| 7296 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. |
| 7297 | * @phba: Pointer to HBA context object. |
| 7298 | * |
| 7299 | * This function allocates the number of elements for the specified |
| 7300 | * resource type. |
| 7301 | **/ |
| 7302 | int |
| 7303 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) |
| 7304 | { |
| 7305 | if (phba->sli4_hba.extents_in_use) { |
| 7306 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 7307 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 7308 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 7309 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 7310 | } else { |
| 7311 | kfree(phba->vpi_bmask); |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 7312 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7313 | kfree(phba->vpi_ids); |
| 7314 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 7315 | kfree(phba->sli4_hba.xri_bmask); |
| 7316 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7317 | kfree(phba->sli4_hba.vfi_bmask); |
| 7318 | kfree(phba->sli4_hba.vfi_ids); |
| 7319 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 7320 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 7321 | } |
| 7322 | |
| 7323 | return 0; |
| 7324 | } |
| 7325 | |
| 7326 | /** |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 7327 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. |
| 7328 | * @phba: Pointer to HBA context object. |
| 7329 | * @type: The resource extent type. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 7330 | * @extnt_cnt: buffer to hold port extent count response |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 7331 | * @extnt_size: buffer to hold port extent size response. |
| 7332 | * |
| 7333 | * This function calls the port to read the host allocated extents |
| 7334 | * for a particular type. |
| 7335 | **/ |
| 7336 | int |
| 7337 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, |
| 7338 | uint16_t *extnt_cnt, uint16_t *extnt_size) |
| 7339 | { |
| 7340 | bool emb; |
| 7341 | int rc = 0; |
| 7342 | uint16_t curr_blks = 0; |
| 7343 | uint32_t req_len, emb_len; |
| 7344 | uint32_t alloc_len, mbox_tmo; |
| 7345 | struct list_head *blk_list_head; |
| 7346 | struct lpfc_rsrc_blks *rsrc_blk; |
| 7347 | LPFC_MBOXQ_t *mbox; |
| 7348 | void *virtaddr = NULL; |
| 7349 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 7350 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 7351 | union lpfc_sli4_cfg_shdr *shdr; |
| 7352 | |
| 7353 | switch (type) { |
| 7354 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 7355 | blk_list_head = &phba->lpfc_vpi_blk_list; |
| 7356 | break; |
| 7357 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 7358 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; |
| 7359 | break; |
| 7360 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 7361 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 7362 | break; |
| 7363 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 7364 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 7365 | break; |
| 7366 | default: |
| 7367 | return -EIO; |
| 7368 | } |
| 7369 | |
| 7370 | /* Count the number of extents currently allocatd for this type. */ |
| 7371 | list_for_each_entry(rsrc_blk, blk_list_head, list) { |
| 7372 | if (curr_blks == 0) { |
| 7373 | /* |
| 7374 | * The GET_ALLOCATED mailbox does not return the size, |
| 7375 | * just the count. The size should be just the size |
| 7376 | * stored in the current allocated block and all sizes |
| 7377 | * for an extent type are the same so set the return |
| 7378 | * value now. |
| 7379 | */ |
| 7380 | *extnt_size = rsrc_blk->rsrc_size; |
| 7381 | } |
| 7382 | curr_blks++; |
| 7383 | } |
| 7384 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 7385 | /* |
| 7386 | * Calculate the size of an embedded mailbox. The uint32_t |
| 7387 | * accounts for extents-specific word. |
| 7388 | */ |
| 7389 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 7390 | sizeof(uint32_t); |
| 7391 | |
| 7392 | /* |
| 7393 | * Presume the allocation and response will fit into an embedded |
| 7394 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 7395 | */ |
| 7396 | emb = LPFC_SLI4_MBX_EMBED; |
| 7397 | req_len = emb_len; |
| 7398 | if (req_len > emb_len) { |
| 7399 | req_len = curr_blks * sizeof(uint16_t) + |
| 7400 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 7401 | sizeof(uint32_t); |
| 7402 | emb = LPFC_SLI4_MBX_NEMBED; |
| 7403 | } |
| 7404 | |
| 7405 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7406 | if (!mbox) |
| 7407 | return -ENOMEM; |
| 7408 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); |
| 7409 | |
| 7410 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7411 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, |
| 7412 | req_len, emb); |
| 7413 | if (alloc_len < req_len) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7414 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 7415 | "2983 Allocated DMA memory size (x%x) is " |
| 7416 | "less than the requested DMA memory " |
| 7417 | "size (x%x)\n", alloc_len, req_len); |
| 7418 | rc = -ENOMEM; |
| 7419 | goto err_exit; |
| 7420 | } |
| 7421 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); |
| 7422 | if (unlikely(rc)) { |
| 7423 | rc = -EIO; |
| 7424 | goto err_exit; |
| 7425 | } |
| 7426 | |
| 7427 | if (!phba->sli4_hba.intr_enable) |
| 7428 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 7429 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7430 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 7431 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 7432 | } |
| 7433 | |
| 7434 | if (unlikely(rc)) { |
| 7435 | rc = -EIO; |
| 7436 | goto err_exit; |
| 7437 | } |
| 7438 | |
| 7439 | /* |
| 7440 | * Figure out where the response is located. Then get local pointers |
| 7441 | * to the response data. The port does not guarantee to respond to |
| 7442 | * all extents counts request so update the local variable with the |
| 7443 | * allocated count from the port. |
| 7444 | */ |
| 7445 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 7446 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 7447 | shdr = &rsrc_ext->header.cfg_shdr; |
| 7448 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 7449 | } else { |
| 7450 | virtaddr = mbox->sge_array->addr[0]; |
| 7451 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 7452 | shdr = &n_rsrc->cfg_shdr; |
| 7453 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 7454 | } |
| 7455 | |
| 7456 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7457 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 7458 | "2984 Failed to read allocated resources " |
| 7459 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", |
| 7460 | type, |
| 7461 | bf_get(lpfc_mbox_hdr_status, &shdr->response), |
| 7462 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); |
| 7463 | rc = -EIO; |
| 7464 | goto err_exit; |
| 7465 | } |
| 7466 | err_exit: |
| 7467 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 7468 | return rc; |
| 7469 | } |
| 7470 | |
| 7471 | /** |
James Smart | 0ef6996 | 2017-04-21 16:04:50 -0700 | [diff] [blame] | 7472 | * lpfc_sli4_repost_sgl_list - Repost the buffers sgl pages as block |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7473 | * @phba: pointer to lpfc hba data structure. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7474 | * @sgl_list: linked link of sgl buffers to post |
| 7475 | * @cnt: number of linked list buffers |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7476 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7477 | * This routine walks the list of buffers that have been allocated and |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7478 | * repost them to the port by using SGL block post. This is needed after a |
| 7479 | * pci_function_reset/warm_start or start. It attempts to construct blocks |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7480 | * of buffer sgls which contains contiguous xris and uses the non-embedded |
| 7481 | * 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] | 7482 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post |
| 7483 | * mailbox command for posting. |
| 7484 | * |
| 7485 | * Returns: 0 = success, non-zero failure. |
| 7486 | **/ |
| 7487 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7488 | lpfc_sli4_repost_sgl_list(struct lpfc_hba *phba, |
| 7489 | struct list_head *sgl_list, int cnt) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7490 | { |
| 7491 | struct lpfc_sglq *sglq_entry = NULL; |
| 7492 | struct lpfc_sglq *sglq_entry_next = NULL; |
| 7493 | struct lpfc_sglq *sglq_entry_first = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7494 | int status, total_cnt; |
| 7495 | int post_cnt = 0, num_posted = 0, block_cnt = 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7496 | int last_xritag = NO_XRI; |
| 7497 | LIST_HEAD(prep_sgl_list); |
| 7498 | LIST_HEAD(blck_sgl_list); |
| 7499 | LIST_HEAD(allc_sgl_list); |
| 7500 | LIST_HEAD(post_sgl_list); |
| 7501 | LIST_HEAD(free_sgl_list); |
| 7502 | |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 7503 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7504 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 7505 | list_splice_init(sgl_list, &allc_sgl_list); |
| 7506 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 7507 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7508 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7509 | total_cnt = cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7510 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 7511 | &allc_sgl_list, list) { |
| 7512 | list_del_init(&sglq_entry->list); |
| 7513 | block_cnt++; |
| 7514 | if ((last_xritag != NO_XRI) && |
| 7515 | (sglq_entry->sli4_xritag != last_xritag + 1)) { |
| 7516 | /* a hole in xri block, form a sgl posting block */ |
| 7517 | list_splice_init(&prep_sgl_list, &blck_sgl_list); |
| 7518 | post_cnt = block_cnt - 1; |
| 7519 | /* prepare list for next posting block */ |
| 7520 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 7521 | block_cnt = 1; |
| 7522 | } else { |
| 7523 | /* prepare list for next posting block */ |
| 7524 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 7525 | /* enough sgls for non-embed sgl mbox command */ |
| 7526 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 7527 | list_splice_init(&prep_sgl_list, |
| 7528 | &blck_sgl_list); |
| 7529 | post_cnt = block_cnt; |
| 7530 | block_cnt = 0; |
| 7531 | } |
| 7532 | } |
| 7533 | num_posted++; |
| 7534 | |
| 7535 | /* keep track of last sgl's xritag */ |
| 7536 | last_xritag = sglq_entry->sli4_xritag; |
| 7537 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7538 | /* end of repost sgl list condition for buffers */ |
| 7539 | if (num_posted == total_cnt) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7540 | if (post_cnt == 0) { |
| 7541 | list_splice_init(&prep_sgl_list, |
| 7542 | &blck_sgl_list); |
| 7543 | post_cnt = block_cnt; |
| 7544 | } else if (block_cnt == 1) { |
| 7545 | status = lpfc_sli4_post_sgl(phba, |
| 7546 | sglq_entry->phys, 0, |
| 7547 | sglq_entry->sli4_xritag); |
| 7548 | if (!status) { |
| 7549 | /* successful, put sgl to posted list */ |
| 7550 | list_add_tail(&sglq_entry->list, |
| 7551 | &post_sgl_list); |
| 7552 | } else { |
| 7553 | /* Failure, put sgl to free list */ |
| 7554 | lpfc_printf_log(phba, KERN_WARNING, |
| 7555 | LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7556 | "3159 Failed to post " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7557 | "sgl, xritag:x%x\n", |
| 7558 | sglq_entry->sli4_xritag); |
| 7559 | list_add_tail(&sglq_entry->list, |
| 7560 | &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 7561 | total_cnt--; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7562 | } |
| 7563 | } |
| 7564 | } |
| 7565 | |
| 7566 | /* continue until a nembed page worth of sgls */ |
| 7567 | if (post_cnt == 0) |
| 7568 | continue; |
| 7569 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7570 | /* post the buffer list sgls as a block */ |
| 7571 | status = lpfc_sli4_post_sgl_list(phba, &blck_sgl_list, |
| 7572 | post_cnt); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7573 | |
| 7574 | if (!status) { |
| 7575 | /* success, put sgl list to posted sgl list */ |
| 7576 | list_splice_init(&blck_sgl_list, &post_sgl_list); |
| 7577 | } else { |
| 7578 | /* Failure, put sgl list to free sgl list */ |
| 7579 | sglq_entry_first = list_first_entry(&blck_sgl_list, |
| 7580 | struct lpfc_sglq, |
| 7581 | list); |
| 7582 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7583 | "3160 Failed to post sgl-list, " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7584 | "xritag:x%x-x%x\n", |
| 7585 | sglq_entry_first->sli4_xritag, |
| 7586 | (sglq_entry_first->sli4_xritag + |
| 7587 | post_cnt - 1)); |
| 7588 | list_splice_init(&blck_sgl_list, &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 7589 | total_cnt -= post_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7590 | } |
| 7591 | |
| 7592 | /* don't reset xirtag due to hole in xri block */ |
| 7593 | if (block_cnt == 0) |
| 7594 | last_xritag = NO_XRI; |
| 7595 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7596 | /* reset sgl post count for next round of posting */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7597 | post_cnt = 0; |
| 7598 | } |
| 7599 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7600 | /* free the sgls failed to post */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7601 | lpfc_free_sgl_list(phba, &free_sgl_list); |
| 7602 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7603 | /* push sgls posted to the available list */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7604 | if (!list_empty(&post_sgl_list)) { |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 7605 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7606 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 7607 | list_splice_init(&post_sgl_list, sgl_list); |
| 7608 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 7609 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7610 | } else { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7611 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7612 | "3161 Failure to post sgl to port.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7613 | return -EIO; |
| 7614 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7615 | |
| 7616 | /* return the number of XRIs actually posted */ |
| 7617 | return total_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7618 | } |
| 7619 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7620 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7621 | * 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] | 7622 | * @phba: pointer to lpfc hba data structure. |
| 7623 | * |
| 7624 | * This routine walks the list of nvme buffers that have been allocated and |
| 7625 | * repost them to the port by using SGL block post. This is needed after a |
| 7626 | * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine |
| 7627 | * 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] | 7628 | * 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] | 7629 | * |
| 7630 | * Returns: 0 = success, non-zero failure. |
| 7631 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 7632 | static int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7633 | lpfc_sli4_repost_io_sgl_list(struct lpfc_hba *phba) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7634 | { |
| 7635 | LIST_HEAD(post_nblist); |
| 7636 | int num_posted, rc = 0; |
| 7637 | |
| 7638 | /* get all NVME buffers need to repost to a local list */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7639 | lpfc_io_buf_flush(phba, &post_nblist); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7640 | |
| 7641 | /* post the list of nvme buffer sgls to port if available */ |
| 7642 | if (!list_empty(&post_nblist)) { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7643 | num_posted = lpfc_sli4_post_io_sgl_list( |
| 7644 | phba, &post_nblist, phba->sli4_hba.io_xri_cnt); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7645 | /* failed to post any nvme buffer, return error */ |
| 7646 | if (num_posted == 0) |
| 7647 | rc = -EIO; |
| 7648 | } |
| 7649 | return rc; |
| 7650 | } |
| 7651 | |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 7652 | static void |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7653 | lpfc_set_host_data(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 7654 | { |
| 7655 | uint32_t len; |
| 7656 | |
| 7657 | len = sizeof(struct lpfc_mbx_set_host_data) - |
| 7658 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 7659 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7660 | LPFC_MBOX_OPCODE_SET_HOST_DATA, len, |
| 7661 | LPFC_SLI4_MBX_EMBED); |
| 7662 | |
| 7663 | 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] | 7664 | mbox->u.mqe.un.set_host_data.param_len = |
| 7665 | LPFC_HOST_OS_DRIVER_VERSION_SIZE; |
James Smart | 3b0009c | 2021-08-16 09:28:47 -0700 | [diff] [blame] | 7666 | snprintf(mbox->u.mqe.un.set_host_data.un.data, |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7667 | LPFC_HOST_OS_DRIVER_VERSION_SIZE, |
| 7668 | "Linux %s v"LPFC_DRIVER_VERSION, |
| 7669 | (phba->hba_flag & HBA_FCOE_MODE) ? "FCoE" : "FC"); |
| 7670 | } |
| 7671 | |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7672 | int |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7673 | lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7674 | struct lpfc_queue *drq, int count, int idx) |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7675 | { |
| 7676 | int rc, i; |
| 7677 | struct lpfc_rqe hrqe; |
| 7678 | struct lpfc_rqe drqe; |
| 7679 | struct lpfc_rqb *rqbp; |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7680 | unsigned long flags; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7681 | struct rqb_dmabuf *rqb_buffer; |
| 7682 | LIST_HEAD(rqb_buf_list); |
| 7683 | |
| 7684 | rqbp = hrq->rqbp; |
| 7685 | for (i = 0; i < count; i++) { |
James Smart | 62e3a931d | 2020-10-20 13:27:11 -0700 | [diff] [blame] | 7686 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7687 | /* IF RQ is already full, don't bother */ |
James Smart | 62e3a931d | 2020-10-20 13:27:11 -0700 | [diff] [blame] | 7688 | if (rqbp->buffer_count + i >= rqbp->entry_count - 1) { |
| 7689 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7690 | break; |
James Smart | 62e3a931d | 2020-10-20 13:27:11 -0700 | [diff] [blame] | 7691 | } |
| 7692 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 7693 | |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7694 | rqb_buffer = rqbp->rqb_alloc_buffer(phba); |
| 7695 | if (!rqb_buffer) |
| 7696 | break; |
| 7697 | rqb_buffer->hrq = hrq; |
| 7698 | rqb_buffer->drq = drq; |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7699 | rqb_buffer->idx = idx; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7700 | list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list); |
| 7701 | } |
James Smart | 62e3a931d | 2020-10-20 13:27:11 -0700 | [diff] [blame] | 7702 | |
| 7703 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7704 | while (!list_empty(&rqb_buf_list)) { |
| 7705 | list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf, |
| 7706 | hbuf.list); |
| 7707 | |
| 7708 | hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys); |
| 7709 | hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys); |
| 7710 | drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys); |
| 7711 | drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys); |
| 7712 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
| 7713 | if (rc < 0) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7714 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7715 | "6421 Cannot post to HRQ %d: %x %x %x " |
| 7716 | "DRQ %x %x\n", |
| 7717 | hrq->queue_id, |
| 7718 | hrq->host_index, |
| 7719 | hrq->hba_index, |
| 7720 | hrq->entry_count, |
| 7721 | drq->host_index, |
| 7722 | drq->hba_index); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7723 | rqbp->rqb_free_buffer(phba, rqb_buffer); |
| 7724 | } else { |
| 7725 | list_add_tail(&rqb_buffer->hbuf.list, |
| 7726 | &rqbp->rqb_buffer_list); |
| 7727 | rqbp->buffer_count++; |
| 7728 | } |
| 7729 | } |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7730 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7731 | return 1; |
| 7732 | } |
| 7733 | |
James Smart | 9064aeb | 2021-08-16 09:28:50 -0700 | [diff] [blame] | 7734 | static void |
| 7735 | lpfc_mbx_cmpl_cgn_set_ftrs(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 7736 | { |
| 7737 | struct lpfc_vport *vport = pmb->vport; |
| 7738 | union lpfc_sli4_cfg_shdr *shdr; |
| 7739 | u32 shdr_status, shdr_add_status; |
| 7740 | u32 sig, acqe; |
| 7741 | |
| 7742 | /* Two outcomes. (1) Set featurs was successul and EDC negotiation |
| 7743 | * is done. (2) Mailbox failed and send FPIN support only. |
| 7744 | */ |
| 7745 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 7746 | &pmb->u.mqe.un.sli4_config.header.cfg_shdr; |
| 7747 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 7748 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 7749 | if (shdr_status || shdr_add_status || pmb->u.mb.mbxStatus) { |
| 7750 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_CGN_MGMT, |
| 7751 | "2516 CGN SET_FEATURE mbox failed with " |
| 7752 | "status x%x add_status x%x, mbx status x%x " |
| 7753 | "Reset Congestion to FPINs only\n", |
| 7754 | shdr_status, shdr_add_status, |
| 7755 | pmb->u.mb.mbxStatus); |
| 7756 | /* If there is a mbox error, move on to RDF */ |
| 7757 | phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED; |
| 7758 | phba->cgn_reg_fpin = LPFC_CGN_FPIN_WARN | LPFC_CGN_FPIN_ALARM; |
| 7759 | goto out; |
| 7760 | } |
| 7761 | |
| 7762 | /* Zero out Congestion Signal ACQE counter */ |
| 7763 | phba->cgn_acqe_cnt = 0; |
| 7764 | atomic64_set(&phba->cgn_acqe_stat.warn, 0); |
| 7765 | atomic64_set(&phba->cgn_acqe_stat.alarm, 0); |
| 7766 | |
| 7767 | acqe = bf_get(lpfc_mbx_set_feature_CGN_acqe_freq, |
| 7768 | &pmb->u.mqe.un.set_feature); |
| 7769 | sig = bf_get(lpfc_mbx_set_feature_CGN_warn_freq, |
| 7770 | &pmb->u.mqe.un.set_feature); |
| 7771 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT, |
| 7772 | "4620 SET_FEATURES Success: Freq: %ds %dms " |
| 7773 | " Reg: x%x x%x\n", acqe, sig, |
| 7774 | phba->cgn_reg_signal, phba->cgn_reg_fpin); |
| 7775 | out: |
| 7776 | mempool_free(pmb, phba->mbox_mem_pool); |
| 7777 | |
| 7778 | /* Register for FPIN events from the fabric now that the |
| 7779 | * EDC common_set_features has completed. |
| 7780 | */ |
| 7781 | lpfc_issue_els_rdf(vport, 0); |
| 7782 | } |
| 7783 | |
| 7784 | int |
| 7785 | lpfc_config_cgn_signal(struct lpfc_hba *phba) |
| 7786 | { |
| 7787 | LPFC_MBOXQ_t *mboxq; |
| 7788 | u32 rc; |
| 7789 | |
| 7790 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7791 | if (!mboxq) |
| 7792 | goto out_rdf; |
| 7793 | |
| 7794 | lpfc_set_features(phba, mboxq, LPFC_SET_CGN_SIGNAL); |
| 7795 | mboxq->vport = phba->pport; |
| 7796 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_cgn_set_ftrs; |
| 7797 | |
| 7798 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT, |
| 7799 | "4621 SET_FEATURES: FREQ sig x%x acqe x%x: " |
| 7800 | "Reg: x%x x%x\n", |
| 7801 | phba->cgn_sig_freq, lpfc_acqe_cgn_frequency, |
| 7802 | phba->cgn_reg_signal, phba->cgn_reg_fpin); |
| 7803 | |
| 7804 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 7805 | if (rc == MBX_NOT_FINISHED) |
| 7806 | goto out; |
| 7807 | return 0; |
| 7808 | |
| 7809 | out: |
| 7810 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7811 | out_rdf: |
| 7812 | /* If there is a mbox error, move on to RDF */ |
| 7813 | phba->cgn_reg_fpin = LPFC_CGN_FPIN_WARN | LPFC_CGN_FPIN_ALARM; |
| 7814 | phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED; |
| 7815 | lpfc_issue_els_rdf(phba->pport, 0); |
| 7816 | return -EIO; |
| 7817 | } |
| 7818 | |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 7819 | /** |
| 7820 | * lpfc_init_idle_stat_hb - Initialize idle_stat tracking |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 7821 | * @phba: pointer to lpfc hba data structure. |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 7822 | * |
| 7823 | * This routine initializes the per-cq idle_stat to dynamically dictate |
| 7824 | * polling decisions. |
| 7825 | * |
| 7826 | * Return codes: |
| 7827 | * None |
| 7828 | **/ |
| 7829 | static void lpfc_init_idle_stat_hb(struct lpfc_hba *phba) |
| 7830 | { |
| 7831 | int i; |
| 7832 | struct lpfc_sli4_hdw_queue *hdwq; |
| 7833 | struct lpfc_queue *cq; |
| 7834 | struct lpfc_idle_stat *idle_stat; |
| 7835 | u64 wall; |
| 7836 | |
| 7837 | for_each_present_cpu(i) { |
| 7838 | hdwq = &phba->sli4_hba.hdwq[phba->sli4_hba.cpu_map[i].hdwq]; |
| 7839 | cq = hdwq->io_cq; |
| 7840 | |
| 7841 | /* Skip if we've already handled this cq's primary CPU */ |
| 7842 | if (cq->chann != i) |
| 7843 | continue; |
| 7844 | |
| 7845 | idle_stat = &phba->sli4_hba.idle_stat[i]; |
| 7846 | |
| 7847 | idle_stat->prev_idle = get_cpu_idle_time(i, &wall, 1); |
| 7848 | idle_stat->prev_wall = wall; |
| 7849 | |
James Smart | 9064aeb | 2021-08-16 09:28:50 -0700 | [diff] [blame] | 7850 | if (phba->nvmet_support || |
| 7851 | phba->cmf_active_mode != LPFC_CFG_OFF) |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 7852 | cq->poll_mode = LPFC_QUEUE_WORK; |
| 7853 | else |
| 7854 | cq->poll_mode = LPFC_IRQ_POLL; |
| 7855 | } |
| 7856 | |
| 7857 | if (!phba->nvmet_support) |
| 7858 | schedule_delayed_work(&phba->idle_stat_delay_work, |
| 7859 | msecs_to_jiffies(LPFC_IDLE_STAT_DELAY)); |
| 7860 | } |
| 7861 | |
Dick Kennedy | f0020e4 | 2020-06-30 14:49:58 -0700 | [diff] [blame] | 7862 | static void lpfc_sli4_dip(struct lpfc_hba *phba) |
| 7863 | { |
| 7864 | uint32_t if_type; |
| 7865 | |
| 7866 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 7867 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2 || |
| 7868 | if_type == LPFC_SLI_INTF_IF_TYPE_6) { |
| 7869 | struct lpfc_register reg_data; |
| 7870 | |
| 7871 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 7872 | ®_data.word0)) |
| 7873 | return; |
| 7874 | |
| 7875 | if (bf_get(lpfc_sliport_status_dip, ®_data)) |
James Smart | 0b3ad32 | 2021-01-04 10:02:39 -0800 | [diff] [blame] | 7876 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
Dick Kennedy | f0020e4 | 2020-06-30 14:49:58 -0700 | [diff] [blame] | 7877 | "2904 Firmware Dump Image Present" |
| 7878 | " on Adapter"); |
| 7879 | } |
| 7880 | } |
| 7881 | |
James Smart | c6a5c747 | 2021-08-16 09:28:48 -0700 | [diff] [blame] | 7882 | /** |
| 7883 | * lpfc_cmf_setup - Initialize idle_stat tracking |
| 7884 | * @phba: Pointer to HBA context object. |
| 7885 | * |
| 7886 | * This is called from HBA setup during driver load or when the HBA |
| 7887 | * comes online. this does all the initialization to support CMF and MI. |
| 7888 | **/ |
| 7889 | static int |
| 7890 | lpfc_cmf_setup(struct lpfc_hba *phba) |
| 7891 | { |
| 7892 | LPFC_MBOXQ_t *mboxq; |
| 7893 | struct lpfc_mqe *mqe; |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 7894 | struct lpfc_dmabuf *mp; |
James Smart | c6a5c747 | 2021-08-16 09:28:48 -0700 | [diff] [blame] | 7895 | struct lpfc_pc_sli4_params *sli4_params; |
| 7896 | struct lpfc_sli4_parameters *mbx_sli4_parameters; |
| 7897 | int length; |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 7898 | int rc, cmf, mi_ver; |
James Smart | c6a5c747 | 2021-08-16 09:28:48 -0700 | [diff] [blame] | 7899 | |
| 7900 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7901 | if (!mboxq) |
| 7902 | return -ENOMEM; |
| 7903 | mqe = &mboxq->u.mqe; |
| 7904 | |
| 7905 | /* Read the port's SLI4 Config Parameters */ |
| 7906 | length = (sizeof(struct lpfc_mbx_get_sli4_parameters) - |
| 7907 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 7908 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7909 | LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS, |
| 7910 | length, LPFC_SLI4_MBX_EMBED); |
| 7911 | |
| 7912 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7913 | if (unlikely(rc)) { |
| 7914 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7915 | return rc; |
| 7916 | } |
| 7917 | |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 7918 | /* Gather info on CMF and MI support */ |
James Smart | c6a5c747 | 2021-08-16 09:28:48 -0700 | [diff] [blame] | 7919 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 7920 | mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters; |
| 7921 | sli4_params->mi_ver = bf_get(cfg_mi_ver, mbx_sli4_parameters); |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 7922 | sli4_params->cmf = bf_get(cfg_cmf, mbx_sli4_parameters); |
James Smart | c6a5c747 | 2021-08-16 09:28:48 -0700 | [diff] [blame] | 7923 | |
| 7924 | /* Are we forcing MI off via module parameter? */ |
| 7925 | if (!phba->cfg_enable_mi) |
| 7926 | sli4_params->mi_ver = 0; |
| 7927 | |
| 7928 | /* Always try to enable MI feature if we can */ |
| 7929 | if (sli4_params->mi_ver) { |
| 7930 | lpfc_set_features(phba, mboxq, LPFC_SET_ENABLE_MI); |
| 7931 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7932 | mi_ver = bf_get(lpfc_mbx_set_feature_mi, |
| 7933 | &mboxq->u.mqe.un.set_feature); |
| 7934 | |
| 7935 | if (rc == MBX_SUCCESS) { |
| 7936 | if (mi_ver) { |
| 7937 | lpfc_printf_log(phba, |
| 7938 | KERN_WARNING, LOG_CGN_MGMT, |
| 7939 | "6215 MI is enabled\n"); |
| 7940 | sli4_params->mi_ver = mi_ver; |
| 7941 | } else { |
| 7942 | lpfc_printf_log(phba, |
| 7943 | KERN_WARNING, LOG_CGN_MGMT, |
| 7944 | "6338 MI is disabled\n"); |
| 7945 | sli4_params->mi_ver = 0; |
| 7946 | } |
| 7947 | } else { |
| 7948 | /* mi_ver is already set from GET_SLI4_PARAMETERS */ |
| 7949 | lpfc_printf_log(phba, KERN_INFO, |
| 7950 | LOG_CGN_MGMT | LOG_INIT, |
| 7951 | "6245 Enable MI Mailbox x%x (x%x/x%x) " |
| 7952 | "failed, rc:x%x mi:x%x\n", |
| 7953 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 7954 | lpfc_sli_config_mbox_subsys_get |
| 7955 | (phba, mboxq), |
| 7956 | lpfc_sli_config_mbox_opcode_get |
| 7957 | (phba, mboxq), |
| 7958 | rc, sli4_params->mi_ver); |
| 7959 | } |
| 7960 | } else { |
| 7961 | lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT, |
| 7962 | "6217 MI is disabled\n"); |
| 7963 | } |
| 7964 | |
| 7965 | /* Ensure FDMI is enabled for MI if enable_mi is set */ |
| 7966 | if (sli4_params->mi_ver) |
| 7967 | phba->cfg_fdmi_on = LPFC_FDMI_SUPPORT; |
| 7968 | |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 7969 | /* Always try to enable CMF feature if we can */ |
| 7970 | if (sli4_params->cmf) { |
| 7971 | lpfc_set_features(phba, mboxq, LPFC_SET_ENABLE_CMF); |
| 7972 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7973 | cmf = bf_get(lpfc_mbx_set_feature_cmf, |
| 7974 | &mboxq->u.mqe.un.set_feature); |
| 7975 | if (rc == MBX_SUCCESS && cmf) { |
| 7976 | lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT, |
| 7977 | "6218 CMF is enabled: mode %d\n", |
| 7978 | phba->cmf_active_mode); |
| 7979 | } else { |
| 7980 | lpfc_printf_log(phba, KERN_WARNING, |
| 7981 | LOG_CGN_MGMT | LOG_INIT, |
| 7982 | "6219 Enable CMF Mailbox x%x (x%x/x%x) " |
| 7983 | "failed, rc:x%x dd:x%x\n", |
| 7984 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 7985 | lpfc_sli_config_mbox_subsys_get |
| 7986 | (phba, mboxq), |
| 7987 | lpfc_sli_config_mbox_opcode_get |
| 7988 | (phba, mboxq), |
| 7989 | rc, cmf); |
| 7990 | sli4_params->cmf = 0; |
| 7991 | phba->cmf_active_mode = LPFC_CFG_OFF; |
| 7992 | goto no_cmf; |
| 7993 | } |
| 7994 | |
| 7995 | /* Allocate Congestion Information Buffer */ |
| 7996 | if (!phba->cgn_i) { |
| 7997 | mp = kmalloc(sizeof(*mp), GFP_KERNEL); |
| 7998 | if (mp) |
| 7999 | mp->virt = dma_alloc_coherent |
| 8000 | (&phba->pcidev->dev, |
| 8001 | sizeof(struct lpfc_cgn_info), |
| 8002 | &mp->phys, GFP_KERNEL); |
| 8003 | if (!mp || !mp->virt) { |
| 8004 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8005 | "2640 Failed to alloc memory " |
| 8006 | "for Congestion Info\n"); |
| 8007 | kfree(mp); |
| 8008 | sli4_params->cmf = 0; |
| 8009 | phba->cmf_active_mode = LPFC_CFG_OFF; |
| 8010 | goto no_cmf; |
| 8011 | } |
| 8012 | phba->cgn_i = mp; |
| 8013 | |
| 8014 | /* initialize congestion buffer info */ |
| 8015 | lpfc_init_congestion_buf(phba); |
| 8016 | lpfc_init_congestion_stat(phba); |
| 8017 | } |
| 8018 | |
| 8019 | rc = lpfc_sli4_cgn_params_read(phba); |
| 8020 | if (rc < 0) { |
| 8021 | lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT, |
| 8022 | "6242 Error reading Cgn Params (%d)\n", |
| 8023 | rc); |
| 8024 | /* Ensure CGN Mode is off */ |
| 8025 | sli4_params->cmf = 0; |
| 8026 | } else if (!rc) { |
| 8027 | lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT, |
| 8028 | "6243 CGN Event empty object.\n"); |
| 8029 | /* Ensure CGN Mode is off */ |
| 8030 | sli4_params->cmf = 0; |
| 8031 | } |
| 8032 | } else { |
| 8033 | no_cmf: |
| 8034 | lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT, |
| 8035 | "6220 CMF is disabled\n"); |
| 8036 | } |
| 8037 | |
| 8038 | /* Only register congestion buffer with firmware if BOTH |
| 8039 | * CMF and E2E are enabled. |
| 8040 | */ |
| 8041 | if (sli4_params->cmf && sli4_params->mi_ver) { |
| 8042 | rc = lpfc_reg_congestion_buf(phba); |
| 8043 | if (rc) { |
| 8044 | dma_free_coherent(&phba->pcidev->dev, |
| 8045 | sizeof(struct lpfc_cgn_info), |
| 8046 | phba->cgn_i->virt, phba->cgn_i->phys); |
| 8047 | kfree(phba->cgn_i); |
| 8048 | phba->cgn_i = NULL; |
| 8049 | /* Ensure CGN Mode is off */ |
| 8050 | phba->cmf_active_mode = LPFC_CFG_OFF; |
| 8051 | return 0; |
| 8052 | } |
| 8053 | } |
James Smart | c6a5c747 | 2021-08-16 09:28:48 -0700 | [diff] [blame] | 8054 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 8055 | "6470 Setup MI version %d CMF %d mode %d\n", |
| 8056 | sli4_params->mi_ver, sli4_params->cmf, |
| 8057 | phba->cmf_active_mode); |
James Smart | c6a5c747 | 2021-08-16 09:28:48 -0700 | [diff] [blame] | 8058 | |
| 8059 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 8c42a65 | 2021-08-16 09:28:51 -0700 | [diff] [blame] | 8060 | |
| 8061 | /* Initialize atomic counters */ |
| 8062 | atomic_set(&phba->cgn_fabric_warn_cnt, 0); |
| 8063 | atomic_set(&phba->cgn_fabric_alarm_cnt, 0); |
| 8064 | atomic_set(&phba->cgn_sync_alarm_cnt, 0); |
| 8065 | atomic_set(&phba->cgn_sync_warn_cnt, 0); |
| 8066 | atomic_set(&phba->cgn_driver_evt_cnt, 0); |
| 8067 | atomic_set(&phba->cgn_latency_evt_cnt, 0); |
| 8068 | atomic64_set(&phba->cgn_latency_evt, 0); |
| 8069 | |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 8070 | phba->cmf_interval_rate = LPFC_CMF_INTERVAL; |
James Smart | c6a5c747 | 2021-08-16 09:28:48 -0700 | [diff] [blame] | 8071 | return 0; |
| 8072 | } |
| 8073 | |
James Smart | 3b0009c | 2021-08-16 09:28:47 -0700 | [diff] [blame] | 8074 | static int |
| 8075 | lpfc_set_host_tm(struct lpfc_hba *phba) |
| 8076 | { |
| 8077 | LPFC_MBOXQ_t *mboxq; |
| 8078 | uint32_t len, rc; |
| 8079 | struct timespec64 cur_time; |
| 8080 | struct tm broken; |
| 8081 | uint32_t month, day, year; |
| 8082 | uint32_t hour, minute, second; |
| 8083 | struct lpfc_mbx_set_host_date_time *tm; |
| 8084 | |
| 8085 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 8086 | if (!mboxq) |
| 8087 | return -ENOMEM; |
| 8088 | |
| 8089 | len = sizeof(struct lpfc_mbx_set_host_data) - |
| 8090 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 8091 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 8092 | LPFC_MBOX_OPCODE_SET_HOST_DATA, len, |
| 8093 | LPFC_SLI4_MBX_EMBED); |
| 8094 | |
| 8095 | mboxq->u.mqe.un.set_host_data.param_id = LPFC_SET_HOST_DATE_TIME; |
| 8096 | mboxq->u.mqe.un.set_host_data.param_len = |
| 8097 | sizeof(struct lpfc_mbx_set_host_date_time); |
| 8098 | tm = &mboxq->u.mqe.un.set_host_data.un.tm; |
| 8099 | ktime_get_real_ts64(&cur_time); |
| 8100 | time64_to_tm(cur_time.tv_sec, 0, &broken); |
| 8101 | month = broken.tm_mon + 1; |
| 8102 | day = broken.tm_mday; |
| 8103 | year = broken.tm_year - 100; |
| 8104 | hour = broken.tm_hour; |
| 8105 | minute = broken.tm_min; |
| 8106 | second = broken.tm_sec; |
| 8107 | bf_set(lpfc_mbx_set_host_month, tm, month); |
| 8108 | bf_set(lpfc_mbx_set_host_day, tm, day); |
| 8109 | bf_set(lpfc_mbx_set_host_year, tm, year); |
| 8110 | bf_set(lpfc_mbx_set_host_hour, tm, hour); |
| 8111 | bf_set(lpfc_mbx_set_host_min, tm, minute); |
| 8112 | bf_set(lpfc_mbx_set_host_sec, tm, second); |
| 8113 | |
| 8114 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8115 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 8116 | return rc; |
| 8117 | } |
| 8118 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 8119 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 8120 | * lpfc_sli4_hba_setup - SLI4 device initialization PCI function |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8121 | * @phba: Pointer to HBA context object. |
| 8122 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 8123 | * This function is the main SLI4 device initialization PCI function. This |
| 8124 | * function is called by the HBA initialization code, HBA reset code and |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8125 | * HBA error attention handler code. Caller is not required to hold any |
| 8126 | * locks. |
| 8127 | **/ |
| 8128 | int |
| 8129 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) |
| 8130 | { |
James Smart | 171f6c4 | 2019-11-04 16:57:07 -0800 | [diff] [blame] | 8131 | int rc, i, cnt, len, dd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8132 | LPFC_MBOXQ_t *mboxq; |
| 8133 | struct lpfc_mqe *mqe; |
| 8134 | uint8_t *vpd; |
| 8135 | uint32_t vpd_size; |
| 8136 | uint32_t ftr_rsp = 0; |
| 8137 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
| 8138 | struct lpfc_vport *vport = phba->pport; |
| 8139 | struct lpfc_dmabuf *mp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8140 | struct lpfc_rqb *rqbp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8141 | |
| 8142 | /* Perform a PCI function reset to start from clean */ |
| 8143 | rc = lpfc_pci_function_reset(phba); |
| 8144 | if (unlikely(rc)) |
| 8145 | return -ENODEV; |
| 8146 | |
| 8147 | /* Check the HBA Host Status Register for readyness */ |
| 8148 | rc = lpfc_sli4_post_status_check(phba); |
| 8149 | if (unlikely(rc)) |
| 8150 | return -ENODEV; |
| 8151 | else { |
| 8152 | spin_lock_irq(&phba->hbalock); |
| 8153 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; |
| 8154 | spin_unlock_irq(&phba->hbalock); |
| 8155 | } |
| 8156 | |
Dick Kennedy | f0020e4 | 2020-06-30 14:49:58 -0700 | [diff] [blame] | 8157 | lpfc_sli4_dip(phba); |
| 8158 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8159 | /* |
| 8160 | * Allocate a single mailbox container for initializing the |
| 8161 | * port. |
| 8162 | */ |
| 8163 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 8164 | if (!mboxq) |
| 8165 | return -ENOMEM; |
| 8166 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8167 | /* Issue READ_REV to collect vpd and FW information. */ |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 8168 | vpd_size = SLI4_PAGE_SIZE; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8169 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
| 8170 | if (!vpd) { |
| 8171 | rc = -ENOMEM; |
| 8172 | goto out_free_mbox; |
| 8173 | } |
| 8174 | |
| 8175 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8176 | if (unlikely(rc)) { |
| 8177 | kfree(vpd); |
| 8178 | goto out_free_mbox; |
| 8179 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 8180 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8181 | mqe = &mboxq->u.mqe; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8182 | 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] | 8183 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8184 | phba->hba_flag |= HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8185 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
| 8186 | } else { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8187 | phba->hba_flag &= ~HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8188 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 8189 | |
| 8190 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == |
| 8191 | LPFC_DCBX_CEE_MODE) |
| 8192 | phba->hba_flag |= HBA_FIP_SUPPORT; |
| 8193 | else |
| 8194 | phba->hba_flag &= ~HBA_FIP_SUPPORT; |
| 8195 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8196 | phba->hba_flag &= ~HBA_IOQ_FLUSH; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 8197 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8198 | if (phba->sli_rev != LPFC_SLI_REV4) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8199 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8200 | "0376 READ_REV Error. SLI Level %d " |
| 8201 | "FCoE enabled %d\n", |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8202 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8203 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8204 | kfree(vpd); |
| 8205 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8206 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 8207 | |
James Smart | 3b0009c | 2021-08-16 09:28:47 -0700 | [diff] [blame] | 8208 | rc = lpfc_set_host_tm(phba); |
| 8209 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 8210 | "6468 Set host date / time: Status x%x:\n", rc); |
| 8211 | |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 8212 | /* |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8213 | * Continue initialization with default values even if driver failed |
| 8214 | * to read FCoE param config regions, only read parameters if the |
| 8215 | * board is FCoE |
| 8216 | */ |
| 8217 | if (phba->hba_flag & HBA_FCOE_MODE && |
| 8218 | lpfc_sli4_read_fcoe_params(phba)) |
| 8219 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, |
| 8220 | "2570 Failed to read FCoE parameters\n"); |
| 8221 | |
| 8222 | /* |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 8223 | * Retrieve sli4 device physical port name, failure of doing it |
| 8224 | * is considered as non-fatal. |
| 8225 | */ |
| 8226 | rc = lpfc_sli4_retrieve_pport_name(phba); |
| 8227 | if (!rc) |
| 8228 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 8229 | "3080 Successful retrieving SLI4 device " |
| 8230 | "physical port name: %s.\n", phba->Port); |
| 8231 | |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 8232 | rc = lpfc_sli4_get_ctl_attr(phba); |
| 8233 | if (!rc) |
| 8234 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 8235 | "8351 Successful retrieving SLI4 device " |
| 8236 | "CTL ATTR\n"); |
| 8237 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8238 | /* |
| 8239 | * Evaluate the read rev and vpd data. Populate the driver |
| 8240 | * state with the results. If this routine fails, the failure |
| 8241 | * is not fatal as the driver will use generic values. |
| 8242 | */ |
| 8243 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); |
| 8244 | if (unlikely(!rc)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8245 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8246 | "0377 Error %d parsing vpd. " |
| 8247 | "Using defaults.\n", rc); |
| 8248 | rc = 0; |
| 8249 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8250 | kfree(vpd); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8251 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8252 | /* Save information as VPD data */ |
| 8253 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; |
| 8254 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; |
James Smart | 4e565cf | 2018-02-22 08:18:50 -0800 | [diff] [blame] | 8255 | |
| 8256 | /* |
| 8257 | * This is because first G7 ASIC doesn't support the standard |
| 8258 | * 0x5a NVME cmd descriptor type/subtype |
| 8259 | */ |
| 8260 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 8261 | LPFC_SLI_INTF_IF_TYPE_6) && |
| 8262 | (phba->vpd.rev.biuRev == LPFC_G7_ASIC_1) && |
| 8263 | (phba->vpd.rev.smRev == 0) && |
| 8264 | (phba->cfg_nvme_embed_cmd == 1)) |
| 8265 | phba->cfg_nvme_embed_cmd = 0; |
| 8266 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8267 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; |
| 8268 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, |
| 8269 | &mqe->un.read_rev); |
| 8270 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, |
| 8271 | &mqe->un.read_rev); |
| 8272 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, |
| 8273 | &mqe->un.read_rev); |
| 8274 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, |
| 8275 | &mqe->un.read_rev); |
| 8276 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; |
| 8277 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); |
| 8278 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; |
| 8279 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); |
| 8280 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; |
| 8281 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); |
| 8282 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 8283 | "(%d):0380 READ_REV Status x%x " |
| 8284 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", |
| 8285 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8286 | bf_get(lpfc_mqe_status, mqe), |
| 8287 | phba->vpd.rev.opFwName, |
| 8288 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, |
| 8289 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8290 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 8291 | 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] | 8292 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 8293 | lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY); |
| 8294 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8295 | if (rc == MBX_SUCCESS) { |
| 8296 | phba->hba_flag |= HBA_RECOVERABLE_UE; |
| 8297 | /* Set 1Sec interval to detect UE */ |
| 8298 | phba->eratt_poll_interval = 1; |
| 8299 | phba->sli4_hba.ue_to_sr = bf_get( |
| 8300 | lpfc_mbx_set_feature_UESR, |
| 8301 | &mboxq->u.mqe.un.set_feature); |
| 8302 | phba->sli4_hba.ue_to_rp = bf_get( |
| 8303 | lpfc_mbx_set_feature_UERP, |
| 8304 | &mboxq->u.mqe.un.set_feature); |
| 8305 | } |
| 8306 | } |
| 8307 | |
| 8308 | if (phba->cfg_enable_mds_diags && phba->mds_diags_support) { |
| 8309 | /* Enable MDS Diagnostics only if the SLI Port supports it */ |
| 8310 | lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS); |
| 8311 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8312 | if (rc != MBX_SUCCESS) |
| 8313 | phba->mds_diags_support = 0; |
| 8314 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 8315 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8316 | /* |
| 8317 | * Discover the port's supported feature set and match it against the |
| 8318 | * hosts requests. |
| 8319 | */ |
| 8320 | lpfc_request_features(phba, mboxq); |
| 8321 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8322 | if (unlikely(rc)) { |
| 8323 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8324 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8325 | } |
| 8326 | |
Gaurav Srivastava | 5e63330 | 2021-06-08 10:05:49 +0530 | [diff] [blame] | 8327 | /* Disable VMID if app header is not supported */ |
| 8328 | if (phba->cfg_vmid_app_header && !(bf_get(lpfc_mbx_rq_ftr_rsp_ashdr, |
| 8329 | &mqe->un.req_ftrs))) { |
| 8330 | bf_set(lpfc_ftr_ashdr, &phba->sli4_hba.sli4_flags, 0); |
| 8331 | phba->cfg_vmid_app_header = 0; |
| 8332 | lpfc_printf_log(phba, KERN_DEBUG, LOG_SLI, |
| 8333 | "1242 vmid feature not supported\n"); |
| 8334 | } |
| 8335 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8336 | /* |
| 8337 | * The port must support FCP initiator mode as this is the |
| 8338 | * only mode running in the host. |
| 8339 | */ |
| 8340 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { |
| 8341 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 8342 | "0378 No support for fcpi mode.\n"); |
| 8343 | ftr_rsp++; |
| 8344 | } |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 8345 | |
| 8346 | /* Performance Hints are ONLY for FCoE */ |
| 8347 | if (phba->hba_flag & HBA_FCOE_MODE) { |
| 8348 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
| 8349 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; |
| 8350 | else |
| 8351 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; |
| 8352 | } |
| 8353 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8354 | /* |
| 8355 | * If the port cannot support the host's requested features |
| 8356 | * then turn off the global config parameters to disable the |
| 8357 | * feature in the driver. This is not a fatal error. |
| 8358 | */ |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 8359 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
| 8360 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) { |
| 8361 | phba->cfg_enable_bg = 0; |
| 8362 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 8363 | ftr_rsp++; |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 8364 | } |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 8365 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8366 | |
| 8367 | if (phba->max_vpi && phba->cfg_enable_npiv && |
| 8368 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 8369 | ftr_rsp++; |
| 8370 | |
| 8371 | if (ftr_rsp) { |
| 8372 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 8373 | "0379 Feature Mismatch Data: x%08x %08x " |
| 8374 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, |
| 8375 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, |
| 8376 | phba->cfg_enable_npiv, phba->max_vpi); |
| 8377 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 8378 | phba->cfg_enable_bg = 0; |
| 8379 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 8380 | phba->cfg_enable_npiv = 0; |
| 8381 | } |
| 8382 | |
| 8383 | /* These SLI3 features are assumed in SLI4 */ |
| 8384 | spin_lock_irq(&phba->hbalock); |
| 8385 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); |
| 8386 | spin_unlock_irq(&phba->hbalock); |
| 8387 | |
James Smart | 171f6c4 | 2019-11-04 16:57:07 -0800 | [diff] [blame] | 8388 | /* Always try to enable dual dump feature if we can */ |
| 8389 | lpfc_set_features(phba, mboxq, LPFC_SET_DUAL_DUMP); |
| 8390 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8391 | dd = bf_get(lpfc_mbx_set_feature_dd, &mboxq->u.mqe.un.set_feature); |
| 8392 | if ((rc == MBX_SUCCESS) && (dd == LPFC_ENABLE_DUAL_DUMP)) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8393 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 171f6c4 | 2019-11-04 16:57:07 -0800 | [diff] [blame] | 8394 | "6448 Dual Dump is enabled\n"); |
| 8395 | else |
| 8396 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI | LOG_INIT, |
| 8397 | "6447 Dual Dump Mailbox x%x (x%x/x%x) failed, " |
| 8398 | "rc:x%x dd:x%x\n", |
| 8399 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 8400 | lpfc_sli_config_mbox_subsys_get( |
| 8401 | phba, mboxq), |
| 8402 | lpfc_sli_config_mbox_opcode_get( |
| 8403 | phba, mboxq), |
| 8404 | rc, dd); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8405 | /* |
| 8406 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent |
| 8407 | * calls depends on these resources to complete port setup. |
| 8408 | */ |
| 8409 | rc = lpfc_sli4_alloc_resource_identifiers(phba); |
| 8410 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8411 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8412 | "2920 Failed to alloc Resource IDs " |
| 8413 | "rc = x%x\n", rc); |
| 8414 | goto out_free_mbox; |
| 8415 | } |
| 8416 | |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 8417 | lpfc_set_host_data(phba, mboxq); |
| 8418 | |
| 8419 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8420 | if (rc) { |
| 8421 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 8422 | "2134 Failed to set host os driver version %x", |
| 8423 | rc); |
| 8424 | } |
| 8425 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8426 | /* Read the port's service parameters. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 8427 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
| 8428 | if (rc) { |
| 8429 | phba->link_state = LPFC_HBA_ERROR; |
| 8430 | rc = -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8431 | goto out_free_mbox; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 8432 | } |
| 8433 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8434 | mboxq->vport = vport; |
| 8435 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8436 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8437 | if (rc == MBX_SUCCESS) { |
| 8438 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); |
| 8439 | rc = 0; |
| 8440 | } |
| 8441 | |
| 8442 | /* |
| 8443 | * This memory was allocated by the lpfc_read_sparam routine. Release |
| 8444 | * it to the mbuf pool. |
| 8445 | */ |
| 8446 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 8447 | kfree(mp); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8448 | mboxq->ctx_buf = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8449 | if (unlikely(rc)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8450 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8451 | "0382 READ_SPARAM command failed " |
| 8452 | "status %d, mbxStatus x%x\n", |
| 8453 | rc, bf_get(lpfc_mqe_status, mqe)); |
| 8454 | phba->link_state = LPFC_HBA_ERROR; |
| 8455 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8456 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8457 | } |
| 8458 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8459 | lpfc_update_vport_wwn(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8460 | |
| 8461 | /* Update the fc_host data structures with new wwn. */ |
| 8462 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 8463 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
| 8464 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8465 | /* Create all the SLI4 queues */ |
| 8466 | rc = lpfc_sli4_queue_create(phba); |
| 8467 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8468 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8469 | "3089 Failed to allocate queues\n"); |
| 8470 | rc = -ENODEV; |
| 8471 | goto out_free_mbox; |
| 8472 | } |
| 8473 | /* Set up all the queues to the device */ |
| 8474 | rc = lpfc_sli4_queue_setup(phba); |
| 8475 | if (unlikely(rc)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8476 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8477 | "0381 Error %d during queue setup.\n ", rc); |
| 8478 | goto out_stop_timers; |
| 8479 | } |
| 8480 | /* Initialize the driver internal SLI layer lists. */ |
| 8481 | lpfc_sli4_setup(phba); |
| 8482 | lpfc_sli4_queue_init(phba); |
| 8483 | |
| 8484 | /* update host els xri-sgl sizes and mappings */ |
| 8485 | rc = lpfc_sli4_els_sgl_update(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 8486 | if (unlikely(rc)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8487 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 8488 | "1400 Failed to update xri-sgl size and " |
| 8489 | "mapping: %d\n", rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8490 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8491 | } |
| 8492 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 8493 | /* register the els sgl pool to the port */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8494 | rc = lpfc_sli4_repost_sgl_list(phba, &phba->sli4_hba.lpfc_els_sgl_list, |
| 8495 | phba->sli4_hba.els_xri_cnt); |
| 8496 | if (unlikely(rc < 0)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8497 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 8498 | "0582 Error %d during els sgl post " |
| 8499 | "operation\n", rc); |
| 8500 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8501 | goto out_destroy_queue; |
| 8502 | } |
| 8503 | phba->sli4_hba.els_xri_cnt = rc; |
| 8504 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 8505 | if (phba->nvmet_support) { |
| 8506 | /* update host nvmet xri-sgl sizes and mappings */ |
| 8507 | rc = lpfc_sli4_nvmet_sgl_update(phba); |
| 8508 | if (unlikely(rc)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8509 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 8510 | "6308 Failed to update nvmet-sgl size " |
| 8511 | "and mapping: %d\n", rc); |
| 8512 | goto out_destroy_queue; |
| 8513 | } |
| 8514 | |
| 8515 | /* register the nvmet sgl pool to the port */ |
| 8516 | rc = lpfc_sli4_repost_sgl_list( |
| 8517 | phba, |
| 8518 | &phba->sli4_hba.lpfc_nvmet_sgl_list, |
| 8519 | phba->sli4_hba.nvmet_xri_cnt); |
| 8520 | if (unlikely(rc < 0)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8521 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 8522 | "3117 Error %d during nvmet " |
| 8523 | "sgl post\n", rc); |
| 8524 | rc = -ENODEV; |
| 8525 | goto out_destroy_queue; |
| 8526 | } |
| 8527 | phba->sli4_hba.nvmet_xri_cnt = rc; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 8528 | |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 8529 | /* We allocate an iocbq for every receive context SGL. |
| 8530 | * The additional allocation is for abort and ls handling. |
| 8531 | */ |
| 8532 | cnt = phba->sli4_hba.nvmet_xri_cnt + |
| 8533 | phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 8534 | } else { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 8535 | /* update host common xri-sgl sizes and mappings */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8536 | rc = lpfc_sli4_io_sgl_update(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8537 | if (unlikely(rc)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8538 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8539 | "6082 Failed to update nvme-sgl size " |
| 8540 | "and mapping: %d\n", rc); |
| 8541 | goto out_destroy_queue; |
| 8542 | } |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 8543 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 8544 | /* register the allocated common sgl pool to the port */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8545 | rc = lpfc_sli4_repost_io_sgl_list(phba); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 8546 | if (unlikely(rc)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8547 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 8548 | "6116 Error %d during nvme sgl post " |
| 8549 | "operation\n", rc); |
| 8550 | /* Some NVME buffers were moved to abort nvme list */ |
| 8551 | /* A pci function reset will repost them */ |
| 8552 | rc = -ENODEV; |
| 8553 | goto out_destroy_queue; |
| 8554 | } |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 8555 | /* Each lpfc_io_buf job structure has an iocbq element. |
| 8556 | * This cnt provides for abort, els, ct and ls requests. |
| 8557 | */ |
| 8558 | cnt = phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 8559 | } |
| 8560 | |
| 8561 | if (!phba->sli.iocbq_lookup) { |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 8562 | /* Initialize and populate the iocb list per host */ |
| 8563 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 8564 | "2821 initialize iocb list with %d entries\n", |
| 8565 | cnt); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 8566 | rc = lpfc_init_iocb_list(phba, cnt); |
| 8567 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8568 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 8569 | "1413 Failed to init iocb list.\n"); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 8570 | goto out_destroy_queue; |
| 8571 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 8572 | } |
| 8573 | |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 8574 | if (phba->nvmet_support) |
| 8575 | lpfc_nvmet_create_targetport(phba); |
| 8576 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8577 | if (phba->nvmet_support && phba->cfg_nvmet_mrq) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8578 | /* Post initial buffers to all RQs created */ |
| 8579 | for (i = 0; i < phba->cfg_nvmet_mrq; i++) { |
| 8580 | rqbp = phba->sli4_hba.nvmet_mrq_hdr[i]->rqbp; |
| 8581 | INIT_LIST_HEAD(&rqbp->rqb_buffer_list); |
| 8582 | rqbp->rqb_alloc_buffer = lpfc_sli4_nvmet_alloc; |
| 8583 | rqbp->rqb_free_buffer = lpfc_sli4_nvmet_free; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 8584 | rqbp->entry_count = LPFC_NVMET_RQE_DEF_COUNT; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8585 | rqbp->buffer_count = 0; |
| 8586 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8587 | lpfc_post_rq_buffer( |
| 8588 | phba, phba->sli4_hba.nvmet_mrq_hdr[i], |
| 8589 | phba->sli4_hba.nvmet_mrq_data[i], |
James Smart | 2448e48 | 2018-04-09 14:24:24 -0700 | [diff] [blame] | 8590 | phba->cfg_nvmet_mrq_post, i); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8591 | } |
| 8592 | } |
| 8593 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8594 | /* Post the rpi header region to the device. */ |
| 8595 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); |
| 8596 | if (unlikely(rc)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8597 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8598 | "0393 Error %d during rpi post operation\n", |
| 8599 | rc); |
| 8600 | rc = -ENODEV; |
James Smart | 5aa615d | 2021-05-14 12:55:56 -0700 | [diff] [blame] | 8601 | goto out_free_iocblist; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8602 | } |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 8603 | lpfc_sli4_node_prep(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8604 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8605 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8606 | if ((phba->nvmet_support == 0) || (phba->cfg_nvmet_mrq == 1)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8607 | /* |
| 8608 | * The FC Port needs to register FCFI (index 0) |
| 8609 | */ |
| 8610 | lpfc_reg_fcfi(phba, mboxq); |
| 8611 | mboxq->vport = phba->pport; |
| 8612 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8613 | if (rc != MBX_SUCCESS) |
| 8614 | goto out_unset_queue; |
| 8615 | rc = 0; |
| 8616 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, |
| 8617 | &mboxq->u.mqe.un.reg_fcfi); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8618 | } else { |
| 8619 | /* We are a NVME Target mode with MRQ > 1 */ |
| 8620 | |
| 8621 | /* First register the FCFI */ |
| 8622 | lpfc_reg_fcfi_mrq(phba, mboxq, 0); |
| 8623 | mboxq->vport = phba->pport; |
| 8624 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8625 | if (rc != MBX_SUCCESS) |
| 8626 | goto out_unset_queue; |
| 8627 | rc = 0; |
| 8628 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_mrq_fcfi, |
| 8629 | &mboxq->u.mqe.un.reg_fcfi_mrq); |
| 8630 | |
| 8631 | /* Next register the MRQs */ |
| 8632 | lpfc_reg_fcfi_mrq(phba, mboxq, 1); |
| 8633 | mboxq->vport = phba->pport; |
| 8634 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8635 | if (rc != MBX_SUCCESS) |
| 8636 | goto out_unset_queue; |
| 8637 | rc = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8638 | } |
| 8639 | /* Check if the port is configured to be disabled */ |
| 8640 | lpfc_sli_read_link_ste(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8641 | } |
| 8642 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 8643 | /* Don't post more new bufs if repost already recovered |
| 8644 | * the nvme sgls. |
| 8645 | */ |
| 8646 | if (phba->nvmet_support == 0) { |
| 8647 | if (phba->sli4_hba.io_xri_cnt == 0) { |
| 8648 | len = lpfc_new_io_buf( |
| 8649 | phba, phba->sli4_hba.io_xri_max); |
| 8650 | if (len == 0) { |
| 8651 | rc = -ENOMEM; |
| 8652 | goto out_unset_queue; |
| 8653 | } |
| 8654 | |
| 8655 | if (phba->cfg_xri_rebalancing) |
| 8656 | lpfc_create_multixri_pools(phba); |
| 8657 | } |
| 8658 | } else { |
| 8659 | phba->cfg_xri_rebalancing = 0; |
| 8660 | } |
| 8661 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8662 | /* Allow asynchronous mailbox command to go through */ |
| 8663 | spin_lock_irq(&phba->hbalock); |
| 8664 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 8665 | spin_unlock_irq(&phba->hbalock); |
| 8666 | |
| 8667 | /* Post receive buffers to the device */ |
| 8668 | lpfc_sli4_rb_setup(phba); |
| 8669 | |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 8670 | /* Reset HBA FCF states after HBA reset */ |
| 8671 | phba->fcf.fcf_flag = 0; |
| 8672 | phba->fcf.current_rec.flag = 0; |
| 8673 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8674 | /* Start the ELS watchdog timer */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8675 | mod_timer(&vport->els_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8676 | jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8677 | |
| 8678 | /* Start heart beat timer */ |
| 8679 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8680 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 8681 | phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8682 | phba->last_completion_time = jiffies; |
| 8683 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8684 | /* start eq_delay heartbeat */ |
| 8685 | if (phba->cfg_auto_imax) |
| 8686 | queue_delayed_work(phba->wq, &phba->eq_delay_work, |
| 8687 | msecs_to_jiffies(LPFC_EQ_DELAY_MSECS)); |
| 8688 | |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 8689 | /* start per phba idle_stat_delay heartbeat */ |
| 8690 | lpfc_init_idle_stat_hb(phba); |
| 8691 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8692 | /* Start error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8693 | mod_timer(&phba->eratt_poll, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 8694 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8695 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8696 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 8697 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 8698 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 8699 | if (!rc) { |
| 8700 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8701 | "2829 This device supports " |
| 8702 | "Advanced Error Reporting (AER)\n"); |
| 8703 | spin_lock_irq(&phba->hbalock); |
| 8704 | phba->hba_flag |= HBA_AER_ENABLED; |
| 8705 | spin_unlock_irq(&phba->hbalock); |
| 8706 | } else { |
| 8707 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8708 | "2830 This device does not support " |
| 8709 | "Advanced Error Reporting (AER)\n"); |
| 8710 | phba->cfg_aer_support = 0; |
| 8711 | } |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 8712 | rc = 0; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8713 | } |
| 8714 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8715 | /* |
| 8716 | * The port is ready, set the host's link state to LINK_DOWN |
| 8717 | * in preparation for link interrupts. |
| 8718 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8719 | spin_lock_irq(&phba->hbalock); |
| 8720 | phba->link_state = LPFC_LINK_DOWN; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 8721 | |
| 8722 | /* Check if physical ports are trunked */ |
| 8723 | if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba)) |
| 8724 | phba->trunk_link.link0.state = LPFC_LINK_DOWN; |
| 8725 | if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba)) |
| 8726 | phba->trunk_link.link1.state = LPFC_LINK_DOWN; |
| 8727 | if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba)) |
| 8728 | phba->trunk_link.link2.state = LPFC_LINK_DOWN; |
| 8729 | if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba)) |
| 8730 | phba->trunk_link.link3.state = LPFC_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8731 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 8732 | |
James Smart | e8869f5 | 2019-03-12 16:30:18 -0700 | [diff] [blame] | 8733 | /* Arm the CQs and then EQs on device */ |
| 8734 | lpfc_sli4_arm_cqeq_intr(phba); |
| 8735 | |
| 8736 | /* Indicate device interrupt mode */ |
| 8737 | phba->sli4_hba.intr_enable = 1; |
| 8738 | |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 8739 | /* Setup CMF after HBA is initialized */ |
| 8740 | lpfc_cmf_setup(phba); |
| 8741 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 8742 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 8743 | (phba->hba_flag & LINK_DISABLED)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8744 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 8745 | "3103 Adapter Link is disabled.\n"); |
| 8746 | lpfc_down_link(phba, mboxq); |
| 8747 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8748 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8749 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 8750 | "3104 Adapter failed to issue " |
| 8751 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 8752 | goto out_io_buff_free; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 8753 | } |
| 8754 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8755 | /* don't perform init_link on SLI4 FC port loopback test */ |
| 8756 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 8757 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 8758 | if (rc) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 8759 | goto out_io_buff_free; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8760 | } |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8761 | } |
| 8762 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 8763 | |
| 8764 | phba->hba_flag |= HBA_SETUP; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8765 | return rc; |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 8766 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 8767 | out_io_buff_free: |
| 8768 | /* Free allocated IO Buffers */ |
| 8769 | lpfc_io_free(phba); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8770 | out_unset_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8771 | /* Unset all the queues set up in this routine when error out */ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8772 | lpfc_sli4_queue_unset(phba); |
James Smart | 5aa615d | 2021-05-14 12:55:56 -0700 | [diff] [blame] | 8773 | out_free_iocblist: |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 8774 | lpfc_free_iocb_list(phba); |
James Smart | 5aa615d | 2021-05-14 12:55:56 -0700 | [diff] [blame] | 8775 | out_destroy_queue: |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8776 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8777 | out_stop_timers: |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8778 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8779 | out_free_mbox: |
| 8780 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 8781 | return rc; |
| 8782 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8783 | |
| 8784 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8785 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 8786 | * @t: Context to fetch pointer to hba structure from. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8787 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8788 | * This is the callback function for mailbox timer. The mailbox |
| 8789 | * timer is armed when a new mailbox command is issued and the timer |
| 8790 | * is deleted when the mailbox complete. The function is called by |
| 8791 | * the kernel timer code when a mailbox does not complete within |
| 8792 | * expected time. This function wakes up the worker thread to |
| 8793 | * process the mailbox timeout and returns. All the processing is |
| 8794 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 8795 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8796 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 8797 | lpfc_mbox_timeout(struct timer_list *t) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8798 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 8799 | struct lpfc_hba *phba = from_timer(phba, t, sli.mbox_tmo); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8800 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8801 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8802 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8803 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8804 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8805 | if (!tmo_posted) |
| 8806 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 8807 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 8808 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8809 | if (!tmo_posted) |
| 8810 | lpfc_worker_wake_up(phba); |
| 8811 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8812 | } |
| 8813 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8814 | /** |
| 8815 | * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions |
| 8816 | * are pending |
| 8817 | * @phba: Pointer to HBA context object. |
| 8818 | * |
| 8819 | * This function checks if any mailbox completions are present on the mailbox |
| 8820 | * completion queue. |
| 8821 | **/ |
Nicholas Krause | 3bb11fc | 2015-08-31 16:48:13 -0400 | [diff] [blame] | 8822 | static bool |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8823 | lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba) |
| 8824 | { |
| 8825 | |
| 8826 | uint32_t idx; |
| 8827 | struct lpfc_queue *mcq; |
| 8828 | struct lpfc_mcqe *mcqe; |
| 8829 | bool pending_completions = false; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8830 | uint8_t qe_valid; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8831 | |
| 8832 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 8833 | return false; |
| 8834 | |
| 8835 | /* Check for completions on mailbox completion queue */ |
| 8836 | |
| 8837 | mcq = phba->sli4_hba.mbx_cq; |
| 8838 | idx = mcq->hba_index; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8839 | qe_valid = mcq->qe_valid; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 8840 | while (bf_get_le32(lpfc_cqe_valid, |
| 8841 | (struct lpfc_cqe *)lpfc_sli4_qe(mcq, idx)) == qe_valid) { |
| 8842 | mcqe = (struct lpfc_mcqe *)(lpfc_sli4_qe(mcq, idx)); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8843 | if (bf_get_le32(lpfc_trailer_completed, mcqe) && |
| 8844 | (!bf_get_le32(lpfc_trailer_async, mcqe))) { |
| 8845 | pending_completions = true; |
| 8846 | break; |
| 8847 | } |
| 8848 | idx = (idx + 1) % mcq->entry_count; |
| 8849 | if (mcq->hba_index == idx) |
| 8850 | break; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8851 | |
| 8852 | /* if the index wrapped around, toggle the valid bit */ |
| 8853 | if (phba->sli4_hba.pc_sli4_params.cqav && !idx) |
| 8854 | qe_valid = (qe_valid) ? 0 : 1; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8855 | } |
| 8856 | return pending_completions; |
| 8857 | |
| 8858 | } |
| 8859 | |
| 8860 | /** |
| 8861 | * lpfc_sli4_process_missed_mbox_completions - process mbox completions |
| 8862 | * that were missed. |
| 8863 | * @phba: Pointer to HBA context object. |
| 8864 | * |
| 8865 | * For sli4, it is possible to miss an interrupt. As such mbox completions |
| 8866 | * maybe missed causing erroneous mailbox timeouts to occur. This function |
| 8867 | * checks to see if mbox completions are on the mailbox completion queue |
| 8868 | * and will process all the completions associated with the eq for the |
| 8869 | * mailbox completion queue. |
| 8870 | **/ |
YueHaibing | d7b761b | 2019-05-31 23:28:41 +0800 | [diff] [blame] | 8871 | static bool |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8872 | lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba) |
| 8873 | { |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 8874 | struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8875 | uint32_t eqidx; |
| 8876 | struct lpfc_queue *fpeq = NULL; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8877 | struct lpfc_queue *eq; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8878 | bool mbox_pending; |
| 8879 | |
| 8880 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 8881 | return false; |
| 8882 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8883 | /* Find the EQ associated with the mbox CQ */ |
| 8884 | if (sli4_hba->hdwq) { |
| 8885 | for (eqidx = 0; eqidx < phba->cfg_irq_chann; eqidx++) { |
| 8886 | eq = phba->sli4_hba.hba_eq_hdl[eqidx].eq; |
Daniel Wagner | 535fb49 | 2019-10-18 18:21:11 +0200 | [diff] [blame] | 8887 | if (eq && eq->queue_id == sli4_hba->mbx_cq->assoc_qid) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8888 | fpeq = eq; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8889 | break; |
| 8890 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8891 | } |
| 8892 | } |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8893 | if (!fpeq) |
| 8894 | return false; |
| 8895 | |
| 8896 | /* Turn off interrupts from this EQ */ |
| 8897 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 8898 | sli4_hba->sli4_eq_clr_intr(fpeq); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8899 | |
| 8900 | /* Check to see if a mbox completion is pending */ |
| 8901 | |
| 8902 | mbox_pending = lpfc_sli4_mbox_completions_pending(phba); |
| 8903 | |
| 8904 | /* |
| 8905 | * If a mbox completion is pending, process all the events on EQ |
| 8906 | * associated with the mbox completion queue (this could include |
| 8907 | * mailbox commands, async events, els commands, receive queue data |
| 8908 | * and fcp commands) |
| 8909 | */ |
| 8910 | |
| 8911 | if (mbox_pending) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8912 | /* process and rearm the EQ */ |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 8913 | lpfc_sli4_process_eq(phba, fpeq, LPFC_QUEUE_REARM); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8914 | else |
| 8915 | /* Always clear and re-arm the EQ */ |
| 8916 | sli4_hba->sli4_write_eq_db(phba, fpeq, 0, LPFC_QUEUE_REARM); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8917 | |
| 8918 | return mbox_pending; |
| 8919 | |
| 8920 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8921 | |
| 8922 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8923 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8924 | * @phba: Pointer to HBA context object. |
| 8925 | * |
| 8926 | * This function is called from worker thread when a mailbox command times out. |
| 8927 | * The caller is not required to hold any locks. This function will reset the |
| 8928 | * HBA and recover all the pending commands. |
| 8929 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8930 | void |
| 8931 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 8932 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8933 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 8934 | MAILBOX_t *mb = NULL; |
| 8935 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 8936 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8937 | |
James Smart | 9ec58ec | 2021-01-04 10:02:35 -0800 | [diff] [blame] | 8938 | /* If the mailbox completed, process the completion */ |
| 8939 | lpfc_sli4_process_missed_mbox_completions(phba); |
| 8940 | |
| 8941 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8942 | return; |
| 8943 | |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 8944 | if (pmbox != NULL) |
| 8945 | mb = &pmbox->u.mb; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8946 | /* Check the pmbox pointer first. There is a race condition |
| 8947 | * between the mbox timeout handler getting executed in the |
| 8948 | * worklist and the mailbox actually completing. When this |
| 8949 | * race condition occurs, the mbox_active will be NULL. |
| 8950 | */ |
| 8951 | spin_lock_irq(&phba->hbalock); |
| 8952 | if (pmbox == NULL) { |
| 8953 | lpfc_printf_log(phba, KERN_WARNING, |
| 8954 | LOG_MBOX | LOG_SLI, |
| 8955 | "0353 Active Mailbox cleared - mailbox timeout " |
| 8956 | "exiting\n"); |
| 8957 | spin_unlock_irq(&phba->hbalock); |
| 8958 | return; |
| 8959 | } |
| 8960 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8961 | /* Mbox cmd <mbxCommand> timeout */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8962 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 8963 | "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] | 8964 | mb->mbxCommand, |
| 8965 | phba->pport->port_state, |
| 8966 | phba->sli.sli_flag, |
| 8967 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8968 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8969 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 8970 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 8971 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8972 | * it to fail all outstanding SCSI IO. |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 8973 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8974 | spin_lock_irq(&phba->pport->work_port_lock); |
| 8975 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 8976 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 8977 | spin_lock_irq(&phba->hbalock); |
| 8978 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 8979 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8980 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 8981 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8982 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 8983 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8984 | |
| 8985 | /* Reset the HBA device */ |
| 8986 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8987 | } |
| 8988 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8989 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8990 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8991 | * @phba: Pointer to HBA context object. |
| 8992 | * @pmbox: Pointer to mailbox object. |
| 8993 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8994 | * |
| 8995 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8996 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 8997 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8998 | * The mailbox command can be submitted in polling mode, in which case |
| 8999 | * this function will wait in a polling loop for the completion of the |
| 9000 | * mailbox. |
| 9001 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 9002 | * function will submit the command and returns immediately without waiting |
| 9003 | * for the mailbox completion. The no_wait is supported only when HBA |
| 9004 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 9005 | * The SLI interface allows only one mailbox pending at a time. If the |
| 9006 | * mailbox is issued in polling mode and there is already a mailbox |
| 9007 | * pending, then the function will return an error. If the mailbox is issued |
| 9008 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 9009 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 9010 | * The sli layer owns the mailbox object until the completion of mailbox |
| 9011 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 9012 | * return codes the caller owns the mailbox command after the return of |
| 9013 | * the function. |
| 9014 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9015 | static int |
| 9016 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 9017 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9018 | { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 9019 | MAILBOX_t *mbx; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9020 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9021 | uint32_t status, evtctr; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 9022 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9023 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9024 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9025 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 9026 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9027 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 9028 | int processing_queue = 0; |
| 9029 | |
| 9030 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 9031 | if (!pmbox) { |
James Smart | 8568a4d | 2009-07-19 10:01:16 -0400 | [diff] [blame] | 9032 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 9033 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9034 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 9035 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 9036 | return MBX_SUCCESS; |
| 9037 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 9038 | processing_queue = 1; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 9039 | pmbox = lpfc_mbox_get(phba); |
| 9040 | if (!pmbox) { |
| 9041 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 9042 | return MBX_SUCCESS; |
| 9043 | } |
| 9044 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9045 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9046 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9047 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9048 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 9049 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9050 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9051 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9052 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9053 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9054 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 9055 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9056 | } |
| 9057 | } |
| 9058 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9059 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 9060 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 9061 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 9062 | goto out_not_finished; |
| 9063 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9064 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9065 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 9066 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 9067 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 9068 | goto out_not_finished; |
| 9069 | } |
| 9070 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9071 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9072 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 9073 | mbx = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9074 | status = MBX_SUCCESS; |
| 9075 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9076 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 9077 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 9078 | |
| 9079 | /* Mbox command <mbxCommand> cannot issue */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9080 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9081 | "(%d):0311 Mailbox command x%x cannot " |
| 9082 | "issue Data: x%x x%x\n", |
| 9083 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 9084 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 9085 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 9086 | } |
| 9087 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 9088 | if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 9089 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
| 9090 | !(hc_copy & HC_MBINT_ENA)) { |
| 9091 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9092 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9093 | "(%d):2528 Mailbox command x%x cannot " |
| 9094 | "issue Data: x%x x%x\n", |
| 9095 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 9096 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 9097 | goto out_not_finished; |
| 9098 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 9099 | } |
| 9100 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9101 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 9102 | /* Polling for a mbox command when another one is already active |
| 9103 | * is not allowed in SLI. Also, the driver must have established |
| 9104 | * SLI2 mode to queue and process multiple mbox commands. |
| 9105 | */ |
| 9106 | |
| 9107 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9108 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9109 | |
| 9110 | /* Mbox command <mbxCommand> cannot issue */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9111 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9112 | "(%d):2529 Mailbox command x%x " |
| 9113 | "cannot issue Data: x%x x%x\n", |
| 9114 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 9115 | pmbox->u.mb.mbxCommand, |
| 9116 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 9117 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9118 | } |
| 9119 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9120 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9121 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9122 | /* Mbox command <mbxCommand> cannot issue */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9123 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9124 | "(%d):2530 Mailbox command x%x " |
| 9125 | "cannot issue Data: x%x x%x\n", |
| 9126 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 9127 | pmbox->u.mb.mbxCommand, |
| 9128 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 9129 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9130 | } |
| 9131 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9132 | /* Another mailbox command is still being processed, queue this |
| 9133 | * command to be processed later. |
| 9134 | */ |
| 9135 | lpfc_mbox_put(phba, pmbox); |
| 9136 | |
| 9137 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9138 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9139 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9140 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9141 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 9142 | mbx->mbxCommand, |
| 9143 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9144 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9145 | |
| 9146 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9147 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9148 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9149 | if (pmbox->vport) { |
| 9150 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 9151 | LPFC_DISC_TRC_MBOX_VPORT, |
| 9152 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 9153 | (uint32_t)mbx->mbxCommand, |
| 9154 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9155 | } |
| 9156 | else { |
| 9157 | lpfc_debugfs_disc_trc(phba->pport, |
| 9158 | LPFC_DISC_TRC_MBOX, |
| 9159 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 9160 | (uint32_t)mbx->mbxCommand, |
| 9161 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9162 | } |
| 9163 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9164 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9165 | } |
| 9166 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9167 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 9168 | |
| 9169 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 9170 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9171 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 9172 | (mbx->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9173 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9174 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9175 | /* Mbox command <mbxCommand> cannot issue */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9176 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9177 | "(%d):2531 Mailbox command x%x " |
| 9178 | "cannot issue Data: x%x x%x\n", |
| 9179 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 9180 | pmbox->u.mb.mbxCommand, |
| 9181 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 9182 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9183 | } |
| 9184 | /* timeout active mbox command */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 9185 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 9186 | 1000); |
| 9187 | mod_timer(&psli->mbox_tmo, jiffies + timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9188 | } |
| 9189 | |
| 9190 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9191 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9192 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9193 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9194 | pmbox->vport ? pmbox->vport->vpi : 0, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 9195 | mbx->mbxCommand, |
| 9196 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9197 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9198 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 9199 | if (mbx->mbxCommand != MBX_HEARTBEAT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9200 | if (pmbox->vport) { |
| 9201 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 9202 | LPFC_DISC_TRC_MBOX_VPORT, |
| 9203 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 9204 | (uint32_t)mbx->mbxCommand, |
| 9205 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9206 | } |
| 9207 | else { |
| 9208 | lpfc_debugfs_disc_trc(phba->pport, |
| 9209 | LPFC_DISC_TRC_MBOX, |
| 9210 | "MBOX Send: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 9211 | (uint32_t)mbx->mbxCommand, |
| 9212 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9213 | } |
| 9214 | } |
| 9215 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9216 | psli->slistat.mbox_cmd++; |
| 9217 | evtctr = psli->slistat.mbox_event; |
| 9218 | |
| 9219 | /* next set own bit for the adapter and copy over command word */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 9220 | mbx->mbxOwner = OWN_CHIP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9221 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9222 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 9223 | /* Populate mbox extension offset word. */ |
| 9224 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 9225 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 9226 | = (uint8_t *)phba->mbox_ext |
| 9227 | - (uint8_t *)phba->mbox; |
| 9228 | } |
| 9229 | |
| 9230 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 9231 | if (pmbox->in_ext_byte_len && pmbox->ctx_buf) { |
| 9232 | lpfc_sli_pcimem_bcopy(pmbox->ctx_buf, |
| 9233 | (uint8_t *)phba->mbox_ext, |
| 9234 | pmbox->in_ext_byte_len); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 9235 | } |
| 9236 | /* Copy command data to host SLIM area */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 9237 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9238 | } else { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 9239 | /* Populate mbox extension offset word. */ |
| 9240 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 9241 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 9242 | = MAILBOX_HBA_EXT_OFFSET; |
| 9243 | |
| 9244 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 9245 | if (pmbox->in_ext_byte_len && pmbox->ctx_buf) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 9246 | lpfc_memcpy_to_slim(phba->MBslimaddr + |
| 9247 | MAILBOX_HBA_EXT_OFFSET, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 9248 | pmbox->ctx_buf, pmbox->in_ext_byte_len); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 9249 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9250 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9251 | /* copy command data into host mbox for cmpl */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9252 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, |
| 9253 | MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9254 | |
| 9255 | /* First copy mbox command data to HBA SLIM, skip past first |
| 9256 | word */ |
| 9257 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 9258 | lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0], |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9259 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 9260 | |
| 9261 | /* Next copy over first word, with mbxOwner set */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 9262 | ldata = *((uint32_t *)mbx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9263 | to_slim = phba->MBslimaddr; |
| 9264 | writel(ldata, to_slim); |
| 9265 | readl(to_slim); /* flush */ |
| 9266 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9267 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9268 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9269 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9270 | } |
| 9271 | |
| 9272 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9273 | |
| 9274 | switch (flag) { |
| 9275 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9276 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9277 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9278 | /* Interrupt board to do it */ |
| 9279 | writel(CA_MBATT, phba->CAregaddr); |
| 9280 | readl(phba->CAregaddr); /* flush */ |
| 9281 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9282 | break; |
| 9283 | |
| 9284 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9285 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9286 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9287 | /* Interrupt board to do it */ |
| 9288 | writel(CA_MBATT, phba->CAregaddr); |
| 9289 | readl(phba->CAregaddr); /* flush */ |
| 9290 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9291 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9292 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 9293 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9294 | word0 = le32_to_cpu(word0); |
| 9295 | } else { |
| 9296 | /* First read mbox status word */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 9297 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
| 9298 | spin_unlock_irqrestore(&phba->hbalock, |
| 9299 | drvr_flag); |
| 9300 | goto out_not_finished; |
| 9301 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9302 | } |
| 9303 | |
| 9304 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 9305 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 9306 | spin_unlock_irqrestore(&phba->hbalock, |
| 9307 | drvr_flag); |
| 9308 | goto out_not_finished; |
| 9309 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9310 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 9311 | 1000) + jiffies; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9312 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9313 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 9314 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 9315 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9316 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9317 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9318 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9319 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9320 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 9321 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9322 | } |
| 9323 | |
| 9324 | /* Check if we took a mbox interrupt while we were |
| 9325 | polling */ |
| 9326 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 9327 | && (evtctr != psli->slistat.mbox_event)) |
| 9328 | break; |
| 9329 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 9330 | if (i++ > 10) { |
| 9331 | spin_unlock_irqrestore(&phba->hbalock, |
| 9332 | drvr_flag); |
| 9333 | msleep(1); |
| 9334 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 9335 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9336 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9337 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9338 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 9339 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9340 | word0 = le32_to_cpu(word0); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 9341 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9342 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 9343 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9344 | /* Check real SLIM for any errors */ |
| 9345 | slimword0 = readl(phba->MBslimaddr); |
| 9346 | slimmb = (MAILBOX_t *) & slimword0; |
| 9347 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 9348 | && slimmb->mbxStatus) { |
| 9349 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9350 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9351 | word0 = slimword0; |
| 9352 | } |
| 9353 | } |
| 9354 | } else { |
| 9355 | /* First copy command data */ |
| 9356 | word0 = readl(phba->MBslimaddr); |
| 9357 | } |
| 9358 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 9359 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 9360 | spin_unlock_irqrestore(&phba->hbalock, |
| 9361 | drvr_flag); |
| 9362 | goto out_not_finished; |
| 9363 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9364 | } |
| 9365 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9366 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9367 | /* copy results back to user */ |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 9368 | lpfc_sli_pcimem_bcopy(phba->mbox, mbx, |
| 9369 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 9370 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 9371 | if (pmbox->out_ext_byte_len && pmbox->ctx_buf) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 9372 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 9373 | pmbox->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 9374 | pmbox->out_ext_byte_len); |
| 9375 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9376 | } else { |
| 9377 | /* First copy command data */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 9378 | lpfc_memcpy_from_slim(mbx, phba->MBslimaddr, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 9379 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 9380 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 9381 | if (pmbox->out_ext_byte_len && pmbox->ctx_buf) { |
| 9382 | lpfc_memcpy_from_slim( |
| 9383 | pmbox->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 9384 | phba->MBslimaddr + |
| 9385 | MAILBOX_HBA_EXT_OFFSET, |
| 9386 | pmbox->out_ext_byte_len); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9387 | } |
| 9388 | } |
| 9389 | |
| 9390 | writel(HA_MBATT, phba->HAregaddr); |
| 9391 | readl(phba->HAregaddr); /* flush */ |
| 9392 | |
| 9393 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 9394 | status = mbx->mbxStatus; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9395 | } |
| 9396 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9397 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 9398 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 9399 | |
| 9400 | out_not_finished: |
| 9401 | if (processing_queue) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9402 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 9403 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 9404 | } |
| 9405 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9406 | } |
| 9407 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9408 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9409 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command |
| 9410 | * @phba: Pointer to HBA context object. |
| 9411 | * |
| 9412 | * The function blocks the posting of SLI4 asynchronous mailbox commands from |
| 9413 | * the driver internal pending mailbox queue. It will then try to wait out the |
| 9414 | * possible outstanding mailbox command before return. |
| 9415 | * |
| 9416 | * Returns: |
| 9417 | * 0 - the outstanding mailbox command completed; otherwise, the wait for |
| 9418 | * the outstanding mailbox command timed out. |
| 9419 | **/ |
| 9420 | static int |
| 9421 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) |
| 9422 | { |
| 9423 | struct lpfc_sli *psli = &phba->sli; |
James Smart | a9978e3 | 2021-07-07 11:43:43 -0700 | [diff] [blame] | 9424 | LPFC_MBOXQ_t *mboxq; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9425 | int rc = 0; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9426 | unsigned long timeout = 0; |
James Smart | a9978e3 | 2021-07-07 11:43:43 -0700 | [diff] [blame] | 9427 | u32 sli_flag; |
| 9428 | u8 cmd, subsys, opcode; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9429 | |
| 9430 | /* Mark the asynchronous mailbox command posting as blocked */ |
| 9431 | spin_lock_irq(&phba->hbalock); |
| 9432 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9433 | /* Determine how long we might wait for the active mailbox |
| 9434 | * command to be gracefully completed by firmware. |
| 9435 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9436 | if (phba->sli.mbox_active) |
| 9437 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 9438 | phba->sli.mbox_active) * |
| 9439 | 1000) + jiffies; |
| 9440 | spin_unlock_irq(&phba->hbalock); |
| 9441 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 9442 | /* Make sure the mailbox is really active */ |
| 9443 | if (timeout) |
| 9444 | lpfc_sli4_process_missed_mbox_completions(phba); |
| 9445 | |
James Smart | a9978e3 | 2021-07-07 11:43:43 -0700 | [diff] [blame] | 9446 | /* Wait for the outstanding mailbox command to complete */ |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9447 | while (phba->sli.mbox_active) { |
| 9448 | /* Check active mailbox complete status every 2ms */ |
| 9449 | msleep(2); |
| 9450 | if (time_after(jiffies, timeout)) { |
James Smart | a9978e3 | 2021-07-07 11:43:43 -0700 | [diff] [blame] | 9451 | /* Timeout, mark the outstanding cmd not complete */ |
| 9452 | |
| 9453 | /* Sanity check sli.mbox_active has not completed or |
| 9454 | * cancelled from another context during last 2ms sleep, |
| 9455 | * so take hbalock to be sure before logging. |
| 9456 | */ |
| 9457 | spin_lock_irq(&phba->hbalock); |
| 9458 | if (phba->sli.mbox_active) { |
| 9459 | mboxq = phba->sli.mbox_active; |
| 9460 | cmd = mboxq->u.mb.mbxCommand; |
| 9461 | subsys = lpfc_sli_config_mbox_subsys_get(phba, |
| 9462 | mboxq); |
| 9463 | opcode = lpfc_sli_config_mbox_opcode_get(phba, |
| 9464 | mboxq); |
| 9465 | sli_flag = psli->sli_flag; |
| 9466 | spin_unlock_irq(&phba->hbalock); |
| 9467 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 9468 | "2352 Mailbox command x%x " |
| 9469 | "(x%x/x%x) sli_flag x%x could " |
| 9470 | "not complete\n", |
| 9471 | cmd, subsys, opcode, |
| 9472 | sli_flag); |
| 9473 | } else { |
| 9474 | spin_unlock_irq(&phba->hbalock); |
| 9475 | } |
| 9476 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9477 | rc = 1; |
| 9478 | break; |
| 9479 | } |
| 9480 | } |
| 9481 | |
| 9482 | /* Can not cleanly block async mailbox command, fails it */ |
| 9483 | if (rc) { |
| 9484 | spin_lock_irq(&phba->hbalock); |
| 9485 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 9486 | spin_unlock_irq(&phba->hbalock); |
| 9487 | } |
| 9488 | return rc; |
| 9489 | } |
| 9490 | |
| 9491 | /** |
| 9492 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command |
| 9493 | * @phba: Pointer to HBA context object. |
| 9494 | * |
| 9495 | * The function unblocks and resume posting of SLI4 asynchronous mailbox |
| 9496 | * commands from the driver internal pending mailbox queue. It makes sure |
| 9497 | * that there is no outstanding mailbox command before resuming posting |
| 9498 | * asynchronous mailbox commands. If, for any reason, there is outstanding |
| 9499 | * mailbox command, it will try to wait it out before resuming asynchronous |
| 9500 | * mailbox command posting. |
| 9501 | **/ |
| 9502 | static void |
| 9503 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) |
| 9504 | { |
| 9505 | struct lpfc_sli *psli = &phba->sli; |
| 9506 | |
| 9507 | spin_lock_irq(&phba->hbalock); |
| 9508 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 9509 | /* Asynchronous mailbox posting is not blocked, do nothing */ |
| 9510 | spin_unlock_irq(&phba->hbalock); |
| 9511 | return; |
| 9512 | } |
| 9513 | |
| 9514 | /* Outstanding synchronous mailbox command is guaranteed to be done, |
| 9515 | * successful or timeout, after timing-out the outstanding mailbox |
| 9516 | * command shall always be removed, so just unblock posting async |
| 9517 | * mailbox command and resume |
| 9518 | */ |
| 9519 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 9520 | spin_unlock_irq(&phba->hbalock); |
| 9521 | |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 9522 | /* wake up worker thread to post asynchronous mailbox command */ |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9523 | lpfc_worker_wake_up(phba); |
| 9524 | } |
| 9525 | |
| 9526 | /** |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 9527 | * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready |
| 9528 | * @phba: Pointer to HBA context object. |
| 9529 | * @mboxq: Pointer to mailbox object. |
| 9530 | * |
| 9531 | * The function waits for the bootstrap mailbox register ready bit from |
| 9532 | * port for twice the regular mailbox command timeout value. |
| 9533 | * |
| 9534 | * 0 - no timeout on waiting for bootstrap mailbox register ready. |
| 9535 | * MBXERR_ERROR - wait for bootstrap mailbox register timed out. |
| 9536 | **/ |
| 9537 | static int |
| 9538 | lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 9539 | { |
| 9540 | uint32_t db_ready; |
| 9541 | unsigned long timeout; |
| 9542 | struct lpfc_register bmbx_reg; |
| 9543 | |
| 9544 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
| 9545 | * 1000) + jiffies; |
| 9546 | |
| 9547 | do { |
| 9548 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 9549 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 9550 | if (!db_ready) |
James Smart | e2ffe4d | 2019-03-12 16:30:15 -0700 | [diff] [blame] | 9551 | mdelay(2); |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 9552 | |
| 9553 | if (time_after(jiffies, timeout)) |
| 9554 | return MBXERR_ERROR; |
| 9555 | } while (!db_ready); |
| 9556 | |
| 9557 | return 0; |
| 9558 | } |
| 9559 | |
| 9560 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9561 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox |
| 9562 | * @phba: Pointer to HBA context object. |
| 9563 | * @mboxq: Pointer to mailbox object. |
| 9564 | * |
| 9565 | * The function posts a mailbox to the port. The mailbox is expected |
| 9566 | * to be comletely filled in and ready for the port to operate on it. |
| 9567 | * This routine executes a synchronous completion operation on the |
| 9568 | * mailbox by polling for its completion. |
| 9569 | * |
| 9570 | * The caller must not be holding any locks when calling this routine. |
| 9571 | * |
| 9572 | * Returns: |
| 9573 | * MBX_SUCCESS - mailbox posted successfully |
| 9574 | * Any of the MBX error values. |
| 9575 | **/ |
| 9576 | static int |
| 9577 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 9578 | { |
| 9579 | int rc = MBX_SUCCESS; |
| 9580 | unsigned long iflag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9581 | uint32_t mcqe_status; |
| 9582 | uint32_t mbx_cmnd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9583 | struct lpfc_sli *psli = &phba->sli; |
| 9584 | struct lpfc_mqe *mb = &mboxq->u.mqe; |
| 9585 | struct lpfc_bmbx_create *mbox_rgn; |
| 9586 | struct dma_address *dma_address; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9587 | |
| 9588 | /* |
| 9589 | * Only one mailbox can be active to the bootstrap mailbox region |
| 9590 | * at a time and there is no queueing provided. |
| 9591 | */ |
| 9592 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 9593 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 9594 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9595 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9596 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9597 | "cannot issue Data: x%x x%x\n", |
| 9598 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 9599 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9600 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 9601 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9602 | psli->sli_flag, MBX_POLL); |
| 9603 | return MBXERR_ERROR; |
| 9604 | } |
| 9605 | /* The server grabs the token and owns it until release */ |
| 9606 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 9607 | phba->sli.mbox_active = mboxq; |
| 9608 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 9609 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 9610 | /* wait for bootstrap mbox register for readyness */ |
| 9611 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 9612 | if (rc) |
| 9613 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9614 | /* |
| 9615 | * Initialize the bootstrap memory region to avoid stale data areas |
| 9616 | * in the mailbox post. Then copy the caller's mailbox contents to |
| 9617 | * the bmbx mailbox region. |
| 9618 | */ |
| 9619 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); |
| 9620 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 9621 | lpfc_sli4_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
| 9622 | sizeof(struct lpfc_mqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9623 | |
| 9624 | /* Post the high mailbox dma address to the port and wait for ready. */ |
| 9625 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 9626 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); |
| 9627 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 9628 | /* wait for bootstrap mbox register for hi-address write done */ |
| 9629 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 9630 | if (rc) |
| 9631 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9632 | |
| 9633 | /* Post the low mailbox dma address to the port. */ |
| 9634 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9635 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 9636 | /* wait for bootstrap mbox register for low address write done */ |
| 9637 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 9638 | if (rc) |
| 9639 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9640 | |
| 9641 | /* |
| 9642 | * Read the CQ to ensure the mailbox has completed. |
| 9643 | * If so, update the mailbox status so that the upper layers |
| 9644 | * can complete the request normally. |
| 9645 | */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 9646 | lpfc_sli4_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
| 9647 | sizeof(struct lpfc_mqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9648 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 9649 | lpfc_sli4_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
| 9650 | sizeof(struct lpfc_mcqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9651 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9652 | /* |
| 9653 | * When the CQE status indicates a failure and the mailbox status |
| 9654 | * indicates success then copy the CQE status into the mailbox status |
| 9655 | * (and prefix it with x4000). |
| 9656 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9657 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9658 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
| 9659 | bf_set(lpfc_mqe_status, mb, |
| 9660 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9661 | rc = MBXERR_ERROR; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 9662 | } else |
| 9663 | lpfc_sli4_swap_str(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9664 | |
| 9665 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9666 | "(%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] | 9667 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
| 9668 | " 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] | 9669 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
| 9670 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 9671 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9672 | bf_get(lpfc_mqe_status, mb), |
| 9673 | mb->un.mb_words[0], mb->un.mb_words[1], |
| 9674 | mb->un.mb_words[2], mb->un.mb_words[3], |
| 9675 | mb->un.mb_words[4], mb->un.mb_words[5], |
| 9676 | mb->un.mb_words[6], mb->un.mb_words[7], |
| 9677 | mb->un.mb_words[8], mb->un.mb_words[9], |
| 9678 | mb->un.mb_words[10], mb->un.mb_words[11], |
| 9679 | mb->un.mb_words[12], mboxq->mcqe.word0, |
| 9680 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 9681 | mboxq->mcqe.trailer); |
| 9682 | exit: |
| 9683 | /* We are holding the token, no needed for lock when release */ |
| 9684 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 9685 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 9686 | phba->sli.mbox_active = NULL; |
| 9687 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 9688 | return rc; |
| 9689 | } |
| 9690 | |
| 9691 | /** |
| 9692 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware |
| 9693 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 9694 | * @mboxq: Pointer to mailbox object. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9695 | * @flag: Flag indicating how the mailbox need to be processed. |
| 9696 | * |
| 9697 | * This function is called by discovery code and HBA management code to submit |
| 9698 | * a mailbox command to firmware with SLI-4 interface spec. |
| 9699 | * |
| 9700 | * Return codes the caller owns the mailbox command after the return of the |
| 9701 | * function. |
| 9702 | **/ |
| 9703 | static int |
| 9704 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 9705 | uint32_t flag) |
| 9706 | { |
| 9707 | struct lpfc_sli *psli = &phba->sli; |
| 9708 | unsigned long iflags; |
| 9709 | int rc; |
| 9710 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 9711 | /* dump from issue mailbox command if setup */ |
| 9712 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); |
| 9713 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 9714 | rc = lpfc_mbox_dev_check(phba); |
| 9715 | if (unlikely(rc)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9716 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9717 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 9718 | "cannot issue Data: x%x x%x\n", |
| 9719 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 9720 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9721 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 9722 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 9723 | psli->sli_flag, flag); |
| 9724 | goto out_not_finished; |
| 9725 | } |
| 9726 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9727 | /* Detect polling mode and jump to a handler */ |
| 9728 | if (!phba->sli4_hba.intr_enable) { |
| 9729 | if (flag == MBX_POLL) |
| 9730 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 9731 | else |
| 9732 | rc = -EIO; |
| 9733 | if (rc != MBX_SUCCESS) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9734 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9735 | "(%d):2541 Mailbox command x%x " |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 9736 | "(x%x/x%x) failure: " |
| 9737 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 9738 | "Data: x%x x%x\n,", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9739 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 9740 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9741 | lpfc_sli_config_mbox_subsys_get(phba, |
| 9742 | mboxq), |
| 9743 | lpfc_sli_config_mbox_opcode_get(phba, |
| 9744 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 9745 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 9746 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 9747 | bf_get(lpfc_mcqe_ext_status, |
| 9748 | &mboxq->mcqe), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9749 | psli->sli_flag, flag); |
| 9750 | return rc; |
| 9751 | } else if (flag == MBX_POLL) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9752 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 9753 | "(%d):2542 Try to issue mailbox command " |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 9754 | "x%x (x%x/x%x) synchronously ahead of async " |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9755 | "mailbox command queue: x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9756 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 9757 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9758 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 9759 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9760 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9761 | /* Try to block the asynchronous mailbox posting */ |
| 9762 | rc = lpfc_sli4_async_mbox_block(phba); |
| 9763 | if (!rc) { |
| 9764 | /* Successfully blocked, now issue sync mbox cmd */ |
| 9765 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 9766 | if (rc != MBX_SUCCESS) |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 9767 | lpfc_printf_log(phba, KERN_WARNING, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9768 | LOG_MBOX | LOG_SLI, |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 9769 | "(%d):2597 Sync Mailbox command " |
| 9770 | "x%x (x%x/x%x) failure: " |
| 9771 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 9772 | "Data: x%x x%x\n,", |
| 9773 | mboxq->vport ? mboxq->vport->vpi : 0, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9774 | mboxq->u.mb.mbxCommand, |
| 9775 | lpfc_sli_config_mbox_subsys_get(phba, |
| 9776 | mboxq), |
| 9777 | lpfc_sli_config_mbox_opcode_get(phba, |
| 9778 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 9779 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 9780 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 9781 | bf_get(lpfc_mcqe_ext_status, |
| 9782 | &mboxq->mcqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9783 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9784 | /* Unblock the async mailbox posting afterward */ |
| 9785 | lpfc_sli4_async_mbox_unblock(phba); |
| 9786 | } |
| 9787 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9788 | } |
| 9789 | |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 9790 | /* Now, interrupt mode asynchronous mailbox command */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9791 | rc = lpfc_mbox_cmd_check(phba, mboxq); |
| 9792 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9793 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9794 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9795 | "cannot issue Data: x%x x%x\n", |
| 9796 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 9797 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9798 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 9799 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9800 | psli->sli_flag, flag); |
| 9801 | goto out_not_finished; |
| 9802 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9803 | |
| 9804 | /* Put the mailbox command to the driver internal FIFO */ |
| 9805 | psli->slistat.mbox_busy++; |
| 9806 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9807 | lpfc_mbox_put(phba, mboxq); |
| 9808 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9809 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 9810 | "(%d):0354 Mbox cmd issue - Enqueue Data: " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9811 | "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] | 9812 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
| 9813 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9814 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 9815 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9816 | phba->pport->port_state, |
| 9817 | psli->sli_flag, MBX_NOWAIT); |
| 9818 | /* Wake up worker thread to transport mailbox command from head */ |
| 9819 | lpfc_worker_wake_up(phba); |
| 9820 | |
| 9821 | return MBX_BUSY; |
| 9822 | |
| 9823 | out_not_finished: |
| 9824 | return MBX_NOT_FINISHED; |
| 9825 | } |
| 9826 | |
| 9827 | /** |
| 9828 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device |
| 9829 | * @phba: Pointer to HBA context object. |
| 9830 | * |
| 9831 | * This function is called by worker thread to send a mailbox command to |
| 9832 | * SLI4 HBA firmware. |
| 9833 | * |
| 9834 | **/ |
| 9835 | int |
| 9836 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) |
| 9837 | { |
| 9838 | struct lpfc_sli *psli = &phba->sli; |
| 9839 | LPFC_MBOXQ_t *mboxq; |
| 9840 | int rc = MBX_SUCCESS; |
| 9841 | unsigned long iflags; |
| 9842 | struct lpfc_mqe *mqe; |
| 9843 | uint32_t mbx_cmnd; |
| 9844 | |
| 9845 | /* Check interrupt mode before post async mailbox command */ |
| 9846 | if (unlikely(!phba->sli4_hba.intr_enable)) |
| 9847 | return MBX_NOT_FINISHED; |
| 9848 | |
| 9849 | /* Check for mailbox command service token */ |
| 9850 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9851 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 9852 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9853 | return MBX_NOT_FINISHED; |
| 9854 | } |
| 9855 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 9856 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9857 | return MBX_NOT_FINISHED; |
| 9858 | } |
| 9859 | if (unlikely(phba->sli.mbox_active)) { |
| 9860 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9861 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9862 | "0384 There is pending active mailbox cmd\n"); |
| 9863 | return MBX_NOT_FINISHED; |
| 9864 | } |
| 9865 | /* Take the mailbox command service token */ |
| 9866 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 9867 | |
| 9868 | /* Get the next mailbox command from head of queue */ |
| 9869 | mboxq = lpfc_mbox_get(phba); |
| 9870 | |
| 9871 | /* If no more mailbox command waiting for post, we're done */ |
| 9872 | if (!mboxq) { |
| 9873 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 9874 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9875 | return MBX_SUCCESS; |
| 9876 | } |
| 9877 | phba->sli.mbox_active = mboxq; |
| 9878 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9879 | |
| 9880 | /* Check device readiness for posting mailbox command */ |
| 9881 | rc = lpfc_mbox_dev_check(phba); |
| 9882 | if (unlikely(rc)) |
| 9883 | /* Driver clean routine will clean up pending mailbox */ |
| 9884 | goto out_not_finished; |
| 9885 | |
| 9886 | /* Prepare the mbox command to be posted */ |
| 9887 | mqe = &mboxq->u.mqe; |
| 9888 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); |
| 9889 | |
| 9890 | /* Start timer for the mbox_tmo and log some mailbox post messages */ |
| 9891 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 9892 | msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq)))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9893 | |
| 9894 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9895 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9896 | "x%x x%x\n", |
| 9897 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9898 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 9899 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9900 | phba->pport->port_state, psli->sli_flag); |
| 9901 | |
| 9902 | if (mbx_cmnd != MBX_HEARTBEAT) { |
| 9903 | if (mboxq->vport) { |
| 9904 | lpfc_debugfs_disc_trc(mboxq->vport, |
| 9905 | LPFC_DISC_TRC_MBOX_VPORT, |
| 9906 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 9907 | mbx_cmnd, mqe->un.mb_words[0], |
| 9908 | mqe->un.mb_words[1]); |
| 9909 | } else { |
| 9910 | lpfc_debugfs_disc_trc(phba->pport, |
| 9911 | LPFC_DISC_TRC_MBOX, |
| 9912 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 9913 | mbx_cmnd, mqe->un.mb_words[0], |
| 9914 | mqe->un.mb_words[1]); |
| 9915 | } |
| 9916 | } |
| 9917 | psli->slistat.mbox_cmd++; |
| 9918 | |
| 9919 | /* Post the mailbox command to the port */ |
| 9920 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); |
| 9921 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9922 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9923 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9924 | "cannot issue Data: x%x x%x\n", |
| 9925 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 9926 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9927 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 9928 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9929 | psli->sli_flag, MBX_NOWAIT); |
| 9930 | goto out_not_finished; |
| 9931 | } |
| 9932 | |
| 9933 | return rc; |
| 9934 | |
| 9935 | out_not_finished: |
| 9936 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 9937 | if (phba->sli.mbox_active) { |
| 9938 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 9939 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 9940 | /* Release the token */ |
| 9941 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 9942 | phba->sli.mbox_active = NULL; |
| 9943 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9944 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9945 | |
| 9946 | return MBX_NOT_FINISHED; |
| 9947 | } |
| 9948 | |
| 9949 | /** |
| 9950 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command |
| 9951 | * @phba: Pointer to HBA context object. |
| 9952 | * @pmbox: Pointer to mailbox object. |
| 9953 | * @flag: Flag indicating how the mailbox need to be processed. |
| 9954 | * |
| 9955 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from |
| 9956 | * the API jump table function pointer from the lpfc_hba struct. |
| 9957 | * |
| 9958 | * Return codes the caller owns the mailbox command after the return of the |
| 9959 | * function. |
| 9960 | **/ |
| 9961 | int |
| 9962 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| 9963 | { |
| 9964 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); |
| 9965 | } |
| 9966 | |
| 9967 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9968 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9969 | * @phba: The hba struct for which this call is being executed. |
| 9970 | * @dev_grp: The HBA PCI-Device group number. |
| 9971 | * |
| 9972 | * This routine sets up the mbox interface API function jump table in @phba |
| 9973 | * struct. |
| 9974 | * Returns: 0 - success, -ENODEV - failure. |
| 9975 | **/ |
| 9976 | int |
| 9977 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 9978 | { |
| 9979 | |
| 9980 | switch (dev_grp) { |
| 9981 | case LPFC_PCI_DEV_LP: |
| 9982 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; |
| 9983 | phba->lpfc_sli_handle_slow_ring_event = |
| 9984 | lpfc_sli_handle_slow_ring_event_s3; |
| 9985 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; |
| 9986 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; |
| 9987 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; |
| 9988 | break; |
| 9989 | case LPFC_PCI_DEV_OC: |
| 9990 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; |
| 9991 | phba->lpfc_sli_handle_slow_ring_event = |
| 9992 | lpfc_sli_handle_slow_ring_event_s4; |
| 9993 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; |
| 9994 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; |
| 9995 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; |
| 9996 | break; |
| 9997 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9998 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9999 | "1420 Invalid HBA PCI-device group: 0x%x\n", |
| 10000 | dev_grp); |
| 10001 | return -ENODEV; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10002 | } |
| 10003 | return 0; |
| 10004 | } |
| 10005 | |
| 10006 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10007 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10008 | * @phba: Pointer to HBA context object. |
| 10009 | * @pring: Pointer to driver SLI ring object. |
| 10010 | * @piocb: Pointer to address of newly added command iocb. |
| 10011 | * |
James Smart | 27f3efd | 2019-10-18 14:18:19 -0700 | [diff] [blame] | 10012 | * This function is called with hbalock held for SLI3 ports or |
| 10013 | * the ring lock held for SLI4 ports to add a command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10014 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 10015 | * to the ring. |
| 10016 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10017 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10018 | __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] | 10019 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10020 | { |
James Smart | 27f3efd | 2019-10-18 14:18:19 -0700 | [diff] [blame] | 10021 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 10022 | lockdep_assert_held(&pring->ring_lock); |
| 10023 | else |
| 10024 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10025 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 10026 | list_add_tail(&piocb->list, &pring->txq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10027 | } |
| 10028 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10029 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10030 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10031 | * @phba: Pointer to HBA context object. |
| 10032 | * @pring: Pointer to driver SLI ring object. |
| 10033 | * @piocb: Pointer to address of newly added command iocb. |
| 10034 | * |
| 10035 | * This function is called with hbalock held before a new |
| 10036 | * iocb is submitted to the firmware. This function checks |
| 10037 | * txq to flush the iocbs in txq to Firmware before |
| 10038 | * submitting new iocbs to the Firmware. |
| 10039 | * If there are iocbs in the txq which need to be submitted |
| 10040 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 10041 | * of the txq after dequeuing it from txq. |
| 10042 | * If there is no iocb in the txq then the function will return |
| 10043 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 10044 | * *piocb to find if there are more commands in the txq. |
| 10045 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10046 | static struct lpfc_iocbq * |
| 10047 | 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] | 10048 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10049 | { |
| 10050 | struct lpfc_iocbq * nextiocb; |
| 10051 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 10052 | lockdep_assert_held(&phba->hbalock); |
| 10053 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10054 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 10055 | if (!nextiocb) { |
| 10056 | nextiocb = *piocb; |
| 10057 | *piocb = NULL; |
| 10058 | } |
| 10059 | |
| 10060 | return nextiocb; |
| 10061 | } |
| 10062 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10063 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10064 | * __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] | 10065 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10066 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10067 | * @piocb: Pointer to command iocb. |
| 10068 | * @flag: Flag indicating if this command can be put into txq. |
| 10069 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10070 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 10071 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 10072 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 10073 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 10074 | * this function allows only iocbs for posting buffers. This function finds |
| 10075 | * next available slot in the command ring and posts the command to the |
| 10076 | * available slot and writes the port attention register to request HBA start |
| 10077 | * processing new iocb. If there is no slot available in the ring and |
| 10078 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 10079 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10080 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10081 | * This function is called with hbalock held. The function will return success |
| 10082 | * after it successfully submit the iocb to firmware or after adding to the |
| 10083 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10084 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10085 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10086 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10087 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 10088 | { |
| 10089 | struct lpfc_iocbq *nextiocb; |
| 10090 | IOCB_t *iocb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10091 | struct lpfc_sli_ring *pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10092 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 10093 | lockdep_assert_held(&phba->hbalock); |
| 10094 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10095 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 10096 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 10097 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10098 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10099 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10100 | piocb->iocb.ulpCommand); |
| 10101 | dump_stack(); |
| 10102 | return IOCB_ERROR; |
| 10103 | } |
| 10104 | |
| 10105 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10106 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 10107 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 10108 | return IOCB_ERROR; |
| 10109 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10110 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 10111 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 10112 | return IOCB_ERROR; |
| 10113 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10114 | /* |
| 10115 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 10116 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10117 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10118 | return IOCB_ERROR; |
| 10119 | |
| 10120 | /* |
| 10121 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 10122 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10123 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 10124 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10125 | goto iocb_busy; |
| 10126 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10127 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10128 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 10129 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10130 | * can be issued if the link is not up. |
| 10131 | */ |
| 10132 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 10133 | case CMD_GEN_REQUEST64_CR: |
| 10134 | case CMD_GEN_REQUEST64_CX: |
| 10135 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 10136 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10137 | FC_RCTL_DD_UNSOL_CMD) || |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 10138 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 10139 | MENLO_TRANSPORT_TYPE)) |
| 10140 | |
| 10141 | goto iocb_busy; |
| 10142 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10143 | case CMD_QUE_RING_BUF_CN: |
| 10144 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10145 | /* |
| 10146 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 10147 | * completion, iocb_cmpl MUST be 0. |
| 10148 | */ |
| 10149 | if (piocb->iocb_cmpl) |
| 10150 | piocb->iocb_cmpl = NULL; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 10151 | fallthrough; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10152 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 10153 | case CMD_CLOSE_XRI_CN: |
| 10154 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10155 | break; |
| 10156 | default: |
| 10157 | goto iocb_busy; |
| 10158 | } |
| 10159 | |
| 10160 | /* |
| 10161 | * For FCP commands, we must be in a state where we can process link |
| 10162 | * attention events. |
| 10163 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10164 | } else if (unlikely(pring->ringno == LPFC_FCP_RING && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10165 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10166 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10167 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10168 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10169 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 10170 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 10171 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 10172 | |
| 10173 | if (iocb) |
| 10174 | lpfc_sli_update_ring(phba, pring); |
| 10175 | else |
| 10176 | lpfc_sli_update_full_ring(phba, pring); |
| 10177 | |
| 10178 | if (!piocb) |
| 10179 | return IOCB_SUCCESS; |
| 10180 | |
| 10181 | goto out_busy; |
| 10182 | |
| 10183 | iocb_busy: |
| 10184 | pring->stats.iocb_cmd_delay++; |
| 10185 | |
| 10186 | out_busy: |
| 10187 | |
| 10188 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10189 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10190 | return IOCB_SUCCESS; |
| 10191 | } |
| 10192 | |
| 10193 | return IOCB_BUSY; |
| 10194 | } |
| 10195 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10196 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10197 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
| 10198 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 10199 | * @piocbq: Pointer to command iocb. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10200 | * @sglq: Pointer to the scatter gather queue object. |
| 10201 | * |
| 10202 | * This routine converts the bpl or bde that is in the IOCB |
| 10203 | * to a sgl list for the sli4 hardware. The physical address |
| 10204 | * of the bpl/bde is converted back to a virtual address. |
| 10205 | * If the IOCB contains a BPL then the list of BDE's is |
| 10206 | * converted to sli4_sge's. If the IOCB contains a single |
| 10207 | * BDE then it is converted to a single sli_sge. |
| 10208 | * The IOCB is still in cpu endianess so the contents of |
| 10209 | * the bpl can be used without byte swapping. |
| 10210 | * |
| 10211 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 10212 | **/ |
| 10213 | static uint16_t |
| 10214 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
| 10215 | struct lpfc_sglq *sglq) |
| 10216 | { |
| 10217 | uint16_t xritag = NO_XRI; |
| 10218 | struct ulp_bde64 *bpl = NULL; |
| 10219 | struct ulp_bde64 bde; |
| 10220 | struct sli4_sge *sgl = NULL; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 10221 | struct lpfc_dmabuf *dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10222 | IOCB_t *icmd; |
| 10223 | int numBdes = 0; |
| 10224 | int i = 0; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 10225 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 10226 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10227 | |
| 10228 | if (!piocbq || !sglq) |
| 10229 | return xritag; |
| 10230 | |
| 10231 | sgl = (struct sli4_sge *)sglq->sgl; |
| 10232 | icmd = &piocbq->iocb; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10233 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
| 10234 | return sglq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10235 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
| 10236 | numBdes = icmd->un.genreq64.bdl.bdeSize / |
| 10237 | sizeof(struct ulp_bde64); |
| 10238 | /* The addrHigh and addrLow fields within the IOCB |
| 10239 | * have not been byteswapped yet so there is no |
| 10240 | * need to swap them back. |
| 10241 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 10242 | if (piocbq->context3) |
| 10243 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; |
| 10244 | else |
| 10245 | return xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10246 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 10247 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10248 | if (!bpl) |
| 10249 | return xritag; |
| 10250 | |
| 10251 | for (i = 0; i < numBdes; i++) { |
| 10252 | /* Should already be byte swapped. */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 10253 | sgl->addr_hi = bpl->addrHigh; |
| 10254 | sgl->addr_lo = bpl->addrLow; |
| 10255 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 10256 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10257 | if ((i+1) == numBdes) |
| 10258 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 10259 | else |
| 10260 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 10261 | /* swap the size field back to the cpu so we |
| 10262 | * can assign it to the sgl. |
| 10263 | */ |
| 10264 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 10265 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 10266 | /* The offsets in the sgl need to be accumulated |
| 10267 | * separately for the request and reply lists. |
| 10268 | * The request is always first, the reply follows. |
| 10269 | */ |
| 10270 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { |
| 10271 | /* add up the reply sg entries */ |
| 10272 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 10273 | inbound++; |
| 10274 | /* first inbound? reset the offset */ |
| 10275 | if (inbound == 1) |
| 10276 | offset = 0; |
| 10277 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 10278 | bf_set(lpfc_sli4_sge_type, sgl, |
| 10279 | LPFC_SGE_TYPE_DATA); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 10280 | offset += bde.tus.f.bdeSize; |
| 10281 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 10282 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10283 | bpl++; |
| 10284 | sgl++; |
| 10285 | } |
| 10286 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { |
| 10287 | /* The addrHigh and addrLow fields of the BDE have not |
| 10288 | * been byteswapped yet so they need to be swapped |
| 10289 | * before putting them in the sgl. |
| 10290 | */ |
| 10291 | sgl->addr_hi = |
| 10292 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); |
| 10293 | sgl->addr_lo = |
| 10294 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 10295 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10296 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 10297 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 10298 | sgl->sge_len = |
| 10299 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10300 | } |
| 10301 | return sglq->sli4_xritag; |
| 10302 | } |
| 10303 | |
| 10304 | /** |
Lee Jones | 8514e2f | 2021-03-03 14:46:18 +0000 | [diff] [blame] | 10305 | * lpfc_sli4_iocb2wqe - Convert the IOCB to a work queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10306 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 10307 | * @iocbq: Pointer to command iocb. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10308 | * @wqe: Pointer to the work queue entry. |
| 10309 | * |
| 10310 | * This routine converts the iocb command to its Work Queue Entry |
| 10311 | * equivalent. The wqe pointer should not have any fields set when |
| 10312 | * this routine is called because it will memcpy over them. |
| 10313 | * This routine does not set the CQ_ID or the WQEC bits in the |
| 10314 | * wqe. |
| 10315 | * |
| 10316 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
| 10317 | **/ |
| 10318 | static int |
| 10319 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 10320 | union lpfc_wqe128 *wqe) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10321 | { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10322 | uint32_t xmit_len = 0, total_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10323 | uint8_t ct = 0; |
| 10324 | uint32_t fip; |
| 10325 | uint32_t abort_tag; |
| 10326 | uint8_t command_type = ELS_COMMAND_NON_FIP; |
| 10327 | uint8_t cmnd; |
| 10328 | uint16_t xritag; |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 10329 | uint16_t abrt_iotag; |
| 10330 | struct lpfc_iocbq *abrtiocbq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10331 | struct ulp_bde64 *bpl = NULL; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10332 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10333 | int numBdes, i; |
| 10334 | struct ulp_bde64 bde; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 10335 | struct lpfc_nodelist *ndlp; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 10336 | uint32_t *pcmd; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 10337 | uint32_t if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10338 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10339 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10340 | /* The fcp commands will set command type */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 10341 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10342 | command_type = FCP_COMMAND; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 10343 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 10344 | command_type = ELS_COMMAND_FIP; |
| 10345 | else |
| 10346 | command_type = ELS_COMMAND_NON_FIP; |
| 10347 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10348 | if (phba->fcp_embed_io) |
| 10349 | memset(wqe, 0, sizeof(union lpfc_wqe128)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10350 | /* Some of the fields are in the right position already */ |
| 10351 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 10352 | /* The ct field has moved so reset */ |
| 10353 | wqe->generic.wqe_com.word7 = 0; |
| 10354 | wqe->generic.wqe_com.word10 = 0; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10355 | |
| 10356 | abort_tag = (uint32_t) iocbq->iotag; |
| 10357 | xritag = iocbq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10358 | /* words0-2 bpl convert bde */ |
| 10359 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10360 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 10361 | sizeof(struct ulp_bde64); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10362 | bpl = (struct ulp_bde64 *) |
| 10363 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; |
| 10364 | if (!bpl) |
| 10365 | return IOCB_ERROR; |
| 10366 | |
| 10367 | /* Should already be byte swapped. */ |
| 10368 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); |
| 10369 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); |
| 10370 | /* swap the size field back to the cpu so we |
| 10371 | * can assign it to the sgl. |
| 10372 | */ |
| 10373 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10374 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
| 10375 | total_len = 0; |
| 10376 | for (i = 0; i < numBdes; i++) { |
| 10377 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 10378 | total_len += bde.tus.f.bdeSize; |
| 10379 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10380 | } else |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10381 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10382 | |
| 10383 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
| 10384 | cmnd = iocbq->iocb.ulpCommand; |
| 10385 | |
| 10386 | switch (iocbq->iocb.ulpCommand) { |
| 10387 | case CMD_ELS_REQUEST64_CR: |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 10388 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
| 10389 | ndlp = iocbq->context_un.ndlp; |
| 10390 | else |
| 10391 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10392 | if (!iocbq->iocb.ulpLe) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10393 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10394 | "2007 Only Limited Edition cmd Format" |
| 10395 | " supported 0x%x\n", |
| 10396 | iocbq->iocb.ulpCommand); |
| 10397 | return IOCB_ERROR; |
| 10398 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 10399 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10400 | wqe->els_req.payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10401 | /* Els_reguest64 has a TMO */ |
| 10402 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, |
| 10403 | iocbq->iocb.ulpTimeout); |
| 10404 | /* Need a VF for word 4 set the vf bit*/ |
| 10405 | bf_set(els_req64_vf, &wqe->els_req, 0); |
| 10406 | /* And a VFID for word 12 */ |
| 10407 | bf_set(els_req64_vfid, &wqe->els_req, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10408 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10409 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 10410 | iocbq->iocb.ulpContext); |
| 10411 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); |
| 10412 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10413 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 10414 | if (command_type == ELS_COMMAND_FIP) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 10415 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
| 10416 | >> LPFC_FIP_ELS_ID_SHIFT); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 10417 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 10418 | iocbq->context2)->virt); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 10419 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 10420 | &phba->sli4_hba.sli_intf); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10421 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 10422 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10423 | *pcmd == ELS_CMD_SCR || |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 10424 | *pcmd == ELS_CMD_RDF || |
James Smart | 9064aeb | 2021-08-16 09:28:50 -0700 | [diff] [blame] | 10425 | *pcmd == ELS_CMD_EDC || |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 10426 | *pcmd == ELS_CMD_RSCN_XMT || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10427 | *pcmd == ELS_CMD_FDISC || |
James Smart | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 10428 | *pcmd == ELS_CMD_LOGO || |
Gaurav Srivastava | f56e86a | 2021-06-08 10:05:53 +0530 | [diff] [blame] | 10429 | *pcmd == ELS_CMD_QFPA || |
| 10430 | *pcmd == ELS_CMD_UVEM || |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 10431 | *pcmd == ELS_CMD_PLOGI)) { |
| 10432 | bf_set(els_req64_sp, &wqe->els_req, 1); |
| 10433 | bf_set(els_req64_sid, &wqe->els_req, |
| 10434 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 10435 | if ((*pcmd == ELS_CMD_FLOGI) && |
| 10436 | !(phba->fc_topology == |
| 10437 | LPFC_TOPOLOGY_LOOP)) |
| 10438 | bf_set(els_req64_sid, &wqe->els_req, 0); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 10439 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
| 10440 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
James Smart | a7dd9c0 | 2012-05-09 21:16:50 -0400 | [diff] [blame] | 10441 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 10442 | } else if (pcmd && iocbq->context1) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 10443 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
| 10444 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 10445 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
| 10446 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 10447 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 10448 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
| 10449 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10450 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
| 10451 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); |
| 10452 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); |
| 10453 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); |
| 10454 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 10455 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 10456 | wqe->els_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10457 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10458 | case CMD_XMIT_SEQUENCE64_CX: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10459 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
| 10460 | iocbq->iocb.un.ulpWord[3]); |
| 10461 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10462 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10463 | /* The entire sequence is transmitted for this IOCB */ |
| 10464 | xmit_len = total_len; |
| 10465 | cmnd = CMD_XMIT_SEQUENCE64_CR; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 10466 | if (phba->link_flag & LS_LOOPBACK_MODE) |
| 10467 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 10468 | fallthrough; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10469 | case CMD_XMIT_SEQUENCE64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10470 | /* word3 iocb=io_tag32 wqe=reserved */ |
| 10471 | wqe->xmit_sequence.rsvd3 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10472 | /* word4 relative_offset memcpy */ |
| 10473 | /* word5 r_ctl/df_ctl memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10474 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
| 10475 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); |
| 10476 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, |
| 10477 | LPFC_WQE_IOD_WRITE); |
| 10478 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, |
| 10479 | LPFC_WQE_LENLOC_WORD12); |
| 10480 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10481 | wqe->xmit_sequence.xmit_len = xmit_len; |
| 10482 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10483 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10484 | case CMD_XMIT_BCAST64_CN: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10485 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
| 10486 | wqe->xmit_bcast64.seq_payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10487 | /* word4 iocb=rsvd wqe=rsvd */ |
| 10488 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ |
| 10489 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10490 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10491 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10492 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
| 10493 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); |
| 10494 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, |
| 10495 | LPFC_WQE_LENLOC_WORD3); |
| 10496 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10497 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10498 | case CMD_FCP_IWRITE64_CR: |
| 10499 | command_type = FCP_COMMAND_DATA_OUT; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10500 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 10501 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 10502 | bf_set(payload_offset_len, &wqe->fcp_iwrite, |
| 10503 | xmit_len + sizeof(struct fcp_rsp)); |
| 10504 | bf_set(cmd_buff_len, &wqe->fcp_iwrite, |
| 10505 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10506 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 10507 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 10508 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, |
| 10509 | iocbq->iocb.ulpFCP2Rcvy); |
| 10510 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); |
| 10511 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10512 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
| 10513 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, |
| 10514 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10515 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 10516 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10517 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 10518 | bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 10519 | bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1); |
| 10520 | if (iocbq->priority) { |
| 10521 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 10522 | (iocbq->priority << 1)); |
| 10523 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10524 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 10525 | (phba->cfg_XLanePriority << 1)); |
| 10526 | } |
| 10527 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10528 | /* Note, word 10 is already initialized to 0 */ |
| 10529 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 10530 | /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */ |
| 10531 | if (phba->cfg_enable_pbde) |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 10532 | bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 1); |
| 10533 | else |
| 10534 | bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 0); |
| 10535 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10536 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10537 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10538 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10539 | struct fcp_cmnd *fcp_cmnd; |
| 10540 | uint32_t *ptr; |
| 10541 | |
| 10542 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10543 | |
| 10544 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 10545 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10546 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 10547 | |
| 10548 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 10549 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10550 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 10551 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 10552 | wqe->generic.bde.addrHigh = 0; |
| 10553 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10554 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 10555 | bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1); |
| 10556 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10557 | |
| 10558 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 10559 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10560 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 10561 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10562 | break; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10563 | case CMD_FCP_IREAD64_CR: |
| 10564 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 10565 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 10566 | bf_set(payload_offset_len, &wqe->fcp_iread, |
| 10567 | xmit_len + sizeof(struct fcp_rsp)); |
| 10568 | bf_set(cmd_buff_len, &wqe->fcp_iread, |
| 10569 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10570 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 10571 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 10572 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, |
| 10573 | iocbq->iocb.ulpFCP2Rcvy); |
| 10574 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10575 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10576 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
| 10577 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, |
| 10578 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10579 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 10580 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10581 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 10582 | bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 10583 | bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1); |
| 10584 | if (iocbq->priority) { |
| 10585 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 10586 | (iocbq->priority << 1)); |
| 10587 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10588 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 10589 | (phba->cfg_XLanePriority << 1)); |
| 10590 | } |
| 10591 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10592 | /* Note, word 10 is already initialized to 0 */ |
| 10593 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 10594 | /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */ |
| 10595 | if (phba->cfg_enable_pbde) |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 10596 | bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 1); |
| 10597 | else |
| 10598 | bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 0); |
| 10599 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10600 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10601 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10602 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10603 | struct fcp_cmnd *fcp_cmnd; |
| 10604 | uint32_t *ptr; |
| 10605 | |
| 10606 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10607 | |
| 10608 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 10609 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10610 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 10611 | |
| 10612 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 10613 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10614 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 10615 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 10616 | wqe->generic.bde.addrHigh = 0; |
| 10617 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10618 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 10619 | bf_set(wqe_wqes, &wqe->fcp_iread.wqe_com, 1); |
| 10620 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10621 | |
| 10622 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 10623 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10624 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 10625 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10626 | break; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 10627 | case CMD_FCP_ICMND64_CR: |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 10628 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 10629 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 10630 | bf_set(payload_offset_len, &wqe->fcp_icmd, |
| 10631 | xmit_len + sizeof(struct fcp_rsp)); |
| 10632 | bf_set(cmd_buff_len, &wqe->fcp_icmd, |
| 10633 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10634 | /* word3 iocb=IO_TAG wqe=reserved */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10635 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 10636 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10637 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
| 10638 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); |
| 10639 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); |
| 10640 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, |
| 10641 | LPFC_WQE_LENLOC_NONE); |
James Smart | 2a94aea | 2012-09-29 11:30:31 -0400 | [diff] [blame] | 10642 | bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com, |
| 10643 | iocbq->iocb.ulpFCP2Rcvy); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10644 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 10645 | bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 10646 | bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1); |
| 10647 | if (iocbq->priority) { |
| 10648 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 10649 | (iocbq->priority << 1)); |
| 10650 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10651 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 10652 | (phba->cfg_XLanePriority << 1)); |
| 10653 | } |
| 10654 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10655 | /* Note, word 10 is already initialized to 0 */ |
| 10656 | |
| 10657 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10658 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10659 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10660 | struct fcp_cmnd *fcp_cmnd; |
| 10661 | uint32_t *ptr; |
| 10662 | |
| 10663 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10664 | |
| 10665 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 10666 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10667 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 10668 | |
| 10669 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 10670 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10671 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 10672 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 10673 | wqe->generic.bde.addrHigh = 0; |
| 10674 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10675 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 10676 | bf_set(wqe_wqes, &wqe->fcp_icmd.wqe_com, 1); |
| 10677 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10678 | |
| 10679 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 10680 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10681 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 10682 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10683 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10684 | case CMD_GEN_REQUEST64_CR: |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 10685 | /* For this command calculate the xmit length of the |
| 10686 | * request bde. |
| 10687 | */ |
| 10688 | xmit_len = 0; |
| 10689 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 10690 | sizeof(struct ulp_bde64); |
| 10691 | for (i = 0; i < numBdes; i++) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 10692 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 10693 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 10694 | break; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 10695 | xmit_len += bde.tus.f.bdeSize; |
| 10696 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10697 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
| 10698 | wqe->gen_req.request_payload_len = xmit_len; |
| 10699 | /* word4 iocb=parameter wqe=relative_offset memcpy */ |
| 10700 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10701 | /* word6 context tag copied in memcpy */ |
| 10702 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { |
| 10703 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10704 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10705 | "2015 Invalid CT %x command 0x%x\n", |
| 10706 | ct, iocbq->iocb.ulpCommand); |
| 10707 | return IOCB_ERROR; |
| 10708 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10709 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
| 10710 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); |
| 10711 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); |
| 10712 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); |
| 10713 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); |
| 10714 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); |
| 10715 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 10716 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 10717 | wqe->gen_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10718 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10719 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10720 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 10721 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10722 | /* words0-2 BDE memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10723 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
| 10724 | wqe->xmit_els_rsp.response_payload_len = xmit_len; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 10725 | /* word4 */ |
| 10726 | wqe->xmit_els_rsp.word4 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10727 | /* word5 iocb=rsvd wge=did */ |
| 10728 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 10729 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
| 10730 | |
| 10731 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 10732 | &phba->sli4_hba.sli_intf); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10733 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 10734 | if (iocbq->vport->fc_flag & FC_PT2PT) { |
| 10735 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 10736 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
| 10737 | iocbq->vport->fc_myDID); |
| 10738 | if (iocbq->vport->fc_myDID == Fabric_DID) { |
| 10739 | bf_set(wqe_els_did, |
| 10740 | &wqe->xmit_els_rsp.wqe_dest, 0); |
| 10741 | } |
| 10742 | } |
| 10743 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10744 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
| 10745 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 10746 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); |
| 10747 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10748 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10749 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10750 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 10751 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10752 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
| 10753 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); |
| 10754 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); |
| 10755 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, |
| 10756 | LPFC_WQE_LENLOC_WORD3); |
| 10757 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 10758 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
| 10759 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 10760 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 10761 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 10762 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 10763 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 10764 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
| 10765 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 10766 | phba->vpi_ids[phba->pport->vpi]); |
| 10767 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10768 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10769 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10770 | case CMD_CLOSE_XRI_CN: |
| 10771 | case CMD_ABORT_XRI_CN: |
| 10772 | case CMD_ABORT_XRI_CX: |
| 10773 | /* words 0-2 memcpy should be 0 rserved */ |
| 10774 | /* port will send abts */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 10775 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
| 10776 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { |
| 10777 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; |
| 10778 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; |
| 10779 | } else |
| 10780 | fip = 0; |
| 10781 | |
| 10782 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10783 | /* |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 10784 | * The link is down, or the command was ELS_FIP |
| 10785 | * so the fw does not need to send abts |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10786 | * on the wire. |
| 10787 | */ |
| 10788 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); |
| 10789 | else |
| 10790 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); |
| 10791 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10792 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
| 10793 | wqe->abort_cmd.rsrvd5 = 0; |
| 10794 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10795 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 10796 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10797 | /* |
| 10798 | * The abort handler will send us CMD_ABORT_XRI_CN or |
| 10799 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX |
| 10800 | */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10801 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 10802 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); |
| 10803 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, |
| 10804 | LPFC_WQE_LENLOC_NONE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10805 | cmnd = CMD_ABORT_XRI_CX; |
| 10806 | command_type = OTHER_COMMAND; |
| 10807 | xritag = 0; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10808 | break; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10809 | case CMD_XMIT_BLS_RSP64_CX: |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10810 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 10811 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10812 | * we re-construct this WQE here based on information in |
| 10813 | * iocbq from scratch. |
| 10814 | */ |
James Smart | d9f492a | 2019-08-14 16:57:04 -0700 | [diff] [blame] | 10815 | memset(wqe, 0, sizeof(*wqe)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10816 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10817 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 10818 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
| 10819 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10820 | LPFC_ABTS_UNSOL_INT) { |
| 10821 | /* ABTS sent by initiator to CT exchange, the |
| 10822 | * RX_ID field will be filled with the newly |
| 10823 | * allocated responder XRI. |
| 10824 | */ |
| 10825 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
| 10826 | iocbq->sli4_xritag); |
| 10827 | } else { |
| 10828 | /* ABTS sent by responder to CT exchange, the |
| 10829 | * RX_ID field will be filled with the responder |
| 10830 | * RX_ID from ABTS. |
| 10831 | */ |
| 10832 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 10833 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10834 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10835 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
| 10836 | 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] | 10837 | |
| 10838 | /* Use CT=VPI */ |
| 10839 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, |
| 10840 | ndlp->nlp_DID); |
| 10841 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, |
| 10842 | iocbq->iocb.ulpContext); |
| 10843 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10844 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10845 | phba->vpi_ids[phba->pport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10846 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
| 10847 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, |
| 10848 | LPFC_WQE_LENLOC_NONE); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10849 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
| 10850 | command_type = OTHER_COMMAND; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 10851 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
| 10852 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, |
| 10853 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); |
| 10854 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, |
| 10855 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); |
| 10856 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, |
| 10857 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); |
| 10858 | } |
| 10859 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10860 | break; |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 10861 | case CMD_SEND_FRAME: |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 10862 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, CMD_SEND_FRAME); |
| 10863 | bf_set(wqe_sof, &wqe->generic.wqe_com, 0x2E); /* SOF byte */ |
| 10864 | bf_set(wqe_eof, &wqe->generic.wqe_com, 0x41); /* EOF byte */ |
| 10865 | bf_set(wqe_lenloc, &wqe->generic.wqe_com, 1); |
| 10866 | bf_set(wqe_xbl, &wqe->generic.wqe_com, 1); |
| 10867 | bf_set(wqe_dbde, &wqe->generic.wqe_com, 1); |
| 10868 | bf_set(wqe_xc, &wqe->generic.wqe_com, 1); |
| 10869 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, 0xA); |
| 10870 | 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] | 10871 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 10872 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 10873 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10874 | case CMD_XRI_ABORTED_CX: |
| 10875 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10876 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
| 10877 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ |
| 10878 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ |
| 10879 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ |
| 10880 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10881 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10882 | "2014 Invalid command 0x%x\n", |
| 10883 | iocbq->iocb.ulpCommand); |
| 10884 | return IOCB_ERROR; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10885 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 10886 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 10887 | if (iocbq->iocb_flag & LPFC_IO_DIF_PASS) |
| 10888 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU); |
| 10889 | else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP) |
| 10890 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP); |
| 10891 | else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT) |
| 10892 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT); |
| 10893 | iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP | |
| 10894 | LPFC_IO_DIF_INSERT); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10895 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 10896 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 10897 | wqe->generic.wqe_com.abort_tag = abort_tag; |
| 10898 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); |
| 10899 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); |
| 10900 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); |
| 10901 | 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] | 10902 | return 0; |
| 10903 | } |
| 10904 | |
| 10905 | /** |
James Smart | 47ff4c5 | 2020-11-15 11:26:41 -0800 | [diff] [blame] | 10906 | * __lpfc_sli_issue_fcp_io_s3 - SLI3 device for sending fcp io iocb |
| 10907 | * @phba: Pointer to HBA context object. |
| 10908 | * @ring_number: SLI ring number to issue wqe on. |
| 10909 | * @piocb: Pointer to command iocb. |
| 10910 | * @flag: Flag indicating if this command can be put into txq. |
| 10911 | * |
| 10912 | * __lpfc_sli_issue_fcp_io_s3 is wrapper function to invoke lockless func to |
| 10913 | * send an iocb command to an HBA with SLI-4 interface spec. |
| 10914 | * |
| 10915 | * This function takes the hbalock before invoking the lockless version. |
| 10916 | * The function will return success after it successfully submit the wqe to |
| 10917 | * firmware or after adding to the txq. |
| 10918 | **/ |
| 10919 | static int |
| 10920 | __lpfc_sli_issue_fcp_io_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| 10921 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 10922 | { |
| 10923 | unsigned long iflags; |
| 10924 | int rc; |
| 10925 | |
| 10926 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 10927 | rc = __lpfc_sli_issue_iocb_s3(phba, ring_number, piocb, flag); |
James Smart | 47ff4c5 | 2020-11-15 11:26:41 -0800 | [diff] [blame] | 10928 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10929 | |
| 10930 | return rc; |
| 10931 | } |
| 10932 | |
| 10933 | /** |
| 10934 | * __lpfc_sli_issue_fcp_io_s4 - SLI4 device for sending fcp io wqe |
| 10935 | * @phba: Pointer to HBA context object. |
| 10936 | * @ring_number: SLI ring number to issue wqe on. |
| 10937 | * @piocb: Pointer to command iocb. |
| 10938 | * @flag: Flag indicating if this command can be put into txq. |
| 10939 | * |
| 10940 | * __lpfc_sli_issue_fcp_io_s4 is used by other functions in the driver to issue |
| 10941 | * an wqe command to an HBA with SLI-4 interface spec. |
| 10942 | * |
| 10943 | * This function is a lockless version. The function will return success |
| 10944 | * after it successfully submit the wqe to firmware or after adding to the |
| 10945 | * txq. |
| 10946 | **/ |
| 10947 | static int |
| 10948 | __lpfc_sli_issue_fcp_io_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 10949 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 10950 | { |
James Smart | 47ff4c5 | 2020-11-15 11:26:41 -0800 | [diff] [blame] | 10951 | int rc; |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 10952 | struct lpfc_io_buf *lpfc_cmd = |
| 10953 | (struct lpfc_io_buf *)piocb->context1; |
| 10954 | union lpfc_wqe128 *wqe = &piocb->wqe; |
| 10955 | struct sli4_sge *sgl; |
James Smart | 47ff4c5 | 2020-11-15 11:26:41 -0800 | [diff] [blame] | 10956 | |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 10957 | /* 128 byte wqe support here */ |
| 10958 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | 47ff4c5 | 2020-11-15 11:26:41 -0800 | [diff] [blame] | 10959 | |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 10960 | if (phba->fcp_embed_io) { |
| 10961 | struct fcp_cmnd *fcp_cmnd; |
| 10962 | u32 *ptr; |
James Smart | 47ff4c5 | 2020-11-15 11:26:41 -0800 | [diff] [blame] | 10963 | |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 10964 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | 47ff4c5 | 2020-11-15 11:26:41 -0800 | [diff] [blame] | 10965 | |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 10966 | /* Word 0-2 - FCP_CMND */ |
| 10967 | wqe->generic.bde.tus.f.bdeFlags = |
| 10968 | BUFF_TYPE_BDE_IMMED; |
| 10969 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 10970 | wqe->generic.bde.addrHigh = 0; |
| 10971 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
| 10972 | |
| 10973 | bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1); |
| 10974 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0); |
| 10975 | |
| 10976 | /* Word 22-29 FCP CMND Payload */ |
| 10977 | ptr = &wqe->words[22]; |
| 10978 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 10979 | } else { |
| 10980 | /* Word 0-2 - Inline BDE */ |
| 10981 | wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 10982 | wqe->generic.bde.tus.f.bdeSize = sizeof(struct fcp_cmnd); |
| 10983 | wqe->generic.bde.addrHigh = sgl->addr_hi; |
| 10984 | wqe->generic.bde.addrLow = sgl->addr_lo; |
| 10985 | |
| 10986 | /* Word 10 */ |
| 10987 | bf_set(wqe_dbde, &wqe->generic.wqe_com, 1); |
| 10988 | bf_set(wqe_wqes, &wqe->generic.wqe_com, 0); |
| 10989 | } |
| 10990 | |
Gaurav Srivastava | f56e86a | 2021-06-08 10:05:53 +0530 | [diff] [blame] | 10991 | /* add the VMID tags as per switch response */ |
| 10992 | if (unlikely(piocb->iocb_flag & LPFC_IO_VMID)) { |
| 10993 | if (phba->pport->vmid_priority_tagging) { |
| 10994 | bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1); |
| 10995 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 10996 | (piocb->vmid_tag.cs_ctl_vmid)); |
| 10997 | } else { |
| 10998 | bf_set(wqe_appid, &wqe->fcp_iwrite.wqe_com, 1); |
| 10999 | bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1); |
| 11000 | wqe->words[31] = piocb->vmid_tag.app_id; |
| 11001 | } |
| 11002 | } |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 11003 | rc = lpfc_sli4_issue_wqe(phba, lpfc_cmd->hdwq, piocb); |
James Smart | 47ff4c5 | 2020-11-15 11:26:41 -0800 | [diff] [blame] | 11004 | return rc; |
| 11005 | } |
| 11006 | |
| 11007 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11008 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb |
| 11009 | * @phba: Pointer to HBA context object. |
| 11010 | * @ring_number: SLI ring number to issue iocb on. |
| 11011 | * @piocb: Pointer to command iocb. |
| 11012 | * @flag: Flag indicating if this command can be put into txq. |
| 11013 | * |
| 11014 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue |
| 11015 | * an iocb command to an HBA with SLI-4 interface spec. |
| 11016 | * |
James Smart | 27f3efd | 2019-10-18 14:18:19 -0700 | [diff] [blame] | 11017 | * This function is called with ringlock held. The function will return success |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11018 | * after it successfully submit the iocb to firmware or after adding to the |
| 11019 | * txq. |
| 11020 | **/ |
| 11021 | static int |
| 11022 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 11023 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 11024 | { |
| 11025 | struct lpfc_sglq *sglq; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 11026 | union lpfc_wqe128 wqe; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 11027 | struct lpfc_queue *wq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11028 | struct lpfc_sli_ring *pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11029 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11030 | /* Get the WQ */ |
| 11031 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
| 11032 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11033 | wq = phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11034 | } else { |
| 11035 | wq = phba->sli4_hba.els_wq; |
| 11036 | } |
| 11037 | |
| 11038 | /* Get corresponding ring */ |
| 11039 | pring = wq->pring; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 11040 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 11041 | /* |
| 11042 | * The WQE can be either 64 or 128 bytes, |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 11043 | */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 11044 | |
James Smart | cda7fa18 | 2019-03-04 15:15:43 -0800 | [diff] [blame] | 11045 | lockdep_assert_held(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11046 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11047 | if (piocb->sli4_xritag == NO_XRI) { |
| 11048 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 11049 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11050 | sglq = NULL; |
| 11051 | else { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11052 | if (!list_empty(&pring->txq)) { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11053 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 11054 | __lpfc_sli_ringtx_put(phba, |
| 11055 | pring, piocb); |
| 11056 | return IOCB_SUCCESS; |
| 11057 | } else { |
| 11058 | return IOCB_BUSY; |
| 11059 | } |
| 11060 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11061 | sglq = __lpfc_sli_get_els_sglq(phba, piocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11062 | if (!sglq) { |
| 11063 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 11064 | __lpfc_sli_ringtx_put(phba, |
| 11065 | pring, |
| 11066 | piocb); |
| 11067 | return IOCB_SUCCESS; |
| 11068 | } else |
| 11069 | return IOCB_BUSY; |
| 11070 | } |
| 11071 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11072 | } |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 11073 | } else if (piocb->iocb_flag & LPFC_IO_FCP) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 11074 | /* These IO's already have an XRI and a mapped sgl. */ |
| 11075 | sglq = NULL; |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 11076 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 11077 | else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 11078 | /* |
| 11079 | * This is a continuation of a commandi,(CX) so this |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11080 | * sglq is on the active list |
| 11081 | */ |
James Smart | edccdc1 | 2013-01-03 15:43:45 -0500 | [diff] [blame] | 11082 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11083 | if (!sglq) |
| 11084 | return IOCB_ERROR; |
| 11085 | } |
| 11086 | |
| 11087 | if (sglq) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 11088 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11089 | piocb->sli4_xritag = sglq->sli4_xritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11090 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11091 | return IOCB_ERROR; |
| 11092 | } |
| 11093 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 11094 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11095 | return IOCB_ERROR; |
| 11096 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 11097 | if (lpfc_sli4_wq_put(wq, &wqe)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11098 | return IOCB_ERROR; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11099 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); |
| 11100 | |
| 11101 | return 0; |
| 11102 | } |
| 11103 | |
Lee Jones | 8514e2f | 2021-03-03 14:46:18 +0000 | [diff] [blame] | 11104 | /* |
James Smart | 47ff4c5 | 2020-11-15 11:26:41 -0800 | [diff] [blame] | 11105 | * lpfc_sli_issue_fcp_io - Wrapper func for issuing fcp i/o |
| 11106 | * |
| 11107 | * This routine wraps the actual fcp i/o function for issusing WQE for sli-4 |
| 11108 | * or IOCB for sli-3 function. |
| 11109 | * pointer from the lpfc_hba struct. |
| 11110 | * |
| 11111 | * Return codes: |
| 11112 | * IOCB_ERROR - Error |
| 11113 | * IOCB_SUCCESS - Success |
| 11114 | * IOCB_BUSY - Busy |
| 11115 | **/ |
| 11116 | int |
| 11117 | lpfc_sli_issue_fcp_io(struct lpfc_hba *phba, uint32_t ring_number, |
| 11118 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 11119 | { |
| 11120 | return phba->__lpfc_sli_issue_fcp_io(phba, ring_number, piocb, flag); |
| 11121 | } |
| 11122 | |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 11123 | /* |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11124 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 11125 | * |
| 11126 | * This routine wraps the actual lockless version for issusing IOCB function |
| 11127 | * pointer from the lpfc_hba struct. |
| 11128 | * |
| 11129 | * Return codes: |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 11130 | * IOCB_ERROR - Error |
| 11131 | * IOCB_SUCCESS - Success |
| 11132 | * IOCB_BUSY - Busy |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11133 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11134 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11135 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 11136 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 11137 | { |
| 11138 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 11139 | } |
| 11140 | |
| 11141 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11142 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11143 | * @phba: The hba struct for which this call is being executed. |
| 11144 | * @dev_grp: The HBA PCI-Device group number. |
| 11145 | * |
| 11146 | * This routine sets up the SLI interface API function jump table in @phba |
| 11147 | * struct. |
| 11148 | * Returns: 0 - success, -ENODEV - failure. |
| 11149 | **/ |
| 11150 | int |
| 11151 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 11152 | { |
| 11153 | |
| 11154 | switch (dev_grp) { |
| 11155 | case LPFC_PCI_DEV_LP: |
| 11156 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 11157 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
James Smart | 47ff4c5 | 2020-11-15 11:26:41 -0800 | [diff] [blame] | 11158 | phba->__lpfc_sli_issue_fcp_io = __lpfc_sli_issue_fcp_io_s3; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11159 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11160 | case LPFC_PCI_DEV_OC: |
| 11161 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; |
| 11162 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; |
James Smart | 47ff4c5 | 2020-11-15 11:26:41 -0800 | [diff] [blame] | 11163 | phba->__lpfc_sli_issue_fcp_io = __lpfc_sli_issue_fcp_io_s4; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11164 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11165 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11166 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11167 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 11168 | dev_grp); |
| 11169 | return -ENODEV; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11170 | } |
| 11171 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 11172 | return 0; |
| 11173 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11174 | |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 11175 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11176 | * lpfc_sli4_calc_ring - Calculates which ring to use |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 11177 | * @phba: Pointer to HBA context object. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 11178 | * @piocb: Pointer to command iocb. |
| 11179 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11180 | * For SLI4 only, FCP IO can deferred to one fo many WQs, based on |
| 11181 | * hba_wqidx, thus we need to calculate the corresponding ring. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 11182 | * 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] | 11183 | * aborting, we use command's hba_wqidx. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 11184 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11185 | struct lpfc_sli_ring * |
| 11186 | lpfc_sli4_calc_ring(struct lpfc_hba *phba, struct lpfc_iocbq *piocb) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11187 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11188 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11189 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11190 | if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11191 | if (unlikely(!phba->sli4_hba.hdwq)) |
James Smart | 7370d10 | 2019-01-28 11:14:20 -0800 | [diff] [blame] | 11192 | return NULL; |
| 11193 | /* |
| 11194 | * for abort iocb hba_wqidx should already |
| 11195 | * be setup based on what work queue we used. |
| 11196 | */ |
| 11197 | if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11198 | lpfc_cmd = (struct lpfc_io_buf *)piocb->context1; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 11199 | piocb->hba_wqidx = lpfc_cmd->hdwq_no; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11200 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11201 | return phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11202 | } else { |
| 11203 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 11204 | return NULL; |
| 11205 | piocb->hba_wqidx = 0; |
| 11206 | return phba->sli4_hba.els_wq->pring; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11207 | } |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11208 | } |
| 11209 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11210 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11211 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11212 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 11213 | * @ring_number: Ring number |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11214 | * @piocb: Pointer to command iocb. |
| 11215 | * @flag: Flag indicating if this command can be put into txq. |
| 11216 | * |
| 11217 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 11218 | * function. This function gets the hbalock and calls |
| 11219 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 11220 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 11221 | * functions which do not hold hbalock. |
| 11222 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11223 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11224 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11225 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 11226 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11227 | struct lpfc_sli_ring *pring; |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11228 | struct lpfc_queue *eq; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11229 | unsigned long iflags; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11230 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11231 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11232 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11233 | eq = phba->sli4_hba.hdwq[piocb->hba_wqidx].hba_eq; |
| 11234 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11235 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 11236 | if (unlikely(pring == NULL)) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11237 | return IOCB_ERROR; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 11238 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11239 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 11240 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 11241 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11242 | |
| 11243 | lpfc_sli4_poll_eq(eq, LPFC_POLL_FASTPATH); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11244 | } else { |
| 11245 | /* For now, SLI2/3 will still use hbalock */ |
| 11246 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11247 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 11248 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11249 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11250 | return rc; |
| 11251 | } |
| 11252 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11253 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11254 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11255 | * @phba: Pointer to HBA context object. |
| 11256 | * |
| 11257 | * This function is called while driver attaches with the |
| 11258 | * HBA to setup the extra ring. The extra ring is used |
| 11259 | * only when driver needs to support target mode functionality |
| 11260 | * or IP over FC functionalities. |
| 11261 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11262 | * This function is called with no lock held. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11263 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 11264 | static int |
| 11265 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 11266 | { |
| 11267 | struct lpfc_sli *psli; |
| 11268 | struct lpfc_sli_ring *pring; |
| 11269 | |
| 11270 | psli = &phba->sli; |
| 11271 | |
| 11272 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 11273 | |
| 11274 | /* Take some away from the FCP ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11275 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11276 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 11277 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 11278 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 11279 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 11280 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 11281 | /* and give them to the extra ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11282 | pring = &psli->sli3_ring[LPFC_EXTRA_RING]; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 11283 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11284 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 11285 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 11286 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 11287 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 11288 | |
| 11289 | /* Setup default profile for this ring */ |
| 11290 | pring->iotag_max = 4096; |
| 11291 | pring->num_mask = 1; |
| 11292 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 11293 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 11294 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 11295 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 11296 | return 0; |
| 11297 | } |
| 11298 | |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 11299 | static void |
| 11300 | lpfc_sli_post_recovery_event(struct lpfc_hba *phba, |
| 11301 | struct lpfc_nodelist *ndlp) |
| 11302 | { |
| 11303 | unsigned long iflags; |
| 11304 | struct lpfc_work_evt *evtp = &ndlp->recovery_evt; |
| 11305 | |
| 11306 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11307 | if (!list_empty(&evtp->evt_listp)) { |
| 11308 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11309 | return; |
| 11310 | } |
| 11311 | |
| 11312 | /* Incrementing the reference count until the queued work is done. */ |
| 11313 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
| 11314 | if (!evtp->evt_arg1) { |
| 11315 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11316 | return; |
| 11317 | } |
| 11318 | evtp->evt = LPFC_EVT_RECOVER_PORT; |
| 11319 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
| 11320 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11321 | |
| 11322 | lpfc_worker_wake_up(phba); |
| 11323 | } |
| 11324 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11325 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
| 11326 | * @phba: Pointer to HBA context object. |
| 11327 | * @iocbq: Pointer to iocb object. |
| 11328 | * |
| 11329 | * The async_event handler calls this routine when it receives |
| 11330 | * an ASYNC_STATUS_CN event from the port. The port generates |
| 11331 | * this event when an Abort Sequence request to an rport fails |
| 11332 | * twice in succession. The abort could be originated by the |
| 11333 | * driver or by the port. The ABTS could have been for an ELS |
| 11334 | * or FCP IO. The port only generates this event when an ABTS |
| 11335 | * fails to complete after one retry. |
| 11336 | */ |
| 11337 | static void |
| 11338 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, |
| 11339 | struct lpfc_iocbq *iocbq) |
| 11340 | { |
| 11341 | struct lpfc_nodelist *ndlp = NULL; |
| 11342 | uint16_t rpi = 0, vpi = 0; |
| 11343 | struct lpfc_vport *vport = NULL; |
| 11344 | |
| 11345 | /* The rpi in the ulpContext is vport-sensitive. */ |
| 11346 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; |
| 11347 | rpi = iocbq->iocb.ulpContext; |
| 11348 | |
| 11349 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11350 | "3092 Port generated ABTS async event " |
| 11351 | "on vpi %d rpi %d status 0x%x\n", |
| 11352 | vpi, rpi, iocbq->iocb.ulpStatus); |
| 11353 | |
| 11354 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 11355 | if (!vport) |
| 11356 | goto err_exit; |
| 11357 | ndlp = lpfc_findnode_rpi(vport, rpi); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 11358 | if (!ndlp) |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11359 | goto err_exit; |
| 11360 | |
| 11361 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) |
| 11362 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 11363 | return; |
| 11364 | |
| 11365 | err_exit: |
| 11366 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 11367 | "3095 Event Context not found, no " |
| 11368 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", |
| 11369 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, |
| 11370 | vpi, rpi); |
| 11371 | } |
| 11372 | |
| 11373 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. |
| 11374 | * @phba: pointer to HBA context object. |
| 11375 | * @ndlp: nodelist pointer for the impacted rport. |
| 11376 | * @axri: pointer to the wcqe containing the failed exchange. |
| 11377 | * |
| 11378 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the |
| 11379 | * port. The port generates this event when an abort exchange request to an |
| 11380 | * rport fails twice in succession with no reply. The abort could be originated |
| 11381 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. |
| 11382 | */ |
| 11383 | void |
| 11384 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, |
| 11385 | struct lpfc_nodelist *ndlp, |
| 11386 | struct sli4_wcqe_xri_aborted *axri) |
| 11387 | { |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 11388 | uint32_t ext_status = 0; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11389 | |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 11390 | if (!ndlp) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11391 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 11392 | "3115 Node Context not found, driver " |
| 11393 | "ignoring abts err event\n"); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 11394 | return; |
| 11395 | } |
| 11396 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11397 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11398 | "3116 Port generated FCP XRI ABORT event on " |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 11399 | "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] | 11400 | ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi], |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11401 | bf_get(lpfc_wcqe_xa_xri, axri), |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 11402 | bf_get(lpfc_wcqe_xa_status, axri), |
| 11403 | axri->parameter); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11404 | |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 11405 | /* |
| 11406 | * Catch the ABTS protocol failure case. Older OCe FW releases returned |
| 11407 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and |
| 11408 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. |
| 11409 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 11410 | ext_status = axri->parameter & IOERR_PARAM_MASK; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 11411 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
| 11412 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 11413 | lpfc_sli_post_recovery_event(phba, ndlp); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11414 | } |
| 11415 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11416 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11417 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11418 | * @phba: Pointer to HBA context object. |
| 11419 | * @pring: Pointer to driver SLI ring object. |
| 11420 | * @iocbq: Pointer to iocb object. |
| 11421 | * |
| 11422 | * This function is called by the slow ring event handler |
| 11423 | * function when there is an ASYNC event iocb in the ring. |
| 11424 | * This function is called with no lock held. |
| 11425 | * Currently this function handles only temperature related |
| 11426 | * ASYNC events. The function decodes the temperature sensor |
| 11427 | * event message and posts events for the management applications. |
| 11428 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 11429 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 11430 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 11431 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 11432 | { |
| 11433 | IOCB_t *icmd; |
| 11434 | uint16_t evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 11435 | struct temp_event temp_event_data; |
| 11436 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11437 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 11438 | |
| 11439 | icmd = &iocbq->iocb; |
| 11440 | evt_code = icmd->un.asyncstat.evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 11441 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11442 | switch (evt_code) { |
| 11443 | case ASYNC_TEMP_WARN: |
| 11444 | case ASYNC_TEMP_SAFE: |
| 11445 | temp_event_data.data = (uint32_t) icmd->ulpContext; |
| 11446 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 11447 | if (evt_code == ASYNC_TEMP_WARN) { |
| 11448 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11449 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11450 | "0347 Adapter is very hot, please take " |
| 11451 | "corrective action. temperature : %d Celsius\n", |
| 11452 | (uint32_t) icmd->ulpContext); |
| 11453 | } else { |
| 11454 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11455 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11456 | "0340 Adapter temperature is OK now. " |
| 11457 | "temperature : %d Celsius\n", |
| 11458 | (uint32_t) icmd->ulpContext); |
| 11459 | } |
| 11460 | |
| 11461 | /* Send temperature change event to applications */ |
| 11462 | shost = lpfc_shost_from_vport(phba->pport); |
| 11463 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 11464 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 11465 | LPFC_NL_VENDOR_ID); |
| 11466 | break; |
| 11467 | case ASYNC_STATUS_CN: |
| 11468 | lpfc_sli_abts_err_handler(phba, iocbq); |
| 11469 | break; |
| 11470 | default: |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11471 | iocb_w = (uint32_t *) icmd; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11472 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 11473 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 11474 | " evt_code 0x%x\n" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11475 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 11476 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 11477 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 11478 | "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] | 11479 | pring->ringno, icmd->un.asyncstat.evt_code, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11480 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 11481 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 11482 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 11483 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 11484 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11485 | break; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 11486 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 11487 | } |
| 11488 | |
| 11489 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11490 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11491 | * lpfc_sli4_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11492 | * @phba: Pointer to HBA context object. |
| 11493 | * |
| 11494 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 11495 | * number of iocbs per ring and iotags. This function is |
| 11496 | * called while driver attach to the HBA and before the |
| 11497 | * interrupts are enabled. So there is no need for locking. |
| 11498 | * |
| 11499 | * This function always returns 0. |
| 11500 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11501 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11502 | lpfc_sli4_setup(struct lpfc_hba *phba) |
| 11503 | { |
| 11504 | struct lpfc_sli_ring *pring; |
| 11505 | |
| 11506 | pring = phba->sli4_hba.els_wq->pring; |
| 11507 | pring->num_mask = LPFC_MAX_RING_MASK; |
| 11508 | pring->prt[0].profile = 0; /* Mask 0 */ |
| 11509 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 11510 | pring->prt[0].type = FC_TYPE_ELS; |
| 11511 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
| 11512 | lpfc_els_unsol_event; |
| 11513 | pring->prt[1].profile = 0; /* Mask 1 */ |
| 11514 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 11515 | pring->prt[1].type = FC_TYPE_ELS; |
| 11516 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
| 11517 | lpfc_els_unsol_event; |
| 11518 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 11519 | /* NameServer Inquiry */ |
| 11520 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| 11521 | /* NameServer */ |
| 11522 | pring->prt[2].type = FC_TYPE_CT; |
| 11523 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
| 11524 | lpfc_ct_unsol_event; |
| 11525 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 11526 | /* NameServer response */ |
| 11527 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| 11528 | /* NameServer */ |
| 11529 | pring->prt[3].type = FC_TYPE_CT; |
| 11530 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
| 11531 | lpfc_ct_unsol_event; |
| 11532 | return 0; |
| 11533 | } |
| 11534 | |
| 11535 | /** |
| 11536 | * lpfc_sli_setup - SLI ring setup function |
| 11537 | * @phba: Pointer to HBA context object. |
| 11538 | * |
| 11539 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 11540 | * number of iocbs per ring and iotags. This function is |
| 11541 | * called while driver attach to the HBA and before the |
| 11542 | * interrupts are enabled. So there is no need for locking. |
| 11543 | * |
| 11544 | * This function always returns 0. SLI3 only. |
| 11545 | **/ |
| 11546 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11547 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 11548 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 11549 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11550 | struct lpfc_sli *psli = &phba->sli; |
| 11551 | struct lpfc_sli_ring *pring; |
| 11552 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11553 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11554 | psli->sli_flag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11555 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11556 | psli->iocbq_lookup = NULL; |
| 11557 | psli->iocbq_lookup_len = 0; |
| 11558 | psli->last_iotag = 0; |
| 11559 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11560 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11561 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11562 | switch (i) { |
| 11563 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 11564 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11565 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 11566 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 11567 | pring->sli.sli3.numCiocb += |
| 11568 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 11569 | pring->sli.sli3.numRiocb += |
| 11570 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 11571 | pring->sli.sli3.numCiocb += |
| 11572 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 11573 | pring->sli.sli3.numRiocb += |
| 11574 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 11575 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11576 | SLI3_IOCB_CMD_SIZE : |
| 11577 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11578 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11579 | SLI3_IOCB_RSP_SIZE : |
| 11580 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11581 | pring->iotag_ctr = 0; |
| 11582 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11583 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11584 | pring->fast_iotag = pring->iotag_max; |
| 11585 | pring->num_mask = 0; |
| 11586 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 11587 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11588 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11589 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 11590 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
| 11591 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11592 | SLI3_IOCB_CMD_SIZE : |
| 11593 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11594 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11595 | SLI3_IOCB_RSP_SIZE : |
| 11596 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11597 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11598 | pring->num_mask = 0; |
| 11599 | break; |
| 11600 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 11601 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11602 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 11603 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
| 11604 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11605 | SLI3_IOCB_CMD_SIZE : |
| 11606 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11607 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11608 | SLI3_IOCB_RSP_SIZE : |
| 11609 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11610 | pring->fast_iotag = 0; |
| 11611 | pring->iotag_ctr = 0; |
| 11612 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 11613 | pring->lpfc_sli_rcv_async_status = |
| 11614 | lpfc_sli_async_event_handler; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 11615 | pring->num_mask = LPFC_MAX_RING_MASK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11616 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11617 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 11618 | pring->prt[0].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11619 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11620 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11621 | pring->prt[1].profile = 0; /* Mask 1 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11622 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 11623 | pring->prt[1].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11624 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11625 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11626 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 11627 | /* NameServer Inquiry */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11628 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11629 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11630 | pring->prt[2].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11631 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11632 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11633 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 11634 | /* NameServer response */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11635 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11636 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11637 | pring->prt[3].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11638 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11639 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11640 | break; |
| 11641 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11642 | totiocbsize += (pring->sli.sli3.numCiocb * |
| 11643 | pring->sli.sli3.sizeCiocb) + |
| 11644 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11645 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 11646 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11647 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11648 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 11649 | "SLI2 SLIM Data: x%x x%lx\n", |
| 11650 | phba->brd_no, totiocbsize, |
| 11651 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11652 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 11653 | if (phba->cfg_multi_ring_support == 2) |
| 11654 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11655 | |
| 11656 | return 0; |
| 11657 | } |
| 11658 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11659 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11660 | * lpfc_sli4_queue_init - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11661 | * @phba: Pointer to HBA context object. |
| 11662 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11663 | * 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] | 11664 | * ring. This function also initializes ring indices of each ring. |
| 11665 | * This function is called during the initialization of the SLI |
| 11666 | * interface of an HBA. |
| 11667 | * This function is called with no lock held and always returns |
| 11668 | * 1. |
| 11669 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11670 | void |
| 11671 | lpfc_sli4_queue_init(struct lpfc_hba *phba) |
| 11672 | { |
| 11673 | struct lpfc_sli *psli; |
| 11674 | struct lpfc_sli_ring *pring; |
| 11675 | int i; |
| 11676 | |
| 11677 | psli = &phba->sli; |
| 11678 | spin_lock_irq(&phba->hbalock); |
| 11679 | INIT_LIST_HEAD(&psli->mboxq); |
| 11680 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| 11681 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11682 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11683 | pring = phba->sli4_hba.hdwq[i].io_wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11684 | pring->flag = 0; |
| 11685 | pring->ringno = LPFC_FCP_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11686 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11687 | INIT_LIST_HEAD(&pring->txq); |
| 11688 | INIT_LIST_HEAD(&pring->txcmplq); |
| 11689 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 11690 | spin_lock_init(&pring->ring_lock); |
| 11691 | } |
| 11692 | pring = phba->sli4_hba.els_wq->pring; |
| 11693 | pring->flag = 0; |
| 11694 | pring->ringno = LPFC_ELS_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11695 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11696 | INIT_LIST_HEAD(&pring->txq); |
| 11697 | INIT_LIST_HEAD(&pring->txcmplq); |
| 11698 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 11699 | spin_lock_init(&pring->ring_lock); |
| 11700 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11701 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11702 | pring = phba->sli4_hba.nvmels_wq->pring; |
| 11703 | pring->flag = 0; |
| 11704 | pring->ringno = LPFC_ELS_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11705 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11706 | INIT_LIST_HEAD(&pring->txq); |
| 11707 | INIT_LIST_HEAD(&pring->txcmplq); |
| 11708 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 11709 | spin_lock_init(&pring->ring_lock); |
| 11710 | } |
| 11711 | |
| 11712 | spin_unlock_irq(&phba->hbalock); |
| 11713 | } |
| 11714 | |
| 11715 | /** |
| 11716 | * lpfc_sli_queue_init - Queue initialization function |
| 11717 | * @phba: Pointer to HBA context object. |
| 11718 | * |
| 11719 | * lpfc_sli_queue_init sets up mailbox queues and iocb queues for each |
| 11720 | * ring. This function also initializes ring indices of each ring. |
| 11721 | * This function is called during the initialization of the SLI |
| 11722 | * interface of an HBA. |
| 11723 | * This function is called with no lock held and always returns |
| 11724 | * 1. |
| 11725 | **/ |
| 11726 | void |
| 11727 | lpfc_sli_queue_init(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11728 | { |
| 11729 | struct lpfc_sli *psli; |
| 11730 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11731 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11732 | |
| 11733 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11734 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11735 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11736 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11737 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 11738 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11739 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11740 | pring->ringno = i; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11741 | pring->sli.sli3.next_cmdidx = 0; |
| 11742 | pring->sli.sli3.local_getidx = 0; |
| 11743 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11744 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 11745 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11746 | INIT_LIST_HEAD(&pring->postbufq); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11747 | pring->flag = 0; |
| 11748 | INIT_LIST_HEAD(&pring->txq); |
| 11749 | INIT_LIST_HEAD(&pring->txcmplq); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11750 | spin_lock_init(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11751 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11752 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11753 | } |
| 11754 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11755 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11756 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system |
| 11757 | * @phba: Pointer to HBA context object. |
| 11758 | * |
| 11759 | * This routine flushes the mailbox command subsystem. It will unconditionally |
| 11760 | * flush all the mailbox commands in the three possible stages in the mailbox |
| 11761 | * command sub-system: pending mailbox command queue; the outstanding mailbox |
| 11762 | * command; and completed mailbox command queue. It is caller's responsibility |
| 11763 | * to make sure that the driver is in the proper state to flush the mailbox |
| 11764 | * command sub-system. Namely, the posting of mailbox commands into the |
| 11765 | * pending mailbox command queue from the various clients must be stopped; |
| 11766 | * either the HBA is in a state that it will never works on the outstanding |
| 11767 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding |
| 11768 | * mailbox command has been completed. |
| 11769 | **/ |
| 11770 | static void |
| 11771 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) |
| 11772 | { |
| 11773 | LIST_HEAD(completions); |
| 11774 | struct lpfc_sli *psli = &phba->sli; |
| 11775 | LPFC_MBOXQ_t *pmb; |
| 11776 | unsigned long iflag; |
| 11777 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 11778 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 11779 | local_bh_disable(); |
| 11780 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11781 | /* Flush all the mailbox commands in the mbox system */ |
| 11782 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 11783 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11784 | /* The pending mailbox command queue */ |
| 11785 | list_splice_init(&phba->sli.mboxq, &completions); |
| 11786 | /* The outstanding active mailbox command */ |
| 11787 | if (psli->mbox_active) { |
| 11788 | list_add_tail(&psli->mbox_active->list, &completions); |
| 11789 | psli->mbox_active = NULL; |
| 11790 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 11791 | } |
| 11792 | /* The completed mailbox command queue */ |
| 11793 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
| 11794 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 11795 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 11796 | /* Enable softirqs again, done with phba->hbalock */ |
| 11797 | local_bh_enable(); |
| 11798 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11799 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ |
| 11800 | while (!list_empty(&completions)) { |
| 11801 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| 11802 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 11803 | if (pmb->mbox_cmpl) |
| 11804 | pmb->mbox_cmpl(phba, pmb); |
| 11805 | } |
| 11806 | } |
| 11807 | |
| 11808 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11809 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11810 | * @vport: Pointer to virtual port object. |
| 11811 | * |
| 11812 | * lpfc_sli_host_down is called to clean up the resources |
| 11813 | * associated with a vport before destroying virtual |
| 11814 | * port data structures. |
| 11815 | * This function does following operations: |
| 11816 | * - Free discovery resources associated with this virtual |
| 11817 | * port. |
| 11818 | * - Free iocbs associated with this virtual port in |
| 11819 | * the txq. |
| 11820 | * - Send abort for all iocb commands associated with this |
| 11821 | * vport in txcmplq. |
| 11822 | * |
| 11823 | * This function is called with no lock held and always returns 1. |
| 11824 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11825 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11826 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 11827 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11828 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11829 | struct lpfc_hba *phba = vport->phba; |
| 11830 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11831 | struct lpfc_queue *qp = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11832 | struct lpfc_sli_ring *pring; |
| 11833 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11834 | int i; |
| 11835 | unsigned long flags = 0; |
| 11836 | uint16_t prev_pring_flag; |
| 11837 | |
| 11838 | lpfc_cleanup_discovery_resources(vport); |
| 11839 | |
| 11840 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11841 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11842 | /* |
| 11843 | * Error everything on the txq since these iocbs |
| 11844 | * have not been given to the FW yet. |
| 11845 | * Also issue ABTS for everything on the txcmplq |
| 11846 | */ |
| 11847 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 11848 | for (i = 0; i < psli->num_rings; i++) { |
| 11849 | pring = &psli->sli3_ring[i]; |
| 11850 | prev_pring_flag = pring->flag; |
| 11851 | /* Only slow rings */ |
| 11852 | if (pring->ringno == LPFC_ELS_RING) { |
| 11853 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 11854 | /* Set the lpfc data pending flag */ |
| 11855 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 11856 | } |
| 11857 | list_for_each_entry_safe(iocb, next_iocb, |
| 11858 | &pring->txq, list) { |
| 11859 | if (iocb->vport != vport) |
| 11860 | continue; |
| 11861 | list_move_tail(&iocb->list, &completions); |
| 11862 | } |
| 11863 | list_for_each_entry_safe(iocb, next_iocb, |
| 11864 | &pring->txcmplq, list) { |
| 11865 | if (iocb->vport != vport) |
| 11866 | continue; |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 11867 | lpfc_sli_issue_abort_iotag(phba, pring, iocb, |
| 11868 | NULL); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11869 | } |
| 11870 | pring->flag = prev_pring_flag; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11871 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11872 | } else { |
| 11873 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 11874 | pring = qp->pring; |
| 11875 | if (!pring) |
| 11876 | continue; |
| 11877 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 11878 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 11879 | /* Set the lpfc data pending flag */ |
| 11880 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 11881 | } |
| 11882 | prev_pring_flag = pring->flag; |
James Smart | 65a3df6 | 2019-09-21 20:58:48 -0700 | [diff] [blame] | 11883 | spin_lock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11884 | list_for_each_entry_safe(iocb, next_iocb, |
| 11885 | &pring->txq, list) { |
| 11886 | if (iocb->vport != vport) |
| 11887 | continue; |
| 11888 | list_move_tail(&iocb->list, &completions); |
| 11889 | } |
James Smart | 65a3df6 | 2019-09-21 20:58:48 -0700 | [diff] [blame] | 11890 | spin_unlock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11891 | list_for_each_entry_safe(iocb, next_iocb, |
| 11892 | &pring->txcmplq, list) { |
| 11893 | if (iocb->vport != vport) |
| 11894 | continue; |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 11895 | lpfc_sli_issue_abort_iotag(phba, pring, iocb, |
| 11896 | NULL); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11897 | } |
| 11898 | pring->flag = prev_pring_flag; |
| 11899 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11900 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11901 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 11902 | |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 11903 | /* Make sure HBA is alive */ |
| 11904 | lpfc_issue_hb_tmo(phba); |
| 11905 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11906 | /* Cancel all the IOCBs from the completions list */ |
| 11907 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 11908 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11909 | return 1; |
| 11910 | } |
| 11911 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11912 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11913 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11914 | * @phba: Pointer to HBA context object. |
| 11915 | * |
| 11916 | * This function cleans up all iocb, buffers, mailbox commands |
| 11917 | * while shutting down the HBA. This function is called with no |
| 11918 | * lock held and always returns 1. |
| 11919 | * This function does the following to cleanup driver resources: |
| 11920 | * - Free discovery resources for each virtual port |
| 11921 | * - Cleanup any pending fabric iocbs |
| 11922 | * - Iterate through the iocb txq and free each entry |
| 11923 | * in the list. |
| 11924 | * - Free up any buffer posted to the HBA |
| 11925 | * - Free mailbox commands in the mailbox queue. |
| 11926 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11927 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11928 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11929 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 11930 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11931 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11932 | struct lpfc_queue *qp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11933 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 11934 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11935 | unsigned long flags = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11936 | int i; |
| 11937 | |
| 11938 | /* Shutdown the mailbox command sub-system */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 11939 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11940 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11941 | lpfc_hba_down_prep(phba); |
| 11942 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 11943 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 11944 | local_bh_disable(); |
| 11945 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11946 | lpfc_fabric_abort_hba(phba); |
| 11947 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11948 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11949 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11950 | /* |
| 11951 | * Error everything on the txq since these iocbs |
| 11952 | * have not been given to the FW yet. |
| 11953 | */ |
| 11954 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 11955 | for (i = 0; i < psli->num_rings; i++) { |
| 11956 | pring = &psli->sli3_ring[i]; |
| 11957 | /* Only slow rings */ |
| 11958 | if (pring->ringno == LPFC_ELS_RING) { |
| 11959 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 11960 | /* Set the lpfc data pending flag */ |
| 11961 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 11962 | } |
| 11963 | list_splice_init(&pring->txq, &completions); |
| 11964 | } |
| 11965 | } else { |
| 11966 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 11967 | pring = qp->pring; |
| 11968 | if (!pring) |
| 11969 | continue; |
James Smart | 4b0a42b | 2019-08-14 16:56:42 -0700 | [diff] [blame] | 11970 | spin_lock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11971 | list_splice_init(&pring->txq, &completions); |
James Smart | 4b0a42b | 2019-08-14 16:56:42 -0700 | [diff] [blame] | 11972 | spin_unlock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11973 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 11974 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 11975 | /* Set the lpfc data pending flag */ |
| 11976 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 11977 | } |
| 11978 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11979 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11980 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11981 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11982 | /* Cancel all the IOCBs from the completions list */ |
| 11983 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 11984 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 11985 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 11986 | spin_lock_irqsave(&phba->hbalock, flags); |
| 11987 | list_splice_init(&phba->elsbuf, &completions); |
| 11988 | phba->elsbuf_cnt = 0; |
| 11989 | phba->elsbuf_prev_cnt = 0; |
| 11990 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 11991 | |
| 11992 | while (!list_empty(&completions)) { |
| 11993 | list_remove_head(&completions, buf_ptr, |
| 11994 | struct lpfc_dmabuf, list); |
| 11995 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 11996 | kfree(buf_ptr); |
| 11997 | } |
| 11998 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 11999 | /* Enable softirqs again, done with phba->hbalock */ |
| 12000 | local_bh_enable(); |
| 12001 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12002 | /* Return any active mbox cmds */ |
| 12003 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12004 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12005 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12006 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12007 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12008 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12009 | return 1; |
| 12010 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12011 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12012 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12013 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12014 | * @srcp: Source memory pointer. |
| 12015 | * @destp: Destination memory pointer. |
| 12016 | * @cnt: Number of words required to be copied. |
| 12017 | * |
| 12018 | * This function is used for copying data between driver memory |
| 12019 | * and the SLI memory. This function also changes the endianness |
| 12020 | * of each word if native endianness is different from SLI |
| 12021 | * endianness. This function can be called with or without |
| 12022 | * lock. |
| 12023 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12024 | void |
| 12025 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 12026 | { |
| 12027 | uint32_t *src = srcp; |
| 12028 | uint32_t *dest = destp; |
| 12029 | uint32_t ldata; |
| 12030 | int i; |
| 12031 | |
| 12032 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 12033 | ldata = *src; |
| 12034 | ldata = le32_to_cpu(ldata); |
| 12035 | *dest = ldata; |
| 12036 | src++; |
| 12037 | dest++; |
| 12038 | } |
| 12039 | } |
| 12040 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12041 | |
| 12042 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 12043 | * lpfc_sli_bemem_bcopy - SLI memory copy function |
| 12044 | * @srcp: Source memory pointer. |
| 12045 | * @destp: Destination memory pointer. |
| 12046 | * @cnt: Number of words required to be copied. |
| 12047 | * |
| 12048 | * This function is used for copying data between a data structure |
| 12049 | * with big endian representation to local endianness. |
| 12050 | * This function can be called with or without lock. |
| 12051 | **/ |
| 12052 | void |
| 12053 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 12054 | { |
| 12055 | uint32_t *src = srcp; |
| 12056 | uint32_t *dest = destp; |
| 12057 | uint32_t ldata; |
| 12058 | int i; |
| 12059 | |
| 12060 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { |
| 12061 | ldata = *src; |
| 12062 | ldata = be32_to_cpu(ldata); |
| 12063 | *dest = ldata; |
| 12064 | src++; |
| 12065 | dest++; |
| 12066 | } |
| 12067 | } |
| 12068 | |
| 12069 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12070 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12071 | * @phba: Pointer to HBA context object. |
| 12072 | * @pring: Pointer to driver SLI ring object. |
| 12073 | * @mp: Pointer to driver buffer object. |
| 12074 | * |
| 12075 | * This function is called with no lock held. |
| 12076 | * It always return zero after adding the buffer to the postbufq |
| 12077 | * buffer list. |
| 12078 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12079 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12080 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 12081 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12082 | { |
| 12083 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 12084 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12085 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12086 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12087 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12088 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12089 | return 0; |
| 12090 | } |
| 12091 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12092 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12093 | * 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] | 12094 | * @phba: Pointer to HBA context object. |
| 12095 | * |
| 12096 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 12097 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 12098 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 12099 | * does not conflict with tags of buffer posted for unsolicited events. |
| 12100 | * The function returns the allocated tag. The function is called with |
| 12101 | * no locks held. |
| 12102 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 12103 | uint32_t |
| 12104 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 12105 | { |
| 12106 | spin_lock_irq(&phba->hbalock); |
| 12107 | phba->buffer_tag_count++; |
| 12108 | /* |
| 12109 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 12110 | * a tag assigned by HBQ. |
| 12111 | */ |
| 12112 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 12113 | spin_unlock_irq(&phba->hbalock); |
| 12114 | return phba->buffer_tag_count; |
| 12115 | } |
| 12116 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12117 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12118 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12119 | * @phba: Pointer to HBA context object. |
| 12120 | * @pring: Pointer to driver SLI ring object. |
| 12121 | * @tag: Buffer tag. |
| 12122 | * |
| 12123 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 12124 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 12125 | * iocb is posted to the response ring with the tag of the buffer. |
| 12126 | * This function searches the pring->postbufq list using the tag |
| 12127 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 12128 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 12129 | * buffer is returned to the caller else NULL is returned. |
| 12130 | * This function is called with no lock held. |
| 12131 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 12132 | struct lpfc_dmabuf * |
| 12133 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 12134 | uint32_t tag) |
| 12135 | { |
| 12136 | struct lpfc_dmabuf *mp, *next_mp; |
| 12137 | struct list_head *slp = &pring->postbufq; |
| 12138 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12139 | /* Search postbufq, from the beginning, looking for a match on tag */ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 12140 | spin_lock_irq(&phba->hbalock); |
| 12141 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 12142 | if (mp->buffer_tag == tag) { |
| 12143 | list_del_init(&mp->list); |
| 12144 | pring->postbufq_cnt--; |
| 12145 | spin_unlock_irq(&phba->hbalock); |
| 12146 | return mp; |
| 12147 | } |
| 12148 | } |
| 12149 | |
| 12150 | spin_unlock_irq(&phba->hbalock); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12151 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 12152 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 12153 | "ring %d Data x%lx x%px x%px x%x\n", |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 12154 | pring->ringno, (unsigned long) tag, |
| 12155 | slp->next, slp->prev, pring->postbufq_cnt); |
| 12156 | |
| 12157 | return NULL; |
| 12158 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12159 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12160 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12161 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12162 | * @phba: Pointer to HBA context object. |
| 12163 | * @pring: Pointer to driver SLI ring object. |
| 12164 | * @phys: DMA address of the buffer. |
| 12165 | * |
| 12166 | * This function searches the buffer list using the dma_address |
| 12167 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 12168 | * corresponding to the dma_address. The function returns the |
| 12169 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 12170 | * This function is called by the ct and els unsolicited event |
| 12171 | * handlers to get the buffer associated with the unsolicited |
| 12172 | * event. |
| 12173 | * |
| 12174 | * This function is called with no lock held. |
| 12175 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12176 | struct lpfc_dmabuf * |
| 12177 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 12178 | dma_addr_t phys) |
| 12179 | { |
| 12180 | struct lpfc_dmabuf *mp, *next_mp; |
| 12181 | struct list_head *slp = &pring->postbufq; |
| 12182 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12183 | /* Search postbufq, from the beginning, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12184 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12185 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 12186 | if (mp->phys == phys) { |
| 12187 | list_del_init(&mp->list); |
| 12188 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12189 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12190 | return mp; |
| 12191 | } |
| 12192 | } |
| 12193 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12194 | spin_unlock_irq(&phba->hbalock); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12195 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12196 | "0410 Cannot find virtual addr for mapped buf on " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 12197 | "ring %d Data x%llx x%px x%px x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12198 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12199 | slp->next, slp->prev, pring->postbufq_cnt); |
| 12200 | return NULL; |
| 12201 | } |
| 12202 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12203 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12204 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12205 | * @phba: Pointer to HBA context object. |
| 12206 | * @cmdiocb: Pointer to driver command iocb object. |
| 12207 | * @rspiocb: Pointer to driver response iocb object. |
| 12208 | * |
| 12209 | * This function is the completion handler for the abort iocbs for |
| 12210 | * ELS commands. This function is called from the ELS ring event |
| 12211 | * handler with no lock held. This function frees memory resources |
| 12212 | * associated with the abort iocb. |
| 12213 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12214 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12215 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 12216 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12217 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12218 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 12219 | uint16_t abort_iotag, abort_context; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 12220 | struct lpfc_iocbq *abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 12221 | |
| 12222 | if (irsp->ulpStatus) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 12223 | |
| 12224 | /* |
| 12225 | * Assume that the port already completed and returned, or |
| 12226 | * will return the iocb. Just Log the message. |
| 12227 | */ |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 12228 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 12229 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 12230 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12231 | spin_lock_irq(&phba->hbalock); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12232 | if (phba->sli_rev < LPFC_SLI_REV4) { |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 12233 | if (irsp->ulpCommand == CMD_ABORT_XRI_CX && |
| 12234 | irsp->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 12235 | irsp->un.ulpWord[4] == IOERR_ABORT_REQUESTED) { |
| 12236 | spin_unlock_irq(&phba->hbalock); |
| 12237 | goto release_iocb; |
| 12238 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12239 | if (abort_iotag != 0 && |
| 12240 | abort_iotag <= phba->sli.last_iotag) |
| 12241 | abort_iocb = |
| 12242 | phba->sli.iocbq_lookup[abort_iotag]; |
| 12243 | } else |
| 12244 | /* For sli4 the abort_tag is the XRI, |
| 12245 | * so the abort routine puts the iotag of the iocb |
| 12246 | * being aborted in the context field of the abort |
| 12247 | * IOCB. |
| 12248 | */ |
| 12249 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 12250 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 12251 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 12252 | "0327 Cannot abort els iocb x%px " |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 12253 | "with tag %x context %x, abort status %x, " |
| 12254 | "abort code %x\n", |
| 12255 | abort_iocb, abort_iotag, abort_context, |
| 12256 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 12257 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 12258 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 12259 | } |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 12260 | release_iocb: |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 12261 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12262 | return; |
| 12263 | } |
| 12264 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12265 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12266 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12267 | * @phba: Pointer to HBA context object. |
| 12268 | * @cmdiocb: Pointer to driver command iocb object. |
| 12269 | * @rspiocb: Pointer to driver response iocb object. |
| 12270 | * |
| 12271 | * The function is called from SLI ring event handler with no |
| 12272 | * lock held. This function is the completion handler for ELS commands |
| 12273 | * which are aborted. The function frees memory resources used for |
| 12274 | * the aborted ELS commands. |
| 12275 | **/ |
James Smart | 9dd83f7 | 2021-03-01 09:18:11 -0800 | [diff] [blame] | 12276 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12277 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 12278 | struct lpfc_iocbq *rspiocb) |
| 12279 | { |
James Smart | 4e670c8a | 2021-07-07 11:43:38 -0700 | [diff] [blame] | 12280 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12281 | IOCB_t *irsp = &rspiocb->iocb; |
| 12282 | |
| 12283 | /* ELS cmd tag <ulpIoTag> completes */ |
| 12284 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 12285 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12286 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12287 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12288 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 4e670c8a | 2021-07-07 11:43:38 -0700 | [diff] [blame] | 12289 | /* |
| 12290 | * Deref the ndlp after free_iocb. sli_release_iocb will access the ndlp |
| 12291 | * if exchange is busy. |
| 12292 | */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12293 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 12294 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 12295 | else |
| 12296 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 4e670c8a | 2021-07-07 11:43:38 -0700 | [diff] [blame] | 12297 | |
| 12298 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12299 | } |
| 12300 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12301 | /** |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 12302 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12303 | * @phba: Pointer to HBA context object. |
| 12304 | * @pring: Pointer to driver SLI ring object. |
| 12305 | * @cmdiocb: Pointer to driver command iocb object. |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 12306 | * @cmpl: completion function. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12307 | * |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 12308 | * This function issues an abort iocb for the provided command iocb. In case |
| 12309 | * of unloading, the abort iocb will not be issued to commands on the ELS |
| 12310 | * ring. Instead, the callback function shall be changed to those commands |
| 12311 | * so that nothing happens when them finishes. This function is called with |
| 12312 | * hbalock held andno ring_lock held (SLI4). The function returns IOCB_SUCCESS |
| 12313 | * when the command iocb is an abort request. |
| 12314 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12315 | **/ |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 12316 | int |
| 12317 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 12318 | struct lpfc_iocbq *cmdiocb, void *cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12319 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12320 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 12321 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12322 | IOCB_t *icmd = NULL; |
| 12323 | IOCB_t *iabt = NULL; |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 12324 | int retval = IOCB_ERROR; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 12325 | unsigned long iflags; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 12326 | struct lpfc_nodelist *ndlp; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 12327 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12328 | /* |
| 12329 | * There are certain command types we don't want to abort. And we |
| 12330 | * don't want to abort commands that are already in the process of |
| 12331 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 12332 | */ |
| 12333 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12334 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12335 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
James Smart | 078c68b | 2021-04-11 18:31:12 -0700 | [diff] [blame] | 12336 | cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 12337 | return IOCB_ABORTING; |
| 12338 | |
| 12339 | if (!pring) { |
| 12340 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 12341 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 12342 | else |
| 12343 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 12344 | return retval; |
| 12345 | } |
| 12346 | |
| 12347 | /* |
| 12348 | * If we're unloading, don't abort iocb on the ELS ring, but change |
| 12349 | * the callback so that nothing happens when it finishes. |
| 12350 | */ |
| 12351 | if ((vport->load_flag & FC_UNLOADING) && |
| 12352 | pring->ringno == LPFC_ELS_RING) { |
| 12353 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 12354 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 12355 | else |
| 12356 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 12357 | return retval; |
| 12358 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 12359 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12360 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12361 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12362 | if (abtsiocbp == NULL) |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 12363 | return IOCB_NORESOURCE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12364 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 12365 | /* This signals the response to set the correct status |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12366 | * before calling the completion handler |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 12367 | */ |
| 12368 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 12369 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12370 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 12371 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 12372 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12373 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12374 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 12375 | if (pring->ringno == LPFC_ELS_RING) |
| 12376 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 12377 | } else { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12378 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 12379 | if (pring->ringno == LPFC_ELS_RING) { |
| 12380 | ndlp = (struct lpfc_nodelist *)(cmdiocb->context1); |
| 12381 | iabt->un.acxri.abortContextTag = ndlp->nlp_rpi; |
| 12382 | } |
| 12383 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12384 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 12385 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12386 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 12387 | /* 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] | 12388 | abtsiocbp->hba_wqidx = cmdiocb->hba_wqidx; |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 12389 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) { |
| 12390 | abtsiocbp->iocb_flag |= LPFC_IO_FCP; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12391 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 12392 | } |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 12393 | if (cmdiocb->iocb_flag & LPFC_IO_FOF) |
| 12394 | abtsiocbp->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 12395 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12396 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 12397 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 12398 | else |
| 12399 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 12400 | |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 12401 | if (cmpl) |
| 12402 | abtsiocbp->iocb_cmpl = cmpl; |
| 12403 | else |
| 12404 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | e6c6acc | 2016-12-19 15:07:23 -0800 | [diff] [blame] | 12405 | abtsiocbp->vport = vport; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 12406 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 12407 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12408 | pring = lpfc_sli4_calc_ring(phba, abtsiocbp); |
| 12409 | if (unlikely(pring == NULL)) |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 12410 | goto abort_iotag_exit; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 12411 | /* Note: both hbalock and ring_lock need to be set here */ |
| 12412 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 12413 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 12414 | abtsiocbp, 0); |
| 12415 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 12416 | } else { |
| 12417 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 12418 | abtsiocbp, 0); |
| 12419 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 12420 | |
| 12421 | abort_iotag_exit: |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 12422 | |
| 12423 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 12424 | "0339 Abort xri x%x, original iotag x%x, " |
| 12425 | "abort cmd iotag x%x retval x%x\n", |
| 12426 | iabt->un.acxri.abortIoTag, |
| 12427 | iabt->un.acxri.abortContextTag, |
| 12428 | abtsiocbp->iotag, retval); |
| 12429 | |
| 12430 | if (retval) { |
| 12431 | cmdiocb->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 12432 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
| 12433 | } |
| 12434 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12435 | /* |
| 12436 | * Caller to this routine should check for IOCB_ERROR |
| 12437 | * and handle it properly. This routine no longer removes |
| 12438 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 12439 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12440 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12441 | } |
| 12442 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12443 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 12444 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. |
| 12445 | * @phba: pointer to lpfc HBA data structure. |
| 12446 | * |
| 12447 | * This routine will abort all pending and outstanding iocbs to an HBA. |
| 12448 | **/ |
| 12449 | void |
| 12450 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) |
| 12451 | { |
| 12452 | struct lpfc_sli *psli = &phba->sli; |
| 12453 | struct lpfc_sli_ring *pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12454 | struct lpfc_queue *qp = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 12455 | int i; |
| 12456 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12457 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 12458 | for (i = 0; i < psli->num_rings; i++) { |
| 12459 | pring = &psli->sli3_ring[i]; |
| 12460 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 12461 | } |
| 12462 | return; |
| 12463 | } |
| 12464 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 12465 | pring = qp->pring; |
| 12466 | if (!pring) |
| 12467 | continue; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 12468 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 12469 | } |
| 12470 | } |
| 12471 | |
| 12472 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12473 | * 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] | 12474 | * @iocbq: Pointer to driver iocb object. |
| 12475 | * @vport: Pointer to driver virtual port object. |
| 12476 | * @tgt_id: SCSI ID of the target. |
| 12477 | * @lun_id: LUN ID of the scsi device. |
| 12478 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 12479 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12480 | * 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] | 12481 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 12482 | * 0 if the filtering criteria is met for the given iocb and will return |
| 12483 | * 1 if the filtering criteria is not met. |
| 12484 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 12485 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 12486 | * lun_id parameter. |
| 12487 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 12488 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 12489 | * parameters. |
| 12490 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 12491 | * given iocb is for the SCSI host associated with the given vport. |
| 12492 | * This function is called with no locks held. |
| 12493 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12494 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12495 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 12496 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 12497 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12498 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 12499 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | e136471 | 2021-04-21 16:44:33 -0700 | [diff] [blame] | 12500 | IOCB_t *icmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12501 | int rc = 1; |
| 12502 | |
James Smart | 9ec58ec | 2021-01-04 10:02:35 -0800 | [diff] [blame] | 12503 | if (!iocbq || iocbq->vport != vport) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 12504 | return rc; |
| 12505 | |
James Smart | e136471 | 2021-04-21 16:44:33 -0700 | [diff] [blame] | 12506 | if (!(iocbq->iocb_flag & LPFC_IO_FCP) || |
| 12507 | !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ) || |
| 12508 | iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 12509 | return rc; |
| 12510 | |
| 12511 | icmd = &iocbq->iocb; |
| 12512 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
| 12513 | icmd->ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12514 | return rc; |
| 12515 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 12516 | 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] | 12517 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 12518 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12519 | return rc; |
| 12520 | |
| 12521 | switch (ctx_cmd) { |
| 12522 | case LPFC_CTX_LUN: |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 12523 | if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) && |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 12524 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 12525 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12526 | rc = 0; |
| 12527 | break; |
| 12528 | case LPFC_CTX_TGT: |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 12529 | if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) && |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 12530 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12531 | rc = 0; |
| 12532 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12533 | case LPFC_CTX_HOST: |
| 12534 | rc = 0; |
| 12535 | break; |
| 12536 | default: |
| 12537 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 12538 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12539 | break; |
| 12540 | } |
| 12541 | |
| 12542 | return rc; |
| 12543 | } |
| 12544 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12545 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12546 | * 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] | 12547 | * @vport: Pointer to virtual port. |
| 12548 | * @tgt_id: SCSI ID of the target. |
| 12549 | * @lun_id: LUN ID of the scsi device. |
| 12550 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 12551 | * |
| 12552 | * This function returns number of FCP commands pending for the vport. |
| 12553 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 12554 | * commands pending on the vport associated with SCSI device specified |
| 12555 | * by tgt_id and lun_id parameters. |
| 12556 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 12557 | * commands pending on the vport associated with SCSI target specified |
| 12558 | * by tgt_id parameter. |
| 12559 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 12560 | * commands pending on the vport. |
| 12561 | * This function returns the number of iocbs which satisfy the filter. |
| 12562 | * This function is called without any lock held. |
| 12563 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12564 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12565 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 12566 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12567 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12568 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 12569 | struct lpfc_iocbq *iocbq; |
| 12570 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12571 | |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 12572 | spin_lock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 12573 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 12574 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12575 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12576 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 12577 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 12578 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12579 | } |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 12580 | spin_unlock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 12581 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12582 | return sum; |
| 12583 | } |
| 12584 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12585 | /** |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 12586 | * lpfc_sli4_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
| 12587 | * @phba: Pointer to HBA context object |
| 12588 | * @cmdiocb: Pointer to command iocb object. |
| 12589 | * @wcqe: pointer to the complete wcqe |
| 12590 | * |
| 12591 | * This function is called when an aborted FCP iocb completes. This |
| 12592 | * function is called by the ring event handler with no lock held. |
| 12593 | * This function frees the iocb. It is called for sli-4 adapters. |
| 12594 | **/ |
| 12595 | void |
| 12596 | lpfc_sli4_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 12597 | struct lpfc_wcqe_complete *wcqe) |
| 12598 | { |
| 12599 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 12600 | "3017 ABORT_XRI_CN completing on rpi x%x " |
| 12601 | "original iotag x%x, abort cmd iotag x%x " |
| 12602 | "status 0x%x, reason 0x%x\n", |
| 12603 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 12604 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 12605 | cmdiocb->iotag, |
| 12606 | (bf_get(lpfc_wcqe_c_status, wcqe) |
| 12607 | & LPFC_IOCB_STATUS_MASK), |
| 12608 | wcqe->parameter); |
| 12609 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| 12610 | } |
| 12611 | |
| 12612 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12613 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12614 | * @phba: Pointer to HBA context object |
| 12615 | * @cmdiocb: Pointer to command iocb object. |
| 12616 | * @rspiocb: Pointer to response iocb object. |
| 12617 | * |
| 12618 | * This function is called when an aborted FCP iocb completes. This |
| 12619 | * function is called by the ring event handler with no lock held. |
| 12620 | * This function frees the iocb. |
| 12621 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 12622 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12623 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 12624 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 12625 | { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 12626 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 8e668af | 2013-05-31 17:04:28 -0400 | [diff] [blame] | 12627 | "3096 ABORT_XRI_CN completing on rpi x%x " |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 12628 | "original iotag x%x, abort cmd iotag x%x " |
| 12629 | "status 0x%x, reason 0x%x\n", |
| 12630 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 12631 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 12632 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, |
| 12633 | rspiocb->iocb.un.ulpWord[4]); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 12634 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 12635 | return; |
| 12636 | } |
| 12637 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12638 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12639 | * 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] | 12640 | * @vport: Pointer to virtual port. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12641 | * @tgt_id: SCSI ID of the target. |
| 12642 | * @lun_id: LUN ID of the scsi device. |
| 12643 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 12644 | * |
| 12645 | * This function sends an abort command for every SCSI command |
| 12646 | * associated with the given virtual port pending on the ring |
| 12647 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 12648 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 12649 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 12650 | * parameters |
| 12651 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 12652 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 12653 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 12654 | * FCP iocbs associated with virtual port. |
James Smart | 078c68b | 2021-04-11 18:31:12 -0700 | [diff] [blame] | 12655 | * The pring used for SLI3 is sli3_ring[LPFC_FCP_RING], for SLI4 |
| 12656 | * lpfc_sli4_calc_ring is used. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12657 | * This function returns number of iocbs it failed to abort. |
| 12658 | * This function is called with no locks held. |
| 12659 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12660 | int |
James Smart | 078c68b | 2021-04-11 18:31:12 -0700 | [diff] [blame] | 12661 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, u16 tgt_id, u64 lun_id, |
| 12662 | lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12663 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12664 | struct lpfc_hba *phba = vport->phba; |
James Smart | 078c68b | 2021-04-11 18:31:12 -0700 | [diff] [blame] | 12665 | struct lpfc_sli_ring *pring = NULL; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 12666 | struct lpfc_iocbq *iocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12667 | int errcnt = 0, ret_val = 0; |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 12668 | unsigned long iflags; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 12669 | int i; |
James Smart | 078c68b | 2021-04-11 18:31:12 -0700 | [diff] [blame] | 12670 | void *fcp_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12671 | |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 12672 | /* all I/Os are in process of being flushed */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 12673 | if (phba->hba_flag & HBA_IOQ_FLUSH) |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 12674 | return errcnt; |
| 12675 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 12676 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 12677 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12678 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12679 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12680 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12681 | continue; |
| 12682 | |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 12683 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 078c68b | 2021-04-11 18:31:12 -0700 | [diff] [blame] | 12684 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 12685 | pring = &phba->sli.sli3_ring[LPFC_FCP_RING]; |
| 12686 | fcp_cmpl = lpfc_sli_abort_fcp_cmpl; |
| 12687 | } else if (phba->sli_rev == LPFC_SLI_REV4) { |
| 12688 | pring = lpfc_sli4_calc_ring(phba, iocbq); |
| 12689 | fcp_cmpl = lpfc_sli4_abort_fcp_cmpl; |
| 12690 | } |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 12691 | ret_val = lpfc_sli_issue_abort_iotag(phba, pring, iocbq, |
James Smart | 078c68b | 2021-04-11 18:31:12 -0700 | [diff] [blame] | 12692 | fcp_cmpl); |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 12693 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12694 | if (ret_val != IOCB_SUCCESS) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12695 | errcnt++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12696 | } |
| 12697 | |
| 12698 | return errcnt; |
| 12699 | } |
| 12700 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12701 | /** |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12702 | * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN |
| 12703 | * @vport: Pointer to virtual port. |
| 12704 | * @pring: Pointer to driver SLI ring object. |
| 12705 | * @tgt_id: SCSI ID of the target. |
| 12706 | * @lun_id: LUN ID of the scsi device. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 12707 | * @cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12708 | * |
| 12709 | * This function sends an abort command for every SCSI command |
| 12710 | * associated with the given virtual port pending on the ring |
| 12711 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 12712 | * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 12713 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 12714 | * parameters |
| 12715 | * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 12716 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 12717 | * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 12718 | * FCP iocbs associated with virtual port. |
| 12719 | * This function returns number of iocbs it aborted . |
| 12720 | * This function is called with no locks held right after a taskmgmt |
| 12721 | * command is sent. |
| 12722 | **/ |
| 12723 | int |
| 12724 | lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 12725 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd) |
| 12726 | { |
| 12727 | struct lpfc_hba *phba = vport->phba; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 12728 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12729 | struct lpfc_iocbq *abtsiocbq; |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 12730 | struct lpfc_nodelist *ndlp; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12731 | struct lpfc_iocbq *iocbq; |
| 12732 | IOCB_t *icmd; |
| 12733 | int sum, i, ret_val; |
| 12734 | unsigned long iflags; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 12735 | struct lpfc_sli_ring *pring_s4 = NULL; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12736 | |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 12737 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12738 | |
| 12739 | /* all I/Os are in process of being flushed */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 12740 | if (phba->hba_flag & HBA_IOQ_FLUSH) { |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 12741 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12742 | return 0; |
| 12743 | } |
| 12744 | sum = 0; |
| 12745 | |
| 12746 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 12747 | iocbq = phba->sli.iocbq_lookup[i]; |
| 12748 | |
| 12749 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
| 12750 | cmd) != 0) |
| 12751 | continue; |
| 12752 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 12753 | /* Guard against IO completion being called at same time */ |
| 12754 | lpfc_cmd = container_of(iocbq, struct lpfc_io_buf, cur_iocbq); |
| 12755 | spin_lock(&lpfc_cmd->buf_lock); |
| 12756 | |
| 12757 | if (!lpfc_cmd->pCmd) { |
| 12758 | spin_unlock(&lpfc_cmd->buf_lock); |
| 12759 | continue; |
| 12760 | } |
| 12761 | |
| 12762 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 12763 | pring_s4 = |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 12764 | phba->sli4_hba.hdwq[iocbq->hba_wqidx].io_wq->pring; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 12765 | if (!pring_s4) { |
| 12766 | spin_unlock(&lpfc_cmd->buf_lock); |
| 12767 | continue; |
| 12768 | } |
| 12769 | /* Note: both hbalock and ring_lock must be set here */ |
| 12770 | spin_lock(&pring_s4->ring_lock); |
| 12771 | } |
| 12772 | |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12773 | /* |
| 12774 | * If the iocbq is already being aborted, don't take a second |
| 12775 | * action, but do count it. |
| 12776 | */ |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 12777 | if ((iocbq->iocb_flag & LPFC_DRIVER_ABORTED) || |
| 12778 | !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ)) { |
| 12779 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 12780 | spin_unlock(&pring_s4->ring_lock); |
| 12781 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12782 | continue; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 12783 | } |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12784 | |
| 12785 | /* issue ABTS for this IOCB based on iotag */ |
| 12786 | abtsiocbq = __lpfc_sli_get_iocbq(phba); |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 12787 | if (!abtsiocbq) { |
| 12788 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 12789 | spin_unlock(&pring_s4->ring_lock); |
| 12790 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12791 | continue; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 12792 | } |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12793 | |
| 12794 | icmd = &iocbq->iocb; |
| 12795 | abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 12796 | abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext; |
| 12797 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 12798 | abtsiocbq->iocb.un.acxri.abortIoTag = |
| 12799 | iocbq->sli4_xritag; |
| 12800 | else |
| 12801 | abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag; |
| 12802 | abtsiocbq->iocb.ulpLe = 1; |
| 12803 | abtsiocbq->iocb.ulpClass = icmd->ulpClass; |
| 12804 | abtsiocbq->vport = vport; |
| 12805 | |
| 12806 | /* 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] | 12807 | abtsiocbq->hba_wqidx = iocbq->hba_wqidx; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12808 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 12809 | abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 12810 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 12811 | abtsiocbq->iocb_flag |= LPFC_IO_FOF; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12812 | |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 12813 | ndlp = lpfc_cmd->rdata->pnode; |
| 12814 | |
| 12815 | if (lpfc_is_link_up(phba) && |
| 12816 | (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12817 | abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 12818 | else |
| 12819 | abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 12820 | |
| 12821 | /* Setup callback routine and issue the command. */ |
| 12822 | abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
| 12823 | |
| 12824 | /* |
| 12825 | * Indicate the IO is being aborted by the driver and set |
| 12826 | * the caller's flag into the aborted IO. |
| 12827 | */ |
| 12828 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 12829 | |
| 12830 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12831 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 12832 | abtsiocbq, 0); |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 12833 | spin_unlock(&pring_s4->ring_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12834 | } else { |
| 12835 | ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 12836 | abtsiocbq, 0); |
| 12837 | } |
| 12838 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 12839 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12840 | |
| 12841 | if (ret_val == IOCB_ERROR) |
| 12842 | __lpfc_sli_release_iocbq(phba, abtsiocbq); |
| 12843 | else |
| 12844 | sum++; |
| 12845 | } |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 12846 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12847 | return sum; |
| 12848 | } |
| 12849 | |
| 12850 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12851 | * 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] | 12852 | * @phba: Pointer to HBA context object. |
| 12853 | * @cmdiocbq: Pointer to command iocb. |
| 12854 | * @rspiocbq: Pointer to response iocb. |
| 12855 | * |
| 12856 | * This function is the completion handler for iocbs issued using |
| 12857 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 12858 | * ring event handler function without any lock held. This function |
| 12859 | * can be called from both worker thread context and interrupt |
| 12860 | * context. This function also can be called from other thread which |
| 12861 | * cleans up the SLI layer objects. |
| 12862 | * This function copy the contents of the response iocb to the |
| 12863 | * response iocb memory object provided by the caller of |
| 12864 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 12865 | * sleeps for the iocb completion. |
| 12866 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12867 | static void |
| 12868 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 12869 | struct lpfc_iocbq *cmdiocbq, |
| 12870 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12871 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12872 | wait_queue_head_t *pdone_q; |
| 12873 | unsigned long iflags; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 12874 | struct lpfc_io_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12875 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12876 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 12877 | if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) { |
| 12878 | |
| 12879 | /* |
| 12880 | * A time out has occurred for the iocb. If a time out |
| 12881 | * completion handler has been supplied, call it. Otherwise, |
| 12882 | * just free the iocbq. |
| 12883 | */ |
| 12884 | |
| 12885 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12886 | cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl; |
| 12887 | cmdiocbq->wait_iocb_cmpl = NULL; |
| 12888 | if (cmdiocbq->iocb_cmpl) |
| 12889 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL); |
| 12890 | else |
| 12891 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
| 12892 | return; |
| 12893 | } |
| 12894 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12895 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 12896 | if (cmdiocbq->context2 && rspiocbq) |
| 12897 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 12898 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 12899 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 12900 | /* Set the exchange busy flag for task management commands */ |
| 12901 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 12902 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 12903 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_io_buf, |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 12904 | cur_iocbq); |
James Smart | 324e1c4 | 2019-10-18 14:18:21 -0700 | [diff] [blame] | 12905 | if (rspiocbq && (rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY)) |
| 12906 | lpfc_cmd->flags |= LPFC_SBUF_XBUSY; |
| 12907 | else |
| 12908 | lpfc_cmd->flags &= ~LPFC_SBUF_XBUSY; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 12909 | } |
| 12910 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12911 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12912 | if (pdone_q) |
| 12913 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12914 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12915 | return; |
| 12916 | } |
| 12917 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12918 | /** |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 12919 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. |
| 12920 | * @phba: Pointer to HBA context object.. |
| 12921 | * @piocbq: Pointer to command iocb. |
| 12922 | * @flag: Flag to test. |
| 12923 | * |
| 12924 | * This routine grabs the hbalock and then test the iocb_flag to |
| 12925 | * see if the passed in flag is set. |
| 12926 | * Returns: |
| 12927 | * 1 if flag is set. |
| 12928 | * 0 if flag is not set. |
| 12929 | **/ |
| 12930 | static int |
| 12931 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, |
| 12932 | struct lpfc_iocbq *piocbq, uint32_t flag) |
| 12933 | { |
| 12934 | unsigned long iflags; |
| 12935 | int ret; |
| 12936 | |
| 12937 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12938 | ret = piocbq->iocb_flag & flag; |
| 12939 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12940 | return ret; |
| 12941 | |
| 12942 | } |
| 12943 | |
| 12944 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12945 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12946 | * @phba: Pointer to HBA context object.. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 12947 | * @ring_number: Ring number |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12948 | * @piocb: Pointer to command iocb. |
| 12949 | * @prspiocbq: Pointer to response iocb. |
| 12950 | * @timeout: Timeout in number of seconds. |
| 12951 | * |
| 12952 | * This function issues the iocb to firmware and waits for the |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 12953 | * iocb to complete. The iocb_cmpl field of the shall be used |
| 12954 | * to handle iocbs which time out. If the field is NULL, the |
| 12955 | * function shall free the iocbq structure. If more clean up is |
| 12956 | * needed, the caller is expected to provide a completion function |
| 12957 | * that will provide the needed clean up. If the iocb command is |
| 12958 | * not completed within timeout seconds, the function will either |
| 12959 | * free the iocbq structure (if iocb_cmpl == NULL) or execute the |
| 12960 | * completion function set in the iocb_cmpl field and then return |
| 12961 | * a status of IOCB_TIMEDOUT. The caller should not free the iocb |
| 12962 | * resources if this function returns IOCB_TIMEDOUT. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12963 | * The function waits for the iocb completion using an |
| 12964 | * non-interruptible wait. |
| 12965 | * This function will sleep while waiting for iocb completion. |
| 12966 | * So, this function should not be called from any context which |
| 12967 | * does not allow sleeping. Due to the same reason, this function |
| 12968 | * cannot be called with interrupt disabled. |
| 12969 | * This function assumes that the iocb completions occur while |
| 12970 | * this function sleep. So, this function cannot be called from |
| 12971 | * the thread which process iocb completion for this ring. |
| 12972 | * This function clears the iocb_flag of the iocb object before |
| 12973 | * issuing the iocb and the iocb completion handler sets this |
| 12974 | * flag and wakes this thread when the iocb completes. |
| 12975 | * The contents of the response iocb will be copied to prspiocbq |
| 12976 | * by the completion handler when the command completes. |
| 12977 | * This function returns IOCB_SUCCESS when success. |
| 12978 | * This function is called with no lock held. |
| 12979 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12980 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12981 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12982 | uint32_t ring_number, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12983 | struct lpfc_iocbq *piocb, |
| 12984 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12985 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12986 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 12987 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12988 | long timeleft, timeout_req = 0; |
| 12989 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 12990 | uint32_t creg_val; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 12991 | struct lpfc_iocbq *iocb; |
| 12992 | int txq_cnt = 0; |
| 12993 | int txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12994 | struct lpfc_sli_ring *pring; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 12995 | unsigned long iflags; |
| 12996 | bool iocb_completed = true; |
| 12997 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12998 | if (phba->sli_rev >= LPFC_SLI_REV4) |
| 12999 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 13000 | else |
| 13001 | pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13002 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 13003 | * If the caller has provided a response iocbq buffer, then context2 |
| 13004 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13005 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 13006 | if (prspiocbq) { |
| 13007 | if (piocb->context2) |
| 13008 | return IOCB_ERROR; |
| 13009 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13010 | } |
| 13011 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 13012 | piocb->wait_iocb_cmpl = piocb->iocb_cmpl; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 13013 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 13014 | piocb->context_un.wait_queue = &done_q; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 13015 | piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13016 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 13017 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 13018 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 13019 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 13020 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 13021 | writel(creg_val, phba->HCregaddr); |
| 13022 | readl(phba->HCregaddr); /* flush */ |
| 13023 | } |
| 13024 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 13025 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 13026 | SLI_IOCB_RET_IOCB); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 13027 | if (retval == IOCB_SUCCESS) { |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 13028 | timeout_req = msecs_to_jiffies(timeout * 1000); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 13029 | timeleft = wait_event_timeout(done_q, |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 13030 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 13031 | timeout_req); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 13032 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13033 | if (!(piocb->iocb_flag & LPFC_IO_WAKE)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13034 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 13035 | /* |
| 13036 | * IOCB timed out. Inform the wake iocb wait |
| 13037 | * completion function and set local status |
| 13038 | */ |
| 13039 | |
| 13040 | iocb_completed = false; |
| 13041 | piocb->iocb_flag |= LPFC_IO_WAKE_TMO; |
| 13042 | } |
| 13043 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13044 | if (iocb_completed) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 13045 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 13046 | "0331 IOCB wake signaled\n"); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 13047 | /* Note: we are not indicating if the IOCB has a success |
| 13048 | * status or not - that's for the caller to check. |
| 13049 | * IOCB_SUCCESS means just that the command was sent and |
| 13050 | * completed. Not that it completed successfully. |
| 13051 | * */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 13052 | } else if (timeleft == 0) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13053 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 13054 | "0338 IOCB wait timeout error - no " |
| 13055 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 13056 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 13057 | } else { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13058 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 13059 | "0330 IOCB wake NOT set, " |
| 13060 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 13061 | timeout, (timeleft / jiffies)); |
| 13062 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13063 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 13064 | } else if (retval == IOCB_BUSY) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13065 | if (phba->cfg_log_verbose & LOG_SLI) { |
| 13066 | list_for_each_entry(iocb, &pring->txq, list) { |
| 13067 | txq_cnt++; |
| 13068 | } |
| 13069 | list_for_each_entry(iocb, &pring->txcmplq, list) { |
| 13070 | txcmplq_cnt++; |
| 13071 | } |
| 13072 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13073 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", |
| 13074 | phba->iocb_cnt, txq_cnt, txcmplq_cnt); |
| 13075 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 13076 | return retval; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 13077 | } else { |
| 13078 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 13079 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 13080 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 13081 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13082 | } |
| 13083 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 13084 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 13085 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 13086 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 13087 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 13088 | writel(creg_val, phba->HCregaddr); |
| 13089 | readl(phba->HCregaddr); /* flush */ |
| 13090 | } |
| 13091 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 13092 | if (prspiocbq) |
| 13093 | piocb->context2 = NULL; |
| 13094 | |
| 13095 | piocb->context_un.wait_queue = NULL; |
| 13096 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13097 | return retval; |
| 13098 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 13099 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 13100 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 13101 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 13102 | * @phba: Pointer to HBA context object. |
| 13103 | * @pmboxq: Pointer to driver mailbox object. |
| 13104 | * @timeout: Timeout in number of seconds. |
| 13105 | * |
| 13106 | * This function issues the mailbox to firmware and waits for the |
| 13107 | * mailbox command to complete. If the mailbox command is not |
| 13108 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 13109 | * The function waits for the mailbox completion using an |
| 13110 | * interruptible wait. If the thread is woken up due to a |
| 13111 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 13112 | * should not free the mailbox resources, if this function returns |
| 13113 | * MBX_TIMEOUT. |
| 13114 | * This function will sleep while waiting for mailbox completion. |
| 13115 | * So, this function should not be called from any context which |
| 13116 | * does not allow sleeping. Due to the same reason, this function |
| 13117 | * cannot be called with interrupt disabled. |
| 13118 | * This function assumes that the mailbox completion occurs while |
| 13119 | * this function sleep. So, this function cannot be called from |
| 13120 | * the worker thread which processes mailbox completion. |
| 13121 | * This function is called in the context of HBA management |
| 13122 | * applications. |
| 13123 | * This function returns MBX_SUCCESS when successful. |
| 13124 | * This function is called with no lock held. |
| 13125 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13126 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 13127 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13128 | uint32_t timeout) |
| 13129 | { |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 13130 | struct completion mbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13131 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 13132 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13133 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 13134 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13135 | /* setup wake call as IOCB callback */ |
| 13136 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13137 | |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 13138 | /* setup context3 field to pass wait_queue pointer to wake function */ |
| 13139 | init_completion(&mbox_done); |
| 13140 | pmboxq->context3 = &mbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13141 | /* now issue the command */ |
| 13142 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13143 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 13144 | wait_for_completion_timeout(&mbox_done, |
| 13145 | msecs_to_jiffies(timeout * 1000)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 13146 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 13147 | spin_lock_irqsave(&phba->hbalock, flag); |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 13148 | pmboxq->context3 = NULL; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 13149 | /* |
| 13150 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 13151 | * else do not free the resources. |
| 13152 | */ |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 13153 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13154 | retval = MBX_SUCCESS; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 13155 | } else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 13156 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 13157 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13158 | } |
| 13159 | spin_unlock_irqrestore(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13160 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13161 | return retval; |
| 13162 | } |
| 13163 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 13164 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13165 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 13166 | * @phba: Pointer to HBA context. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 13167 | * @mbx_action: Mailbox shutdown options. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 13168 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13169 | * This function is called to shutdown the driver's mailbox sub-system. |
| 13170 | * It first marks the mailbox sub-system is in a block state to prevent |
| 13171 | * the asynchronous mailbox command from issued off the pending mailbox |
| 13172 | * command queue. If the mailbox command sub-system shutdown is due to |
| 13173 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 13174 | * the mailbox sub-system flush routine to forcefully bring down the |
| 13175 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 13176 | * as with offline or HBA function reset), this routine will wait for the |
| 13177 | * outstanding mailbox command to complete before invoking the mailbox |
| 13178 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 13179 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13180 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 13181 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 13182 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13183 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13184 | unsigned long timeout; |
| 13185 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 13186 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
| 13187 | /* delay 100ms for port state */ |
| 13188 | msleep(100); |
| 13189 | lpfc_sli_mbox_sys_flush(phba); |
| 13190 | return; |
| 13191 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 13192 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 13193 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 13194 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 13195 | local_bh_disable(); |
| 13196 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13197 | spin_lock_irq(&phba->hbalock); |
| 13198 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13199 | |
| 13200 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13201 | /* Determine how long we might wait for the active mailbox |
| 13202 | * command to be gracefully completed by firmware. |
| 13203 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 13204 | if (phba->sli.mbox_active) |
| 13205 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 13206 | phba->sli.mbox_active) * |
| 13207 | 1000) + jiffies; |
| 13208 | spin_unlock_irq(&phba->hbalock); |
| 13209 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 13210 | /* Enable softirqs again, done with phba->hbalock */ |
| 13211 | local_bh_enable(); |
| 13212 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13213 | while (phba->sli.mbox_active) { |
| 13214 | /* Check active mailbox complete status every 2ms */ |
| 13215 | msleep(2); |
| 13216 | if (time_after(jiffies, timeout)) |
| 13217 | /* Timeout, let the mailbox flush routine to |
| 13218 | * forcefully release active mailbox command |
| 13219 | */ |
| 13220 | break; |
| 13221 | } |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 13222 | } else { |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 13223 | spin_unlock_irq(&phba->hbalock); |
| 13224 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 13225 | /* Enable softirqs again, done with phba->hbalock */ |
| 13226 | local_bh_enable(); |
| 13227 | } |
| 13228 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13229 | lpfc_sli_mbox_sys_flush(phba); |
| 13230 | } |
| 13231 | |
| 13232 | /** |
| 13233 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 13234 | * @phba: Pointer to HBA context. |
| 13235 | * |
| 13236 | * This function is called to read the SLI3 device error attention registers |
| 13237 | * for possible error attention events. The caller must hold the hostlock |
| 13238 | * with spin_lock_irq(). |
| 13239 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 13240 | * 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] | 13241 | * Register and returns 0 otherwise. |
| 13242 | **/ |
| 13243 | static int |
| 13244 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 13245 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 13246 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 13247 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13248 | /* Read chip Host Attention (HA) register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 13249 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 13250 | goto unplug_err; |
| 13251 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13252 | if (ha_copy & HA_ERATT) { |
| 13253 | /* Read host status register to retrieve error event */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 13254 | if (lpfc_sli_read_hs(phba)) |
| 13255 | goto unplug_err; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 13256 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13257 | /* Check if there is a deferred error condition is active */ |
| 13258 | if ((HS_FFER1 & phba->work_hs) && |
| 13259 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 13260 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13261 | phba->hba_flag |= DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13262 | /* Clear all interrupt enable conditions */ |
| 13263 | writel(0, phba->HCregaddr); |
| 13264 | readl(phba->HCregaddr); |
| 13265 | } |
| 13266 | |
| 13267 | /* Set the driver HA work bitmap */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13268 | phba->work_ha |= HA_ERATT; |
| 13269 | /* Indicate polling handles this ERATT */ |
| 13270 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13271 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 13272 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13273 | return 0; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 13274 | |
| 13275 | unplug_err: |
| 13276 | /* Set the driver HS work bitmap */ |
| 13277 | phba->work_hs |= UNPLUG_ERR; |
| 13278 | /* Set the driver HA work bitmap */ |
| 13279 | phba->work_ha |= HA_ERATT; |
| 13280 | /* Indicate polling handles this ERATT */ |
| 13281 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 13282 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 13283 | } |
| 13284 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 13285 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13286 | * lpfc_sli4_eratt_read - read sli-4 error attention events |
| 13287 | * @phba: Pointer to HBA context. |
| 13288 | * |
| 13289 | * This function is called to read the SLI4 device error attention registers |
| 13290 | * for possible error attention events. The caller must hold the hostlock |
| 13291 | * with spin_lock_irq(). |
| 13292 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 13293 | * 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] | 13294 | * Register and returns 0 otherwise. |
| 13295 | **/ |
| 13296 | static int |
| 13297 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) |
| 13298 | { |
| 13299 | uint32_t uerr_sta_hi, uerr_sta_lo; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 13300 | uint32_t if_type, portsmphr; |
| 13301 | struct lpfc_register portstat_reg; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13302 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 13303 | /* |
| 13304 | * For now, use the SLI4 device internal unrecoverable error |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13305 | * registers for error attention. This can be changed later. |
| 13306 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 13307 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 13308 | switch (if_type) { |
| 13309 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 13310 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 13311 | &uerr_sta_lo) || |
| 13312 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, |
| 13313 | &uerr_sta_hi)) { |
| 13314 | phba->work_hs |= UNPLUG_ERR; |
| 13315 | phba->work_ha |= HA_ERATT; |
| 13316 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 13317 | return 1; |
| 13318 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 13319 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
| 13320 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13321 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 13322 | "1423 HBA Unrecoverable error: " |
| 13323 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " |
| 13324 | "ue_mask_lo_reg=0x%x, " |
| 13325 | "ue_mask_hi_reg=0x%x\n", |
| 13326 | uerr_sta_lo, uerr_sta_hi, |
| 13327 | phba->sli4_hba.ue_mask_lo, |
| 13328 | phba->sli4_hba.ue_mask_hi); |
| 13329 | phba->work_status[0] = uerr_sta_lo; |
| 13330 | phba->work_status[1] = uerr_sta_hi; |
| 13331 | phba->work_ha |= HA_ERATT; |
| 13332 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 13333 | return 1; |
| 13334 | } |
| 13335 | break; |
| 13336 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 13337 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 13338 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 13339 | &portstat_reg.word0) || |
| 13340 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 13341 | &portsmphr)){ |
| 13342 | phba->work_hs |= UNPLUG_ERR; |
| 13343 | phba->work_ha |= HA_ERATT; |
| 13344 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 13345 | return 1; |
| 13346 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 13347 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
| 13348 | phba->work_status[0] = |
| 13349 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 13350 | phba->work_status[1] = |
| 13351 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13352 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13353 | "2885 Port Status Event: " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 13354 | "port status reg 0x%x, " |
| 13355 | "port smphr reg 0x%x, " |
| 13356 | "error 1=0x%x, error 2=0x%x\n", |
| 13357 | portstat_reg.word0, |
| 13358 | portsmphr, |
| 13359 | phba->work_status[0], |
| 13360 | phba->work_status[1]); |
| 13361 | phba->work_ha |= HA_ERATT; |
| 13362 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 13363 | return 1; |
| 13364 | } |
| 13365 | break; |
| 13366 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 13367 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13368 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 13369 | "2886 HBA Error Attention on unsupported " |
| 13370 | "if type %d.", if_type); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 13371 | return 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13372 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 13373 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13374 | return 0; |
| 13375 | } |
| 13376 | |
| 13377 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 13378 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13379 | * @phba: Pointer to HBA context. |
| 13380 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13381 | * 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] | 13382 | * error attention register bit for error attention events. |
| 13383 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 13384 | * 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] | 13385 | * Register and returns 0 otherwise. |
| 13386 | **/ |
| 13387 | int |
| 13388 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 13389 | { |
| 13390 | uint32_t ha_copy; |
| 13391 | |
| 13392 | /* If somebody is waiting to handle an eratt, don't process it |
| 13393 | * here. The brdkill function will do this. |
| 13394 | */ |
| 13395 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 13396 | return 0; |
| 13397 | |
| 13398 | /* Check if interrupt handler handles this ERATT */ |
| 13399 | spin_lock_irq(&phba->hbalock); |
| 13400 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 13401 | /* Interrupt handler has handled ERATT */ |
| 13402 | spin_unlock_irq(&phba->hbalock); |
| 13403 | return 0; |
| 13404 | } |
| 13405 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 13406 | /* |
| 13407 | * If there is deferred error attention, do not check for error |
| 13408 | * attention |
| 13409 | */ |
| 13410 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 13411 | spin_unlock_irq(&phba->hbalock); |
| 13412 | return 0; |
| 13413 | } |
| 13414 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13415 | /* If PCI channel is offline, don't process it */ |
| 13416 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13417 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13418 | return 0; |
| 13419 | } |
| 13420 | |
| 13421 | switch (phba->sli_rev) { |
| 13422 | case LPFC_SLI_REV2: |
| 13423 | case LPFC_SLI_REV3: |
| 13424 | /* Read chip Host Attention (HA) register */ |
| 13425 | ha_copy = lpfc_sli_eratt_read(phba); |
| 13426 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13427 | case LPFC_SLI_REV4: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 13428 | /* Read device Uncoverable Error (UERR) registers */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13429 | ha_copy = lpfc_sli4_eratt_read(phba); |
| 13430 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13431 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13432 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13433 | "0299 Invalid SLI revision (%d)\n", |
| 13434 | phba->sli_rev); |
| 13435 | ha_copy = 0; |
| 13436 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13437 | } |
| 13438 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13439 | |
| 13440 | return ha_copy; |
| 13441 | } |
| 13442 | |
| 13443 | /** |
| 13444 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 13445 | * @phba: Pointer to HBA context. |
| 13446 | * |
| 13447 | * This inline routine checks whether a device or its PCI slot is in a state |
| 13448 | * that the interrupt should be handled. |
| 13449 | * |
| 13450 | * This function returns 0 if the device or the PCI slot is in a state that |
| 13451 | * interrupt should be handled, otherwise -EIO. |
| 13452 | */ |
| 13453 | static inline int |
| 13454 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 13455 | { |
| 13456 | /* If the pci channel is offline, ignore all the interrupts */ |
| 13457 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 13458 | return -EIO; |
| 13459 | |
| 13460 | /* Update device level interrupt statistics */ |
| 13461 | phba->sli.slistat.sli_intr++; |
| 13462 | |
| 13463 | /* Ignore all interrupts during initialization. */ |
| 13464 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 13465 | return -EIO; |
| 13466 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13467 | return 0; |
| 13468 | } |
| 13469 | |
| 13470 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13471 | * 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] | 13472 | * @irq: Interrupt number. |
| 13473 | * @dev_id: The device context pointer. |
| 13474 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13475 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13476 | * service routine when device with SLI-3 interface spec is enabled with |
| 13477 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 13478 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 13479 | * interrupt mode, this function is called as part of the device-level |
| 13480 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 13481 | * is undergoing initialization, the interrupt handler will not process |
| 13482 | * the interrupt. The link attention and ELS ring attention events are |
| 13483 | * handled by the worker thread. The interrupt handler signals the worker |
| 13484 | * thread and returns for these events. This function is called without |
| 13485 | * 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] | 13486 | * structures. |
| 13487 | * |
| 13488 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 13489 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 13490 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13491 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13492 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13493 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 13494 | struct lpfc_hba *phba; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 13495 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13496 | uint32_t work_ha_copy; |
| 13497 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13498 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13499 | uint32_t control; |
| 13500 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 13501 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 13502 | struct lpfc_vport *vport; |
| 13503 | struct lpfc_nodelist *ndlp; |
| 13504 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 13505 | LPFC_MBOXQ_t *pmb; |
| 13506 | int rc; |
| 13507 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13508 | /* |
| 13509 | * Get the driver's phba structure from the dev_id and |
| 13510 | * assume the HBA is not interrupting. |
| 13511 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13512 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13513 | |
| 13514 | if (unlikely(!phba)) |
| 13515 | return IRQ_NONE; |
| 13516 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13517 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13518 | * Stuff needs to be attented to when this function is invoked as an |
| 13519 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13520 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13521 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13522 | /* Check device state for handling interrupt */ |
| 13523 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13524 | return IRQ_NONE; |
| 13525 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13526 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 13527 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 13528 | goto unplug_error; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13529 | /* If somebody is waiting to handle an eratt don't process it |
| 13530 | * here. The brdkill function will do this. |
| 13531 | */ |
| 13532 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 13533 | ha_copy &= ~HA_ERATT; |
| 13534 | /* Check the need for handling ERATT in interrupt handler */ |
| 13535 | if (ha_copy & HA_ERATT) { |
| 13536 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 13537 | /* ERATT polling has handled ERATT */ |
| 13538 | ha_copy &= ~HA_ERATT; |
| 13539 | else |
| 13540 | /* Indicate interrupt handler handles ERATT */ |
| 13541 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 13542 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 13543 | |
| 13544 | /* |
| 13545 | * If there is deferred error attention, do not check for any |
| 13546 | * interrupt. |
| 13547 | */ |
| 13548 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13549 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 13550 | return IRQ_NONE; |
| 13551 | } |
| 13552 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13553 | /* Clear up only attention source related to slow-path */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 13554 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 13555 | goto unplug_error; |
| 13556 | |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 13557 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
| 13558 | HC_LAINT_ENA | HC_ERINT_ENA), |
| 13559 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13560 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 13561 | phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 13562 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13563 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13564 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13565 | } else |
| 13566 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13567 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13568 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 13569 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13570 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13571 | if (work_ha_copy & HA_LATT) { |
| 13572 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 13573 | /* |
| 13574 | * Turn off Link Attention interrupts |
| 13575 | * until CLEAR_LA done |
| 13576 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13577 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13578 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 13579 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 13580 | goto unplug_error; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13581 | control &= ~HC_LAINT_ENA; |
| 13582 | writel(control, phba->HCregaddr); |
| 13583 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13584 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13585 | } |
| 13586 | else |
| 13587 | work_ha_copy &= ~HA_LATT; |
| 13588 | } |
| 13589 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13590 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 13591 | /* |
| 13592 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 13593 | * the only slow ring. |
| 13594 | */ |
| 13595 | status = (work_ha_copy & |
| 13596 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 13597 | status >>= (4*LPFC_ELS_RING); |
| 13598 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13599 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 13600 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 13601 | goto unplug_error; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 13602 | |
| 13603 | lpfc_debugfs_slow_ring_trc(phba, |
| 13604 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 13605 | control, status, |
| 13606 | (uint32_t)phba->sli.slistat.sli_intr); |
| 13607 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 13608 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 13609 | lpfc_debugfs_slow_ring_trc(phba, |
| 13610 | "ISR Disable ring:" |
| 13611 | "pwork:x%x hawork:x%x wait:x%x", |
| 13612 | phba->work_ha, work_ha_copy, |
| 13613 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 13614 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 13615 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 13616 | control &= |
| 13617 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13618 | writel(control, phba->HCregaddr); |
| 13619 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13620 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 13621 | else { |
| 13622 | lpfc_debugfs_slow_ring_trc(phba, |
| 13623 | "ISR slow ring: pwork:" |
| 13624 | "x%x hawork:x%x wait:x%x", |
| 13625 | phba->work_ha, work_ha_copy, |
| 13626 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 13627 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 13628 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13629 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13630 | } |
| 13631 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13632 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 13633 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 13634 | if (lpfc_sli_read_hs(phba)) |
| 13635 | goto unplug_error; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 13636 | /* |
| 13637 | * Check if there is a deferred error condition |
| 13638 | * is active |
| 13639 | */ |
| 13640 | if ((HS_FFER1 & phba->work_hs) && |
| 13641 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 13642 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
| 13643 | phba->work_hs)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 13644 | phba->hba_flag |= DEFER_ERATT; |
| 13645 | /* Clear all interrupt enable conditions */ |
| 13646 | writel(0, phba->HCregaddr); |
| 13647 | readl(phba->HCregaddr); |
| 13648 | } |
| 13649 | } |
| 13650 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13651 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 13652 | pmb = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13653 | pmbox = &pmb->u.mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 13654 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 13655 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 13656 | |
| 13657 | /* First check out the status word */ |
| 13658 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 13659 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13660 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 13661 | /* |
| 13662 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 13663 | * mbxStatus <status> |
| 13664 | */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13665 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 13666 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 13667 | "Interrupt mbxCommand x%x " |
| 13668 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 13669 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 13670 | pmbox->mbxCommand, |
| 13671 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 13672 | /* clear mailbox attention bit */ |
| 13673 | work_ha_copy &= ~HA_MBATT; |
| 13674 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 13675 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13676 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 13677 | phba->last_completion_time = jiffies; |
| 13678 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 13679 | if (pmb->mbox_cmpl) { |
| 13680 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 13681 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 13682 | if (pmb->out_ext_byte_len && |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13683 | pmb->ctx_buf) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 13684 | lpfc_sli_pcimem_bcopy( |
| 13685 | phba->mbox_ext, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13686 | pmb->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 13687 | pmb->out_ext_byte_len); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 13688 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 13689 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 13690 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 13691 | |
| 13692 | lpfc_debugfs_disc_trc(vport, |
| 13693 | LPFC_DISC_TRC_MBOX_VPORT, |
| 13694 | "MBOX dflt rpi: : " |
| 13695 | "status:x%x rpi:x%x", |
| 13696 | (uint32_t)pmbox->mbxStatus, |
| 13697 | pmbox->un.varWords[0], 0); |
| 13698 | |
| 13699 | if (!pmbox->mbxStatus) { |
| 13700 | mp = (struct lpfc_dmabuf *) |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13701 | (pmb->ctx_buf); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 13702 | ndlp = (struct lpfc_nodelist *) |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13703 | pmb->ctx_ndlp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 13704 | |
| 13705 | /* Reg_LOGIN of dflt RPI was |
| 13706 | * successful. new lets get |
| 13707 | * rid of the RPI using the |
| 13708 | * same mbox buffer. |
| 13709 | */ |
| 13710 | lpfc_unreg_login(phba, |
| 13711 | vport->vpi, |
| 13712 | pmbox->un.varWords[0], |
| 13713 | pmb); |
| 13714 | pmb->mbox_cmpl = |
| 13715 | lpfc_mbx_cmpl_dflt_rpi; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13716 | pmb->ctx_buf = mp; |
| 13717 | pmb->ctx_ndlp = ndlp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 13718 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 13719 | rc = lpfc_sli_issue_mbox(phba, |
| 13720 | pmb, |
| 13721 | MBX_NOWAIT); |
| 13722 | if (rc != MBX_BUSY) |
| 13723 | lpfc_printf_log(phba, |
| 13724 | KERN_ERR, |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13725 | LOG_TRACE_EVENT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 13726 | "0350 rc should have" |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 13727 | "been MBX_BUSY\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13728 | if (rc != MBX_NOT_FINISHED) |
| 13729 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 13730 | } |
| 13731 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13732 | spin_lock_irqsave( |
| 13733 | &phba->pport->work_port_lock, |
| 13734 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 13735 | phba->pport->work_port_events &= |
| 13736 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13737 | spin_unlock_irqrestore( |
| 13738 | &phba->pport->work_port_lock, |
| 13739 | iflag); |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 13740 | |
| 13741 | /* Do NOT queue MBX_HEARTBEAT to the worker |
| 13742 | * thread for processing. |
| 13743 | */ |
| 13744 | if (pmbox->mbxCommand == MBX_HEARTBEAT) { |
| 13745 | /* Process mbox now */ |
| 13746 | phba->sli.mbox_active = NULL; |
| 13747 | phba->sli.sli_flag &= |
| 13748 | ~LPFC_SLI_MBOX_ACTIVE; |
| 13749 | if (pmb->mbox_cmpl) |
| 13750 | pmb->mbox_cmpl(phba, pmb); |
| 13751 | } else { |
| 13752 | /* Queue to worker thread to process */ |
| 13753 | lpfc_mbox_cmpl_put(phba, pmb); |
| 13754 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 13755 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 13756 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13757 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13758 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 13759 | if ((work_ha_copy & HA_MBATT) && |
| 13760 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 13761 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 13762 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 13763 | do { |
| 13764 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 13765 | MBX_NOWAIT); |
| 13766 | } while (rc == MBX_NOT_FINISHED); |
| 13767 | if (rc != MBX_SUCCESS) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13768 | lpfc_printf_log(phba, KERN_ERR, |
| 13769 | LOG_TRACE_EVENT, |
| 13770 | "0349 rc should be " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 13771 | "MBX_SUCCESS\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 13772 | } |
| 13773 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13774 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13775 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13776 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 13777 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13778 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13779 | return IRQ_HANDLED; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 13780 | unplug_error: |
| 13781 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 13782 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13783 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13784 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13785 | |
| 13786 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13787 | * 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] | 13788 | * @irq: Interrupt number. |
| 13789 | * @dev_id: The device context pointer. |
| 13790 | * |
| 13791 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13792 | * service routine when device with SLI-3 interface spec is enabled with |
| 13793 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 13794 | * ring event in the HBA. However, when the device is enabled with either |
| 13795 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 13796 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 13797 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 13798 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 13799 | * the intrrupt context. This function is called without any lock held. |
| 13800 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13801 | * |
| 13802 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 13803 | * returns IRQ_NONE. |
| 13804 | **/ |
| 13805 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13806 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13807 | { |
| 13808 | struct lpfc_hba *phba; |
| 13809 | uint32_t ha_copy; |
| 13810 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13811 | unsigned long iflag; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13812 | struct lpfc_sli_ring *pring; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13813 | |
| 13814 | /* Get the driver's phba structure from the dev_id and |
| 13815 | * assume the HBA is not interrupting. |
| 13816 | */ |
| 13817 | phba = (struct lpfc_hba *) dev_id; |
| 13818 | |
| 13819 | if (unlikely(!phba)) |
| 13820 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13821 | |
| 13822 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13823 | * Stuff needs to be attented to when this function is invoked as an |
| 13824 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13825 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13826 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13827 | /* Check device state for handling interrupt */ |
| 13828 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13829 | return IRQ_NONE; |
| 13830 | /* Need to read HA REG for FCP ring and other ring events */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 13831 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 13832 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13833 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13834 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 13835 | /* |
| 13836 | * If there is deferred error attention, do not check for |
| 13837 | * any interrupt. |
| 13838 | */ |
| 13839 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13840 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 13841 | return IRQ_NONE; |
| 13842 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13843 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 13844 | phba->HAregaddr); |
| 13845 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13846 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13847 | } else |
| 13848 | ha_copy = phba->ha_copy; |
| 13849 | |
| 13850 | /* |
| 13851 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 13852 | */ |
| 13853 | ha_copy &= ~(phba->work_ha_mask); |
| 13854 | |
| 13855 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13856 | status >>= (4*LPFC_FCP_RING); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13857 | pring = &phba->sli.sli3_ring[LPFC_FCP_RING]; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 13858 | if (status & HA_RXMASK) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13859 | lpfc_sli_handle_fast_ring_event(phba, pring, status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 13860 | |
| 13861 | if (phba->cfg_multi_ring_support == 2) { |
| 13862 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13863 | * Process all events on extra ring. Take the optimized path |
| 13864 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 13865 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13866 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 13867 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 13868 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 13869 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13870 | &phba->sli.sli3_ring[LPFC_EXTRA_RING], |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 13871 | status); |
| 13872 | } |
| 13873 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13874 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13875 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13876 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13877 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13878 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13879 | * @irq: Interrupt number. |
| 13880 | * @dev_id: The device context pointer. |
| 13881 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13882 | * This function is the HBA device-level interrupt handler to device with |
| 13883 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 13884 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 13885 | * requires driver attention. This function invokes the slow-path interrupt |
| 13886 | * attention handling function and fast-path interrupt attention handling |
| 13887 | * function in turn to process the relevant HBA attention events. This |
| 13888 | * function is called without any lock held. It gets the hbalock to access |
| 13889 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13890 | * |
| 13891 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 13892 | * returns IRQ_NONE. |
| 13893 | **/ |
| 13894 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13895 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13896 | { |
| 13897 | struct lpfc_hba *phba; |
| 13898 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 13899 | unsigned long status1, status2; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 13900 | uint32_t hc_copy; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13901 | |
| 13902 | /* |
| 13903 | * Get the driver's phba structure from the dev_id and |
| 13904 | * assume the HBA is not interrupting. |
| 13905 | */ |
| 13906 | phba = (struct lpfc_hba *) dev_id; |
| 13907 | |
| 13908 | if (unlikely(!phba)) |
| 13909 | return IRQ_NONE; |
| 13910 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13911 | /* Check device state for handling interrupt */ |
| 13912 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13913 | return IRQ_NONE; |
| 13914 | |
| 13915 | spin_lock(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 13916 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
| 13917 | spin_unlock(&phba->hbalock); |
| 13918 | return IRQ_HANDLED; |
| 13919 | } |
| 13920 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13921 | if (unlikely(!phba->ha_copy)) { |
| 13922 | spin_unlock(&phba->hbalock); |
| 13923 | return IRQ_NONE; |
| 13924 | } else if (phba->ha_copy & HA_ERATT) { |
| 13925 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 13926 | /* ERATT polling has handled ERATT */ |
| 13927 | phba->ha_copy &= ~HA_ERATT; |
| 13928 | else |
| 13929 | /* Indicate interrupt handler handles ERATT */ |
| 13930 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 13931 | } |
| 13932 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 13933 | /* |
| 13934 | * If there is deferred error attention, do not check for any interrupt. |
| 13935 | */ |
| 13936 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 13937 | spin_unlock(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 13938 | return IRQ_NONE; |
| 13939 | } |
| 13940 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13941 | /* Clear attention sources except link and error attentions */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 13942 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
| 13943 | spin_unlock(&phba->hbalock); |
| 13944 | return IRQ_HANDLED; |
| 13945 | } |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 13946 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
| 13947 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), |
| 13948 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13949 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 13950 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13951 | readl(phba->HAregaddr); /* flush */ |
| 13952 | spin_unlock(&phba->hbalock); |
| 13953 | |
| 13954 | /* |
| 13955 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 13956 | */ |
| 13957 | |
| 13958 | /* status of events with mailbox and link attention */ |
| 13959 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 13960 | |
| 13961 | /* status of events with ELS ring */ |
| 13962 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 13963 | status2 >>= (4*LPFC_ELS_RING); |
| 13964 | |
| 13965 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13966 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13967 | else |
| 13968 | sp_irq_rc = IRQ_NONE; |
| 13969 | |
| 13970 | /* |
| 13971 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 13972 | */ |
| 13973 | |
| 13974 | /* status of events with FCP ring */ |
| 13975 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 13976 | status1 >>= (4*LPFC_FCP_RING); |
| 13977 | |
| 13978 | /* status of events with extra ring */ |
| 13979 | if (phba->cfg_multi_ring_support == 2) { |
| 13980 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 13981 | status2 >>= (4*LPFC_EXTRA_RING); |
| 13982 | } else |
| 13983 | status2 = 0; |
| 13984 | |
| 13985 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13986 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13987 | else |
| 13988 | fp_irq_rc = IRQ_NONE; |
| 13989 | |
| 13990 | /* Return device-level interrupt handling status */ |
| 13991 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13992 | } /* lpfc_sli_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13993 | |
| 13994 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13995 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event |
| 13996 | * @phba: pointer to lpfc hba data structure. |
| 13997 | * |
| 13998 | * This routine is invoked by the worker thread to process all the pending |
| 13999 | * SLI4 els abort xri events. |
| 14000 | **/ |
| 14001 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) |
| 14002 | { |
| 14003 | struct lpfc_cq_event *cq_event; |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 14004 | unsigned long iflags; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14005 | |
| 14006 | /* First, declare the els xri abort event has been handled */ |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 14007 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14008 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 14009 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 14010 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14011 | /* Now, handle all the els xri abort events */ |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 14012 | spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14013 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { |
| 14014 | /* Get the first event from the head of the event queue */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14015 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 14016 | cq_event, struct lpfc_cq_event, list); |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 14017 | spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock, |
| 14018 | iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14019 | /* Notify aborted XRI for ELS work queue */ |
| 14020 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 14021 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14022 | /* Free the event processed back to the free pool */ |
| 14023 | lpfc_sli4_cq_event_release(phba, cq_event); |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 14024 | spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock, |
| 14025 | iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14026 | } |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 14027 | spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14028 | } |
| 14029 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 14030 | /** |
| 14031 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn |
| 14032 | * @phba: pointer to lpfc hba data structure |
| 14033 | * @pIocbIn: pointer to the rspiocbq |
| 14034 | * @pIocbOut: pointer to the cmdiocbq |
| 14035 | * @wcqe: pointer to the complete wcqe |
| 14036 | * |
| 14037 | * This routine transfers the fields of a command iocbq to a response iocbq |
| 14038 | * by copying all the IOCB fields from command iocbq and transferring the |
| 14039 | * completion status information from the complete wcqe. |
| 14040 | **/ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14041 | static void |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 14042 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
| 14043 | struct lpfc_iocbq *pIocbIn, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14044 | struct lpfc_iocbq *pIocbOut, |
| 14045 | struct lpfc_wcqe_complete *wcqe) |
| 14046 | { |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 14047 | int numBdes, i; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 14048 | unsigned long iflags; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 14049 | uint32_t status, max_response; |
| 14050 | struct lpfc_dmabuf *dmabuf; |
| 14051 | struct ulp_bde64 *bpl, bde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14052 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
| 14053 | |
| 14054 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, |
| 14055 | sizeof(struct lpfc_iocbq) - offset); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14056 | /* Map WCQE parameters into irspiocb parameters */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 14057 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 14058 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14059 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
| 14060 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 14061 | pIocbIn->iocb.un.fcpi.fcpi_parm = |
| 14062 | pIocbOut->iocb.un.fcpi.fcpi_parm - |
| 14063 | wcqe->total_data_placed; |
| 14064 | else |
| 14065 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 14066 | else { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14067 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 14068 | switch (pIocbOut->iocb.ulpCommand) { |
| 14069 | case CMD_ELS_REQUEST64_CR: |
| 14070 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 14071 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 14072 | bde.tus.w = le32_to_cpu(bpl[1].tus.w); |
| 14073 | max_response = bde.tus.f.bdeSize; |
| 14074 | break; |
| 14075 | case CMD_GEN_REQUEST64_CR: |
| 14076 | max_response = 0; |
| 14077 | if (!pIocbOut->context3) |
| 14078 | break; |
| 14079 | numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/ |
| 14080 | sizeof(struct ulp_bde64); |
| 14081 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 14082 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 14083 | for (i = 0; i < numBdes; i++) { |
| 14084 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 14085 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 14086 | max_response += bde.tus.f.bdeSize; |
| 14087 | } |
| 14088 | break; |
| 14089 | default: |
| 14090 | max_response = wcqe->total_data_placed; |
| 14091 | break; |
| 14092 | } |
| 14093 | if (max_response < wcqe->total_data_placed) |
| 14094 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response; |
| 14095 | else |
| 14096 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = |
| 14097 | wcqe->total_data_placed; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 14098 | } |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 14099 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 14100 | /* Convert BG errors for completion status */ |
| 14101 | if (status == CQE_STATUS_DI_ERROR) { |
| 14102 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 14103 | |
| 14104 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) |
| 14105 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; |
| 14106 | else |
| 14107 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; |
| 14108 | |
| 14109 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; |
| 14110 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ |
| 14111 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 14112 | BGS_GUARD_ERR_MASK; |
| 14113 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ |
| 14114 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 14115 | BGS_APPTAG_ERR_MASK; |
| 14116 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ |
| 14117 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 14118 | BGS_REFTAG_ERR_MASK; |
| 14119 | |
| 14120 | /* Check to see if there was any good data before the error */ |
| 14121 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { |
| 14122 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 14123 | BGS_HI_WATER_MARK_PRESENT_MASK; |
| 14124 | pIocbIn->iocb.unsli3.sli3_bg.bghm = |
| 14125 | wcqe->total_data_placed; |
| 14126 | } |
| 14127 | |
| 14128 | /* |
| 14129 | * Set ALL the error bits to indicate we don't know what |
| 14130 | * type of error it is. |
| 14131 | */ |
| 14132 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) |
| 14133 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 14134 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | |
| 14135 | BGS_GUARD_ERR_MASK); |
| 14136 | } |
| 14137 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 14138 | /* Pick up HBA exchange busy condition */ |
| 14139 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
| 14140 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 14141 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; |
| 14142 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 14143 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14144 | } |
| 14145 | |
| 14146 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14147 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe |
| 14148 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 14149 | * @irspiocbq: Pointer to work-queue completion queue entry. |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14150 | * |
| 14151 | * This routine handles an ELS work-queue completion event and construct |
| 14152 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common |
| 14153 | * discovery engine to handle. |
| 14154 | * |
| 14155 | * Return: Pointer to the receive IOCBQ, NULL otherwise. |
| 14156 | **/ |
| 14157 | static struct lpfc_iocbq * |
| 14158 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, |
| 14159 | struct lpfc_iocbq *irspiocbq) |
| 14160 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14161 | struct lpfc_sli_ring *pring; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14162 | struct lpfc_iocbq *cmdiocbq; |
| 14163 | struct lpfc_wcqe_complete *wcqe; |
| 14164 | unsigned long iflags; |
| 14165 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14166 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 14167 | if (unlikely(!pring)) |
| 14168 | return NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14169 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14170 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14171 | pring->stats.iocb_event++; |
| 14172 | /* Look up the ELS command IOCB and create pseudo response IOCB */ |
| 14173 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 14174 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14175 | if (unlikely(!cmdiocbq)) { |
| 14176 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 14177 | "0386 ELS complete with no corresponding " |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 14178 | "cmdiocb: 0x%x 0x%x 0x%x 0x%x\n", |
| 14179 | wcqe->word0, wcqe->total_data_placed, |
| 14180 | wcqe->parameter, wcqe->word3); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14181 | lpfc_sli_release_iocbq(phba, irspiocbq); |
| 14182 | return NULL; |
| 14183 | } |
| 14184 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 14185 | spin_lock_irqsave(&pring->ring_lock, iflags); |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 14186 | /* Put the iocb back on the txcmplq */ |
| 14187 | lpfc_sli_ringtxcmpl_put(phba, pring, cmdiocbq); |
| 14188 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 14189 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14190 | /* Fake the irspiocbq and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 14191 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14192 | |
| 14193 | return irspiocbq; |
| 14194 | } |
| 14195 | |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 14196 | inline struct lpfc_cq_event * |
| 14197 | lpfc_cq_event_setup(struct lpfc_hba *phba, void *entry, int size) |
| 14198 | { |
| 14199 | struct lpfc_cq_event *cq_event; |
| 14200 | |
| 14201 | /* Allocate a new internal CQ_EVENT entry */ |
| 14202 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 14203 | if (!cq_event) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14204 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 14205 | "0602 Failed to alloc CQ_EVENT entry\n"); |
| 14206 | return NULL; |
| 14207 | } |
| 14208 | |
| 14209 | /* Move the CQE into the event */ |
| 14210 | memcpy(&cq_event->cqe, entry, size); |
| 14211 | return cq_event; |
| 14212 | } |
| 14213 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14214 | /** |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 14215 | * lpfc_sli4_sp_handle_async_event - Handle an asynchronous event |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14216 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 14217 | * @mcqe: Pointer to mailbox completion queue entry. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14218 | * |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 14219 | * This routine process a mailbox completion queue entry with asynchronous |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14220 | * event. |
| 14221 | * |
| 14222 | * Return: true if work posted to worker thread, otherwise false. |
| 14223 | **/ |
| 14224 | static bool |
| 14225 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 14226 | { |
| 14227 | struct lpfc_cq_event *cq_event; |
| 14228 | unsigned long iflags; |
| 14229 | |
| 14230 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 14231 | "0392 Async Event: word0:x%x, word1:x%x, " |
| 14232 | "word2:x%x, word3:x%x\n", mcqe->word0, |
| 14233 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); |
| 14234 | |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 14235 | cq_event = lpfc_cq_event_setup(phba, mcqe, sizeof(struct lpfc_mcqe)); |
| 14236 | if (!cq_event) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14237 | return false; |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 14238 | |
| 14239 | spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14240 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 14241 | spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags); |
| 14242 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14243 | /* Set the async event flag */ |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 14244 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14245 | phba->hba_flag |= ASYNC_EVENT; |
| 14246 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 14247 | |
| 14248 | return true; |
| 14249 | } |
| 14250 | |
| 14251 | /** |
| 14252 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event |
| 14253 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 14254 | * @mcqe: Pointer to mailbox completion queue entry. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14255 | * |
| 14256 | * This routine process a mailbox completion queue entry with mailbox |
| 14257 | * completion event. |
| 14258 | * |
| 14259 | * Return: true if work posted to worker thread, otherwise false. |
| 14260 | **/ |
| 14261 | static bool |
| 14262 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 14263 | { |
| 14264 | uint32_t mcqe_status; |
| 14265 | MAILBOX_t *mbox, *pmbox; |
| 14266 | struct lpfc_mqe *mqe; |
| 14267 | struct lpfc_vport *vport; |
| 14268 | struct lpfc_nodelist *ndlp; |
| 14269 | struct lpfc_dmabuf *mp; |
| 14270 | unsigned long iflags; |
| 14271 | LPFC_MBOXQ_t *pmb; |
| 14272 | bool workposted = false; |
| 14273 | int rc; |
| 14274 | |
| 14275 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ |
| 14276 | if (!bf_get(lpfc_trailer_completed, mcqe)) |
| 14277 | goto out_no_mqe_complete; |
| 14278 | |
| 14279 | /* Get the reference to the active mbox command */ |
| 14280 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 14281 | pmb = phba->sli.mbox_active; |
| 14282 | if (unlikely(!pmb)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14283 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14284 | "1832 No pending MBOX command to handle\n"); |
| 14285 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 14286 | goto out_no_mqe_complete; |
| 14287 | } |
| 14288 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 14289 | mqe = &pmb->u.mqe; |
| 14290 | pmbox = (MAILBOX_t *)&pmb->u.mqe; |
| 14291 | mbox = phba->mbox; |
| 14292 | vport = pmb->vport; |
| 14293 | |
| 14294 | /* Reset heartbeat timer */ |
| 14295 | phba->last_completion_time = jiffies; |
| 14296 | del_timer(&phba->sli.mbox_tmo); |
| 14297 | |
| 14298 | /* Move mbox data to caller's mailbox region, do endian swapping */ |
| 14299 | if (pmb->mbox_cmpl && mbox) |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 14300 | lpfc_sli4_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14301 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 14302 | /* |
| 14303 | * For mcqe errors, conditionally move a modified error code to |
| 14304 | * the mbox so that the error will not be missed. |
| 14305 | */ |
| 14306 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); |
| 14307 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
| 14308 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) |
| 14309 | bf_set(lpfc_mqe_status, mqe, |
| 14310 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
| 14311 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14312 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 14313 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 14314 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, |
| 14315 | "MBOX dflt rpi: status:x%x rpi:x%x", |
| 14316 | mcqe_status, |
| 14317 | pmbox->un.varWords[0], 0); |
| 14318 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 14319 | mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 14320 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | 01131e7 | 2021-05-14 12:55:49 -0700 | [diff] [blame] | 14321 | |
| 14322 | /* Reg_LOGIN of dflt RPI was successful. Mark the |
| 14323 | * node as having an UNREG_LOGIN in progress to stop |
| 14324 | * an unsolicited PLOGI from the same NPortId from |
| 14325 | * starting another mailbox transaction. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14326 | */ |
James Smart | 01131e7 | 2021-05-14 12:55:49 -0700 | [diff] [blame] | 14327 | spin_lock_irqsave(&ndlp->lock, iflags); |
| 14328 | ndlp->nlp_flag |= NLP_UNREG_INP; |
| 14329 | spin_unlock_irqrestore(&ndlp->lock, iflags); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14330 | lpfc_unreg_login(phba, vport->vpi, |
| 14331 | pmbox->un.varWords[0], pmb); |
| 14332 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 14333 | pmb->ctx_buf = mp; |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 14334 | |
| 14335 | /* No reference taken here. This is a default |
| 14336 | * RPI reg/immediate unreg cycle. The reference was |
| 14337 | * taken in the reg rpi path and is released when |
| 14338 | * this mailbox completes. |
| 14339 | */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 14340 | pmb->ctx_ndlp = ndlp; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14341 | pmb->vport = vport; |
| 14342 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 14343 | if (rc != MBX_BUSY) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14344 | lpfc_printf_log(phba, KERN_ERR, |
| 14345 | LOG_TRACE_EVENT, |
| 14346 | "0385 rc should " |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14347 | "have been MBX_BUSY\n"); |
| 14348 | if (rc != MBX_NOT_FINISHED) |
| 14349 | goto send_current_mbox; |
| 14350 | } |
| 14351 | } |
| 14352 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 14353 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 14354 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 14355 | |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 14356 | /* Do NOT queue MBX_HEARTBEAT to the worker thread for processing. */ |
| 14357 | if (pmbox->mbxCommand == MBX_HEARTBEAT) { |
| 14358 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 14359 | /* Release the mailbox command posting token */ |
| 14360 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 14361 | phba->sli.mbox_active = NULL; |
| 14362 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 14363 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
| 14364 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 14365 | |
| 14366 | /* Post the next mbox command, if there is one */ |
| 14367 | lpfc_sli4_post_async_mbox(phba); |
| 14368 | |
| 14369 | /* Process cmpl now */ |
| 14370 | if (pmb->mbox_cmpl) |
| 14371 | pmb->mbox_cmpl(phba, pmb); |
| 14372 | return false; |
| 14373 | } |
| 14374 | |
| 14375 | /* There is mailbox completion work to queue to the worker thread */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14376 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 14377 | __lpfc_mbox_cmpl_put(phba, pmb); |
| 14378 | phba->work_ha |= HA_MBATT; |
| 14379 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 14380 | workposted = true; |
| 14381 | |
| 14382 | send_current_mbox: |
| 14383 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 14384 | /* Release the mailbox command posting token */ |
| 14385 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 14386 | /* Setting active mailbox pointer need to be in sync to flag clear */ |
| 14387 | phba->sli.mbox_active = NULL; |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame] | 14388 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 14389 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14390 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 14391 | /* Wake up worker thread to post the next pending mailbox command */ |
| 14392 | lpfc_worker_wake_up(phba); |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame] | 14393 | return workposted; |
| 14394 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14395 | out_no_mqe_complete: |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame] | 14396 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14397 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 14398 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame] | 14399 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 14400 | return false; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14401 | } |
| 14402 | |
| 14403 | /** |
| 14404 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry |
| 14405 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 14406 | * @cq: Pointer to associated CQ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14407 | * @cqe: Pointer to mailbox completion queue entry. |
| 14408 | * |
| 14409 | * This routine process a mailbox completion queue entry, it invokes the |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 14410 | * proper mailbox complete handling or asynchronous event handling routine |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14411 | * according to the MCQE's async bit. |
| 14412 | * |
| 14413 | * Return: true if work posted to worker thread, otherwise false. |
| 14414 | **/ |
| 14415 | static bool |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14416 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 14417 | struct lpfc_cqe *cqe) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14418 | { |
| 14419 | struct lpfc_mcqe mcqe; |
| 14420 | bool workposted; |
| 14421 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14422 | cq->CQ_mbox++; |
| 14423 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14424 | /* Copy the mailbox MCQE and convert endian order as needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 14425 | lpfc_sli4_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14426 | |
| 14427 | /* Invoke the proper event handling routine */ |
| 14428 | if (!bf_get(lpfc_trailer_async, &mcqe)) |
| 14429 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); |
| 14430 | else |
| 14431 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); |
| 14432 | return workposted; |
| 14433 | } |
| 14434 | |
| 14435 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14436 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event |
| 14437 | * @phba: Pointer to HBA context object. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 14438 | * @cq: Pointer to associated CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14439 | * @wcqe: Pointer to work-queue completion queue entry. |
| 14440 | * |
| 14441 | * This routine handles an ELS work-queue completion event. |
| 14442 | * |
| 14443 | * Return: true if work posted to worker thread, otherwise false. |
| 14444 | **/ |
| 14445 | static bool |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 14446 | 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] | 14447 | struct lpfc_wcqe_complete *wcqe) |
| 14448 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14449 | struct lpfc_iocbq *irspiocbq; |
| 14450 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 14451 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 14452 | int txq_cnt = 0; |
| 14453 | int txcmplq_cnt = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14454 | |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 14455 | /* Check for response status */ |
| 14456 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 14457 | /* Log the error status */ |
| 14458 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 14459 | "0357 ELS CQE error: status=x%x: " |
| 14460 | "CQE: %08x %08x %08x %08x\n", |
| 14461 | bf_get(lpfc_wcqe_c_status, wcqe), |
| 14462 | wcqe->word0, wcqe->total_data_placed, |
| 14463 | wcqe->parameter, wcqe->word3); |
| 14464 | } |
| 14465 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14466 | /* Get an irspiocbq for later ELS response processing use */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14467 | irspiocbq = lpfc_sli_get_iocbq(phba); |
| 14468 | if (!irspiocbq) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 14469 | if (!list_empty(&pring->txq)) |
| 14470 | txq_cnt++; |
| 14471 | if (!list_empty(&pring->txcmplq)) |
| 14472 | txcmplq_cnt++; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14473 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 14474 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
James Smart | ff349bc | 2019-09-21 20:59:05 -0700 | [diff] [blame] | 14475 | "els_txcmplq_cnt=%d\n", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 14476 | txq_cnt, phba->iocb_cnt, |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 14477 | txcmplq_cnt); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14478 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14479 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14480 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14481 | /* Save off the slow-path queue event for work thread to process */ |
| 14482 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14483 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14484 | list_add_tail(&irspiocbq->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14485 | &phba->sli4_hba.sp_queue_event); |
| 14486 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14487 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14488 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14489 | return true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14490 | } |
| 14491 | |
| 14492 | /** |
| 14493 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event |
| 14494 | * @phba: Pointer to HBA context object. |
| 14495 | * @wcqe: Pointer to work-queue completion queue entry. |
| 14496 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 14497 | * This routine handles slow-path WQ entry consumed event by invoking the |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14498 | * proper WQ release routine to the slow-path WQ. |
| 14499 | **/ |
| 14500 | static void |
| 14501 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, |
| 14502 | struct lpfc_wcqe_release *wcqe) |
| 14503 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14504 | /* sanity check on queue memory */ |
| 14505 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 14506 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14507 | /* Check for the slow-path ELS work queue */ |
| 14508 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) |
| 14509 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, |
| 14510 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 14511 | else |
| 14512 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 14513 | "2579 Slow-path wqe consume event carries " |
| 14514 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", |
| 14515 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), |
| 14516 | phba->sli4_hba.els_wq->queue_id); |
| 14517 | } |
| 14518 | |
| 14519 | /** |
| 14520 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event |
| 14521 | * @phba: Pointer to HBA context object. |
| 14522 | * @cq: Pointer to a WQ completion queue. |
| 14523 | * @wcqe: Pointer to work-queue completion queue entry. |
| 14524 | * |
| 14525 | * This routine handles an XRI abort event. |
| 14526 | * |
| 14527 | * Return: true if work posted to worker thread, otherwise false. |
| 14528 | **/ |
| 14529 | static bool |
| 14530 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, |
| 14531 | struct lpfc_queue *cq, |
| 14532 | struct sli4_wcqe_xri_aborted *wcqe) |
| 14533 | { |
| 14534 | bool workposted = false; |
| 14535 | struct lpfc_cq_event *cq_event; |
| 14536 | unsigned long iflags; |
| 14537 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14538 | switch (cq->subtype) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 14539 | case LPFC_IO: |
| 14540 | lpfc_sli4_io_xri_aborted(phba, wcqe, cq->hdwq); |
| 14541 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 14542 | /* Notify aborted XRI for NVME work queue */ |
| 14543 | if (phba->nvmet_support) |
| 14544 | lpfc_sli4_nvmet_xri_aborted(phba, wcqe); |
| 14545 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 14546 | workposted = false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14547 | break; |
James Smart | 422c4cb | 2017-11-20 16:00:32 -0800 | [diff] [blame] | 14548 | case LPFC_NVME_LS: /* NVME LS uses ELS resources */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14549 | case LPFC_ELS: |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 14550 | cq_event = lpfc_cq_event_setup(phba, wcqe, sizeof(*wcqe)); |
| 14551 | if (!cq_event) { |
| 14552 | workposted = false; |
| 14553 | break; |
| 14554 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 14555 | cq_event->hdwq = cq->hdwq; |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 14556 | spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock, |
| 14557 | iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14558 | list_add_tail(&cq_event->list, |
| 14559 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 14560 | /* Set the els xri abort event flag */ |
| 14561 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 14562 | spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock, |
| 14563 | iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14564 | workposted = true; |
| 14565 | break; |
| 14566 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14567 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 14568 | "0603 Invalid CQ subtype %d: " |
| 14569 | "%08x %08x %08x %08x\n", |
| 14570 | cq->subtype, wcqe->word0, wcqe->parameter, |
| 14571 | wcqe->word2, wcqe->word3); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14572 | workposted = false; |
| 14573 | break; |
| 14574 | } |
| 14575 | return workposted; |
| 14576 | } |
| 14577 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 14578 | #define FC_RCTL_MDS_DIAGS 0xF4 |
| 14579 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14580 | /** |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14581 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14582 | * @phba: Pointer to HBA context object. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14583 | * @rcqe: Pointer to receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14584 | * |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14585 | * This routine process a receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14586 | * |
| 14587 | * Return: true if work posted to worker thread, otherwise false. |
| 14588 | **/ |
| 14589 | static bool |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14590 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
| 14591 | { |
| 14592 | bool workposted = false; |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 14593 | struct fc_frame_header *fc_hdr; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14594 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; |
| 14595 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 14596 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14597 | struct hbq_dmabuf *dma_buf; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14598 | uint32_t status, rq_id; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14599 | unsigned long iflags; |
| 14600 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14601 | /* sanity check on queue memory */ |
| 14602 | if (unlikely(!hrq) || unlikely(!drq)) |
| 14603 | return workposted; |
| 14604 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14605 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 14606 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 14607 | else |
| 14608 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 14609 | if (rq_id != hrq->queue_id) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14610 | goto out; |
| 14611 | |
| 14612 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 14613 | switch (status) { |
| 14614 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14615 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14616 | "2537 Receive Frame Truncated!!\n"); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 14617 | fallthrough; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14618 | case FC_STATUS_RQ_SUCCESS: |
| 14619 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 14620 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14621 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); |
| 14622 | if (!dma_buf) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14623 | hrq->RQ_no_buf_found++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14624 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 14625 | goto out; |
| 14626 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14627 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 14628 | hrq->RQ_buf_posted--; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14629 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14630 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 14631 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 14632 | |
| 14633 | if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS || |
| 14634 | fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) { |
| 14635 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 14636 | /* Handle MDS Loopback frames */ |
Dick Kennedy | 24411fc | 2020-08-03 14:02:25 -0700 | [diff] [blame] | 14637 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 14638 | lpfc_sli4_handle_mds_loopback(phba->pport, |
| 14639 | dma_buf); |
| 14640 | else |
| 14641 | lpfc_in_buf_free(phba, &dma_buf->dbuf); |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 14642 | break; |
| 14643 | } |
| 14644 | |
| 14645 | /* save off the frame for the work thread to process */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14646 | list_add_tail(&dma_buf->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14647 | &phba->sli4_hba.sp_queue_event); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14648 | /* Frame received */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14649 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14650 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 14651 | workposted = true; |
| 14652 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14653 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 14654 | if (phba->nvmet_support) { |
| 14655 | tgtp = phba->targetport->private; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14656 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 14657 | "6402 RQE Error x%x, posted %d err_cnt " |
| 14658 | "%d: %x %x %x\n", |
| 14659 | status, hrq->RQ_buf_posted, |
| 14660 | hrq->RQ_no_posted_buf, |
| 14661 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 14662 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 14663 | atomic_read(&tgtp->xmt_fcp_release)); |
| 14664 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 14665 | fallthrough; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 14666 | |
| 14667 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14668 | hrq->RQ_no_posted_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14669 | /* Post more buffers if possible */ |
| 14670 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 14671 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; |
| 14672 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 14673 | workposted = true; |
| 14674 | break; |
| 14675 | } |
| 14676 | out: |
| 14677 | return workposted; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14678 | } |
| 14679 | |
| 14680 | /** |
| 14681 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry |
| 14682 | * @phba: Pointer to HBA context object. |
| 14683 | * @cq: Pointer to the completion queue. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14684 | * @cqe: Pointer to a completion queue entry. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14685 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 14686 | * 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] | 14687 | * entry. |
| 14688 | * |
| 14689 | * Return: true if work posted to worker thread, otherwise false. |
| 14690 | **/ |
| 14691 | static bool |
| 14692 | 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] | 14693 | struct lpfc_cqe *cqe) |
| 14694 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14695 | struct lpfc_cqe cqevt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14696 | bool workposted = false; |
| 14697 | |
| 14698 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 14699 | lpfc_sli4_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14700 | |
| 14701 | /* Check and process for different type of WCQE and dispatch */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14702 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14703 | case CQE_CODE_COMPL_WQE: |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14704 | /* Process the WQ/RQ complete event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 14705 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 14706 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14707 | (struct lpfc_wcqe_complete *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14708 | break; |
| 14709 | case CQE_CODE_RELEASE_WQE: |
| 14710 | /* Process the WQ release event */ |
| 14711 | lpfc_sli4_sp_handle_rel_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14712 | (struct lpfc_wcqe_release *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14713 | break; |
| 14714 | case CQE_CODE_XRI_ABORTED: |
| 14715 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 14716 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14717 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14718 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14719 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14720 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14721 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14722 | /* Process the RQ event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 14723 | phba->last_completion_time = jiffies; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14724 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14725 | (struct lpfc_rcqe *)&cqevt); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14726 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14727 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14728 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14729 | "0388 Not a valid WCQE code: x%x\n", |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14730 | bf_get(lpfc_cqe_code, &cqevt)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14731 | break; |
| 14732 | } |
| 14733 | return workposted; |
| 14734 | } |
| 14735 | |
| 14736 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14737 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry |
| 14738 | * @phba: Pointer to HBA context object. |
| 14739 | * @eqe: Pointer to fast-path event queue entry. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 14740 | * @speq: Pointer to slow-path event queue. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14741 | * |
| 14742 | * This routine process a event queue entry from the slow-path event queue. |
| 14743 | * It will check the MajorCode and MinorCode to determine this is for a |
| 14744 | * completion event on a completion queue, if not, an error shall be logged |
| 14745 | * and just return. Otherwise, it will get to the corresponding completion |
| 14746 | * queue and process all the entries on that completion queue, rearm the |
| 14747 | * completion queue, and then return. |
| 14748 | * |
| 14749 | **/ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14750 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14751 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 14752 | struct lpfc_queue *speq) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14753 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14754 | struct lpfc_queue *cq = NULL, *childq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14755 | uint16_t cqid; |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 14756 | int ret = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14757 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14758 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14759 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14760 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14761 | list_for_each_entry(childq, &speq->child_list, list) { |
| 14762 | if (childq->queue_id == cqid) { |
| 14763 | cq = childq; |
| 14764 | break; |
| 14765 | } |
| 14766 | } |
| 14767 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 14768 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14769 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 14770 | "0365 Slow-path CQ identifier " |
| 14771 | "(%d) does not exist\n", cqid); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14772 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14773 | } |
| 14774 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14775 | /* Save EQ associated with this CQ */ |
| 14776 | cq->assoc_qp = speq; |
| 14777 | |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 14778 | if (is_kdump_kernel()) |
| 14779 | ret = queue_work(phba->wq, &cq->spwork); |
| 14780 | else |
| 14781 | ret = queue_work_on(cq->chann, phba->wq, &cq->spwork); |
| 14782 | |
| 14783 | if (!ret) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14784 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 14785 | "0390 Cannot schedule queue work " |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14786 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
Bart Van Assche | d6d189c | 2019-03-28 11:06:22 -0700 | [diff] [blame] | 14787 | cqid, cq->queue_id, raw_smp_processor_id()); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14788 | } |
| 14789 | |
| 14790 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14791 | * __lpfc_sli4_process_cq - Process elements of a CQ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14792 | * @phba: Pointer to HBA context object. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14793 | * @cq: Pointer to CQ to be processed |
| 14794 | * @handler: Routine to process each cqe |
| 14795 | * @delay: Pointer to usdelay to set in case of rescheduling of the handler |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 14796 | * @poll_mode: Polling mode we were called from |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14797 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14798 | * This routine processes completion queue entries in a CQ. While a valid |
| 14799 | * queue element is found, the handler is called. During processing checks |
| 14800 | * are made for periodic doorbell writes to let the hardware know of |
| 14801 | * element consumption. |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14802 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14803 | * If the max limit on cqes to process is hit, or there are no more valid |
| 14804 | * entries, the loop stops. If we processed a sufficient number of elements, |
| 14805 | * meaning there is sufficient load, rather than rearming and generating |
| 14806 | * another interrupt, a cq rescheduling delay will be set. A delay of 0 |
| 14807 | * indicates no rescheduling. |
| 14808 | * |
| 14809 | * Returns True if work scheduled, False otherwise. |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14810 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14811 | static bool |
| 14812 | __lpfc_sli4_process_cq(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 14813 | bool (*handler)(struct lpfc_hba *, struct lpfc_queue *, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 14814 | struct lpfc_cqe *), unsigned long *delay, |
| 14815 | enum lpfc_poll_mode poll_mode) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14816 | { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14817 | struct lpfc_cqe *cqe; |
| 14818 | bool workposted = false; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14819 | int count = 0, consumed = 0; |
| 14820 | bool arm = true; |
| 14821 | |
| 14822 | /* default - no reschedule */ |
| 14823 | *delay = 0; |
| 14824 | |
| 14825 | if (cmpxchg(&cq->queue_claimed, 0, 1) != 0) |
| 14826 | goto rearm_and_exit; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14827 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14828 | /* Process all the entries to the CQ */ |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 14829 | cq->q_flag = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14830 | cqe = lpfc_sli4_cq_get(cq); |
| 14831 | while (cqe) { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14832 | workposted |= handler(phba, cq, cqe); |
| 14833 | __lpfc_sli4_consume_cqe(phba, cq, cqe); |
| 14834 | |
| 14835 | consumed++; |
| 14836 | if (!(++count % cq->max_proc_limit)) |
| 14837 | break; |
| 14838 | |
| 14839 | if (!(count % cq->notify_interval)) { |
| 14840 | phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed, |
| 14841 | LPFC_QUEUE_NOARM); |
| 14842 | consumed = 0; |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 14843 | cq->assoc_qp->q_flag |= HBA_EQ_DELAY_CHK; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14844 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14845 | |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 14846 | if (count == LPFC_NVMET_CQ_NOTIFY) |
| 14847 | cq->q_flag |= HBA_NVMET_CQ_NOTIFY; |
| 14848 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14849 | cqe = lpfc_sli4_cq_get(cq); |
| 14850 | } |
| 14851 | if (count >= phba->cfg_cq_poll_threshold) { |
| 14852 | *delay = 1; |
| 14853 | arm = false; |
| 14854 | } |
| 14855 | |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 14856 | /* Note: complete the irq_poll softirq before rearming CQ */ |
| 14857 | if (poll_mode == LPFC_IRQ_POLL) |
| 14858 | irq_poll_complete(&cq->iop); |
| 14859 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14860 | /* Track the max number of CQEs processed in 1 EQ */ |
| 14861 | if (count > cq->CQ_max_cqe) |
| 14862 | cq->CQ_max_cqe = count; |
| 14863 | |
| 14864 | cq->assoc_qp->EQ_cqe_cnt += count; |
| 14865 | |
| 14866 | /* Catch the no cq entry condition */ |
| 14867 | if (unlikely(count == 0)) |
| 14868 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 14869 | "0369 No entry from completion queue " |
| 14870 | "qid=%d\n", cq->queue_id); |
| 14871 | |
Dick Kennedy | 164ba8d | 2020-05-01 14:43:03 -0700 | [diff] [blame] | 14872 | xchg(&cq->queue_claimed, 0); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14873 | |
| 14874 | rearm_and_exit: |
| 14875 | phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed, |
| 14876 | arm ? LPFC_QUEUE_REARM : LPFC_QUEUE_NOARM); |
| 14877 | |
| 14878 | return workposted; |
| 14879 | } |
| 14880 | |
| 14881 | /** |
Lee Jones | 8514e2f | 2021-03-03 14:46:18 +0000 | [diff] [blame] | 14882 | * __lpfc_sli4_sp_process_cq - Process a slow-path event queue entry |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14883 | * @cq: pointer to CQ to process |
| 14884 | * |
| 14885 | * This routine calls the cq processing routine with a handler specific |
| 14886 | * to the type of queue bound to it. |
| 14887 | * |
| 14888 | * The CQ routine returns two values: the first is the calling status, |
| 14889 | * which indicates whether work was queued to the background discovery |
| 14890 | * thread. If true, the routine should wakeup the discovery thread; |
| 14891 | * the second is the delay parameter. If non-zero, rather than rearming |
| 14892 | * the CQ and yet another interrupt, the CQ handler should be queued so |
| 14893 | * that it is processed in a subsequent polling action. The value of |
| 14894 | * the delay indicates when to reschedule it. |
| 14895 | **/ |
| 14896 | static void |
| 14897 | __lpfc_sli4_sp_process_cq(struct lpfc_queue *cq) |
| 14898 | { |
| 14899 | struct lpfc_hba *phba = cq->phba; |
| 14900 | unsigned long delay; |
| 14901 | bool workposted = false; |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 14902 | int ret = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14903 | |
| 14904 | /* Process and rearm the CQ */ |
| 14905 | switch (cq->type) { |
| 14906 | case LPFC_MCQ: |
| 14907 | workposted |= __lpfc_sli4_process_cq(phba, cq, |
| 14908 | lpfc_sli4_sp_handle_mcqe, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 14909 | &delay, LPFC_QUEUE_WORK); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14910 | break; |
| 14911 | case LPFC_WCQ: |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 14912 | if (cq->subtype == LPFC_IO) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14913 | workposted |= __lpfc_sli4_process_cq(phba, cq, |
| 14914 | lpfc_sli4_fp_handle_cqe, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 14915 | &delay, LPFC_QUEUE_WORK); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14916 | else |
| 14917 | workposted |= __lpfc_sli4_process_cq(phba, cq, |
| 14918 | lpfc_sli4_sp_handle_cqe, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 14919 | &delay, LPFC_QUEUE_WORK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14920 | break; |
| 14921 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14922 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14923 | "0370 Invalid completion queue type (%d)\n", |
| 14924 | cq->type); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14925 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14926 | } |
| 14927 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14928 | if (delay) { |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 14929 | if (is_kdump_kernel()) |
| 14930 | ret = queue_delayed_work(phba->wq, &cq->sched_spwork, |
| 14931 | delay); |
| 14932 | else |
| 14933 | ret = queue_delayed_work_on(cq->chann, phba->wq, |
| 14934 | &cq->sched_spwork, delay); |
| 14935 | if (!ret) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14936 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 14937 | "0394 Cannot schedule queue work " |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14938 | "for cqid=%d on CPU %d\n", |
| 14939 | cq->queue_id, cq->chann); |
| 14940 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14941 | |
| 14942 | /* wake up worker thread if there are works to be done */ |
| 14943 | if (workposted) |
| 14944 | lpfc_worker_wake_up(phba); |
| 14945 | } |
| 14946 | |
| 14947 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14948 | * lpfc_sli4_sp_process_cq - slow-path work handler when started by |
| 14949 | * interrupt |
| 14950 | * @work: pointer to work element |
| 14951 | * |
| 14952 | * translates from the work handler and calls the slow-path handler. |
| 14953 | **/ |
| 14954 | static void |
| 14955 | lpfc_sli4_sp_process_cq(struct work_struct *work) |
| 14956 | { |
| 14957 | struct lpfc_queue *cq = container_of(work, struct lpfc_queue, spwork); |
| 14958 | |
| 14959 | __lpfc_sli4_sp_process_cq(cq); |
| 14960 | } |
| 14961 | |
| 14962 | /** |
| 14963 | * lpfc_sli4_dly_sp_process_cq - slow-path work handler when started by timer |
| 14964 | * @work: pointer to work element |
| 14965 | * |
| 14966 | * translates from the work handler and calls the slow-path handler. |
| 14967 | **/ |
| 14968 | static void |
| 14969 | lpfc_sli4_dly_sp_process_cq(struct work_struct *work) |
| 14970 | { |
| 14971 | struct lpfc_queue *cq = container_of(to_delayed_work(work), |
| 14972 | struct lpfc_queue, sched_spwork); |
| 14973 | |
| 14974 | __lpfc_sli4_sp_process_cq(cq); |
| 14975 | } |
| 14976 | |
| 14977 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14978 | * 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] | 14979 | * @phba: Pointer to HBA context object. |
| 14980 | * @cq: Pointer to associated CQ |
| 14981 | * @wcqe: Pointer to work-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14982 | * |
| 14983 | * This routine process a fast-path work queue completion entry from fast-path |
| 14984 | * event queue for FCP command response completion. |
| 14985 | **/ |
| 14986 | static void |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 14987 | 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] | 14988 | struct lpfc_wcqe_complete *wcqe) |
| 14989 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 14990 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14991 | struct lpfc_iocbq *cmdiocbq; |
| 14992 | struct lpfc_iocbq irspiocbq; |
| 14993 | unsigned long iflags; |
| 14994 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14995 | /* Check for response status */ |
| 14996 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 14997 | /* If resource errors reported from HBA, reduce queue |
| 14998 | * depth of the SCSI device. |
| 14999 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 15000 | if (((bf_get(lpfc_wcqe_c_status, wcqe) == |
| 15001 | IOSTAT_LOCAL_REJECT)) && |
| 15002 | ((wcqe->parameter & IOERR_PARAM_MASK) == |
| 15003 | IOERR_NO_RESOURCES)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15004 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 15005 | |
Dick Kennedy | 28ed737 | 2020-06-30 14:49:56 -0700 | [diff] [blame] | 15006 | /* Log the cmpl status */ |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 15007 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
Dick Kennedy | 28ed737 | 2020-06-30 14:49:56 -0700 | [diff] [blame] | 15008 | "0373 FCP CQE cmpl: status=x%x: " |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 15009 | "CQE: %08x %08x %08x %08x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15010 | bf_get(lpfc_wcqe_c_status, wcqe), |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 15011 | wcqe->word0, wcqe->total_data_placed, |
| 15012 | wcqe->parameter, wcqe->word3); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15013 | } |
| 15014 | |
| 15015 | /* Look up the FCP command IOCB and create pseudo response IOCB */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 15016 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 15017 | pring->stats.iocb_event++; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 15018 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15019 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 15020 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15021 | if (unlikely(!cmdiocbq)) { |
| 15022 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 15023 | "0374 FCP complete with no corresponding " |
| 15024 | "cmdiocb: iotag (%d)\n", |
| 15025 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 15026 | return; |
| 15027 | } |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 15028 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 15029 | cmdiocbq->isr_timestamp = cq->isr_timestamp; |
| 15030 | #endif |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15031 | if (cmdiocbq->iocb_cmpl == NULL) { |
| 15032 | if (cmdiocbq->wqe_cmpl) { |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 15033 | /* For FCP the flag is cleared in wqe_cmpl */ |
| 15034 | if (!(cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 15035 | cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15036 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 15037 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 15038 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 15039 | } |
| 15040 | |
| 15041 | /* Pass the cmd_iocb and the wcqe to the upper layer */ |
| 15042 | (cmdiocbq->wqe_cmpl)(phba, cmdiocbq, wcqe); |
| 15043 | return; |
| 15044 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15045 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 15046 | "0375 FCP cmdiocb not callback function " |
| 15047 | "iotag: (%d)\n", |
| 15048 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 15049 | return; |
| 15050 | } |
| 15051 | |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 15052 | /* Only SLI4 non-IO commands stil use IOCB */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15053 | /* Fake the irspiocb and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 15054 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15055 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 15056 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 15057 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 15058 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 15059 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 15060 | } |
| 15061 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15062 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
| 15063 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); |
| 15064 | } |
| 15065 | |
| 15066 | /** |
| 15067 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event |
| 15068 | * @phba: Pointer to HBA context object. |
| 15069 | * @cq: Pointer to completion queue. |
| 15070 | * @wcqe: Pointer to work-queue completion queue entry. |
| 15071 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 15072 | * 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] | 15073 | * proper WQ release routine to the slow-path WQ. |
| 15074 | **/ |
| 15075 | static void |
| 15076 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 15077 | struct lpfc_wcqe_release *wcqe) |
| 15078 | { |
| 15079 | struct lpfc_queue *childwq; |
| 15080 | bool wqid_matched = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15081 | uint16_t hba_wqid; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15082 | |
| 15083 | /* Check for fast-path FCP work queue release */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15084 | hba_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15085 | list_for_each_entry(childwq, &cq->child_list, list) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15086 | if (childwq->queue_id == hba_wqid) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15087 | lpfc_sli4_wq_release(childwq, |
| 15088 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
James Smart | 6e8e1c1 | 2018-01-30 15:58:49 -0800 | [diff] [blame] | 15089 | if (childwq->q_flag & HBA_NVMET_WQFULL) |
| 15090 | lpfc_nvmet_wqfull_process(phba, childwq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15091 | wqid_matched = true; |
| 15092 | break; |
| 15093 | } |
| 15094 | } |
| 15095 | /* Report warning log message if no match found */ |
| 15096 | if (wqid_matched != true) |
| 15097 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 15098 | "2580 Fast-path wqe consume event carries " |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15099 | "miss-matched qid: wcqe-qid=x%x\n", hba_wqid); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15100 | } |
| 15101 | |
| 15102 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15103 | * lpfc_sli4_nvmet_handle_rcqe - Process a receive-queue completion queue entry |
| 15104 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 15105 | * @cq: Pointer to completion queue. |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15106 | * @rcqe: Pointer to receive-queue completion queue entry. |
| 15107 | * |
| 15108 | * This routine process a receive-queue completion queue entry. |
| 15109 | * |
| 15110 | * Return: true if work posted to worker thread, otherwise false. |
| 15111 | **/ |
| 15112 | static bool |
| 15113 | lpfc_sli4_nvmet_handle_rcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 15114 | struct lpfc_rcqe *rcqe) |
| 15115 | { |
| 15116 | bool workposted = false; |
| 15117 | struct lpfc_queue *hrq; |
| 15118 | struct lpfc_queue *drq; |
| 15119 | struct rqb_dmabuf *dma_buf; |
| 15120 | struct fc_frame_header *fc_hdr; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 15121 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15122 | uint32_t status, rq_id; |
| 15123 | unsigned long iflags; |
| 15124 | uint32_t fctl, idx; |
| 15125 | |
| 15126 | if ((phba->nvmet_support == 0) || |
| 15127 | (phba->sli4_hba.nvmet_cqset == NULL)) |
| 15128 | return workposted; |
| 15129 | |
| 15130 | idx = cq->queue_id - phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 15131 | hrq = phba->sli4_hba.nvmet_mrq_hdr[idx]; |
| 15132 | drq = phba->sli4_hba.nvmet_mrq_data[idx]; |
| 15133 | |
| 15134 | /* sanity check on queue memory */ |
| 15135 | if (unlikely(!hrq) || unlikely(!drq)) |
| 15136 | return workposted; |
| 15137 | |
| 15138 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 15139 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 15140 | else |
| 15141 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 15142 | |
| 15143 | if ((phba->nvmet_support == 0) || |
| 15144 | (rq_id != hrq->queue_id)) |
| 15145 | return workposted; |
| 15146 | |
| 15147 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 15148 | switch (status) { |
| 15149 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15150 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15151 | "6126 Receive Frame Truncated!!\n"); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 15152 | fallthrough; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15153 | case FC_STATUS_RQ_SUCCESS: |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15154 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 15155 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15156 | dma_buf = lpfc_sli_rqbuf_get(phba, hrq); |
| 15157 | if (!dma_buf) { |
| 15158 | hrq->RQ_no_buf_found++; |
| 15159 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 15160 | goto out; |
| 15161 | } |
| 15162 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 15163 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 15164 | hrq->RQ_buf_posted--; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15165 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 15166 | |
| 15167 | /* Just some basic sanity checks on FCP Command frame */ |
| 15168 | fctl = (fc_hdr->fh_f_ctl[0] << 16 | |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 15169 | fc_hdr->fh_f_ctl[1] << 8 | |
| 15170 | fc_hdr->fh_f_ctl[2]); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15171 | if (((fctl & |
| 15172 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) != |
| 15173 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) || |
| 15174 | (fc_hdr->fh_seq_cnt != 0)) /* 0 byte swapped is still 0 */ |
| 15175 | goto drop; |
| 15176 | |
| 15177 | if (fc_hdr->fh_type == FC_TYPE_FCP) { |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 15178 | dma_buf->bytes_recv = bf_get(lpfc_rcqe_length, rcqe); |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 15179 | lpfc_nvmet_unsol_fcp_event( |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 15180 | phba, idx, dma_buf, cq->isr_timestamp, |
| 15181 | cq->q_flag & HBA_NVMET_CQ_NOTIFY); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15182 | return false; |
| 15183 | } |
| 15184 | drop: |
James Smart | 22b738a | 2019-03-12 16:30:11 -0700 | [diff] [blame] | 15185 | lpfc_rq_buf_free(phba, &dma_buf->hbuf); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15186 | break; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15187 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 15188 | if (phba->nvmet_support) { |
| 15189 | tgtp = phba->targetport->private; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15190 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 15191 | "6401 RQE Error x%x, posted %d err_cnt " |
| 15192 | "%d: %x %x %x\n", |
| 15193 | status, hrq->RQ_buf_posted, |
| 15194 | hrq->RQ_no_posted_buf, |
| 15195 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 15196 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 15197 | atomic_read(&tgtp->xmt_fcp_release)); |
| 15198 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 15199 | fallthrough; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 15200 | |
| 15201 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15202 | hrq->RQ_no_posted_buf++; |
| 15203 | /* Post more buffers if possible */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15204 | break; |
| 15205 | } |
| 15206 | out: |
| 15207 | return workposted; |
| 15208 | } |
| 15209 | |
| 15210 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15211 | * lpfc_sli4_fp_handle_cqe - Process fast-path work queue completion entry |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15212 | * @phba: adapter with cq |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15213 | * @cq: Pointer to the completion queue. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 15214 | * @cqe: Pointer to fast-path completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15215 | * |
| 15216 | * This routine process a fast-path work queue completion entry from fast-path |
| 15217 | * event queue for FCP command response completion. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15218 | * |
| 15219 | * Return: true if work posted to worker thread, otherwise false. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15220 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15221 | static bool |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15222 | 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] | 15223 | struct lpfc_cqe *cqe) |
| 15224 | { |
| 15225 | struct lpfc_wcqe_release wcqe; |
| 15226 | bool workposted = false; |
| 15227 | |
| 15228 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 15229 | lpfc_sli4_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15230 | |
| 15231 | /* Check and process for different type of WCQE and dispatch */ |
| 15232 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { |
| 15233 | case CQE_CODE_COMPL_WQE: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15234 | case CQE_CODE_NVME_ERSP: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 15235 | cq->CQ_wq++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15236 | /* Process the WQ complete event */ |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 15237 | phba->last_completion_time = jiffies; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 15238 | if (cq->subtype == LPFC_IO || cq->subtype == LPFC_NVME_LS) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15239 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15240 | (struct lpfc_wcqe_complete *)&wcqe); |
| 15241 | break; |
| 15242 | case CQE_CODE_RELEASE_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 15243 | cq->CQ_release_wqe++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15244 | /* Process the WQ release event */ |
| 15245 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, |
| 15246 | (struct lpfc_wcqe_release *)&wcqe); |
| 15247 | break; |
| 15248 | case CQE_CODE_XRI_ABORTED: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 15249 | cq->CQ_xri_aborted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15250 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 15251 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15252 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
| 15253 | (struct sli4_wcqe_xri_aborted *)&wcqe); |
| 15254 | break; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15255 | case CQE_CODE_RECEIVE_V1: |
| 15256 | case CQE_CODE_RECEIVE: |
| 15257 | phba->last_completion_time = jiffies; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15258 | if (cq->subtype == LPFC_NVMET) { |
| 15259 | workposted = lpfc_sli4_nvmet_handle_rcqe( |
| 15260 | phba, cq, (struct lpfc_rcqe *)&wcqe); |
| 15261 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15262 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15263 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15264 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15265 | "0144 Not a valid CQE code: x%x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15266 | bf_get(lpfc_wcqe_c_code, &wcqe)); |
| 15267 | break; |
| 15268 | } |
| 15269 | return workposted; |
| 15270 | } |
| 15271 | |
| 15272 | /** |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 15273 | * lpfc_sli4_sched_cq_work - Schedules cq work |
| 15274 | * @phba: Pointer to HBA context object. |
| 15275 | * @cq: Pointer to CQ |
| 15276 | * @cqid: CQ ID |
| 15277 | * |
| 15278 | * This routine checks the poll mode of the CQ corresponding to |
| 15279 | * cq->chann, then either schedules a softirq or queue_work to complete |
| 15280 | * cq work. |
| 15281 | * |
| 15282 | * queue_work path is taken if in NVMET mode, or if poll_mode is in |
| 15283 | * LPFC_QUEUE_WORK mode. Otherwise, softirq path is taken. |
| 15284 | * |
| 15285 | **/ |
| 15286 | static void lpfc_sli4_sched_cq_work(struct lpfc_hba *phba, |
| 15287 | struct lpfc_queue *cq, uint16_t cqid) |
| 15288 | { |
| 15289 | int ret = 0; |
| 15290 | |
| 15291 | switch (cq->poll_mode) { |
| 15292 | case LPFC_IRQ_POLL: |
James Smart | 9064aeb | 2021-08-16 09:28:50 -0700 | [diff] [blame] | 15293 | /* CGN mgmt is mutually exclusive from softirq processing */ |
| 15294 | if (phba->cmf_active_mode == LPFC_CFG_OFF) { |
| 15295 | irq_poll_sched(&cq->iop); |
| 15296 | break; |
| 15297 | } |
| 15298 | fallthrough; |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 15299 | case LPFC_QUEUE_WORK: |
| 15300 | default: |
| 15301 | if (is_kdump_kernel()) |
| 15302 | ret = queue_work(phba->wq, &cq->irqwork); |
| 15303 | else |
| 15304 | ret = queue_work_on(cq->chann, phba->wq, &cq->irqwork); |
| 15305 | if (!ret) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15306 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 15307 | "0383 Cannot schedule queue work " |
| 15308 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
| 15309 | cqid, cq->queue_id, |
| 15310 | raw_smp_processor_id()); |
| 15311 | } |
| 15312 | } |
| 15313 | |
| 15314 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 15315 | * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15316 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 15317 | * @eq: Pointer to the queue structure. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15318 | * @eqe: Pointer to fast-path event queue entry. |
| 15319 | * |
| 15320 | * This routine process a event queue entry from the fast-path event queue. |
| 15321 | * It will check the MajorCode and MinorCode to determine this is for a |
| 15322 | * completion event on a completion queue, if not, an error shall be logged |
| 15323 | * and just return. Otherwise, it will get to the corresponding completion |
| 15324 | * queue and process all the entries on the completion queue, rearm the |
| 15325 | * completion queue, and then return. |
| 15326 | **/ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 15327 | static void |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15328 | lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_queue *eq, |
| 15329 | struct lpfc_eqe *eqe) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15330 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15331 | struct lpfc_queue *cq = NULL; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15332 | uint32_t qidx = eq->hdwq; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15333 | uint16_t cqid, id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15334 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 15335 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15336 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 15337 | "0366 Not a valid completion " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15338 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 15339 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 15340 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 15341 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15342 | } |
| 15343 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 15344 | /* Get the reference to the corresponding CQ */ |
| 15345 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 15346 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15347 | /* Use the fast lookup method first */ |
| 15348 | if (cqid <= phba->sli4_hba.cq_max) { |
| 15349 | cq = phba->sli4_hba.cq_lookup[cqid]; |
| 15350 | if (cq) |
| 15351 | goto work_cq; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 15352 | } |
| 15353 | |
| 15354 | /* Next check for NVMET completion */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15355 | if (phba->cfg_nvmet_mrq && phba->sli4_hba.nvmet_cqset) { |
| 15356 | id = phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 15357 | if ((cqid >= id) && (cqid < (id + phba->cfg_nvmet_mrq))) { |
| 15358 | /* Process NVMET unsol rcv */ |
| 15359 | cq = phba->sli4_hba.nvmet_cqset[cqid - id]; |
| 15360 | goto process_cq; |
| 15361 | } |
| 15362 | } |
| 15363 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15364 | if (phba->sli4_hba.nvmels_cq && |
| 15365 | (cqid == phba->sli4_hba.nvmels_cq->queue_id)) { |
| 15366 | /* Process NVME unsol rcv */ |
| 15367 | cq = phba->sli4_hba.nvmels_cq; |
| 15368 | } |
| 15369 | |
| 15370 | /* Otherwise this is a Slow path event */ |
| 15371 | if (cq == NULL) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 15372 | lpfc_sli4_sp_handle_eqe(phba, eqe, |
| 15373 | phba->sli4_hba.hdwq[qidx].hba_eq); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 15374 | return; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 15375 | } |
| 15376 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15377 | process_cq: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15378 | if (unlikely(cqid != cq->queue_id)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15379 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15380 | "0368 Miss-matched fast-path completion " |
| 15381 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", |
| 15382 | cqid, cq->queue_id); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 15383 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15384 | } |
| 15385 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15386 | work_cq: |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 15387 | #if defined(CONFIG_SCSI_LPFC_DEBUG_FS) |
| 15388 | if (phba->ktime_on) |
| 15389 | cq->isr_timestamp = ktime_get_ns(); |
| 15390 | else |
| 15391 | cq->isr_timestamp = 0; |
| 15392 | #endif |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 15393 | lpfc_sli4_sched_cq_work(phba, cq, cqid); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 15394 | } |
| 15395 | |
| 15396 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15397 | * __lpfc_sli4_hba_process_cq - Process a fast-path event queue entry |
| 15398 | * @cq: Pointer to CQ to be processed |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 15399 | * @poll_mode: Enum lpfc_poll_state to determine poll mode |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 15400 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15401 | * This routine calls the cq processing routine with the handler for |
| 15402 | * fast path CQEs. |
| 15403 | * |
| 15404 | * The CQ routine returns two values: the first is the calling status, |
| 15405 | * which indicates whether work was queued to the background discovery |
| 15406 | * thread. If true, the routine should wakeup the discovery thread; |
| 15407 | * the second is the delay parameter. If non-zero, rather than rearming |
| 15408 | * the CQ and yet another interrupt, the CQ handler should be queued so |
| 15409 | * that it is processed in a subsequent polling action. The value of |
| 15410 | * the delay indicates when to reschedule it. |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 15411 | **/ |
| 15412 | static void |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 15413 | __lpfc_sli4_hba_process_cq(struct lpfc_queue *cq, |
| 15414 | enum lpfc_poll_mode poll_mode) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 15415 | { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 15416 | struct lpfc_hba *phba = cq->phba; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15417 | unsigned long delay; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 15418 | bool workposted = false; |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 15419 | int ret = 0; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 15420 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15421 | /* process and rearm the CQ */ |
| 15422 | workposted |= __lpfc_sli4_process_cq(phba, cq, lpfc_sli4_fp_handle_cqe, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 15423 | &delay, poll_mode); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15424 | |
| 15425 | if (delay) { |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 15426 | if (is_kdump_kernel()) |
| 15427 | ret = queue_delayed_work(phba->wq, &cq->sched_irqwork, |
| 15428 | delay); |
| 15429 | else |
| 15430 | ret = queue_delayed_work_on(cq->chann, phba->wq, |
| 15431 | &cq->sched_irqwork, delay); |
| 15432 | if (!ret) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15433 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 15434 | "0367 Cannot schedule queue work " |
| 15435 | "for cqid=%d on CPU %d\n", |
| 15436 | cq->queue_id, cq->chann); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15437 | } |
| 15438 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15439 | /* wake up worker thread if there are works to be done */ |
| 15440 | if (workposted) |
| 15441 | lpfc_worker_wake_up(phba); |
| 15442 | } |
| 15443 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 15444 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15445 | * lpfc_sli4_hba_process_cq - fast-path work handler when started by |
| 15446 | * interrupt |
| 15447 | * @work: pointer to work element |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 15448 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15449 | * translates from the work handler and calls the fast-path handler. |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 15450 | **/ |
| 15451 | static void |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15452 | lpfc_sli4_hba_process_cq(struct work_struct *work) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 15453 | { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15454 | struct lpfc_queue *cq = container_of(work, struct lpfc_queue, irqwork); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 15455 | |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 15456 | __lpfc_sli4_hba_process_cq(cq, LPFC_QUEUE_WORK); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 15457 | } |
| 15458 | |
| 15459 | /** |
Lee Jones | 8514e2f | 2021-03-03 14:46:18 +0000 | [diff] [blame] | 15460 | * lpfc_sli4_dly_hba_process_cq - fast-path work handler when started by timer |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15461 | * @work: pointer to work element |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 15462 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15463 | * translates from the work handler and calls the fast-path handler. |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 15464 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15465 | static void |
| 15466 | lpfc_sli4_dly_hba_process_cq(struct work_struct *work) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 15467 | { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15468 | struct lpfc_queue *cq = container_of(to_delayed_work(work), |
| 15469 | struct lpfc_queue, sched_irqwork); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 15470 | |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 15471 | __lpfc_sli4_hba_process_cq(cq, LPFC_QUEUE_WORK); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 15472 | } |
| 15473 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15474 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 15475 | * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15476 | * @irq: Interrupt number. |
| 15477 | * @dev_id: The device context pointer. |
| 15478 | * |
| 15479 | * This function is directly called from the PCI layer as an interrupt |
| 15480 | * service routine when device with SLI-4 interface spec is enabled with |
| 15481 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 15482 | * ring event in the HBA. However, when the device is enabled with either |
| 15483 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 15484 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 15485 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 15486 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 15487 | * the intrrupt context. This function is called without any lock held. |
| 15488 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 15489 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is |
| 15490 | * equal to that of FCP CQ index. |
| 15491 | * |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 15492 | * The link attention and ELS ring attention events are handled |
| 15493 | * by the worker thread. The interrupt handler signals the worker thread |
| 15494 | * and returns for these events. This function is called without any lock |
| 15495 | * held. It gets the hbalock to access and update SLI data structures. |
| 15496 | * |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15497 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 15498 | * returns IRQ_NONE. |
| 15499 | **/ |
| 15500 | irqreturn_t |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 15501 | lpfc_sli4_hba_intr_handler(int irq, void *dev_id) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15502 | { |
| 15503 | struct lpfc_hba *phba; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15504 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15505 | struct lpfc_queue *fpeq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15506 | unsigned long iflag; |
| 15507 | int ecount = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15508 | int hba_eqidx; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15509 | struct lpfc_eq_intr_info *eqi; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15510 | |
| 15511 | /* Get the driver's phba structure from the dev_id */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15512 | hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id; |
| 15513 | phba = hba_eq_hdl->phba; |
| 15514 | hba_eqidx = hba_eq_hdl->idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15515 | |
| 15516 | if (unlikely(!phba)) |
| 15517 | return IRQ_NONE; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 15518 | if (unlikely(!phba->sli4_hba.hdwq)) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 15519 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15520 | |
| 15521 | /* Get to the EQ struct associated with this vector */ |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 15522 | fpeq = phba->sli4_hba.hba_eq_hdl[hba_eqidx].eq; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15523 | if (unlikely(!fpeq)) |
| 15524 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15525 | |
| 15526 | /* Check device state for handling interrupt */ |
| 15527 | if (unlikely(lpfc_intr_state_check(phba))) { |
| 15528 | /* Check again for link_state with lock held */ |
| 15529 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 15530 | if (phba->link_state < LPFC_LINK_DOWN) |
| 15531 | /* Flush, clear interrupt, and rearm the EQ */ |
James Smart | 24c7c0a | 2019-09-21 20:58:58 -0700 | [diff] [blame] | 15532 | lpfc_sli4_eqcq_flush(phba, fpeq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15533 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 15534 | return IRQ_NONE; |
| 15535 | } |
| 15536 | |
Dick Kennedy | a7fc071 | 2020-05-01 14:43:08 -0700 | [diff] [blame] | 15537 | eqi = this_cpu_ptr(phba->sli4_hba.eq_info); |
| 15538 | eqi->icnt++; |
| 15539 | |
Bart Van Assche | d6d189c | 2019-03-28 11:06:22 -0700 | [diff] [blame] | 15540 | fpeq->last_cpu = raw_smp_processor_id(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15541 | |
Dick Kennedy | a7fc071 | 2020-05-01 14:43:08 -0700 | [diff] [blame] | 15542 | if (eqi->icnt > LPFC_EQD_ISR_TRIGGER && |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 15543 | fpeq->q_flag & HBA_EQ_DELAY_CHK && |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15544 | phba->cfg_auto_imax && |
| 15545 | fpeq->q_mode != LPFC_MAX_AUTO_EQ_DELAY && |
| 15546 | phba->sli.sli_flag & LPFC_SLI_USE_EQDR) |
| 15547 | 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] | 15548 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15549 | /* process and rearm the EQ */ |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 15550 | ecount = lpfc_sli4_process_eq(phba, fpeq, LPFC_QUEUE_REARM); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15551 | |
| 15552 | if (unlikely(ecount == 0)) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 15553 | fpeq->EQ_no_entry++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15554 | if (phba->intr_type == MSIX) |
| 15555 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 15556 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 15557 | "0358 MSI-X interrupt with no EQE\n"); |
| 15558 | else |
| 15559 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 15560 | return IRQ_NONE; |
| 15561 | } |
| 15562 | |
| 15563 | return IRQ_HANDLED; |
James Smart | 3bfab8a | 2021-04-11 18:31:23 -0700 | [diff] [blame] | 15564 | } /* lpfc_sli4_hba_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15565 | |
| 15566 | /** |
| 15567 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device |
| 15568 | * @irq: Interrupt number. |
| 15569 | * @dev_id: The device context pointer. |
| 15570 | * |
| 15571 | * This function is the device-level interrupt handler to device with SLI-4 |
| 15572 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ |
| 15573 | * interrupt mode is enabled and there is an event in the HBA which requires |
| 15574 | * driver attention. This function invokes the slow-path interrupt attention |
| 15575 | * handling function and fast-path interrupt attention handling function in |
| 15576 | * turn to process the relevant HBA attention events. This function is called |
| 15577 | * without any lock held. It gets the hbalock to access and update SLI data |
| 15578 | * structures. |
| 15579 | * |
| 15580 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 15581 | * returns IRQ_NONE. |
| 15582 | **/ |
| 15583 | irqreturn_t |
| 15584 | lpfc_sli4_intr_handler(int irq, void *dev_id) |
| 15585 | { |
| 15586 | struct lpfc_hba *phba; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 15587 | irqreturn_t hba_irq_rc; |
| 15588 | bool hba_handled = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15589 | int qidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15590 | |
| 15591 | /* Get the driver's phba structure from the dev_id */ |
| 15592 | phba = (struct lpfc_hba *)dev_id; |
| 15593 | |
| 15594 | if (unlikely(!phba)) |
| 15595 | return IRQ_NONE; |
| 15596 | |
| 15597 | /* |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15598 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 15599 | */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15600 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 15601 | hba_irq_rc = lpfc_sli4_hba_intr_handler(irq, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15602 | &phba->sli4_hba.hba_eq_hdl[qidx]); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 15603 | if (hba_irq_rc == IRQ_HANDLED) |
| 15604 | hba_handled |= true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15605 | } |
| 15606 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 15607 | return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15608 | } /* lpfc_sli4_intr_handler */ |
| 15609 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 15610 | void lpfc_sli4_poll_hbtimer(struct timer_list *t) |
| 15611 | { |
| 15612 | struct lpfc_hba *phba = from_timer(phba, t, cpuhp_poll_timer); |
| 15613 | struct lpfc_queue *eq; |
| 15614 | int i = 0; |
| 15615 | |
| 15616 | rcu_read_lock(); |
| 15617 | |
| 15618 | list_for_each_entry_rcu(eq, &phba->poll_list, _poll_list) |
| 15619 | i += lpfc_sli4_poll_eq(eq, LPFC_POLL_SLOWPATH); |
| 15620 | if (!list_empty(&phba->poll_list)) |
| 15621 | mod_timer(&phba->cpuhp_poll_timer, |
| 15622 | jiffies + msecs_to_jiffies(LPFC_POLL_HB)); |
| 15623 | |
| 15624 | rcu_read_unlock(); |
| 15625 | } |
| 15626 | |
| 15627 | inline int lpfc_sli4_poll_eq(struct lpfc_queue *eq, uint8_t path) |
| 15628 | { |
| 15629 | struct lpfc_hba *phba = eq->phba; |
| 15630 | int i = 0; |
| 15631 | |
| 15632 | /* |
| 15633 | * Unlocking an irq is one of the entry point to check |
| 15634 | * for re-schedule, but we are good for io submission |
| 15635 | * path as midlayer does a get_cpu to glue us in. Flush |
| 15636 | * out the invalidate queue so we can see the updated |
| 15637 | * value for flag. |
| 15638 | */ |
| 15639 | smp_rmb(); |
| 15640 | |
| 15641 | if (READ_ONCE(eq->mode) == LPFC_EQ_POLL) |
| 15642 | /* We will not likely get the completion for the caller |
| 15643 | * during this iteration but i guess that's fine. |
| 15644 | * Future io's coming on this eq should be able to |
| 15645 | * pick it up. As for the case of single io's, they |
| 15646 | * will be handled through a sched from polling timer |
| 15647 | * function which is currently triggered every 1msec. |
| 15648 | */ |
| 15649 | i = lpfc_sli4_process_eq(phba, eq, LPFC_QUEUE_NOARM); |
| 15650 | |
| 15651 | return i; |
| 15652 | } |
| 15653 | |
| 15654 | static inline void lpfc_sli4_add_to_poll_list(struct lpfc_queue *eq) |
| 15655 | { |
| 15656 | struct lpfc_hba *phba = eq->phba; |
| 15657 | |
James Smart | f861f59 | 2020-03-22 11:12:54 -0700 | [diff] [blame] | 15658 | /* kickstart slowpath processing if needed */ |
| 15659 | if (list_empty(&phba->poll_list)) |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 15660 | mod_timer(&phba->cpuhp_poll_timer, |
| 15661 | jiffies + msecs_to_jiffies(LPFC_POLL_HB)); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 15662 | |
| 15663 | list_add_rcu(&eq->_poll_list, &phba->poll_list); |
| 15664 | synchronize_rcu(); |
| 15665 | } |
| 15666 | |
| 15667 | static inline void lpfc_sli4_remove_from_poll_list(struct lpfc_queue *eq) |
| 15668 | { |
| 15669 | struct lpfc_hba *phba = eq->phba; |
| 15670 | |
| 15671 | /* Disable slowpath processing for this eq. Kick start the eq |
| 15672 | * by RE-ARMING the eq's ASAP |
| 15673 | */ |
| 15674 | list_del_rcu(&eq->_poll_list); |
| 15675 | synchronize_rcu(); |
| 15676 | |
| 15677 | if (list_empty(&phba->poll_list)) |
| 15678 | del_timer_sync(&phba->cpuhp_poll_timer); |
| 15679 | } |
| 15680 | |
James Smart | d480e57 | 2019-11-11 15:03:58 -0800 | [diff] [blame] | 15681 | void lpfc_sli4_cleanup_poll_list(struct lpfc_hba *phba) |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 15682 | { |
| 15683 | struct lpfc_queue *eq, *next; |
| 15684 | |
| 15685 | list_for_each_entry_safe(eq, next, &phba->poll_list, _poll_list) |
| 15686 | list_del(&eq->_poll_list); |
| 15687 | |
| 15688 | INIT_LIST_HEAD(&phba->poll_list); |
| 15689 | synchronize_rcu(); |
| 15690 | } |
| 15691 | |
| 15692 | static inline void |
| 15693 | __lpfc_sli4_switch_eqmode(struct lpfc_queue *eq, uint8_t mode) |
| 15694 | { |
| 15695 | if (mode == eq->mode) |
| 15696 | return; |
| 15697 | /* |
| 15698 | * currently this function is only called during a hotplug |
| 15699 | * event and the cpu on which this function is executing |
| 15700 | * is going offline. By now the hotplug has instructed |
| 15701 | * the scheduler to remove this cpu from cpu active mask. |
| 15702 | * So we don't need to work about being put aside by the |
| 15703 | * scheduler for a high priority process. Yes, the inte- |
| 15704 | * rrupts could come but they are known to retire ASAP. |
| 15705 | */ |
| 15706 | |
| 15707 | /* Disable polling in the fastpath */ |
| 15708 | WRITE_ONCE(eq->mode, mode); |
| 15709 | /* flush out the store buffer */ |
| 15710 | smp_wmb(); |
| 15711 | |
| 15712 | /* |
| 15713 | * Add this eq to the polling list and start polling. For |
| 15714 | * a grace period both interrupt handler and poller will |
| 15715 | * try to process the eq _but_ that's fine. We have a |
| 15716 | * synchronization mechanism in place (queue_claimed) to |
| 15717 | * deal with it. This is just a draining phase for int- |
| 15718 | * errupt handler (not eq's) as we have guranteed through |
| 15719 | * barrier that all the CPUs have seen the new CQ_POLLED |
| 15720 | * state. which will effectively disable the REARMING of |
| 15721 | * the EQ. The whole idea is eq's die off eventually as |
| 15722 | * we are not rearming EQ's anymore. |
| 15723 | */ |
| 15724 | mode ? lpfc_sli4_add_to_poll_list(eq) : |
| 15725 | lpfc_sli4_remove_from_poll_list(eq); |
| 15726 | } |
| 15727 | |
| 15728 | void lpfc_sli4_start_polling(struct lpfc_queue *eq) |
| 15729 | { |
| 15730 | __lpfc_sli4_switch_eqmode(eq, LPFC_EQ_POLL); |
| 15731 | } |
| 15732 | |
| 15733 | void lpfc_sli4_stop_polling(struct lpfc_queue *eq) |
| 15734 | { |
| 15735 | struct lpfc_hba *phba = eq->phba; |
| 15736 | |
| 15737 | __lpfc_sli4_switch_eqmode(eq, LPFC_EQ_INTERRUPT); |
| 15738 | |
| 15739 | /* Kick start for the pending io's in h/w. |
| 15740 | * Once we switch back to interrupt processing on a eq |
| 15741 | * the io path completion will only arm eq's when it |
| 15742 | * receives a completion. But since eq's are in disa- |
| 15743 | * rmed state it doesn't receive a completion. This |
| 15744 | * creates a deadlock scenaro. |
| 15745 | */ |
| 15746 | phba->sli4_hba.sli4_write_eq_db(phba, eq, 0, LPFC_QUEUE_REARM); |
| 15747 | } |
| 15748 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15749 | /** |
| 15750 | * lpfc_sli4_queue_free - free a queue structure and associated memory |
| 15751 | * @queue: The queue structure to free. |
| 15752 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 15753 | * This function frees a queue structure and the DMAable memory used for |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15754 | * the host resident queue. This function must be called after destroying the |
| 15755 | * queue on the HBA. |
| 15756 | **/ |
| 15757 | void |
| 15758 | lpfc_sli4_queue_free(struct lpfc_queue *queue) |
| 15759 | { |
| 15760 | struct lpfc_dmabuf *dmabuf; |
| 15761 | |
| 15762 | if (!queue) |
| 15763 | return; |
| 15764 | |
James Smart | 4645f7b | 2019-03-12 16:30:14 -0700 | [diff] [blame] | 15765 | if (!list_empty(&queue->wq_list)) |
| 15766 | list_del(&queue->wq_list); |
| 15767 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15768 | while (!list_empty(&queue->page_list)) { |
| 15769 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, |
| 15770 | list); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15771 | dma_free_coherent(&queue->phba->pcidev->dev, queue->page_size, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15772 | dmabuf->virt, dmabuf->phys); |
| 15773 | kfree(dmabuf); |
| 15774 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15775 | if (queue->rqbp) { |
| 15776 | lpfc_free_rq_buffer(queue->phba, queue); |
| 15777 | kfree(queue->rqbp); |
| 15778 | } |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 15779 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15780 | if (!list_empty(&queue->cpu_list)) |
| 15781 | list_del(&queue->cpu_list); |
| 15782 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15783 | kfree(queue); |
| 15784 | return; |
| 15785 | } |
| 15786 | |
| 15787 | /** |
| 15788 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure |
| 15789 | * @phba: The HBA that this queue is being created on. |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15790 | * @page_size: The size of a queue page |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15791 | * @entry_size: The size of each queue entry for this queue. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 15792 | * @entry_count: The number of entries that this queue will handle. |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 15793 | * @cpu: The cpu that will primarily utilize this queue. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15794 | * |
| 15795 | * This function allocates a queue structure and the DMAable memory used for |
| 15796 | * the host resident queue. This function must be called before creating the |
| 15797 | * queue on the HBA. |
| 15798 | **/ |
| 15799 | struct lpfc_queue * |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15800 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t page_size, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 15801 | uint32_t entry_size, uint32_t entry_count, int cpu) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15802 | { |
| 15803 | struct lpfc_queue *queue; |
| 15804 | struct lpfc_dmabuf *dmabuf; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 15805 | 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] | 15806 | uint16_t x, pgcnt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15807 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 15808 | if (!phba->sli4_hba.pc_sli4_params.supported) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15809 | hw_page_size = page_size; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 15810 | |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 15811 | pgcnt = ALIGN(entry_size * entry_count, hw_page_size) / hw_page_size; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15812 | |
| 15813 | /* If needed, Adjust page count to match the max the adapter supports */ |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 15814 | if (pgcnt > phba->sli4_hba.pc_sli4_params.wqpcnt) |
| 15815 | pgcnt = phba->sli4_hba.pc_sli4_params.wqpcnt; |
| 15816 | |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 15817 | queue = kzalloc_node(sizeof(*queue) + (sizeof(void *) * pgcnt), |
| 15818 | GFP_KERNEL, cpu_to_node(cpu)); |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 15819 | if (!queue) |
| 15820 | return NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15821 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15822 | INIT_LIST_HEAD(&queue->list); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 15823 | INIT_LIST_HEAD(&queue->_poll_list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15824 | INIT_LIST_HEAD(&queue->wq_list); |
James Smart | 6e8e1c1 | 2018-01-30 15:58:49 -0800 | [diff] [blame] | 15825 | INIT_LIST_HEAD(&queue->wqfull_list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15826 | INIT_LIST_HEAD(&queue->page_list); |
| 15827 | INIT_LIST_HEAD(&queue->child_list); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15828 | INIT_LIST_HEAD(&queue->cpu_list); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15829 | |
| 15830 | /* Set queue parameters now. If the system cannot provide memory |
| 15831 | * resources, the free routine needs to know what was allocated. |
| 15832 | */ |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 15833 | queue->page_count = pgcnt; |
| 15834 | queue->q_pgs = (void **)&queue[1]; |
| 15835 | queue->entry_cnt_per_pg = hw_page_size / entry_size; |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15836 | queue->entry_size = entry_size; |
| 15837 | queue->entry_count = entry_count; |
| 15838 | queue->page_size = hw_page_size; |
| 15839 | queue->phba = phba; |
| 15840 | |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 15841 | for (x = 0; x < queue->page_count; x++) { |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 15842 | dmabuf = kzalloc_node(sizeof(*dmabuf), GFP_KERNEL, |
| 15843 | dev_to_node(&phba->pcidev->dev)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15844 | if (!dmabuf) |
| 15845 | goto out_fail; |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 15846 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 15847 | hw_page_size, &dmabuf->phys, |
| 15848 | GFP_KERNEL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15849 | if (!dmabuf->virt) { |
| 15850 | kfree(dmabuf); |
| 15851 | goto out_fail; |
| 15852 | } |
| 15853 | dmabuf->buffer_tag = x; |
| 15854 | list_add_tail(&dmabuf->list, &queue->page_list); |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 15855 | /* use lpfc_sli4_qe to index a paritcular entry in this page */ |
| 15856 | queue->q_pgs[x] = dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15857 | } |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 15858 | INIT_WORK(&queue->irqwork, lpfc_sli4_hba_process_cq); |
| 15859 | INIT_WORK(&queue->spwork, lpfc_sli4_sp_process_cq); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15860 | INIT_DELAYED_WORK(&queue->sched_irqwork, lpfc_sli4_dly_hba_process_cq); |
| 15861 | INIT_DELAYED_WORK(&queue->sched_spwork, lpfc_sli4_dly_sp_process_cq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15862 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15863 | /* notify_interval will be set during q creation */ |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 15864 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15865 | return queue; |
| 15866 | out_fail: |
| 15867 | lpfc_sli4_queue_free(queue); |
| 15868 | return NULL; |
| 15869 | } |
| 15870 | |
| 15871 | /** |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15872 | * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory |
| 15873 | * @phba: HBA structure that indicates port to create a queue on. |
| 15874 | * @pci_barset: PCI BAR set flag. |
| 15875 | * |
| 15876 | * This function shall perform iomap of the specified PCI BAR address to host |
| 15877 | * memory address if not already done so and return it. The returned host |
| 15878 | * memory address can be NULL. |
| 15879 | */ |
| 15880 | static void __iomem * |
| 15881 | lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset) |
| 15882 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15883 | if (!phba->pcidev) |
| 15884 | return NULL; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15885 | |
| 15886 | switch (pci_barset) { |
| 15887 | case WQ_PCI_BAR_0_AND_1: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15888 | return phba->pci_bar0_memmap_p; |
| 15889 | case WQ_PCI_BAR_2_AND_3: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15890 | return phba->pci_bar2_memmap_p; |
| 15891 | case WQ_PCI_BAR_4_AND_5: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15892 | return phba->pci_bar4_memmap_p; |
| 15893 | default: |
| 15894 | break; |
| 15895 | } |
| 15896 | return NULL; |
| 15897 | } |
| 15898 | |
| 15899 | /** |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15900 | * lpfc_modify_hba_eq_delay - Modify Delay Multiplier on EQs |
| 15901 | * @phba: HBA structure that EQs are on. |
| 15902 | * @startq: The starting EQ index to modify |
| 15903 | * @numq: The number of EQs (consecutive indexes) to modify |
| 15904 | * @usdelay: amount of delay |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15905 | * |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15906 | * This function revises the EQ delay on 1 or more EQs. The EQ delay |
| 15907 | * is set either by writing to a register (if supported by the SLI Port) |
| 15908 | * or by mailbox command. The mailbox command allows several EQs to be |
| 15909 | * updated at once. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15910 | * |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15911 | * The @phba struct is used to send a mailbox command to HBA. The @startq |
| 15912 | * is used to get the starting EQ index to change. The @numq value is |
| 15913 | * used to specify how many consecutive EQ indexes, starting at EQ index, |
| 15914 | * are to be changed. This function is asynchronous and will wait for any |
| 15915 | * mailbox commands to finish before returning. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15916 | * |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15917 | * On success this function will return a zero. If unable to allocate |
| 15918 | * enough memory this function will return -ENOMEM. If a mailbox command |
| 15919 | * fails this function will return -ENXIO. Note: on ENXIO, some EQs may |
| 15920 | * have had their delay multipler changed. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15921 | **/ |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15922 | void |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 15923 | lpfc_modify_hba_eq_delay(struct lpfc_hba *phba, uint32_t startq, |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15924 | uint32_t numq, uint32_t usdelay) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15925 | { |
| 15926 | struct lpfc_mbx_modify_eq_delay *eq_delay; |
| 15927 | LPFC_MBOXQ_t *mbox; |
| 15928 | struct lpfc_queue *eq; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15929 | int cnt = 0, rc, length; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15930 | uint32_t shdr_status, shdr_add_status; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15931 | uint32_t dmult; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15932 | int qidx; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15933 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15934 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15935 | if (startq >= phba->cfg_irq_chann) |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15936 | return; |
| 15937 | |
| 15938 | if (usdelay > 0xFFFF) { |
| 15939 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP | LOG_NVME, |
| 15940 | "6429 usdelay %d too large. Scaled down to " |
| 15941 | "0xFFFF.\n", usdelay); |
| 15942 | usdelay = 0xFFFF; |
| 15943 | } |
| 15944 | |
| 15945 | /* set values by EQ_DELAY register if supported */ |
| 15946 | if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) { |
| 15947 | for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 15948 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15949 | if (!eq) |
| 15950 | continue; |
| 15951 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15952 | lpfc_sli4_mod_hba_eq_delay(phba, eq, usdelay); |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15953 | |
| 15954 | if (++cnt >= numq) |
| 15955 | break; |
| 15956 | } |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15957 | return; |
| 15958 | } |
| 15959 | |
| 15960 | /* Otherwise, set values by mailbox cmd */ |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15961 | |
| 15962 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15963 | if (!mbox) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15964 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15965 | "6428 Failed allocating mailbox cmd buffer." |
| 15966 | " EQ delay was not set.\n"); |
| 15967 | return; |
| 15968 | } |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15969 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - |
| 15970 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15971 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15972 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, |
| 15973 | length, LPFC_SLI4_MBX_EMBED); |
| 15974 | eq_delay = &mbox->u.mqe.un.eq_delay; |
| 15975 | |
| 15976 | /* Calculate delay multiper from maximum interrupt per second */ |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15977 | dmult = (usdelay * LPFC_DMULT_CONST) / LPFC_SEC_TO_USEC; |
| 15978 | if (dmult) |
| 15979 | dmult--; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 15980 | if (dmult > LPFC_DMULT_MAX) |
| 15981 | dmult = LPFC_DMULT_MAX; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15982 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15983 | for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 15984 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15985 | if (!eq) |
| 15986 | continue; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15987 | eq->q_mode = usdelay; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15988 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; |
| 15989 | eq_delay->u.request.eq[cnt].phase = 0; |
| 15990 | eq_delay->u.request.eq[cnt].delay_multi = dmult; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 15991 | |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15992 | if (++cnt >= numq) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15993 | break; |
| 15994 | } |
| 15995 | eq_delay->u.request.num_eq = cnt; |
| 15996 | |
| 15997 | mbox->vport = phba->pport; |
| 15998 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 15999 | mbox->ctx_buf = NULL; |
| 16000 | mbox->ctx_ndlp = NULL; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 16001 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16002 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; |
| 16003 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16004 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16005 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16006 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 16007 | "2512 MODIFY_EQ_DELAY mailbox failed with " |
| 16008 | "status x%x add_status x%x, mbx status x%x\n", |
| 16009 | shdr_status, shdr_add_status, rc); |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 16010 | } |
| 16011 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 16012 | return; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 16013 | } |
| 16014 | |
| 16015 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16016 | * lpfc_eq_create - Create an Event Queue on the HBA |
| 16017 | * @phba: HBA structure that indicates port to create a queue on. |
| 16018 | * @eq: The queue structure to use to create the event queue. |
| 16019 | * @imax: The maximum interrupt per second limit. |
| 16020 | * |
| 16021 | * This function creates an event queue, as detailed in @eq, on a port, |
| 16022 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. |
| 16023 | * |
| 16024 | * The @phba struct is used to send mailbox command to HBA. The @eq struct |
| 16025 | * is used to get the entry count and entry size that are necessary to |
| 16026 | * determine the number of pages to allocate and use for this queue. This |
| 16027 | * function will send the EQ_CREATE mailbox command to the HBA to setup the |
| 16028 | * event queue. This function is asynchronous and will wait for the mailbox |
| 16029 | * command to finish before continuing. |
| 16030 | * |
| 16031 | * 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] | 16032 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 16033 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16034 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16035 | int |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 16036 | 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] | 16037 | { |
| 16038 | struct lpfc_mbx_eq_create *eq_create; |
| 16039 | LPFC_MBOXQ_t *mbox; |
| 16040 | int rc, length, status = 0; |
| 16041 | struct lpfc_dmabuf *dmabuf; |
| 16042 | uint32_t shdr_status, shdr_add_status; |
| 16043 | union lpfc_sli4_cfg_shdr *shdr; |
| 16044 | uint16_t dmult; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16045 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 16046 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16047 | /* sanity check on queue memory */ |
| 16048 | if (!eq) |
| 16049 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16050 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 16051 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16052 | |
| 16053 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16054 | if (!mbox) |
| 16055 | return -ENOMEM; |
| 16056 | length = (sizeof(struct lpfc_mbx_eq_create) - |
| 16057 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16058 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16059 | LPFC_MBOX_OPCODE_EQ_CREATE, |
| 16060 | length, LPFC_SLI4_MBX_EMBED); |
| 16061 | eq_create = &mbox->u.mqe.un.eq_create; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 16062 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16063 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, |
| 16064 | eq->page_count); |
| 16065 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, |
| 16066 | LPFC_EQE_SIZE); |
| 16067 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 16068 | |
| 16069 | /* Use version 2 of CREATE_EQ if eqav is set */ |
| 16070 | if (phba->sli4_hba.pc_sli4_params.eqav) { |
| 16071 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 16072 | LPFC_Q_CREATE_VERSION_2); |
| 16073 | bf_set(lpfc_eq_context_autovalid, &eq_create->u.request.context, |
| 16074 | phba->sli4_hba.pc_sli4_params.eqav); |
| 16075 | } |
| 16076 | |
James Smart | 2c9c5a0 | 2015-04-07 15:07:15 -0400 | [diff] [blame] | 16077 | /* don't setup delay multiplier using EQ_CREATE */ |
| 16078 | dmult = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16079 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
| 16080 | dmult); |
| 16081 | switch (eq->entry_count) { |
| 16082 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16083 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16084 | "0360 Unsupported EQ count. (%d)\n", |
| 16085 | eq->entry_count); |
James Smart | 04d210c | 2019-05-21 17:49:03 -0700 | [diff] [blame] | 16086 | if (eq->entry_count < 256) { |
| 16087 | status = -EINVAL; |
| 16088 | goto out; |
| 16089 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 16090 | fallthrough; /* otherwise default to smallest count */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16091 | case 256: |
| 16092 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 16093 | LPFC_EQ_CNT_256); |
| 16094 | break; |
| 16095 | case 512: |
| 16096 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 16097 | LPFC_EQ_CNT_512); |
| 16098 | break; |
| 16099 | case 1024: |
| 16100 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 16101 | LPFC_EQ_CNT_1024); |
| 16102 | break; |
| 16103 | case 2048: |
| 16104 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 16105 | LPFC_EQ_CNT_2048); |
| 16106 | break; |
| 16107 | case 4096: |
| 16108 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 16109 | LPFC_EQ_CNT_4096); |
| 16110 | break; |
| 16111 | } |
| 16112 | list_for_each_entry(dmabuf, &eq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16113 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16114 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 16115 | putPaddrLow(dmabuf->phys); |
| 16116 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 16117 | putPaddrHigh(dmabuf->phys); |
| 16118 | } |
| 16119 | mbox->vport = phba->pport; |
| 16120 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 16121 | mbox->ctx_buf = NULL; |
| 16122 | mbox->ctx_ndlp = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16123 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16124 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16125 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16126 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16127 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16128 | "2500 EQ_CREATE mailbox failed with " |
| 16129 | "status x%x add_status x%x, mbx status x%x\n", |
| 16130 | shdr_status, shdr_add_status, rc); |
| 16131 | status = -ENXIO; |
| 16132 | } |
| 16133 | eq->type = LPFC_EQ; |
| 16134 | eq->subtype = LPFC_NONE; |
| 16135 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); |
| 16136 | if (eq->queue_id == 0xFFFF) |
| 16137 | status = -ENXIO; |
| 16138 | eq->host_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16139 | eq->notify_interval = LPFC_EQ_NOTIFY_INTRVL; |
| 16140 | eq->max_proc_limit = LPFC_EQ_MAX_PROC_LIMIT; |
James Smart | 04d210c | 2019-05-21 17:49:03 -0700 | [diff] [blame] | 16141 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16142 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16143 | return status; |
| 16144 | } |
| 16145 | |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 16146 | static int lpfc_cq_poll_hdler(struct irq_poll *iop, int budget) |
| 16147 | { |
| 16148 | struct lpfc_queue *cq = container_of(iop, struct lpfc_queue, iop); |
| 16149 | |
Colin Ian King | 26e0b9a | 2020-07-07 16:00:18 +0100 | [diff] [blame] | 16150 | __lpfc_sli4_hba_process_cq(cq, LPFC_IRQ_POLL); |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 16151 | |
| 16152 | return 1; |
| 16153 | } |
| 16154 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16155 | /** |
| 16156 | * lpfc_cq_create - Create a Completion Queue on the HBA |
| 16157 | * @phba: HBA structure that indicates port to create a queue on. |
| 16158 | * @cq: The queue structure to use to create the completion queue. |
| 16159 | * @eq: The event queue to bind this completion queue to. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 16160 | * @type: Type of queue (EQ, GCQ, MCQ, WCQ, etc). |
| 16161 | * @subtype: Functional purpose of the queue (MBOX, IO, ELS, NVMET, etc). |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16162 | * |
| 16163 | * This function creates a completion queue, as detailed in @wq, on a port, |
| 16164 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. |
| 16165 | * |
| 16166 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 16167 | * is used to get the entry count and entry size that are necessary to |
| 16168 | * determine the number of pages to allocate and use for this queue. The @eq |
| 16169 | * is used to indicate which event queue to bind this completion queue to. This |
| 16170 | * function will send the CQ_CREATE mailbox command to the HBA to setup the |
| 16171 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 16172 | * command to finish before continuing. |
| 16173 | * |
| 16174 | * 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] | 16175 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 16176 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16177 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16178 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16179 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 16180 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) |
| 16181 | { |
| 16182 | struct lpfc_mbx_cq_create *cq_create; |
| 16183 | struct lpfc_dmabuf *dmabuf; |
| 16184 | LPFC_MBOXQ_t *mbox; |
| 16185 | int rc, length, status = 0; |
| 16186 | uint32_t shdr_status, shdr_add_status; |
| 16187 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16188 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16189 | /* sanity check on queue memory */ |
| 16190 | if (!cq || !eq) |
| 16191 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16192 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16193 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16194 | if (!mbox) |
| 16195 | return -ENOMEM; |
| 16196 | length = (sizeof(struct lpfc_mbx_cq_create) - |
| 16197 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16198 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16199 | LPFC_MBOX_OPCODE_CQ_CREATE, |
| 16200 | length, LPFC_SLI4_MBX_EMBED); |
| 16201 | cq_create = &mbox->u.mqe.un.cq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16202 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16203 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
| 16204 | cq->page_count); |
| 16205 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); |
| 16206 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16207 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 16208 | phba->sli4_hba.pc_sli4_params.cqv); |
| 16209 | 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] | 16210 | bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, |
| 16211 | (cq->page_size / SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16212 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
| 16213 | eq->queue_id); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 16214 | bf_set(lpfc_cq_context_autovalid, &cq_create->u.request.context, |
| 16215 | phba->sli4_hba.pc_sli4_params.cqav); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16216 | } else { |
| 16217 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, |
| 16218 | eq->queue_id); |
| 16219 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16220 | switch (cq->entry_count) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 16221 | case 2048: |
| 16222 | case 4096: |
| 16223 | if (phba->sli4_hba.pc_sli4_params.cqv == |
| 16224 | LPFC_Q_CREATE_VERSION_2) { |
| 16225 | cq_create->u.request.context.lpfc_cq_context_count = |
| 16226 | cq->entry_count; |
| 16227 | bf_set(lpfc_cq_context_count, |
| 16228 | &cq_create->u.request.context, |
| 16229 | LPFC_CQ_CNT_WORD7); |
| 16230 | break; |
| 16231 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 16232 | fallthrough; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16233 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16234 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 16235 | "0361 Unsupported CQ count: " |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 16236 | "entry cnt %d sz %d pg cnt %d\n", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 16237 | cq->entry_count, cq->entry_size, |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 16238 | cq->page_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 16239 | if (cq->entry_count < 256) { |
| 16240 | status = -EINVAL; |
| 16241 | goto out; |
| 16242 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 16243 | fallthrough; /* otherwise default to smallest count */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16244 | case 256: |
| 16245 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 16246 | LPFC_CQ_CNT_256); |
| 16247 | break; |
| 16248 | case 512: |
| 16249 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 16250 | LPFC_CQ_CNT_512); |
| 16251 | break; |
| 16252 | case 1024: |
| 16253 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 16254 | LPFC_CQ_CNT_1024); |
| 16255 | break; |
| 16256 | } |
| 16257 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 16258 | memset(dmabuf->virt, 0, cq->page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16259 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 16260 | putPaddrLow(dmabuf->phys); |
| 16261 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 16262 | putPaddrHigh(dmabuf->phys); |
| 16263 | } |
| 16264 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16265 | |
| 16266 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16267 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16268 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16269 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16270 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16271 | "2501 CQ_CREATE mailbox failed with " |
| 16272 | "status x%x add_status x%x, mbx status x%x\n", |
| 16273 | shdr_status, shdr_add_status, rc); |
| 16274 | status = -ENXIO; |
| 16275 | goto out; |
| 16276 | } |
| 16277 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
| 16278 | if (cq->queue_id == 0xFFFF) { |
| 16279 | status = -ENXIO; |
| 16280 | goto out; |
| 16281 | } |
| 16282 | /* link the cq onto the parent eq child list */ |
| 16283 | list_add_tail(&cq->list, &eq->child_list); |
| 16284 | /* Set up completion queue's type and subtype */ |
| 16285 | cq->type = type; |
| 16286 | cq->subtype = subtype; |
| 16287 | 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] | 16288 | cq->assoc_qid = eq->queue_id; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 16289 | cq->assoc_qp = eq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16290 | cq->host_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16291 | cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL; |
| 16292 | 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] | 16293 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 16294 | if (cq->queue_id > phba->sli4_hba.cq_max) |
| 16295 | phba->sli4_hba.cq_max = cq->queue_id; |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 16296 | |
| 16297 | irq_poll_init(&cq->iop, LPFC_IRQ_POLL_WEIGHT, lpfc_cq_poll_hdler); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16298 | out: |
| 16299 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16300 | return status; |
| 16301 | } |
| 16302 | |
| 16303 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16304 | * lpfc_cq_create_set - Create a set of Completion Queues on the HBA for MRQ |
| 16305 | * @phba: HBA structure that indicates port to create a queue on. |
| 16306 | * @cqp: The queue structure array to use to create the completion queues. |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 16307 | * @hdwq: The hardware queue array with the EQ to bind completion queues to. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 16308 | * @type: Type of queue (EQ, GCQ, MCQ, WCQ, etc). |
| 16309 | * @subtype: Functional purpose of the queue (MBOX, IO, ELS, NVMET, etc). |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16310 | * |
| 16311 | * This function creates a set of completion queue, s to support MRQ |
| 16312 | * as detailed in @cqp, on a port, |
| 16313 | * described by @phba by sending a CREATE_CQ_SET mailbox command to the HBA. |
| 16314 | * |
| 16315 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 16316 | * is used to get the entry count and entry size that are necessary to |
| 16317 | * determine the number of pages to allocate and use for this queue. The @eq |
| 16318 | * is used to indicate which event queue to bind this completion queue to. This |
| 16319 | * function will send the CREATE_CQ_SET mailbox command to the HBA to setup the |
| 16320 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 16321 | * command to finish before continuing. |
| 16322 | * |
| 16323 | * On success this function will return a zero. If unable to allocate enough |
| 16324 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 16325 | * fails this function will return -ENXIO. |
| 16326 | **/ |
| 16327 | int |
| 16328 | lpfc_cq_create_set(struct lpfc_hba *phba, struct lpfc_queue **cqp, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 16329 | struct lpfc_sli4_hdw_queue *hdwq, uint32_t type, |
| 16330 | uint32_t subtype) |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16331 | { |
| 16332 | struct lpfc_queue *cq; |
| 16333 | struct lpfc_queue *eq; |
| 16334 | struct lpfc_mbx_cq_create_set *cq_set; |
| 16335 | struct lpfc_dmabuf *dmabuf; |
| 16336 | LPFC_MBOXQ_t *mbox; |
| 16337 | int rc, length, alloclen, status = 0; |
| 16338 | int cnt, idx, numcq, page_idx = 0; |
| 16339 | uint32_t shdr_status, shdr_add_status; |
| 16340 | union lpfc_sli4_cfg_shdr *shdr; |
| 16341 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 16342 | |
| 16343 | /* sanity check on queue memory */ |
| 16344 | numcq = phba->cfg_nvmet_mrq; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 16345 | if (!cqp || !hdwq || !numcq) |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16346 | return -ENODEV; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16347 | |
| 16348 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16349 | if (!mbox) |
| 16350 | return -ENOMEM; |
| 16351 | |
| 16352 | length = sizeof(struct lpfc_mbx_cq_create_set); |
| 16353 | length += ((numcq * cqp[0]->page_count) * |
| 16354 | sizeof(struct dma_address)); |
| 16355 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16356 | LPFC_MBOX_OPCODE_FCOE_CQ_CREATE_SET, length, |
| 16357 | LPFC_SLI4_MBX_NEMBED); |
| 16358 | if (alloclen < length) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16359 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16360 | "3098 Allocated DMA memory size (%d) is " |
| 16361 | "less than the requested DMA memory size " |
| 16362 | "(%d)\n", alloclen, length); |
| 16363 | status = -ENOMEM; |
| 16364 | goto out; |
| 16365 | } |
| 16366 | cq_set = mbox->sge_array->addr[0]; |
| 16367 | shdr = (union lpfc_sli4_cfg_shdr *)&cq_set->cfg_shdr; |
| 16368 | bf_set(lpfc_mbox_hdr_version, &shdr->request, 0); |
| 16369 | |
| 16370 | for (idx = 0; idx < numcq; idx++) { |
| 16371 | cq = cqp[idx]; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 16372 | eq = hdwq[idx].hba_eq; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16373 | if (!cq || !eq) { |
| 16374 | status = -ENOMEM; |
| 16375 | goto out; |
| 16376 | } |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 16377 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 16378 | hw_page_size = cq->page_size; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16379 | |
| 16380 | switch (idx) { |
| 16381 | case 0: |
| 16382 | bf_set(lpfc_mbx_cq_create_set_page_size, |
| 16383 | &cq_set->u.request, |
| 16384 | (hw_page_size / SLI4_PAGE_SIZE)); |
| 16385 | bf_set(lpfc_mbx_cq_create_set_num_pages, |
| 16386 | &cq_set->u.request, cq->page_count); |
| 16387 | bf_set(lpfc_mbx_cq_create_set_evt, |
| 16388 | &cq_set->u.request, 1); |
| 16389 | bf_set(lpfc_mbx_cq_create_set_valid, |
| 16390 | &cq_set->u.request, 1); |
| 16391 | bf_set(lpfc_mbx_cq_create_set_cqe_size, |
| 16392 | &cq_set->u.request, 0); |
| 16393 | bf_set(lpfc_mbx_cq_create_set_num_cq, |
| 16394 | &cq_set->u.request, numcq); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 16395 | bf_set(lpfc_mbx_cq_create_set_autovalid, |
| 16396 | &cq_set->u.request, |
| 16397 | phba->sli4_hba.pc_sli4_params.cqav); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16398 | switch (cq->entry_count) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 16399 | case 2048: |
| 16400 | case 4096: |
| 16401 | if (phba->sli4_hba.pc_sli4_params.cqv == |
| 16402 | LPFC_Q_CREATE_VERSION_2) { |
| 16403 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 16404 | &cq_set->u.request, |
| 16405 | cq->entry_count); |
| 16406 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 16407 | &cq_set->u.request, |
| 16408 | LPFC_CQ_CNT_WORD7); |
| 16409 | break; |
| 16410 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 16411 | fallthrough; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16412 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16413 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16414 | "3118 Bad CQ count. (%d)\n", |
| 16415 | cq->entry_count); |
| 16416 | if (cq->entry_count < 256) { |
| 16417 | status = -EINVAL; |
| 16418 | goto out; |
| 16419 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 16420 | fallthrough; /* otherwise default to smallest */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16421 | case 256: |
| 16422 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 16423 | &cq_set->u.request, LPFC_CQ_CNT_256); |
| 16424 | break; |
| 16425 | case 512: |
| 16426 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 16427 | &cq_set->u.request, LPFC_CQ_CNT_512); |
| 16428 | break; |
| 16429 | case 1024: |
| 16430 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 16431 | &cq_set->u.request, LPFC_CQ_CNT_1024); |
| 16432 | break; |
| 16433 | } |
| 16434 | bf_set(lpfc_mbx_cq_create_set_eq_id0, |
| 16435 | &cq_set->u.request, eq->queue_id); |
| 16436 | break; |
| 16437 | case 1: |
| 16438 | bf_set(lpfc_mbx_cq_create_set_eq_id1, |
| 16439 | &cq_set->u.request, eq->queue_id); |
| 16440 | break; |
| 16441 | case 2: |
| 16442 | bf_set(lpfc_mbx_cq_create_set_eq_id2, |
| 16443 | &cq_set->u.request, eq->queue_id); |
| 16444 | break; |
| 16445 | case 3: |
| 16446 | bf_set(lpfc_mbx_cq_create_set_eq_id3, |
| 16447 | &cq_set->u.request, eq->queue_id); |
| 16448 | break; |
| 16449 | case 4: |
| 16450 | bf_set(lpfc_mbx_cq_create_set_eq_id4, |
| 16451 | &cq_set->u.request, eq->queue_id); |
| 16452 | break; |
| 16453 | case 5: |
| 16454 | bf_set(lpfc_mbx_cq_create_set_eq_id5, |
| 16455 | &cq_set->u.request, eq->queue_id); |
| 16456 | break; |
| 16457 | case 6: |
| 16458 | bf_set(lpfc_mbx_cq_create_set_eq_id6, |
| 16459 | &cq_set->u.request, eq->queue_id); |
| 16460 | break; |
| 16461 | case 7: |
| 16462 | bf_set(lpfc_mbx_cq_create_set_eq_id7, |
| 16463 | &cq_set->u.request, eq->queue_id); |
| 16464 | break; |
| 16465 | case 8: |
| 16466 | bf_set(lpfc_mbx_cq_create_set_eq_id8, |
| 16467 | &cq_set->u.request, eq->queue_id); |
| 16468 | break; |
| 16469 | case 9: |
| 16470 | bf_set(lpfc_mbx_cq_create_set_eq_id9, |
| 16471 | &cq_set->u.request, eq->queue_id); |
| 16472 | break; |
| 16473 | case 10: |
| 16474 | bf_set(lpfc_mbx_cq_create_set_eq_id10, |
| 16475 | &cq_set->u.request, eq->queue_id); |
| 16476 | break; |
| 16477 | case 11: |
| 16478 | bf_set(lpfc_mbx_cq_create_set_eq_id11, |
| 16479 | &cq_set->u.request, eq->queue_id); |
| 16480 | break; |
| 16481 | case 12: |
| 16482 | bf_set(lpfc_mbx_cq_create_set_eq_id12, |
| 16483 | &cq_set->u.request, eq->queue_id); |
| 16484 | break; |
| 16485 | case 13: |
| 16486 | bf_set(lpfc_mbx_cq_create_set_eq_id13, |
| 16487 | &cq_set->u.request, eq->queue_id); |
| 16488 | break; |
| 16489 | case 14: |
| 16490 | bf_set(lpfc_mbx_cq_create_set_eq_id14, |
| 16491 | &cq_set->u.request, eq->queue_id); |
| 16492 | break; |
| 16493 | case 15: |
| 16494 | bf_set(lpfc_mbx_cq_create_set_eq_id15, |
| 16495 | &cq_set->u.request, eq->queue_id); |
| 16496 | break; |
| 16497 | } |
| 16498 | |
| 16499 | /* link the cq onto the parent eq child list */ |
| 16500 | list_add_tail(&cq->list, &eq->child_list); |
| 16501 | /* Set up completion queue's type and subtype */ |
| 16502 | cq->type = type; |
| 16503 | cq->subtype = subtype; |
| 16504 | cq->assoc_qid = eq->queue_id; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 16505 | cq->assoc_qp = eq; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16506 | cq->host_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16507 | cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL; |
| 16508 | cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit, |
| 16509 | cq->entry_count); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 16510 | cq->chann = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16511 | |
| 16512 | rc = 0; |
| 16513 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
| 16514 | memset(dmabuf->virt, 0, hw_page_size); |
| 16515 | cnt = page_idx + dmabuf->buffer_tag; |
| 16516 | cq_set->u.request.page[cnt].addr_lo = |
| 16517 | putPaddrLow(dmabuf->phys); |
| 16518 | cq_set->u.request.page[cnt].addr_hi = |
| 16519 | putPaddrHigh(dmabuf->phys); |
| 16520 | rc++; |
| 16521 | } |
| 16522 | page_idx += rc; |
| 16523 | } |
| 16524 | |
| 16525 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16526 | |
| 16527 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16528 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16529 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16530 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16531 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16532 | "3119 CQ_CREATE_SET mailbox failed with " |
| 16533 | "status x%x add_status x%x, mbx status x%x\n", |
| 16534 | shdr_status, shdr_add_status, rc); |
| 16535 | status = -ENXIO; |
| 16536 | goto out; |
| 16537 | } |
| 16538 | rc = bf_get(lpfc_mbx_cq_create_set_base_id, &cq_set->u.response); |
| 16539 | if (rc == 0xFFFF) { |
| 16540 | status = -ENXIO; |
| 16541 | goto out; |
| 16542 | } |
| 16543 | |
| 16544 | for (idx = 0; idx < numcq; idx++) { |
| 16545 | cq = cqp[idx]; |
| 16546 | cq->queue_id = rc + idx; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 16547 | if (cq->queue_id > phba->sli4_hba.cq_max) |
| 16548 | phba->sli4_hba.cq_max = cq->queue_id; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16549 | } |
| 16550 | |
| 16551 | out: |
| 16552 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16553 | return status; |
| 16554 | } |
| 16555 | |
| 16556 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16557 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16558 | * @phba: HBA structure that indicates port to create a queue on. |
| 16559 | * @mq: The queue structure to use to create the mailbox queue. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16560 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
| 16561 | * @cq: The completion queue to associate with this cq. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16562 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16563 | * This function provides failback (fb) functionality when the |
| 16564 | * mq_create_ext fails on older FW generations. It's purpose is identical |
| 16565 | * to mq_create_ext otherwise. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16566 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16567 | * This routine cannot fail as all attributes were previously accessed and |
| 16568 | * initialized in mq_create_ext. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16569 | **/ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16570 | static void |
| 16571 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 16572 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16573 | { |
| 16574 | struct lpfc_mbx_mq_create *mq_create; |
| 16575 | struct lpfc_dmabuf *dmabuf; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16576 | int length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16577 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16578 | length = (sizeof(struct lpfc_mbx_mq_create) - |
| 16579 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16580 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16581 | LPFC_MBOX_OPCODE_MQ_CREATE, |
| 16582 | length, LPFC_SLI4_MBX_EMBED); |
| 16583 | mq_create = &mbox->u.mqe.un.mq_create; |
| 16584 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16585 | mq->page_count); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16586 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16587 | cq->queue_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16588 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); |
| 16589 | switch (mq->entry_count) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16590 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16591 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 16592 | LPFC_MQ_RING_SIZE_16); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16593 | break; |
| 16594 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16595 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 16596 | LPFC_MQ_RING_SIZE_32); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16597 | break; |
| 16598 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16599 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 16600 | LPFC_MQ_RING_SIZE_64); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16601 | break; |
| 16602 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16603 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 16604 | LPFC_MQ_RING_SIZE_128); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16605 | break; |
| 16606 | } |
| 16607 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
| 16608 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16609 | putPaddrLow(dmabuf->phys); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16610 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16611 | putPaddrHigh(dmabuf->phys); |
| 16612 | } |
| 16613 | } |
| 16614 | |
| 16615 | /** |
| 16616 | * lpfc_mq_create - Create a mailbox Queue on the HBA |
| 16617 | * @phba: HBA structure that indicates port to create a queue on. |
| 16618 | * @mq: The queue structure to use to create the mailbox queue. |
| 16619 | * @cq: The completion queue to associate with this cq. |
| 16620 | * @subtype: The queue's subtype. |
| 16621 | * |
| 16622 | * This function creates a mailbox queue, as detailed in @mq, on a port, |
| 16623 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. |
| 16624 | * |
| 16625 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 16626 | * is used to get the entry count and entry size that are necessary to |
| 16627 | * determine the number of pages to allocate and use for this queue. This |
| 16628 | * function will send the MQ_CREATE mailbox command to the HBA to setup the |
| 16629 | * mailbox queue. This function is asynchronous and will wait for the mailbox |
| 16630 | * command to finish before continuing. |
| 16631 | * |
| 16632 | * 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] | 16633 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 16634 | * fails this function will return -ENXIO. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16635 | **/ |
| 16636 | int32_t |
| 16637 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 16638 | struct lpfc_queue *cq, uint32_t subtype) |
| 16639 | { |
| 16640 | struct lpfc_mbx_mq_create *mq_create; |
| 16641 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
| 16642 | struct lpfc_dmabuf *dmabuf; |
| 16643 | LPFC_MBOXQ_t *mbox; |
| 16644 | int rc, length, status = 0; |
| 16645 | uint32_t shdr_status, shdr_add_status; |
| 16646 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16647 | 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] | 16648 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16649 | /* sanity check on queue memory */ |
| 16650 | if (!mq || !cq) |
| 16651 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16652 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 16653 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16654 | |
| 16655 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16656 | if (!mbox) |
| 16657 | return -ENOMEM; |
| 16658 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
| 16659 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16660 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16661 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
| 16662 | length, LPFC_SLI4_MBX_EMBED); |
| 16663 | |
| 16664 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16665 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 16666 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
| 16667 | &mq_create_ext->u.request, mq->page_count); |
| 16668 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, |
| 16669 | &mq_create_ext->u.request, 1); |
| 16670 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16671 | &mq_create_ext->u.request, 1); |
| 16672 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, |
| 16673 | &mq_create_ext->u.request, 1); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 16674 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
| 16675 | &mq_create_ext->u.request, 1); |
| 16676 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, |
| 16677 | &mq_create_ext->u.request, 1); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16678 | 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] | 16679 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 16680 | phba->sli4_hba.pc_sli4_params.mqv); |
| 16681 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) |
| 16682 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, |
| 16683 | cq->queue_id); |
| 16684 | else |
| 16685 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, |
| 16686 | cq->queue_id); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16687 | switch (mq->entry_count) { |
| 16688 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16689 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16690 | "0362 Unsupported MQ count. (%d)\n", |
| 16691 | mq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 16692 | if (mq->entry_count < 16) { |
| 16693 | status = -EINVAL; |
| 16694 | goto out; |
| 16695 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 16696 | fallthrough; /* otherwise default to smallest count */ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16697 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16698 | bf_set(lpfc_mq_context_ring_size, |
| 16699 | &mq_create_ext->u.request.context, |
| 16700 | LPFC_MQ_RING_SIZE_16); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16701 | break; |
| 16702 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16703 | bf_set(lpfc_mq_context_ring_size, |
| 16704 | &mq_create_ext->u.request.context, |
| 16705 | LPFC_MQ_RING_SIZE_32); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16706 | break; |
| 16707 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16708 | bf_set(lpfc_mq_context_ring_size, |
| 16709 | &mq_create_ext->u.request.context, |
| 16710 | LPFC_MQ_RING_SIZE_64); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16711 | break; |
| 16712 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16713 | bf_set(lpfc_mq_context_ring_size, |
| 16714 | &mq_create_ext->u.request.context, |
| 16715 | LPFC_MQ_RING_SIZE_128); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16716 | break; |
| 16717 | } |
| 16718 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16719 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16720 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 16721 | putPaddrLow(dmabuf->phys); |
| 16722 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16723 | putPaddrHigh(dmabuf->phys); |
| 16724 | } |
| 16725 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16726 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 16727 | &mq_create_ext->u.response); |
| 16728 | if (rc != MBX_SUCCESS) { |
| 16729 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 16730 | "2795 MQ_CREATE_EXT failed with " |
| 16731 | "status x%x. Failback to MQ_CREATE.\n", |
| 16732 | rc); |
| 16733 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); |
| 16734 | mq_create = &mbox->u.mqe.un.mq_create; |
| 16735 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16736 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; |
| 16737 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 16738 | &mq_create->u.response); |
| 16739 | } |
| 16740 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16741 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16742 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16743 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16744 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16745 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16746 | "2502 MQ_CREATE mailbox failed with " |
| 16747 | "status x%x add_status x%x, mbx status x%x\n", |
| 16748 | shdr_status, shdr_add_status, rc); |
| 16749 | status = -ENXIO; |
| 16750 | goto out; |
| 16751 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16752 | if (mq->queue_id == 0xFFFF) { |
| 16753 | status = -ENXIO; |
| 16754 | goto out; |
| 16755 | } |
| 16756 | mq->type = LPFC_MQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 16757 | mq->assoc_qid = cq->queue_id; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16758 | mq->subtype = subtype; |
| 16759 | mq->host_index = 0; |
| 16760 | mq->hba_index = 0; |
| 16761 | |
| 16762 | /* link the mq onto the parent cq child list */ |
| 16763 | list_add_tail(&mq->list, &cq->child_list); |
| 16764 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16765 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16766 | return status; |
| 16767 | } |
| 16768 | |
| 16769 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16770 | * lpfc_wq_create - Create a Work Queue on the HBA |
| 16771 | * @phba: HBA structure that indicates port to create a queue on. |
| 16772 | * @wq: The queue structure to use to create the work queue. |
| 16773 | * @cq: The completion queue to bind this work queue to. |
| 16774 | * @subtype: The subtype of the work queue indicating its functionality. |
| 16775 | * |
| 16776 | * This function creates a work queue, as detailed in @wq, on a port, described |
| 16777 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. |
| 16778 | * |
| 16779 | * The @phba struct is used to send mailbox command to HBA. The @wq struct |
| 16780 | * is used to get the entry count and entry size that are necessary to |
| 16781 | * determine the number of pages to allocate and use for this queue. The @cq |
| 16782 | * is used to indicate which completion queue to bind this work queue to. This |
| 16783 | * function will send the WQ_CREATE mailbox command to the HBA to setup the |
| 16784 | * work queue. This function is asynchronous and will wait for the mailbox |
| 16785 | * command to finish before continuing. |
| 16786 | * |
| 16787 | * 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] | 16788 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 16789 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16790 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16791 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16792 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
| 16793 | struct lpfc_queue *cq, uint32_t subtype) |
| 16794 | { |
| 16795 | struct lpfc_mbx_wq_create *wq_create; |
| 16796 | struct lpfc_dmabuf *dmabuf; |
| 16797 | LPFC_MBOXQ_t *mbox; |
| 16798 | int rc, length, status = 0; |
| 16799 | uint32_t shdr_status, shdr_add_status; |
| 16800 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16801 | 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] | 16802 | struct dma_address *page; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16803 | void __iomem *bar_memmap_p; |
| 16804 | uint32_t db_offset; |
| 16805 | uint16_t pci_barset; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16806 | uint8_t dpp_barset; |
| 16807 | uint32_t dpp_offset; |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 16808 | uint8_t wq_create_version; |
Lee Jones | 11d8e56 | 2020-07-21 17:41:44 +0100 | [diff] [blame] | 16809 | #ifdef CONFIG_X86 |
| 16810 | unsigned long pg_addr; |
| 16811 | #endif |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16812 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16813 | /* sanity check on queue memory */ |
| 16814 | if (!wq || !cq) |
| 16815 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16816 | if (!phba->sli4_hba.pc_sli4_params.supported) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 16817 | hw_page_size = wq->page_size; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16818 | |
| 16819 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16820 | if (!mbox) |
| 16821 | return -ENOMEM; |
| 16822 | length = (sizeof(struct lpfc_mbx_wq_create) - |
| 16823 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16824 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16825 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, |
| 16826 | length, LPFC_SLI4_MBX_EMBED); |
| 16827 | wq_create = &mbox->u.mqe.un.wq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16828 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16829 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
| 16830 | wq->page_count); |
| 16831 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, |
| 16832 | cq->queue_id); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 16833 | |
| 16834 | /* wqv is the earliest version supported, NOT the latest */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16835 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 16836 | phba->sli4_hba.pc_sli4_params.wqv); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16837 | |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 16838 | if ((phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) || |
| 16839 | (wq->page_size > SLI4_PAGE_SIZE)) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 16840 | wq_create_version = LPFC_Q_CREATE_VERSION_1; |
| 16841 | else |
| 16842 | wq_create_version = LPFC_Q_CREATE_VERSION_0; |
| 16843 | |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16844 | switch (wq_create_version) { |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 16845 | case LPFC_Q_CREATE_VERSION_1: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16846 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
| 16847 | wq->entry_count); |
James Smart | 3f247de | 2017-04-21 16:04:56 -0700 | [diff] [blame] | 16848 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 16849 | LPFC_Q_CREATE_VERSION_1); |
| 16850 | |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16851 | switch (wq->entry_size) { |
| 16852 | default: |
| 16853 | case 64: |
| 16854 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 16855 | &wq_create->u.request_1, |
| 16856 | LPFC_WQ_WQE_SIZE_64); |
| 16857 | break; |
| 16858 | case 128: |
| 16859 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 16860 | &wq_create->u.request_1, |
| 16861 | LPFC_WQ_WQE_SIZE_128); |
| 16862 | break; |
| 16863 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16864 | /* Request DPP by default */ |
| 16865 | 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] | 16866 | bf_set(lpfc_mbx_wq_create_page_size, |
| 16867 | &wq_create->u.request_1, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 16868 | (wq->page_size / SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16869 | page = wq_create->u.request_1.page; |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 16870 | break; |
| 16871 | default: |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16872 | page = wq_create->u.request.page; |
| 16873 | break; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16874 | } |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 16875 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16876 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16877 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16878 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
| 16879 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16880 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16881 | |
| 16882 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 16883 | bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1); |
| 16884 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16885 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16886 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16887 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16888 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16889 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16890 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16891 | "2503 WQ_CREATE mailbox failed with " |
| 16892 | "status x%x add_status x%x, mbx status x%x\n", |
| 16893 | shdr_status, shdr_add_status, rc); |
| 16894 | status = -ENXIO; |
| 16895 | goto out; |
| 16896 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16897 | |
| 16898 | if (wq_create_version == LPFC_Q_CREATE_VERSION_0) |
| 16899 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, |
| 16900 | &wq_create->u.response); |
| 16901 | else |
| 16902 | wq->queue_id = bf_get(lpfc_mbx_wq_create_v1_q_id, |
| 16903 | &wq_create->u.response_1); |
| 16904 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16905 | if (wq->queue_id == 0xFFFF) { |
| 16906 | status = -ENXIO; |
| 16907 | goto out; |
| 16908 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16909 | |
| 16910 | wq->db_format = LPFC_DB_LIST_FORMAT; |
| 16911 | if (wq_create_version == LPFC_Q_CREATE_VERSION_0) { |
| 16912 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 16913 | wq->db_format = bf_get(lpfc_mbx_wq_create_db_format, |
| 16914 | &wq_create->u.response); |
| 16915 | if ((wq->db_format != LPFC_DB_LIST_FORMAT) && |
| 16916 | (wq->db_format != LPFC_DB_RING_FORMAT)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16917 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16918 | "3265 WQ[%d] doorbell format " |
| 16919 | "not supported: x%x\n", |
| 16920 | wq->queue_id, wq->db_format); |
| 16921 | status = -EINVAL; |
| 16922 | goto out; |
| 16923 | } |
| 16924 | pci_barset = bf_get(lpfc_mbx_wq_create_bar_set, |
| 16925 | &wq_create->u.response); |
| 16926 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 16927 | pci_barset); |
| 16928 | if (!bar_memmap_p) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16929 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16930 | "3263 WQ[%d] failed to memmap " |
| 16931 | "pci barset:x%x\n", |
| 16932 | wq->queue_id, pci_barset); |
| 16933 | status = -ENOMEM; |
| 16934 | goto out; |
| 16935 | } |
| 16936 | db_offset = wq_create->u.response.doorbell_offset; |
| 16937 | if ((db_offset != LPFC_ULP0_WQ_DOORBELL) && |
| 16938 | (db_offset != LPFC_ULP1_WQ_DOORBELL)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16939 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16940 | "3252 WQ[%d] doorbell offset " |
| 16941 | "not supported: x%x\n", |
| 16942 | wq->queue_id, db_offset); |
| 16943 | status = -EINVAL; |
| 16944 | goto out; |
| 16945 | } |
| 16946 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 16947 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 16948 | "3264 WQ[%d]: barset:x%x, offset:x%x, " |
| 16949 | "format:x%x\n", wq->queue_id, |
| 16950 | pci_barset, db_offset, wq->db_format); |
| 16951 | } else |
| 16952 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16953 | } else { |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16954 | /* Check if DPP was honored by the firmware */ |
| 16955 | wq->dpp_enable = bf_get(lpfc_mbx_wq_create_dpp_rsp, |
| 16956 | &wq_create->u.response_1); |
| 16957 | if (wq->dpp_enable) { |
| 16958 | pci_barset = bf_get(lpfc_mbx_wq_create_v1_bar_set, |
| 16959 | &wq_create->u.response_1); |
| 16960 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 16961 | pci_barset); |
| 16962 | if (!bar_memmap_p) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16963 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16964 | "3267 WQ[%d] failed to memmap " |
| 16965 | "pci barset:x%x\n", |
| 16966 | wq->queue_id, pci_barset); |
| 16967 | status = -ENOMEM; |
| 16968 | goto out; |
| 16969 | } |
| 16970 | db_offset = wq_create->u.response_1.doorbell_offset; |
| 16971 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 16972 | wq->dpp_id = bf_get(lpfc_mbx_wq_create_dpp_id, |
| 16973 | &wq_create->u.response_1); |
| 16974 | dpp_barset = bf_get(lpfc_mbx_wq_create_dpp_bar, |
| 16975 | &wq_create->u.response_1); |
| 16976 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 16977 | dpp_barset); |
| 16978 | if (!bar_memmap_p) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16979 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16980 | "3268 WQ[%d] failed to memmap " |
| 16981 | "pci barset:x%x\n", |
| 16982 | wq->queue_id, dpp_barset); |
| 16983 | status = -ENOMEM; |
| 16984 | goto out; |
| 16985 | } |
| 16986 | dpp_offset = wq_create->u.response_1.dpp_offset; |
| 16987 | wq->dpp_regaddr = bar_memmap_p + dpp_offset; |
| 16988 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 16989 | "3271 WQ[%d]: barset:x%x, offset:x%x, " |
| 16990 | "dpp_id:x%x dpp_barset:x%x " |
| 16991 | "dpp_offset:x%x\n", |
| 16992 | wq->queue_id, pci_barset, db_offset, |
| 16993 | wq->dpp_id, dpp_barset, dpp_offset); |
| 16994 | |
Lee Jones | 3c1311a | 2020-07-21 17:41:28 +0100 | [diff] [blame] | 16995 | #ifdef CONFIG_X86 |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16996 | /* Enable combined writes for DPP aperture */ |
| 16997 | pg_addr = (unsigned long)(wq->dpp_regaddr) & PAGE_MASK; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16998 | rc = set_memory_wc(pg_addr, 1); |
| 16999 | if (rc) { |
| 17000 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 17001 | "3272 Cannot setup Combined " |
| 17002 | "Write on WQ[%d] - disable DPP\n", |
| 17003 | wq->queue_id); |
| 17004 | phba->cfg_enable_dpp = 0; |
| 17005 | } |
| 17006 | #else |
| 17007 | phba->cfg_enable_dpp = 0; |
| 17008 | #endif |
| 17009 | } else |
| 17010 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 17011 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17012 | wq->pring = kzalloc(sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 17013 | if (wq->pring == NULL) { |
| 17014 | status = -ENOMEM; |
| 17015 | goto out; |
| 17016 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17017 | wq->type = LPFC_WQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 17018 | wq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17019 | wq->subtype = subtype; |
| 17020 | wq->host_index = 0; |
| 17021 | wq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 17022 | wq->notify_interval = LPFC_WQ_NOTIFY_INTRVL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17023 | |
| 17024 | /* link the wq onto the parent cq child list */ |
| 17025 | list_add_tail(&wq->list, &cq->child_list); |
| 17026 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 17027 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17028 | return status; |
| 17029 | } |
| 17030 | |
| 17031 | /** |
| 17032 | * lpfc_rq_create - Create a Receive Queue on the HBA |
| 17033 | * @phba: HBA structure that indicates port to create a queue on. |
| 17034 | * @hrq: The queue structure to use to create the header receive queue. |
| 17035 | * @drq: The queue structure to use to create the data receive queue. |
| 17036 | * @cq: The completion queue to bind this work queue to. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 17037 | * @subtype: The subtype of the work queue indicating its functionality. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17038 | * |
| 17039 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 17040 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 17041 | * to the HBA. |
| 17042 | * |
| 17043 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 17044 | * struct is used to get the entry count that is necessary to determine the |
| 17045 | * number of pages to use for this queue. The @cq is used to indicate which |
| 17046 | * completion queue to bind received buffers that are posted to these queues to. |
| 17047 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 17048 | * receive queue pair. This function is asynchronous and will wait for the |
| 17049 | * mailbox command to finish before continuing. |
| 17050 | * |
| 17051 | * 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] | 17052 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 17053 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17054 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 17055 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17056 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 17057 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) |
| 17058 | { |
| 17059 | struct lpfc_mbx_rq_create *rq_create; |
| 17060 | struct lpfc_dmabuf *dmabuf; |
| 17061 | LPFC_MBOXQ_t *mbox; |
| 17062 | int rc, length, status = 0; |
| 17063 | uint32_t shdr_status, shdr_add_status; |
| 17064 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 17065 | 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] | 17066 | void __iomem *bar_memmap_p; |
| 17067 | uint32_t db_offset; |
| 17068 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 17069 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 17070 | /* sanity check on queue memory */ |
| 17071 | if (!hrq || !drq || !cq) |
| 17072 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 17073 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 17074 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17075 | |
| 17076 | if (hrq->entry_count != drq->entry_count) |
| 17077 | return -EINVAL; |
| 17078 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17079 | if (!mbox) |
| 17080 | return -ENOMEM; |
| 17081 | length = (sizeof(struct lpfc_mbx_rq_create) - |
| 17082 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 17083 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 17084 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 17085 | length, LPFC_SLI4_MBX_EMBED); |
| 17086 | rq_create = &mbox->u.mqe.un.rq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 17087 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 17088 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 17089 | phba->sli4_hba.pc_sli4_params.rqv); |
| 17090 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 17091 | bf_set(lpfc_rq_context_rqe_count_1, |
| 17092 | &rq_create->u.request.context, |
| 17093 | hrq->entry_count); |
| 17094 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 17095 | bf_set(lpfc_rq_context_rqe_size, |
| 17096 | &rq_create->u.request.context, |
| 17097 | LPFC_RQE_SIZE_8); |
| 17098 | bf_set(lpfc_rq_context_page_size, |
| 17099 | &rq_create->u.request.context, |
James Smart | 8ea73db | 2017-02-12 13:52:25 -0800 | [diff] [blame] | 17100 | LPFC_RQ_PAGE_SIZE_4096); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 17101 | } else { |
| 17102 | switch (hrq->entry_count) { |
| 17103 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17104 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 17105 | "2535 Unsupported RQ count. (%d)\n", |
| 17106 | hrq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 17107 | if (hrq->entry_count < 512) { |
| 17108 | status = -EINVAL; |
| 17109 | goto out; |
| 17110 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 17111 | fallthrough; /* otherwise default to smallest count */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 17112 | case 512: |
| 17113 | bf_set(lpfc_rq_context_rqe_count, |
| 17114 | &rq_create->u.request.context, |
| 17115 | LPFC_RQ_RING_SIZE_512); |
| 17116 | break; |
| 17117 | case 1024: |
| 17118 | bf_set(lpfc_rq_context_rqe_count, |
| 17119 | &rq_create->u.request.context, |
| 17120 | LPFC_RQ_RING_SIZE_1024); |
| 17121 | break; |
| 17122 | case 2048: |
| 17123 | bf_set(lpfc_rq_context_rqe_count, |
| 17124 | &rq_create->u.request.context, |
| 17125 | LPFC_RQ_RING_SIZE_2048); |
| 17126 | break; |
| 17127 | case 4096: |
| 17128 | bf_set(lpfc_rq_context_rqe_count, |
| 17129 | &rq_create->u.request.context, |
| 17130 | LPFC_RQ_RING_SIZE_4096); |
| 17131 | break; |
| 17132 | } |
| 17133 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 17134 | LPFC_HDR_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17135 | } |
| 17136 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 17137 | cq->queue_id); |
| 17138 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 17139 | hrq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17140 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 17141 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17142 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 17143 | putPaddrLow(dmabuf->phys); |
| 17144 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 17145 | putPaddrHigh(dmabuf->phys); |
| 17146 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 17147 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 17148 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
| 17149 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17150 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 17151 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17152 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17153 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 17154 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17155 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17156 | "2504 RQ_CREATE mailbox failed with " |
| 17157 | "status x%x add_status x%x, mbx status x%x\n", |
| 17158 | shdr_status, shdr_add_status, rc); |
| 17159 | status = -ENXIO; |
| 17160 | goto out; |
| 17161 | } |
| 17162 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 17163 | if (hrq->queue_id == 0xFFFF) { |
| 17164 | status = -ENXIO; |
| 17165 | goto out; |
| 17166 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 17167 | |
| 17168 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 17169 | hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format, |
| 17170 | &rq_create->u.response); |
| 17171 | if ((hrq->db_format != LPFC_DB_LIST_FORMAT) && |
| 17172 | (hrq->db_format != LPFC_DB_RING_FORMAT)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17173 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 17174 | "3262 RQ [%d] doorbell format not " |
| 17175 | "supported: x%x\n", hrq->queue_id, |
| 17176 | hrq->db_format); |
| 17177 | status = -EINVAL; |
| 17178 | goto out; |
| 17179 | } |
| 17180 | |
| 17181 | pci_barset = bf_get(lpfc_mbx_rq_create_bar_set, |
| 17182 | &rq_create->u.response); |
| 17183 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 17184 | if (!bar_memmap_p) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17185 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 17186 | "3269 RQ[%d] failed to memmap pci " |
| 17187 | "barset:x%x\n", hrq->queue_id, |
| 17188 | pci_barset); |
| 17189 | status = -ENOMEM; |
| 17190 | goto out; |
| 17191 | } |
| 17192 | |
| 17193 | db_offset = rq_create->u.response.doorbell_offset; |
| 17194 | if ((db_offset != LPFC_ULP0_RQ_DOORBELL) && |
| 17195 | (db_offset != LPFC_ULP1_RQ_DOORBELL)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17196 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 17197 | "3270 RQ[%d] doorbell offset not " |
| 17198 | "supported: x%x\n", hrq->queue_id, |
| 17199 | db_offset); |
| 17200 | status = -EINVAL; |
| 17201 | goto out; |
| 17202 | } |
| 17203 | hrq->db_regaddr = bar_memmap_p + db_offset; |
| 17204 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 17205 | "3266 RQ[qid:%d]: barset:x%x, offset:x%x, " |
| 17206 | "format:x%x\n", hrq->queue_id, pci_barset, |
| 17207 | db_offset, hrq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 17208 | } else { |
| 17209 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 17210 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 17211 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17212 | hrq->type = LPFC_HRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 17213 | hrq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17214 | hrq->subtype = subtype; |
| 17215 | hrq->host_index = 0; |
| 17216 | hrq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 17217 | hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17218 | |
| 17219 | /* now create the data queue */ |
| 17220 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 17221 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 17222 | length, LPFC_SLI4_MBX_EMBED); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 17223 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 17224 | phba->sli4_hba.pc_sli4_params.rqv); |
| 17225 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 17226 | bf_set(lpfc_rq_context_rqe_count_1, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 17227 | &rq_create->u.request.context, hrq->entry_count); |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 17228 | if (subtype == LPFC_NVMET) |
| 17229 | rq_create->u.request.context.buffer_size = |
| 17230 | LPFC_NVMET_DATA_BUF_SIZE; |
| 17231 | else |
| 17232 | rq_create->u.request.context.buffer_size = |
| 17233 | LPFC_DATA_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 17234 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
| 17235 | LPFC_RQE_SIZE_8); |
| 17236 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, |
| 17237 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 17238 | } else { |
| 17239 | switch (drq->entry_count) { |
| 17240 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17241 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 17242 | "2536 Unsupported RQ count. (%d)\n", |
| 17243 | drq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 17244 | if (drq->entry_count < 512) { |
| 17245 | status = -EINVAL; |
| 17246 | goto out; |
| 17247 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 17248 | fallthrough; /* otherwise default to smallest count */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 17249 | case 512: |
| 17250 | bf_set(lpfc_rq_context_rqe_count, |
| 17251 | &rq_create->u.request.context, |
| 17252 | LPFC_RQ_RING_SIZE_512); |
| 17253 | break; |
| 17254 | case 1024: |
| 17255 | bf_set(lpfc_rq_context_rqe_count, |
| 17256 | &rq_create->u.request.context, |
| 17257 | LPFC_RQ_RING_SIZE_1024); |
| 17258 | break; |
| 17259 | case 2048: |
| 17260 | bf_set(lpfc_rq_context_rqe_count, |
| 17261 | &rq_create->u.request.context, |
| 17262 | LPFC_RQ_RING_SIZE_2048); |
| 17263 | break; |
| 17264 | case 4096: |
| 17265 | bf_set(lpfc_rq_context_rqe_count, |
| 17266 | &rq_create->u.request.context, |
| 17267 | LPFC_RQ_RING_SIZE_4096); |
| 17268 | break; |
| 17269 | } |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 17270 | if (subtype == LPFC_NVMET) |
| 17271 | bf_set(lpfc_rq_context_buf_size, |
| 17272 | &rq_create->u.request.context, |
| 17273 | LPFC_NVMET_DATA_BUF_SIZE); |
| 17274 | else |
| 17275 | bf_set(lpfc_rq_context_buf_size, |
| 17276 | &rq_create->u.request.context, |
| 17277 | LPFC_DATA_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17278 | } |
| 17279 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 17280 | cq->queue_id); |
| 17281 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 17282 | drq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17283 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 17284 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 17285 | putPaddrLow(dmabuf->phys); |
| 17286 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 17287 | putPaddrHigh(dmabuf->phys); |
| 17288 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 17289 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 17290 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17291 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 17292 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 17293 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 17294 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17295 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 17296 | if (shdr_status || shdr_add_status || rc) { |
| 17297 | status = -ENXIO; |
| 17298 | goto out; |
| 17299 | } |
| 17300 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 17301 | if (drq->queue_id == 0xFFFF) { |
| 17302 | status = -ENXIO; |
| 17303 | goto out; |
| 17304 | } |
| 17305 | drq->type = LPFC_DRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 17306 | drq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17307 | drq->subtype = subtype; |
| 17308 | drq->host_index = 0; |
| 17309 | drq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 17310 | drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17311 | |
| 17312 | /* link the header and data RQs onto the parent cq child list */ |
| 17313 | list_add_tail(&hrq->list, &cq->child_list); |
| 17314 | list_add_tail(&drq->list, &cq->child_list); |
| 17315 | |
| 17316 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 17317 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17318 | return status; |
| 17319 | } |
| 17320 | |
| 17321 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 17322 | * lpfc_mrq_create - Create MRQ Receive Queues on the HBA |
| 17323 | * @phba: HBA structure that indicates port to create a queue on. |
| 17324 | * @hrqp: The queue structure array to use to create the header receive queues. |
| 17325 | * @drqp: The queue structure array to use to create the data receive queues. |
| 17326 | * @cqp: The completion queue array to bind these receive queues to. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 17327 | * @subtype: Functional purpose of the queue (MBOX, IO, ELS, NVMET, etc). |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 17328 | * |
| 17329 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 17330 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 17331 | * to the HBA. |
| 17332 | * |
| 17333 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 17334 | * struct is used to get the entry count that is necessary to determine the |
| 17335 | * number of pages to use for this queue. The @cq is used to indicate which |
| 17336 | * completion queue to bind received buffers that are posted to these queues to. |
| 17337 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 17338 | * receive queue pair. This function is asynchronous and will wait for the |
| 17339 | * mailbox command to finish before continuing. |
| 17340 | * |
| 17341 | * On success this function will return a zero. If unable to allocate enough |
| 17342 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 17343 | * fails this function will return -ENXIO. |
| 17344 | **/ |
| 17345 | int |
| 17346 | lpfc_mrq_create(struct lpfc_hba *phba, struct lpfc_queue **hrqp, |
| 17347 | struct lpfc_queue **drqp, struct lpfc_queue **cqp, |
| 17348 | uint32_t subtype) |
| 17349 | { |
| 17350 | struct lpfc_queue *hrq, *drq, *cq; |
| 17351 | struct lpfc_mbx_rq_create_v2 *rq_create; |
| 17352 | struct lpfc_dmabuf *dmabuf; |
| 17353 | LPFC_MBOXQ_t *mbox; |
| 17354 | int rc, length, alloclen, status = 0; |
| 17355 | int cnt, idx, numrq, page_idx = 0; |
| 17356 | uint32_t shdr_status, shdr_add_status; |
| 17357 | union lpfc_sli4_cfg_shdr *shdr; |
| 17358 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 17359 | |
| 17360 | numrq = phba->cfg_nvmet_mrq; |
| 17361 | /* sanity check on array memory */ |
| 17362 | if (!hrqp || !drqp || !cqp || !numrq) |
| 17363 | return -ENODEV; |
| 17364 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 17365 | hw_page_size = SLI4_PAGE_SIZE; |
| 17366 | |
| 17367 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17368 | if (!mbox) |
| 17369 | return -ENOMEM; |
| 17370 | |
| 17371 | length = sizeof(struct lpfc_mbx_rq_create_v2); |
| 17372 | length += ((2 * numrq * hrqp[0]->page_count) * |
| 17373 | sizeof(struct dma_address)); |
| 17374 | |
| 17375 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 17376 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, length, |
| 17377 | LPFC_SLI4_MBX_NEMBED); |
| 17378 | if (alloclen < length) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17379 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 17380 | "3099 Allocated DMA memory size (%d) is " |
| 17381 | "less than the requested DMA memory size " |
| 17382 | "(%d)\n", alloclen, length); |
| 17383 | status = -ENOMEM; |
| 17384 | goto out; |
| 17385 | } |
| 17386 | |
| 17387 | |
| 17388 | |
| 17389 | rq_create = mbox->sge_array->addr[0]; |
| 17390 | shdr = (union lpfc_sli4_cfg_shdr *)&rq_create->cfg_shdr; |
| 17391 | |
| 17392 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_Q_CREATE_VERSION_2); |
| 17393 | cnt = 0; |
| 17394 | |
| 17395 | for (idx = 0; idx < numrq; idx++) { |
| 17396 | hrq = hrqp[idx]; |
| 17397 | drq = drqp[idx]; |
| 17398 | cq = cqp[idx]; |
| 17399 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 17400 | /* sanity check on queue memory */ |
| 17401 | if (!hrq || !drq || !cq) { |
| 17402 | status = -ENODEV; |
| 17403 | goto out; |
| 17404 | } |
| 17405 | |
James Smart | 7aabe84 | 2017-03-04 09:30:22 -0800 | [diff] [blame] | 17406 | if (hrq->entry_count != drq->entry_count) { |
| 17407 | status = -EINVAL; |
| 17408 | goto out; |
| 17409 | } |
| 17410 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 17411 | if (idx == 0) { |
| 17412 | bf_set(lpfc_mbx_rq_create_num_pages, |
| 17413 | &rq_create->u.request, |
| 17414 | hrq->page_count); |
| 17415 | bf_set(lpfc_mbx_rq_create_rq_cnt, |
| 17416 | &rq_create->u.request, (numrq * 2)); |
| 17417 | bf_set(lpfc_mbx_rq_create_dnb, &rq_create->u.request, |
| 17418 | 1); |
| 17419 | bf_set(lpfc_rq_context_base_cq, |
| 17420 | &rq_create->u.request.context, |
| 17421 | cq->queue_id); |
| 17422 | bf_set(lpfc_rq_context_data_size, |
| 17423 | &rq_create->u.request.context, |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 17424 | LPFC_NVMET_DATA_BUF_SIZE); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 17425 | bf_set(lpfc_rq_context_hdr_size, |
| 17426 | &rq_create->u.request.context, |
| 17427 | LPFC_HDR_BUF_SIZE); |
| 17428 | bf_set(lpfc_rq_context_rqe_count_1, |
| 17429 | &rq_create->u.request.context, |
| 17430 | hrq->entry_count); |
| 17431 | bf_set(lpfc_rq_context_rqe_size, |
| 17432 | &rq_create->u.request.context, |
| 17433 | LPFC_RQE_SIZE_8); |
| 17434 | bf_set(lpfc_rq_context_page_size, |
| 17435 | &rq_create->u.request.context, |
| 17436 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 17437 | } |
| 17438 | rc = 0; |
| 17439 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
| 17440 | memset(dmabuf->virt, 0, hw_page_size); |
| 17441 | cnt = page_idx + dmabuf->buffer_tag; |
| 17442 | rq_create->u.request.page[cnt].addr_lo = |
| 17443 | putPaddrLow(dmabuf->phys); |
| 17444 | rq_create->u.request.page[cnt].addr_hi = |
| 17445 | putPaddrHigh(dmabuf->phys); |
| 17446 | rc++; |
| 17447 | } |
| 17448 | page_idx += rc; |
| 17449 | |
| 17450 | rc = 0; |
| 17451 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 17452 | memset(dmabuf->virt, 0, hw_page_size); |
| 17453 | cnt = page_idx + dmabuf->buffer_tag; |
| 17454 | rq_create->u.request.page[cnt].addr_lo = |
| 17455 | putPaddrLow(dmabuf->phys); |
| 17456 | rq_create->u.request.page[cnt].addr_hi = |
| 17457 | putPaddrHigh(dmabuf->phys); |
| 17458 | rc++; |
| 17459 | } |
| 17460 | page_idx += rc; |
| 17461 | |
| 17462 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 17463 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 17464 | hrq->type = LPFC_HRQ; |
| 17465 | hrq->assoc_qid = cq->queue_id; |
| 17466 | hrq->subtype = subtype; |
| 17467 | hrq->host_index = 0; |
| 17468 | hrq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 17469 | hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 17470 | |
| 17471 | drq->db_format = LPFC_DB_RING_FORMAT; |
| 17472 | drq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 17473 | drq->type = LPFC_DRQ; |
| 17474 | drq->assoc_qid = cq->queue_id; |
| 17475 | drq->subtype = subtype; |
| 17476 | drq->host_index = 0; |
| 17477 | drq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 17478 | drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 17479 | |
| 17480 | list_add_tail(&hrq->list, &cq->child_list); |
| 17481 | list_add_tail(&drq->list, &cq->child_list); |
| 17482 | } |
| 17483 | |
| 17484 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 17485 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 17486 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17487 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 17488 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17489 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 17490 | "3120 RQ_CREATE mailbox failed with " |
| 17491 | "status x%x add_status x%x, mbx status x%x\n", |
| 17492 | shdr_status, shdr_add_status, rc); |
| 17493 | status = -ENXIO; |
| 17494 | goto out; |
| 17495 | } |
| 17496 | rc = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 17497 | if (rc == 0xFFFF) { |
| 17498 | status = -ENXIO; |
| 17499 | goto out; |
| 17500 | } |
| 17501 | |
| 17502 | /* Initialize all RQs with associated queue id */ |
| 17503 | for (idx = 0; idx < numrq; idx++) { |
| 17504 | hrq = hrqp[idx]; |
| 17505 | hrq->queue_id = rc + (2 * idx); |
| 17506 | drq = drqp[idx]; |
| 17507 | drq->queue_id = rc + (2 * idx) + 1; |
| 17508 | } |
| 17509 | |
| 17510 | out: |
| 17511 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 17512 | return status; |
| 17513 | } |
| 17514 | |
| 17515 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17516 | * lpfc_eq_destroy - Destroy an event Queue on the HBA |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 17517 | * @phba: HBA structure that indicates port to destroy a queue on. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17518 | * @eq: The queue structure associated with the queue to destroy. |
| 17519 | * |
| 17520 | * This function destroys a queue, as detailed in @eq by sending an mailbox |
| 17521 | * command, specific to the type of queue, to the HBA. |
| 17522 | * |
| 17523 | * The @eq struct is used to get the queue ID of the queue to destroy. |
| 17524 | * |
| 17525 | * 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] | 17526 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17527 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 17528 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17529 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 17530 | { |
| 17531 | LPFC_MBOXQ_t *mbox; |
| 17532 | int rc, length, status = 0; |
| 17533 | uint32_t shdr_status, shdr_add_status; |
| 17534 | union lpfc_sli4_cfg_shdr *shdr; |
| 17535 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 17536 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17537 | if (!eq) |
| 17538 | return -ENODEV; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 17539 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17540 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); |
| 17541 | if (!mbox) |
| 17542 | return -ENOMEM; |
| 17543 | length = (sizeof(struct lpfc_mbx_eq_destroy) - |
| 17544 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 17545 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 17546 | LPFC_MBOX_OPCODE_EQ_DESTROY, |
| 17547 | length, LPFC_SLI4_MBX_EMBED); |
| 17548 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, |
| 17549 | eq->queue_id); |
| 17550 | mbox->vport = eq->phba->pport; |
| 17551 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 17552 | |
| 17553 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); |
| 17554 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 17555 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 17556 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; |
| 17557 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17558 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 17559 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17560 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17561 | "2505 EQ_DESTROY mailbox failed with " |
| 17562 | "status x%x add_status x%x, mbx status x%x\n", |
| 17563 | shdr_status, shdr_add_status, rc); |
| 17564 | status = -ENXIO; |
| 17565 | } |
| 17566 | |
| 17567 | /* Remove eq from any list */ |
| 17568 | list_del_init(&eq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 17569 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17570 | return status; |
| 17571 | } |
| 17572 | |
| 17573 | /** |
| 17574 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 17575 | * @phba: HBA structure that indicates port to destroy a queue on. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17576 | * @cq: The queue structure associated with the queue to destroy. |
| 17577 | * |
| 17578 | * This function destroys a queue, as detailed in @cq by sending an mailbox |
| 17579 | * command, specific to the type of queue, to the HBA. |
| 17580 | * |
| 17581 | * The @cq struct is used to get the queue ID of the queue to destroy. |
| 17582 | * |
| 17583 | * 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] | 17584 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17585 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 17586 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17587 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
| 17588 | { |
| 17589 | LPFC_MBOXQ_t *mbox; |
| 17590 | int rc, length, status = 0; |
| 17591 | uint32_t shdr_status, shdr_add_status; |
| 17592 | union lpfc_sli4_cfg_shdr *shdr; |
| 17593 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 17594 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17595 | if (!cq) |
| 17596 | return -ENODEV; |
| 17597 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); |
| 17598 | if (!mbox) |
| 17599 | return -ENOMEM; |
| 17600 | length = (sizeof(struct lpfc_mbx_cq_destroy) - |
| 17601 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 17602 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 17603 | LPFC_MBOX_OPCODE_CQ_DESTROY, |
| 17604 | length, LPFC_SLI4_MBX_EMBED); |
| 17605 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, |
| 17606 | cq->queue_id); |
| 17607 | mbox->vport = cq->phba->pport; |
| 17608 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 17609 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); |
| 17610 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 17611 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 17612 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; |
| 17613 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17614 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 17615 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17616 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17617 | "2506 CQ_DESTROY mailbox failed with " |
| 17618 | "status x%x add_status x%x, mbx status x%x\n", |
| 17619 | shdr_status, shdr_add_status, rc); |
| 17620 | status = -ENXIO; |
| 17621 | } |
| 17622 | /* Remove cq from any list */ |
| 17623 | list_del_init(&cq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 17624 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17625 | return status; |
| 17626 | } |
| 17627 | |
| 17628 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 17629 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 17630 | * @phba: HBA structure that indicates port to destroy a queue on. |
| 17631 | * @mq: The queue structure associated with the queue to destroy. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 17632 | * |
| 17633 | * This function destroys a queue, as detailed in @mq by sending an mailbox |
| 17634 | * command, specific to the type of queue, to the HBA. |
| 17635 | * |
| 17636 | * The @mq struct is used to get the queue ID of the queue to destroy. |
| 17637 | * |
| 17638 | * 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] | 17639 | * command fails this function will return -ENXIO. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 17640 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 17641 | int |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 17642 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
| 17643 | { |
| 17644 | LPFC_MBOXQ_t *mbox; |
| 17645 | int rc, length, status = 0; |
| 17646 | uint32_t shdr_status, shdr_add_status; |
| 17647 | union lpfc_sli4_cfg_shdr *shdr; |
| 17648 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 17649 | /* sanity check on queue memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 17650 | if (!mq) |
| 17651 | return -ENODEV; |
| 17652 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); |
| 17653 | if (!mbox) |
| 17654 | return -ENOMEM; |
| 17655 | length = (sizeof(struct lpfc_mbx_mq_destroy) - |
| 17656 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 17657 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 17658 | LPFC_MBOX_OPCODE_MQ_DESTROY, |
| 17659 | length, LPFC_SLI4_MBX_EMBED); |
| 17660 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, |
| 17661 | mq->queue_id); |
| 17662 | mbox->vport = mq->phba->pport; |
| 17663 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 17664 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); |
| 17665 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 17666 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 17667 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; |
| 17668 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17669 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 17670 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17671 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 17672 | "2507 MQ_DESTROY mailbox failed with " |
| 17673 | "status x%x add_status x%x, mbx status x%x\n", |
| 17674 | shdr_status, shdr_add_status, rc); |
| 17675 | status = -ENXIO; |
| 17676 | } |
| 17677 | /* Remove mq from any list */ |
| 17678 | list_del_init(&mq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 17679 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 17680 | return status; |
| 17681 | } |
| 17682 | |
| 17683 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17684 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 17685 | * @phba: HBA structure that indicates port to destroy a queue on. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17686 | * @wq: The queue structure associated with the queue to destroy. |
| 17687 | * |
| 17688 | * This function destroys a queue, as detailed in @wq by sending an mailbox |
| 17689 | * command, specific to the type of queue, to the HBA. |
| 17690 | * |
| 17691 | * The @wq struct is used to get the queue ID of the queue to destroy. |
| 17692 | * |
| 17693 | * 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] | 17694 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17695 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 17696 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17697 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
| 17698 | { |
| 17699 | LPFC_MBOXQ_t *mbox; |
| 17700 | int rc, length, status = 0; |
| 17701 | uint32_t shdr_status, shdr_add_status; |
| 17702 | union lpfc_sli4_cfg_shdr *shdr; |
| 17703 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 17704 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17705 | if (!wq) |
| 17706 | return -ENODEV; |
| 17707 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); |
| 17708 | if (!mbox) |
| 17709 | return -ENOMEM; |
| 17710 | length = (sizeof(struct lpfc_mbx_wq_destroy) - |
| 17711 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 17712 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 17713 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, |
| 17714 | length, LPFC_SLI4_MBX_EMBED); |
| 17715 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, |
| 17716 | wq->queue_id); |
| 17717 | mbox->vport = wq->phba->pport; |
| 17718 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 17719 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); |
| 17720 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 17721 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; |
| 17722 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17723 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 17724 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17725 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17726 | "2508 WQ_DESTROY mailbox failed with " |
| 17727 | "status x%x add_status x%x, mbx status x%x\n", |
| 17728 | shdr_status, shdr_add_status, rc); |
| 17729 | status = -ENXIO; |
| 17730 | } |
| 17731 | /* Remove wq from any list */ |
| 17732 | list_del_init(&wq->list); |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 17733 | kfree(wq->pring); |
| 17734 | wq->pring = NULL; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 17735 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17736 | return status; |
| 17737 | } |
| 17738 | |
| 17739 | /** |
| 17740 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 17741 | * @phba: HBA structure that indicates port to destroy a queue on. |
| 17742 | * @hrq: The queue structure associated with the queue to destroy. |
| 17743 | * @drq: The queue structure associated with the queue to destroy. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17744 | * |
| 17745 | * This function destroys a queue, as detailed in @rq by sending an mailbox |
| 17746 | * command, specific to the type of queue, to the HBA. |
| 17747 | * |
| 17748 | * The @rq struct is used to get the queue ID of the queue to destroy. |
| 17749 | * |
| 17750 | * 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] | 17751 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17752 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 17753 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17754 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 17755 | struct lpfc_queue *drq) |
| 17756 | { |
| 17757 | LPFC_MBOXQ_t *mbox; |
| 17758 | int rc, length, status = 0; |
| 17759 | uint32_t shdr_status, shdr_add_status; |
| 17760 | union lpfc_sli4_cfg_shdr *shdr; |
| 17761 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 17762 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17763 | if (!hrq || !drq) |
| 17764 | return -ENODEV; |
| 17765 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); |
| 17766 | if (!mbox) |
| 17767 | return -ENOMEM; |
| 17768 | length = (sizeof(struct lpfc_mbx_rq_destroy) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 17769 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17770 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 17771 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, |
| 17772 | length, LPFC_SLI4_MBX_EMBED); |
| 17773 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 17774 | hrq->queue_id); |
| 17775 | mbox->vport = hrq->phba->pport; |
| 17776 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 17777 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); |
| 17778 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 17779 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 17780 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 17781 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17782 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 17783 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17784 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17785 | "2509 RQ_DESTROY mailbox failed with " |
| 17786 | "status x%x add_status x%x, mbx status x%x\n", |
| 17787 | shdr_status, shdr_add_status, rc); |
James Smart | 304ee43 | 2021-04-11 18:31:17 -0700 | [diff] [blame] | 17788 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17789 | return -ENXIO; |
| 17790 | } |
| 17791 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 17792 | drq->queue_id); |
| 17793 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); |
| 17794 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 17795 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 17796 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17797 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 17798 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17799 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17800 | "2510 RQ_DESTROY mailbox failed with " |
| 17801 | "status x%x add_status x%x, mbx status x%x\n", |
| 17802 | shdr_status, shdr_add_status, rc); |
| 17803 | status = -ENXIO; |
| 17804 | } |
| 17805 | list_del_init(&hrq->list); |
| 17806 | list_del_init(&drq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 17807 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17808 | return status; |
| 17809 | } |
| 17810 | |
| 17811 | /** |
| 17812 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA |
| 17813 | * @phba: The virtual port for which this call being executed. |
| 17814 | * @pdma_phys_addr0: Physical address of the 1st SGL page. |
| 17815 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. |
| 17816 | * @xritag: the xritag that ties this io to the SGL pages. |
| 17817 | * |
| 17818 | * This routine will post the sgl pages for the IO that has the xritag |
| 17819 | * that is in the iocbq structure. The xritag is assigned during iocbq |
| 17820 | * creation and persists for as long as the driver is loaded. |
| 17821 | * if the caller has fewer than 256 scatter gather segments to map then |
| 17822 | * pdma_phys_addr1 should be 0. |
| 17823 | * If the caller needs to map more than 256 scatter gather segment then |
| 17824 | * pdma_phys_addr1 should be a valid physical address. |
| 17825 | * physical address for SGLs must be 64 byte aligned. |
| 17826 | * If you are going to map 2 SGL's then the first one must have 256 entries |
| 17827 | * the second sgl can have between 1 and 256 entries. |
| 17828 | * |
| 17829 | * Return codes: |
| 17830 | * 0 - Success |
| 17831 | * -ENXIO, -ENOMEM - Failure |
| 17832 | **/ |
| 17833 | int |
| 17834 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, |
| 17835 | dma_addr_t pdma_phys_addr0, |
| 17836 | dma_addr_t pdma_phys_addr1, |
| 17837 | uint16_t xritag) |
| 17838 | { |
| 17839 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; |
| 17840 | LPFC_MBOXQ_t *mbox; |
| 17841 | int rc; |
| 17842 | uint32_t shdr_status, shdr_add_status; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17843 | uint32_t mbox_tmo; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17844 | union lpfc_sli4_cfg_shdr *shdr; |
| 17845 | |
| 17846 | if (xritag == NO_XRI) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17847 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17848 | "0364 Invalid param:\n"); |
| 17849 | return -EINVAL; |
| 17850 | } |
| 17851 | |
| 17852 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17853 | if (!mbox) |
| 17854 | return -ENOMEM; |
| 17855 | |
| 17856 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 17857 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 17858 | sizeof(struct lpfc_mbx_post_sgl_pages) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 17859 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17860 | |
| 17861 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) |
| 17862 | &mbox->u.mqe.un.post_sgl_pages; |
| 17863 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); |
| 17864 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); |
| 17865 | |
| 17866 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = |
| 17867 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); |
| 17868 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = |
| 17869 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); |
| 17870 | |
| 17871 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = |
| 17872 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); |
| 17873 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = |
| 17874 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); |
| 17875 | if (!phba->sli4_hba.intr_enable) |
| 17876 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17877 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 17878 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17879 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 17880 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17881 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 17882 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; |
| 17883 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17884 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 304ee43 | 2021-04-11 18:31:17 -0700 | [diff] [blame] | 17885 | if (!phba->sli4_hba.intr_enable) |
| 17886 | mempool_free(mbox, phba->mbox_mem_pool); |
| 17887 | else if (rc != MBX_TIMEOUT) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17888 | mempool_free(mbox, phba->mbox_mem_pool); |
| 17889 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17890 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17891 | "2511 POST_SGL mailbox failed with " |
| 17892 | "status x%x add_status x%x, mbx status x%x\n", |
| 17893 | shdr_status, shdr_add_status, rc); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17894 | } |
| 17895 | return 0; |
| 17896 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17897 | |
| 17898 | /** |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 17899 | * 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] | 17900 | * @phba: pointer to lpfc hba data structure. |
| 17901 | * |
| 17902 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 17903 | * HBA consistent with the SLI-4 interface spec. This routine |
| 17904 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 17905 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17906 | * |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 17907 | * Returns |
| 17908 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
| 17909 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 17910 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17911 | static uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17912 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
| 17913 | { |
| 17914 | unsigned long xri; |
| 17915 | |
| 17916 | /* |
| 17917 | * Fetch the next logical xri. Because this index is logical, |
| 17918 | * the driver starts at 0 each time. |
| 17919 | */ |
| 17920 | spin_lock_irq(&phba->hbalock); |
| 17921 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, |
| 17922 | phba->sli4_hba.max_cfg_param.max_xri, 0); |
| 17923 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { |
| 17924 | spin_unlock_irq(&phba->hbalock); |
| 17925 | return NO_XRI; |
| 17926 | } else { |
| 17927 | set_bit(xri, phba->sli4_hba.xri_bmask); |
| 17928 | phba->sli4_hba.max_cfg_param.xri_used++; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17929 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17930 | spin_unlock_irq(&phba->hbalock); |
| 17931 | return xri; |
| 17932 | } |
| 17933 | |
| 17934 | /** |
Lee Jones | 8514e2f | 2021-03-03 14:46:18 +0000 | [diff] [blame] | 17935 | * __lpfc_sli4_free_xri - Release an xri for reuse. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17936 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 17937 | * @xri: xri to release. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17938 | * |
| 17939 | * This routine is invoked to release an xri to the pool of |
| 17940 | * available rpis maintained by the driver. |
| 17941 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17942 | static void |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17943 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 17944 | { |
| 17945 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17946 | phba->sli4_hba.max_cfg_param.xri_used--; |
| 17947 | } |
| 17948 | } |
| 17949 | |
| 17950 | /** |
| 17951 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 17952 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 17953 | * @xri: xri to release. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17954 | * |
| 17955 | * This routine is invoked to release an xri to the pool of |
| 17956 | * available rpis maintained by the driver. |
| 17957 | **/ |
| 17958 | void |
| 17959 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 17960 | { |
| 17961 | spin_lock_irq(&phba->hbalock); |
| 17962 | __lpfc_sli4_free_xri(phba, xri); |
| 17963 | spin_unlock_irq(&phba->hbalock); |
| 17964 | } |
| 17965 | |
| 17966 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17967 | * lpfc_sli4_next_xritag - Get an xritag for the io |
| 17968 | * @phba: Pointer to HBA context object. |
| 17969 | * |
| 17970 | * This function gets an xritag for the iocb. If there is no unused xritag |
| 17971 | * it will return 0xffff. |
| 17972 | * The function returns the allocated xritag if successful, else returns zero. |
| 17973 | * Zero is not a valid xritag. |
| 17974 | * The caller is not required to hold any lock. |
| 17975 | **/ |
| 17976 | uint16_t |
| 17977 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) |
| 17978 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17979 | uint16_t xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17980 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17981 | xri_index = lpfc_sli4_alloc_xri(phba); |
James Smart | 8137805 | 2012-05-09 21:17:37 -0400 | [diff] [blame] | 17982 | if (xri_index == NO_XRI) |
| 17983 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 17984 | "2004 Failed to allocate XRI.last XRITAG is %d" |
| 17985 | " Max XRI is %d, Used XRI is %d\n", |
| 17986 | xri_index, |
| 17987 | phba->sli4_hba.max_cfg_param.max_xri, |
| 17988 | phba->sli4_hba.max_cfg_param.xri_used); |
| 17989 | return xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17990 | } |
| 17991 | |
| 17992 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17993 | * 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] | 17994 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 17995 | * @post_sgl_list: pointer to els sgl entry list. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 17996 | * @post_cnt: number of els sgl entries on the list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17997 | * |
| 17998 | * This routine is invoked to post a block of driver's sgl pages to the |
| 17999 | * HBA using non-embedded mailbox command. No Lock is held. This routine |
| 18000 | * is only called when the driver is loading and after all IO has been |
| 18001 | * stopped. |
| 18002 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 18003 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18004 | lpfc_sli4_post_sgl_list(struct lpfc_hba *phba, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 18005 | struct list_head *post_sgl_list, |
| 18006 | int post_cnt) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18007 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 18008 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18009 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 18010 | struct sgl_page_pairs *sgl_pg_pairs; |
| 18011 | void *viraddr; |
| 18012 | LPFC_MBOXQ_t *mbox; |
| 18013 | uint32_t reqlen, alloclen, pg_pairs; |
| 18014 | uint32_t mbox_tmo; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 18015 | uint16_t xritag_start = 0; |
| 18016 | int rc = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18017 | uint32_t shdr_status, shdr_add_status; |
| 18018 | union lpfc_sli4_cfg_shdr *shdr; |
| 18019 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18020 | reqlen = post_cnt * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18021 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 18022 | if (reqlen > SLI4_PAGE_SIZE) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 18023 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18024 | "2559 Block sgl registration required DMA " |
| 18025 | "size (%d) great than a page\n", reqlen); |
| 18026 | return -ENOMEM; |
| 18027 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18028 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18029 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18030 | if (!mbox) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18031 | return -ENOMEM; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18032 | |
| 18033 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 18034 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18035 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 18036 | LPFC_SLI4_MBX_NEMBED); |
| 18037 | |
| 18038 | if (alloclen < reqlen) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 18039 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18040 | "0285 Allocated DMA memory size (%d) is " |
| 18041 | "less than the requested DMA memory " |
| 18042 | "size (%d)\n", alloclen, reqlen); |
| 18043 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 18044 | return -ENOMEM; |
| 18045 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18046 | /* Set up the SGL pages in the non-embedded DMA pages */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18047 | viraddr = mbox->sge_array->addr[0]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18048 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 18049 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 18050 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 18051 | pg_pairs = 0; |
| 18052 | 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] | 18053 | /* Set up the sge entry */ |
| 18054 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 18055 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); |
| 18056 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 18057 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); |
| 18058 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 18059 | cpu_to_le32(putPaddrLow(0)); |
| 18060 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 18061 | cpu_to_le32(putPaddrHigh(0)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18062 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18063 | /* Keep the first xritag on the list */ |
| 18064 | if (pg_pairs == 0) |
| 18065 | xritag_start = sglq_entry->sli4_xritag; |
| 18066 | sgl_pg_pairs++; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 18067 | pg_pairs++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18068 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18069 | |
| 18070 | /* Complete initialization and perform endian conversion. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18071 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18072 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, post_cnt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18073 | sgl->word0 = cpu_to_le32(sgl->word0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18074 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18075 | if (!phba->sli4_hba.intr_enable) |
| 18076 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 18077 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 18078 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18079 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 18080 | } |
| 18081 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 18082 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 18083 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 304ee43 | 2021-04-11 18:31:17 -0700 | [diff] [blame] | 18084 | if (!phba->sli4_hba.intr_enable) |
| 18085 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 18086 | else if (rc != MBX_TIMEOUT) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18087 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 18088 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 18089 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18090 | "2513 POST_SGL_BLOCK mailbox command failed " |
| 18091 | "status x%x add_status x%x mbx status x%x\n", |
| 18092 | shdr_status, shdr_add_status, rc); |
| 18093 | rc = -ENXIO; |
| 18094 | } |
| 18095 | return rc; |
| 18096 | } |
| 18097 | |
| 18098 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 18099 | * 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] | 18100 | * @phba: pointer to lpfc hba data structure. |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 18101 | * @nblist: pointer to nvme buffer list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18102 | * @count: number of scsi buffers on the list. |
| 18103 | * |
| 18104 | * 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] | 18105 | * SCSI buffer list @nblist to the HBA using non-embedded mailbox command. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18106 | * No Lock is held. |
| 18107 | * |
| 18108 | **/ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 18109 | static int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 18110 | lpfc_sli4_post_io_sgl_block(struct lpfc_hba *phba, struct list_head *nblist, |
| 18111 | int count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18112 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 18113 | struct lpfc_io_buf *lpfc_ncmd; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18114 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 18115 | struct sgl_page_pairs *sgl_pg_pairs; |
| 18116 | void *viraddr; |
| 18117 | LPFC_MBOXQ_t *mbox; |
| 18118 | uint32_t reqlen, alloclen, pg_pairs; |
| 18119 | uint32_t mbox_tmo; |
| 18120 | uint16_t xritag_start = 0; |
| 18121 | int rc = 0; |
| 18122 | uint32_t shdr_status, shdr_add_status; |
| 18123 | dma_addr_t pdma_phys_bpl1; |
| 18124 | union lpfc_sli4_cfg_shdr *shdr; |
| 18125 | |
| 18126 | /* Calculate the requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 18127 | reqlen = count * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18128 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 18129 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18130 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 18131 | "6118 Block sgl registration required DMA " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18132 | "size (%d) great than a page\n", reqlen); |
| 18133 | return -ENOMEM; |
| 18134 | } |
| 18135 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18136 | if (!mbox) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 18137 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 18138 | "6119 Failed to allocate mbox cmd memory\n"); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18139 | return -ENOMEM; |
| 18140 | } |
| 18141 | |
| 18142 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 18143 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 18144 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 18145 | reqlen, LPFC_SLI4_MBX_NEMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18146 | |
| 18147 | if (alloclen < reqlen) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 18148 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 18149 | "6120 Allocated DMA memory size (%d) is " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18150 | "less than the requested DMA memory " |
| 18151 | "size (%d)\n", alloclen, reqlen); |
| 18152 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 18153 | return -ENOMEM; |
| 18154 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18155 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18156 | /* Get the first SGE entry from the non-embedded DMA memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18157 | viraddr = mbox->sge_array->addr[0]; |
| 18158 | |
| 18159 | /* Set up the SGL pages in the non-embedded DMA pages */ |
| 18160 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 18161 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 18162 | |
| 18163 | pg_pairs = 0; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 18164 | list_for_each_entry(lpfc_ncmd, nblist, list) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18165 | /* Set up the sge entry */ |
| 18166 | sgl_pg_pairs->sgl_pg0_addr_lo = |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 18167 | cpu_to_le32(putPaddrLow(lpfc_ncmd->dma_phys_sgl)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18168 | sgl_pg_pairs->sgl_pg0_addr_hi = |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 18169 | cpu_to_le32(putPaddrHigh(lpfc_ncmd->dma_phys_sgl)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18170 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 18171 | pdma_phys_bpl1 = lpfc_ncmd->dma_phys_sgl + |
| 18172 | SGL_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18173 | else |
| 18174 | pdma_phys_bpl1 = 0; |
| 18175 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 18176 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); |
| 18177 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 18178 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); |
| 18179 | /* Keep the first xritag on the list */ |
| 18180 | if (pg_pairs == 0) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 18181 | xritag_start = lpfc_ncmd->cur_iocbq.sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18182 | sgl_pg_pairs++; |
| 18183 | pg_pairs++; |
| 18184 | } |
| 18185 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
| 18186 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); |
| 18187 | /* Perform endian conversion if necessary */ |
| 18188 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 18189 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 18190 | if (!phba->sli4_hba.intr_enable) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18191 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 18192 | } else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 18193 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18194 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 18195 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 18196 | shdr = (union lpfc_sli4_cfg_shdr *)&sgl->cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18197 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 18198 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 304ee43 | 2021-04-11 18:31:17 -0700 | [diff] [blame] | 18199 | if (!phba->sli4_hba.intr_enable) |
| 18200 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 18201 | else if (rc != MBX_TIMEOUT) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18202 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 18203 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 18204 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 18205 | "6125 POST_SGL_BLOCK mailbox command failed " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18206 | "status x%x add_status x%x mbx status x%x\n", |
| 18207 | shdr_status, shdr_add_status, rc); |
| 18208 | rc = -ENXIO; |
| 18209 | } |
| 18210 | return rc; |
| 18211 | } |
| 18212 | |
| 18213 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 18214 | * 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] | 18215 | * @phba: pointer to lpfc hba data structure. |
| 18216 | * @post_nblist: pointer to the nvme buffer list. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 18217 | * @sb_count: number of nvme buffers. |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 18218 | * |
| 18219 | * This routine walks a list of nvme buffers that was passed in. It attempts |
| 18220 | * to construct blocks of nvme buffer sgls which contains contiguous xris and |
| 18221 | * uses the non-embedded SGL block post mailbox commands to post to the port. |
| 18222 | * For single NVME buffer sgl with non-contiguous xri, if any, it shall use |
| 18223 | * embedded SGL post mailbox command for posting. The @post_nblist passed in |
| 18224 | * must be local list, thus no lock is needed when manipulate the list. |
| 18225 | * |
| 18226 | * Returns: 0 = failure, non-zero number of successfully posted buffers. |
| 18227 | **/ |
| 18228 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 18229 | lpfc_sli4_post_io_sgl_list(struct lpfc_hba *phba, |
| 18230 | struct list_head *post_nblist, int sb_count) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 18231 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 18232 | struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 18233 | int status, sgl_size; |
| 18234 | int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0; |
| 18235 | dma_addr_t pdma_phys_sgl1; |
| 18236 | int last_xritag = NO_XRI; |
| 18237 | int cur_xritag; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 18238 | LIST_HEAD(prep_nblist); |
| 18239 | LIST_HEAD(blck_nblist); |
| 18240 | LIST_HEAD(nvme_nblist); |
| 18241 | |
| 18242 | /* sanity check */ |
| 18243 | if (sb_count <= 0) |
| 18244 | return -EINVAL; |
| 18245 | |
| 18246 | sgl_size = phba->cfg_sg_dma_buf_size; |
| 18247 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, post_nblist, list) { |
| 18248 | list_del_init(&lpfc_ncmd->list); |
| 18249 | block_cnt++; |
| 18250 | if ((last_xritag != NO_XRI) && |
| 18251 | (lpfc_ncmd->cur_iocbq.sli4_xritag != last_xritag + 1)) { |
| 18252 | /* a hole in xri block, form a sgl posting block */ |
| 18253 | list_splice_init(&prep_nblist, &blck_nblist); |
| 18254 | post_cnt = block_cnt - 1; |
| 18255 | /* prepare list for next posting block */ |
| 18256 | list_add_tail(&lpfc_ncmd->list, &prep_nblist); |
| 18257 | block_cnt = 1; |
| 18258 | } else { |
| 18259 | /* prepare list for next posting block */ |
| 18260 | list_add_tail(&lpfc_ncmd->list, &prep_nblist); |
| 18261 | /* enough sgls for non-embed sgl mbox command */ |
| 18262 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 18263 | list_splice_init(&prep_nblist, &blck_nblist); |
| 18264 | post_cnt = block_cnt; |
| 18265 | block_cnt = 0; |
| 18266 | } |
| 18267 | } |
| 18268 | num_posting++; |
| 18269 | last_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag; |
| 18270 | |
| 18271 | /* end of repost sgl list condition for NVME buffers */ |
| 18272 | if (num_posting == sb_count) { |
| 18273 | if (post_cnt == 0) { |
| 18274 | /* last sgl posting block */ |
| 18275 | list_splice_init(&prep_nblist, &blck_nblist); |
| 18276 | post_cnt = block_cnt; |
| 18277 | } else if (block_cnt == 1) { |
| 18278 | /* last single sgl with non-contiguous xri */ |
| 18279 | if (sgl_size > SGL_PAGE_SIZE) |
| 18280 | pdma_phys_sgl1 = |
| 18281 | lpfc_ncmd->dma_phys_sgl + |
| 18282 | SGL_PAGE_SIZE; |
| 18283 | else |
| 18284 | pdma_phys_sgl1 = 0; |
| 18285 | cur_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag; |
| 18286 | status = lpfc_sli4_post_sgl( |
| 18287 | phba, lpfc_ncmd->dma_phys_sgl, |
| 18288 | pdma_phys_sgl1, cur_xritag); |
| 18289 | if (status) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 18290 | /* Post error. Buffer unavailable. */ |
| 18291 | lpfc_ncmd->flags |= |
| 18292 | LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 18293 | } else { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 18294 | /* Post success. Bffer available. */ |
| 18295 | lpfc_ncmd->flags &= |
| 18296 | ~LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 18297 | lpfc_ncmd->status = IOSTAT_SUCCESS; |
| 18298 | num_posted++; |
| 18299 | } |
| 18300 | /* success, put on NVME buffer sgl list */ |
| 18301 | list_add_tail(&lpfc_ncmd->list, &nvme_nblist); |
| 18302 | } |
| 18303 | } |
| 18304 | |
| 18305 | /* continue until a nembed page worth of sgls */ |
| 18306 | if (post_cnt == 0) |
| 18307 | continue; |
| 18308 | |
| 18309 | /* post block of NVME buffer list sgls */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 18310 | status = lpfc_sli4_post_io_sgl_block(phba, &blck_nblist, |
| 18311 | post_cnt); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 18312 | |
| 18313 | /* don't reset xirtag due to hole in xri block */ |
| 18314 | if (block_cnt == 0) |
| 18315 | last_xritag = NO_XRI; |
| 18316 | |
| 18317 | /* reset NVME buffer post count for next round of posting */ |
| 18318 | post_cnt = 0; |
| 18319 | |
| 18320 | /* put posted NVME buffer-sgl posted on NVME buffer sgl list */ |
| 18321 | while (!list_empty(&blck_nblist)) { |
| 18322 | list_remove_head(&blck_nblist, lpfc_ncmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 18323 | struct lpfc_io_buf, list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 18324 | if (status) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 18325 | /* Post error. Mark buffer unavailable. */ |
| 18326 | lpfc_ncmd->flags |= LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 18327 | } else { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 18328 | /* Post success, Mark buffer available. */ |
| 18329 | lpfc_ncmd->flags &= ~LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 18330 | lpfc_ncmd->status = IOSTAT_SUCCESS; |
| 18331 | num_posted++; |
| 18332 | } |
| 18333 | list_add_tail(&lpfc_ncmd->list, &nvme_nblist); |
| 18334 | } |
| 18335 | } |
| 18336 | /* Push NVME buffers with sgl posted to the available list */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 18337 | lpfc_io_buf_replenish(phba, &nvme_nblist); |
| 18338 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 18339 | return num_posted; |
| 18340 | } |
| 18341 | |
| 18342 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18343 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle |
| 18344 | * @phba: pointer to lpfc_hba struct that the frame was received on |
| 18345 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 18346 | * |
| 18347 | * This function checks the fields in the @fc_hdr to see if the FC frame is a |
| 18348 | * valid type of frame that the LPFC driver will handle. This function will |
| 18349 | * return a zero if the frame is a valid frame or a non zero value when the |
| 18350 | * frame does not pass the check. |
| 18351 | **/ |
| 18352 | static int |
| 18353 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) |
| 18354 | { |
Tomas Henzl | 474ffb7 | 2010-12-22 16:52:40 +0100 | [diff] [blame] | 18355 | /* make rctl_names static to save stack space */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18356 | struct fc_vft_header *fc_vft_hdr; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18357 | uint32_t *header = (uint32_t *) fc_hdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18358 | |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 18359 | #define FC_RCTL_MDS_DIAGS 0xF4 |
| 18360 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18361 | switch (fc_hdr->fh_r_ctl) { |
| 18362 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ |
| 18363 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ |
| 18364 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ |
| 18365 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ |
| 18366 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ |
| 18367 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ |
| 18368 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ |
| 18369 | case FC_RCTL_DD_CMD_STATUS: /* command status */ |
| 18370 | case FC_RCTL_ELS_REQ: /* extended link services request */ |
| 18371 | case FC_RCTL_ELS_REP: /* extended link services reply */ |
| 18372 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ |
| 18373 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ |
| 18374 | case FC_RCTL_BA_NOP: /* basic link service NOP */ |
| 18375 | case FC_RCTL_BA_ABTS: /* basic link service abort */ |
| 18376 | case FC_RCTL_BA_RMC: /* remove connection */ |
| 18377 | case FC_RCTL_BA_ACC: /* basic accept */ |
| 18378 | case FC_RCTL_BA_RJT: /* basic reject */ |
| 18379 | case FC_RCTL_BA_PRMT: |
| 18380 | case FC_RCTL_ACK_1: /* acknowledge_1 */ |
| 18381 | case FC_RCTL_ACK_0: /* acknowledge_0 */ |
| 18382 | case FC_RCTL_P_RJT: /* port reject */ |
| 18383 | case FC_RCTL_F_RJT: /* fabric reject */ |
| 18384 | case FC_RCTL_P_BSY: /* port busy */ |
| 18385 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ |
| 18386 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ |
| 18387 | case FC_RCTL_LCR: /* link credit reset */ |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18388 | case FC_RCTL_MDS_DIAGS: /* MDS Diagnostics */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18389 | case FC_RCTL_END: /* end */ |
| 18390 | break; |
| 18391 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ |
| 18392 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 18393 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; |
| 18394 | return lpfc_fc_frame_check(phba, fc_hdr); |
| 18395 | default: |
| 18396 | goto drop; |
| 18397 | } |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18398 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18399 | switch (fc_hdr->fh_type) { |
| 18400 | case FC_TYPE_BLS: |
| 18401 | case FC_TYPE_ELS: |
| 18402 | case FC_TYPE_FCP: |
| 18403 | case FC_TYPE_CT: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18404 | case FC_TYPE_NVME: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18405 | break; |
| 18406 | case FC_TYPE_IP: |
| 18407 | case FC_TYPE_ILS: |
| 18408 | default: |
| 18409 | goto drop; |
| 18410 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18411 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18412 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 18413 | "2538 Received frame rctl:x%x, type:x%x, " |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 18414 | "frame Data:%08x %08x %08x %08x %08x %08x %08x\n", |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 18415 | fc_hdr->fh_r_ctl, fc_hdr->fh_type, |
| 18416 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
| 18417 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), |
| 18418 | be32_to_cpu(header[4]), be32_to_cpu(header[5]), |
| 18419 | be32_to_cpu(header[6])); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18420 | return 0; |
| 18421 | drop: |
| 18422 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 18423 | "2539 Dropped frame rctl:x%x type:x%x\n", |
| 18424 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18425 | return 1; |
| 18426 | } |
| 18427 | |
| 18428 | /** |
| 18429 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame |
| 18430 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 18431 | * |
| 18432 | * This function processes the FC header to retrieve the VFI from the VF |
| 18433 | * header, if one exists. This function will return the VFI if one exists |
| 18434 | * or 0 if no VSAN Header exists. |
| 18435 | **/ |
| 18436 | static uint32_t |
| 18437 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) |
| 18438 | { |
| 18439 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 18440 | |
| 18441 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) |
| 18442 | return 0; |
| 18443 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); |
| 18444 | } |
| 18445 | |
| 18446 | /** |
| 18447 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to |
| 18448 | * @phba: Pointer to the HBA structure to search for the vport on |
| 18449 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 18450 | * @fcfi: The FC Fabric ID that the frame came from |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 18451 | * @did: Destination ID to match against |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18452 | * |
| 18453 | * This function searches the @phba for a vport that matches the content of the |
| 18454 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the |
| 18455 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function |
| 18456 | * returns the matching vport pointer or NULL if unable to match frame to a |
| 18457 | * vport. |
| 18458 | **/ |
| 18459 | static struct lpfc_vport * |
| 18460 | 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] | 18461 | uint16_t fcfi, uint32_t did) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18462 | { |
| 18463 | struct lpfc_vport **vports; |
| 18464 | struct lpfc_vport *vport = NULL; |
| 18465 | int i; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 18466 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 18467 | if (did == Fabric_DID) |
| 18468 | return phba->pport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 18469 | if ((phba->pport->fc_flag & FC_PT2PT) && |
| 18470 | !(phba->link_state == LPFC_HBA_READY)) |
| 18471 | return phba->pport; |
| 18472 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18473 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18474 | if (vports != NULL) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18475 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 18476 | if (phba->fcf.fcfi == fcfi && |
| 18477 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && |
| 18478 | vports[i]->fc_myDID == did) { |
| 18479 | vport = vports[i]; |
| 18480 | break; |
| 18481 | } |
| 18482 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18483 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18484 | lpfc_destroy_vport_work_array(phba, vports); |
| 18485 | return vport; |
| 18486 | } |
| 18487 | |
| 18488 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 18489 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp |
| 18490 | * @vport: The vport to work on. |
| 18491 | * |
| 18492 | * This function updates the receive sequence time stamp for this vport. The |
| 18493 | * receive sequence time stamp indicates the time that the last frame of the |
| 18494 | * the sequence that has been idle for the longest amount of time was received. |
| 18495 | * the driver uses this time stamp to indicate if any received sequences have |
| 18496 | * timed out. |
| 18497 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18498 | static void |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 18499 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
| 18500 | { |
| 18501 | struct lpfc_dmabuf *h_buf; |
| 18502 | struct hbq_dmabuf *dmabuf = NULL; |
| 18503 | |
| 18504 | /* get the oldest sequence on the rcv list */ |
| 18505 | h_buf = list_get_first(&vport->rcv_buffer_list, |
| 18506 | struct lpfc_dmabuf, list); |
| 18507 | if (!h_buf) |
| 18508 | return; |
| 18509 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 18510 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; |
| 18511 | } |
| 18512 | |
| 18513 | /** |
| 18514 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. |
| 18515 | * @vport: The vport that the received sequences were sent to. |
| 18516 | * |
| 18517 | * This function cleans up all outstanding received sequences. This is called |
| 18518 | * by the driver when a link event or user action invalidates all the received |
| 18519 | * sequences. |
| 18520 | **/ |
| 18521 | void |
| 18522 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) |
| 18523 | { |
| 18524 | struct lpfc_dmabuf *h_buf, *hnext; |
| 18525 | struct lpfc_dmabuf *d_buf, *dnext; |
| 18526 | struct hbq_dmabuf *dmabuf = NULL; |
| 18527 | |
| 18528 | /* start with the oldest sequence on the rcv list */ |
| 18529 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 18530 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 18531 | list_del_init(&dmabuf->hbuf.list); |
| 18532 | list_for_each_entry_safe(d_buf, dnext, |
| 18533 | &dmabuf->dbuf.list, list) { |
| 18534 | list_del_init(&d_buf->list); |
| 18535 | lpfc_in_buf_free(vport->phba, d_buf); |
| 18536 | } |
| 18537 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 18538 | } |
| 18539 | } |
| 18540 | |
| 18541 | /** |
| 18542 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. |
| 18543 | * @vport: The vport that the received sequences were sent to. |
| 18544 | * |
| 18545 | * This function determines whether any received sequences have timed out by |
| 18546 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp |
| 18547 | * indicates that there is at least one timed out sequence this routine will |
| 18548 | * go through the received sequences one at a time from most inactive to most |
| 18549 | * active to determine which ones need to be cleaned up. Once it has determined |
| 18550 | * that a sequence needs to be cleaned up it will simply free up the resources |
| 18551 | * without sending an abort. |
| 18552 | **/ |
| 18553 | void |
| 18554 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) |
| 18555 | { |
| 18556 | struct lpfc_dmabuf *h_buf, *hnext; |
| 18557 | struct lpfc_dmabuf *d_buf, *dnext; |
| 18558 | struct hbq_dmabuf *dmabuf = NULL; |
| 18559 | unsigned long timeout; |
| 18560 | int abort_count = 0; |
| 18561 | |
| 18562 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 18563 | vport->rcv_buffer_time_stamp); |
| 18564 | if (list_empty(&vport->rcv_buffer_list) || |
| 18565 | time_before(jiffies, timeout)) |
| 18566 | return; |
| 18567 | /* start with the oldest sequence on the rcv list */ |
| 18568 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 18569 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 18570 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 18571 | dmabuf->time_stamp); |
| 18572 | if (time_before(jiffies, timeout)) |
| 18573 | break; |
| 18574 | abort_count++; |
| 18575 | list_del_init(&dmabuf->hbuf.list); |
| 18576 | list_for_each_entry_safe(d_buf, dnext, |
| 18577 | &dmabuf->dbuf.list, list) { |
| 18578 | list_del_init(&d_buf->list); |
| 18579 | lpfc_in_buf_free(vport->phba, d_buf); |
| 18580 | } |
| 18581 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 18582 | } |
| 18583 | if (abort_count) |
| 18584 | lpfc_update_rcv_time_stamp(vport); |
| 18585 | } |
| 18586 | |
| 18587 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18588 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 18589 | * @vport: pointer to a vitural port |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18590 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame |
| 18591 | * |
| 18592 | * This function searches through the existing incomplete sequences that have |
| 18593 | * been sent to this @vport. If the frame matches one of the incomplete |
| 18594 | * sequences then the dbuf in the @dmabuf is added to the list of frames that |
| 18595 | * make up that sequence. If no sequence is found that matches this frame then |
| 18596 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list |
| 18597 | * This function returns a pointer to the first dmabuf in the sequence list that |
| 18598 | * the frame was linked to. |
| 18599 | **/ |
| 18600 | static struct hbq_dmabuf * |
| 18601 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 18602 | { |
| 18603 | struct fc_frame_header *new_hdr; |
| 18604 | struct fc_frame_header *temp_hdr; |
| 18605 | struct lpfc_dmabuf *d_buf; |
| 18606 | struct lpfc_dmabuf *h_buf; |
| 18607 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 18608 | struct hbq_dmabuf *temp_dmabuf = NULL; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 18609 | uint8_t found = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18610 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18611 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 18612 | dmabuf->time_stamp = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18613 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 18614 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18615 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
| 18616 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 18617 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 18618 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 18619 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 18620 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 18621 | continue; |
| 18622 | /* found a pending sequence that matches this frame */ |
| 18623 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 18624 | break; |
| 18625 | } |
| 18626 | if (!seq_dmabuf) { |
| 18627 | /* |
| 18628 | * This indicates first frame received for this sequence. |
| 18629 | * Queue the buffer on the vport's rcv_buffer_list. |
| 18630 | */ |
| 18631 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 18632 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18633 | return dmabuf; |
| 18634 | } |
| 18635 | temp_hdr = seq_dmabuf->hbuf.virt; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 18636 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
| 18637 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18638 | list_del_init(&seq_dmabuf->hbuf.list); |
| 18639 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 18640 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 18641 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18642 | return dmabuf; |
| 18643 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 18644 | /* move this sequence to the tail to indicate a young sequence */ |
| 18645 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 18646 | seq_dmabuf->time_stamp = jiffies; |
| 18647 | lpfc_update_rcv_time_stamp(vport); |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 18648 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 18649 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
| 18650 | return seq_dmabuf; |
| 18651 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18652 | /* find the correct place in the sequence to insert this frame */ |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 18653 | d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list); |
| 18654 | while (!found) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18655 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 18656 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; |
| 18657 | /* |
| 18658 | * If the frame's sequence count is greater than the frame on |
| 18659 | * the list then insert the frame right after this frame |
| 18660 | */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 18661 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
| 18662 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18663 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 18664 | found = 1; |
| 18665 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18666 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 18667 | |
| 18668 | if (&d_buf->list == &seq_dmabuf->dbuf.list) |
| 18669 | break; |
| 18670 | d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18671 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 18672 | |
| 18673 | if (found) |
| 18674 | return seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18675 | return NULL; |
| 18676 | } |
| 18677 | |
| 18678 | /** |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18679 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence |
| 18680 | * @vport: pointer to a vitural port |
| 18681 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 18682 | * |
| 18683 | * This function tries to abort from the partially assembed sequence, described |
| 18684 | * by the information from basic abbort @dmabuf. It checks to see whether such |
| 18685 | * partially assembled sequence held by the driver. If so, it shall free up all |
| 18686 | * the frames from the partially assembled sequence. |
| 18687 | * |
| 18688 | * Return |
| 18689 | * true -- if there is matching partially assembled sequence present and all |
| 18690 | * the frames freed with the sequence; |
| 18691 | * false -- if there is no matching partially assembled sequence present so |
| 18692 | * nothing got aborted in the lower layer driver |
| 18693 | **/ |
| 18694 | static bool |
| 18695 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, |
| 18696 | struct hbq_dmabuf *dmabuf) |
| 18697 | { |
| 18698 | struct fc_frame_header *new_hdr; |
| 18699 | struct fc_frame_header *temp_hdr; |
| 18700 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; |
| 18701 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 18702 | |
| 18703 | /* Use the hdr_buf to find the sequence that matches this frame */ |
| 18704 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
| 18705 | INIT_LIST_HEAD(&dmabuf->hbuf.list); |
| 18706 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 18707 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 18708 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 18709 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 18710 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 18711 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 18712 | continue; |
| 18713 | /* found a pending sequence that matches this frame */ |
| 18714 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 18715 | break; |
| 18716 | } |
| 18717 | |
| 18718 | /* Free up all the frames from the partially assembled sequence */ |
| 18719 | if (seq_dmabuf) { |
| 18720 | list_for_each_entry_safe(d_buf, n_buf, |
| 18721 | &seq_dmabuf->dbuf.list, list) { |
| 18722 | list_del_init(&d_buf->list); |
| 18723 | lpfc_in_buf_free(vport->phba, d_buf); |
| 18724 | } |
| 18725 | return true; |
| 18726 | } |
| 18727 | return false; |
| 18728 | } |
| 18729 | |
| 18730 | /** |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18731 | * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp |
| 18732 | * @vport: pointer to a vitural port |
| 18733 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 18734 | * |
| 18735 | * This function tries to abort from the assembed sequence from upper level |
| 18736 | * protocol, described by the information from basic abbort @dmabuf. It |
| 18737 | * checks to see whether such pending context exists at upper level protocol. |
| 18738 | * If so, it shall clean up the pending context. |
| 18739 | * |
| 18740 | * Return |
| 18741 | * true -- if there is matching pending context of the sequence cleaned |
| 18742 | * at ulp; |
| 18743 | * false -- if there is no matching pending context of the sequence present |
| 18744 | * at ulp. |
| 18745 | **/ |
| 18746 | static bool |
| 18747 | lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 18748 | { |
| 18749 | struct lpfc_hba *phba = vport->phba; |
| 18750 | int handled; |
| 18751 | |
| 18752 | /* Accepting abort at ulp with SLI4 only */ |
| 18753 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 18754 | return false; |
| 18755 | |
| 18756 | /* Register all caring upper level protocols to attend abort */ |
| 18757 | handled = lpfc_ct_handle_unsol_abort(phba, dmabuf); |
| 18758 | if (handled) |
| 18759 | return true; |
| 18760 | |
| 18761 | return false; |
| 18762 | } |
| 18763 | |
| 18764 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18765 | * 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] | 18766 | * @phba: Pointer to HBA context object. |
| 18767 | * @cmd_iocbq: pointer to the command iocbq structure. |
| 18768 | * @rsp_iocbq: pointer to the response iocbq structure. |
| 18769 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18770 | * This function handles the sequence abort response iocb command complete |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18771 | * event. It properly releases the memory allocated to the sequence abort |
| 18772 | * accept iocb. |
| 18773 | **/ |
| 18774 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18775 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18776 | struct lpfc_iocbq *cmd_iocbq, |
| 18777 | struct lpfc_iocbq *rsp_iocbq) |
| 18778 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18779 | struct lpfc_nodelist *ndlp; |
| 18780 | |
| 18781 | if (cmd_iocbq) { |
| 18782 | ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1; |
| 18783 | lpfc_nlp_put(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18784 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18785 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18786 | |
| 18787 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ |
| 18788 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 18789 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18790 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", |
| 18791 | rsp_iocbq->iocb.ulpStatus, |
| 18792 | rsp_iocbq->iocb.un.ulpWord[4]); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18793 | } |
| 18794 | |
| 18795 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18796 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. |
| 18797 | * @phba: Pointer to HBA context object. |
| 18798 | * @xri: xri id in transaction. |
| 18799 | * |
| 18800 | * This function validates the xri maps to the known range of XRIs allocated an |
| 18801 | * used by the driver. |
| 18802 | **/ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18803 | uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18804 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
| 18805 | uint16_t xri) |
| 18806 | { |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 18807 | uint16_t i; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18808 | |
| 18809 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { |
| 18810 | if (xri == phba->sli4_hba.xri_ids[i]) |
| 18811 | return i; |
| 18812 | } |
| 18813 | return NO_XRI; |
| 18814 | } |
| 18815 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18816 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18817 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
James Smart | 3bfab8a | 2021-04-11 18:31:23 -0700 | [diff] [blame] | 18818 | * @vport: pointer to a virtual port. |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18819 | * @fc_hdr: pointer to a FC frame header. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 18820 | * @aborted: was the partially assembled receive sequence successfully aborted |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18821 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18822 | * This function sends a basic response to a previous unsol sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18823 | * event after aborting the sequence handling. |
| 18824 | **/ |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 18825 | void |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18826 | lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport, |
| 18827 | struct fc_frame_header *fc_hdr, bool aborted) |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18828 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18829 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18830 | struct lpfc_iocbq *ctiocb = NULL; |
| 18831 | struct lpfc_nodelist *ndlp; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 18832 | uint16_t oxid, rxid, xri, lxri; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 18833 | uint32_t sid, fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18834 | IOCB_t *icmd; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18835 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18836 | |
| 18837 | if (!lpfc_is_link_up(phba)) |
| 18838 | return; |
| 18839 | |
| 18840 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 18841 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 18842 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18843 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18844 | ndlp = lpfc_findnode_did(vport, sid); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18845 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 18846 | ndlp = lpfc_nlp_init(vport, sid); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18847 | if (!ndlp) { |
| 18848 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 18849 | "1268 Failed to allocate ndlp for " |
| 18850 | "oxid:x%x SID:x%x\n", oxid, sid); |
| 18851 | return; |
| 18852 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18853 | /* Put ndlp onto pport node list */ |
| 18854 | lpfc_enqueue_node(vport, ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18855 | } |
| 18856 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18857 | /* Allocate buffer for rsp iocb */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18858 | ctiocb = lpfc_sli_get_iocbq(phba); |
| 18859 | if (!ctiocb) |
| 18860 | return; |
| 18861 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 18862 | /* Extract the F_CTL field from FC_HDR */ |
| 18863 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); |
| 18864 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18865 | icmd = &ctiocb->iocb; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18866 | icmd->un.xseq64.bdl.bdeSize = 0; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 18867 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18868 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 18869 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; |
| 18870 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; |
| 18871 | |
| 18872 | /* Fill in the rest of iocb fields */ |
| 18873 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; |
| 18874 | icmd->ulpBdeCount = 0; |
| 18875 | icmd->ulpLe = 1; |
| 18876 | icmd->ulpClass = CLASS3; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18877 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18878 | ctiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 18879 | if (!ctiocb->context1) { |
| 18880 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 18881 | return; |
| 18882 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18883 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18884 | ctiocb->vport = phba->pport; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18885 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18886 | ctiocb->sli4_lxritag = NO_XRI; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18887 | ctiocb->sli4_xritag = NO_XRI; |
| 18888 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 18889 | if (fctl & FC_FC_EX_CTX) |
| 18890 | /* Exchange responder sent the abort so we |
| 18891 | * own the oxid. |
| 18892 | */ |
| 18893 | xri = oxid; |
| 18894 | else |
| 18895 | xri = rxid; |
| 18896 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 18897 | if (lxri != NO_XRI) |
| 18898 | lpfc_set_rrq_active(phba, ndlp, lxri, |
| 18899 | (xri == oxid) ? rxid : oxid, 0); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18900 | /* For BA_ABTS from exchange responder, if the logical xri with |
| 18901 | * the oxid maps to the FCP XRI range, the port no longer has |
| 18902 | * that exchange context, send a BLS_RJT. Override the IOCB for |
| 18903 | * a BA_RJT. |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18904 | */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18905 | if ((fctl & FC_FC_EX_CTX) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18906 | (lxri > lpfc_sli4_get_iocb_cnt(phba))) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18907 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 18908 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 18909 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 18910 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 18911 | } |
| 18912 | |
| 18913 | /* If BA_ABTS failed to abort a partially assembled receive sequence, |
| 18914 | * the driver no longer has that exchange, send a BLS_RJT. Override |
| 18915 | * the IOCB for a BA_RJT. |
| 18916 | */ |
| 18917 | if (aborted == false) { |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18918 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 18919 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 18920 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 18921 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 18922 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18923 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 18924 | if (fctl & FC_FC_EX_CTX) { |
| 18925 | /* ABTS sent by responder to CT exchange, construction |
| 18926 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG |
| 18927 | * field and RX_ID from ABTS for RX_ID field. |
| 18928 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18929 | 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] | 18930 | } else { |
| 18931 | /* ABTS sent by initiator to CT exchange, construction |
| 18932 | * 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] | 18933 | * XRI_TAG field. |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 18934 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18935 | 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] | 18936 | } |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 18937 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18938 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 18939 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18940 | /* Xmit CT abts response on exchange <xid> */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18941 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 18942 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
| 18943 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18944 | |
| 18945 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
| 18946 | if (rc == IOCB_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 18947 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18948 | "2925 Failed to issue CT ABTS RSP x%x on " |
| 18949 | "xri x%x, Data x%x\n", |
| 18950 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, |
| 18951 | phba->link_state); |
| 18952 | lpfc_nlp_put(ndlp); |
| 18953 | ctiocb->context1 = NULL; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18954 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 18955 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18956 | } |
| 18957 | |
| 18958 | /** |
| 18959 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event |
| 18960 | * @vport: Pointer to the vport on which this sequence was received |
| 18961 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 18962 | * |
| 18963 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited |
| 18964 | * receive sequence is only partially assembed by the driver, it shall abort |
| 18965 | * the partially assembled frames for the sequence. Otherwise, if the |
| 18966 | * unsolicited receive sequence has been completely assembled and passed to |
Ferruh Yigit | 02e3e58 | 2020-07-28 15:56:06 +0100 | [diff] [blame] | 18967 | * the Upper Layer Protocol (ULP), it then mark the per oxid status for the |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18968 | * unsolicited sequence has been aborted. After that, it will issue a basic |
| 18969 | * accept to accept the abort. |
| 18970 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18971 | static void |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18972 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
| 18973 | struct hbq_dmabuf *dmabuf) |
| 18974 | { |
| 18975 | struct lpfc_hba *phba = vport->phba; |
| 18976 | struct fc_frame_header fc_hdr; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 18977 | uint32_t fctl; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18978 | bool aborted; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18979 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18980 | /* Make a copy of fc_hdr before the dmabuf being released */ |
| 18981 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 18982 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18983 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 18984 | if (fctl & FC_FC_EX_CTX) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18985 | /* ABTS by responder to exchange, no cleanup needed */ |
| 18986 | aborted = true; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 18987 | } else { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18988 | /* ABTS by initiator to exchange, need to do cleanup */ |
| 18989 | aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf); |
| 18990 | if (aborted == false) |
| 18991 | aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 18992 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18993 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18994 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 18995 | if (phba->nvmet_support) { |
| 18996 | lpfc_nvmet_rcv_unsol_abort(vport, &fc_hdr); |
| 18997 | return; |
| 18998 | } |
| 18999 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 19000 | /* Respond with BA_ACC or BA_RJT accordingly */ |
| 19001 | lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 19002 | } |
| 19003 | |
| 19004 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 19005 | * lpfc_seq_complete - Indicates if a sequence is complete |
| 19006 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 19007 | * |
| 19008 | * This function checks the sequence, starting with the frame described by |
| 19009 | * @dmabuf, to see if all the frames associated with this sequence are present. |
| 19010 | * the frames associated with this sequence are linked to the @dmabuf using the |
| 19011 | * dbuf list. This function looks for two major things. 1) That the first frame |
| 19012 | * has a sequence count of zero. 2) There is a frame with last frame of sequence |
| 19013 | * set. 3) That there are no holes in the sequence count. The function will |
| 19014 | * return 1 when the sequence is complete, otherwise it will return 0. |
| 19015 | **/ |
| 19016 | static int |
| 19017 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) |
| 19018 | { |
| 19019 | struct fc_frame_header *hdr; |
| 19020 | struct lpfc_dmabuf *d_buf; |
| 19021 | struct hbq_dmabuf *seq_dmabuf; |
| 19022 | uint32_t fctl; |
| 19023 | int seq_count = 0; |
| 19024 | |
| 19025 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 19026 | /* make sure first fame of sequence has a sequence count of zero */ |
| 19027 | if (hdr->fh_seq_cnt != seq_count) |
| 19028 | return 0; |
| 19029 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 19030 | hdr->fh_f_ctl[1] << 8 | |
| 19031 | hdr->fh_f_ctl[2]); |
| 19032 | /* If last frame of sequence we can return success. */ |
| 19033 | if (fctl & FC_FC_END_SEQ) |
| 19034 | return 1; |
| 19035 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { |
| 19036 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 19037 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 19038 | /* If there is a hole in the sequence count then fail. */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 19039 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 19040 | return 0; |
| 19041 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 19042 | hdr->fh_f_ctl[1] << 8 | |
| 19043 | hdr->fh_f_ctl[2]); |
| 19044 | /* If last frame of sequence we can return success. */ |
| 19045 | if (fctl & FC_FC_END_SEQ) |
| 19046 | return 1; |
| 19047 | } |
| 19048 | return 0; |
| 19049 | } |
| 19050 | |
| 19051 | /** |
| 19052 | * lpfc_prep_seq - Prep sequence for ULP processing |
| 19053 | * @vport: Pointer to the vport on which this sequence was received |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 19054 | * @seq_dmabuf: pointer to a dmabuf that describes the FC sequence |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 19055 | * |
| 19056 | * This function takes a sequence, described by a list of frames, and creates |
| 19057 | * a list of iocbq structures to describe the sequence. This iocbq list will be |
| 19058 | * used to issue to the generic unsolicited sequence handler. This routine |
| 19059 | * returns a pointer to the first iocbq in the list. If the function is unable |
| 19060 | * to allocate an iocbq then it throw out the received frames that were not |
| 19061 | * able to be described and return a pointer to the first iocbq. If unable to |
| 19062 | * allocate any iocbqs (including the first) this function will return NULL. |
| 19063 | **/ |
| 19064 | static struct lpfc_iocbq * |
| 19065 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) |
| 19066 | { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 19067 | struct hbq_dmabuf *hbq_buf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 19068 | struct lpfc_dmabuf *d_buf, *n_buf; |
| 19069 | struct lpfc_iocbq *first_iocbq, *iocbq; |
| 19070 | struct fc_frame_header *fc_hdr; |
| 19071 | uint32_t sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 19072 | uint32_t len, tot_len; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 19073 | struct ulp_bde64 *pbde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 19074 | |
| 19075 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 19076 | /* remove from receive buffer list */ |
| 19077 | list_del_init(&seq_dmabuf->hbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 19078 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 19079 | /* get the Remote Port's SID */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 19080 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 19081 | tot_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 19082 | /* Get an iocbq struct to fill in. */ |
| 19083 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 19084 | if (first_iocbq) { |
| 19085 | /* Initialize the first IOCB. */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 19086 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 19087 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19088 | first_iocbq->vport = vport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 19089 | |
| 19090 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ |
| 19091 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { |
| 19092 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; |
| 19093 | first_iocbq->iocb.un.rcvels.parmRo = |
| 19094 | sli4_did_from_fc_hdr(fc_hdr); |
| 19095 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; |
| 19096 | } else |
| 19097 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 19098 | first_iocbq->iocb.ulpContext = NO_XRI; |
| 19099 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = |
| 19100 | be16_to_cpu(fc_hdr->fh_ox_id); |
| 19101 | /* iocbq is prepped for internal consumption. Physical vpi. */ |
| 19102 | first_iocbq->iocb.unsli3.rcvsli3.vpi = |
| 19103 | vport->phba->vpi_ids[vport->vpi]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 19104 | /* put the first buffer into the first IOCBq */ |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 19105 | tot_len = bf_get(lpfc_rcqe_length, |
| 19106 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
| 19107 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 19108 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
| 19109 | first_iocbq->context3 = NULL; |
| 19110 | first_iocbq->iocb.ulpBdeCount = 1; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 19111 | if (tot_len > LPFC_DATA_BUF_SIZE) |
| 19112 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 19113 | LPFC_DATA_BUF_SIZE; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 19114 | else |
| 19115 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len; |
| 19116 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 19117 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 19118 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 19119 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 19120 | } |
| 19121 | iocbq = first_iocbq; |
| 19122 | /* |
| 19123 | * Each IOCBq can have two Buffers assigned, so go through the list |
| 19124 | * of buffers for this sequence and save two buffers in each IOCBq |
| 19125 | */ |
| 19126 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { |
| 19127 | if (!iocbq) { |
| 19128 | lpfc_in_buf_free(vport->phba, d_buf); |
| 19129 | continue; |
| 19130 | } |
| 19131 | if (!iocbq->context3) { |
| 19132 | iocbq->context3 = d_buf; |
| 19133 | iocbq->iocb.ulpBdeCount++; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 19134 | /* We need to get the size out of the right CQE */ |
| 19135 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 19136 | len = bf_get(lpfc_rcqe_length, |
| 19137 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 19138 | pbde = (struct ulp_bde64 *) |
| 19139 | &iocbq->iocb.unsli3.sli3Words[4]; |
| 19140 | if (len > LPFC_DATA_BUF_SIZE) |
| 19141 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; |
| 19142 | else |
| 19143 | pbde->tus.f.bdeSize = len; |
| 19144 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 19145 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
| 19146 | tot_len += len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 19147 | } else { |
| 19148 | iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 19149 | if (!iocbq) { |
| 19150 | if (first_iocbq) { |
| 19151 | first_iocbq->iocb.ulpStatus = |
| 19152 | IOSTAT_FCP_RSP_ERROR; |
| 19153 | first_iocbq->iocb.un.ulpWord[4] = |
| 19154 | IOERR_NO_RESOURCES; |
| 19155 | } |
| 19156 | lpfc_in_buf_free(vport->phba, d_buf); |
| 19157 | continue; |
| 19158 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 19159 | /* We need to get the size out of the right CQE */ |
| 19160 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 19161 | len = bf_get(lpfc_rcqe_length, |
| 19162 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 19163 | iocbq->context2 = d_buf; |
| 19164 | iocbq->context3 = NULL; |
| 19165 | iocbq->iocb.ulpBdeCount = 1; |
| 19166 | if (len > LPFC_DATA_BUF_SIZE) |
| 19167 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 19168 | LPFC_DATA_BUF_SIZE; |
| 19169 | else |
| 19170 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = len; |
| 19171 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 19172 | tot_len += len; |
| 19173 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
| 19174 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 19175 | iocbq->iocb.un.rcvels.remoteID = sid; |
| 19176 | list_add_tail(&iocbq->list, &first_iocbq->list); |
| 19177 | } |
| 19178 | } |
James Smart | 39c4f1a | 2020-01-27 16:23:01 -0800 | [diff] [blame] | 19179 | /* Free the sequence's header buffer */ |
| 19180 | if (!first_iocbq) |
| 19181 | lpfc_in_buf_free(vport->phba, &seq_dmabuf->dbuf); |
| 19182 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 19183 | return first_iocbq; |
| 19184 | } |
| 19185 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 19186 | static void |
| 19187 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, |
| 19188 | struct hbq_dmabuf *seq_dmabuf) |
| 19189 | { |
| 19190 | struct fc_frame_header *fc_hdr; |
| 19191 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; |
| 19192 | struct lpfc_hba *phba = vport->phba; |
| 19193 | |
| 19194 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 19195 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); |
| 19196 | if (!iocbq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 19197 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 19198 | "2707 Ring %d handler: Failed to allocate " |
| 19199 | "iocb Rctl x%x Type x%x received\n", |
| 19200 | LPFC_ELS_RING, |
| 19201 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 19202 | return; |
| 19203 | } |
| 19204 | if (!lpfc_complete_unsol_iocb(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19205 | phba->sli4_hba.els_wq->pring, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 19206 | iocbq, fc_hdr->fh_r_ctl, |
| 19207 | fc_hdr->fh_type)) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 19208 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 19209 | "2540 Ring %d handler: unexpected Rctl " |
| 19210 | "x%x Type x%x received\n", |
| 19211 | LPFC_ELS_RING, |
| 19212 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 19213 | |
| 19214 | /* Free iocb created in lpfc_prep_seq */ |
| 19215 | list_for_each_entry_safe(curr_iocb, next_iocb, |
| 19216 | &iocbq->list, list) { |
| 19217 | list_del_init(&curr_iocb->list); |
| 19218 | lpfc_sli_release_iocbq(phba, curr_iocb); |
| 19219 | } |
| 19220 | lpfc_sli_release_iocbq(phba, iocbq); |
| 19221 | } |
| 19222 | |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 19223 | static void |
| 19224 | lpfc_sli4_mds_loopback_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 19225 | struct lpfc_iocbq *rspiocb) |
| 19226 | { |
| 19227 | struct lpfc_dmabuf *pcmd = cmdiocb->context2; |
| 19228 | |
| 19229 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 19230 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 19231 | kfree(pcmd); |
| 19232 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 19233 | lpfc_drain_txq(phba); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 19234 | } |
| 19235 | |
| 19236 | static void |
| 19237 | lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport, |
| 19238 | struct hbq_dmabuf *dmabuf) |
| 19239 | { |
| 19240 | struct fc_frame_header *fc_hdr; |
| 19241 | struct lpfc_hba *phba = vport->phba; |
| 19242 | struct lpfc_iocbq *iocbq = NULL; |
| 19243 | union lpfc_wqe *wqe; |
| 19244 | struct lpfc_dmabuf *pcmd = NULL; |
| 19245 | uint32_t frame_len; |
| 19246 | int rc; |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 19247 | unsigned long iflags; |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 19248 | |
| 19249 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 19250 | frame_len = bf_get(lpfc_rcqe_length, &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 19251 | |
| 19252 | /* Send the received frame back */ |
| 19253 | iocbq = lpfc_sli_get_iocbq(phba); |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 19254 | if (!iocbq) { |
| 19255 | /* Queue cq event and wakeup worker thread to process it */ |
| 19256 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 19257 | list_add_tail(&dmabuf->cq_event.list, |
| 19258 | &phba->sli4_hba.sp_queue_event); |
| 19259 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
| 19260 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 19261 | lpfc_worker_wake_up(phba); |
| 19262 | return; |
| 19263 | } |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 19264 | |
| 19265 | /* Allocate buffer for command payload */ |
| 19266 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 19267 | if (pcmd) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 19268 | pcmd->virt = dma_pool_alloc(phba->lpfc_drb_pool, GFP_KERNEL, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 19269 | &pcmd->phys); |
| 19270 | if (!pcmd || !pcmd->virt) |
| 19271 | goto exit; |
| 19272 | |
| 19273 | INIT_LIST_HEAD(&pcmd->list); |
| 19274 | |
| 19275 | /* copyin the payload */ |
| 19276 | memcpy(pcmd->virt, dmabuf->dbuf.virt, frame_len); |
| 19277 | |
| 19278 | /* fill in BDE's for command */ |
| 19279 | iocbq->iocb.un.xseq64.bdl.addrHigh = putPaddrHigh(pcmd->phys); |
| 19280 | iocbq->iocb.un.xseq64.bdl.addrLow = putPaddrLow(pcmd->phys); |
| 19281 | iocbq->iocb.un.xseq64.bdl.bdeFlags = BUFF_TYPE_BDE_64; |
| 19282 | iocbq->iocb.un.xseq64.bdl.bdeSize = frame_len; |
| 19283 | |
| 19284 | iocbq->context2 = pcmd; |
| 19285 | iocbq->vport = vport; |
| 19286 | iocbq->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
| 19287 | iocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
| 19288 | |
| 19289 | /* |
| 19290 | * Setup rest of the iocb as though it were a WQE |
| 19291 | * Build the SEND_FRAME WQE |
| 19292 | */ |
| 19293 | wqe = (union lpfc_wqe *)&iocbq->iocb; |
| 19294 | |
| 19295 | wqe->send_frame.frame_len = frame_len; |
| 19296 | wqe->send_frame.fc_hdr_wd0 = be32_to_cpu(*((uint32_t *)fc_hdr)); |
| 19297 | wqe->send_frame.fc_hdr_wd1 = be32_to_cpu(*((uint32_t *)fc_hdr + 1)); |
| 19298 | wqe->send_frame.fc_hdr_wd2 = be32_to_cpu(*((uint32_t *)fc_hdr + 2)); |
| 19299 | wqe->send_frame.fc_hdr_wd3 = be32_to_cpu(*((uint32_t *)fc_hdr + 3)); |
| 19300 | wqe->send_frame.fc_hdr_wd4 = be32_to_cpu(*((uint32_t *)fc_hdr + 4)); |
| 19301 | wqe->send_frame.fc_hdr_wd5 = be32_to_cpu(*((uint32_t *)fc_hdr + 5)); |
| 19302 | |
| 19303 | iocbq->iocb.ulpCommand = CMD_SEND_FRAME; |
| 19304 | iocbq->iocb.ulpLe = 1; |
| 19305 | iocbq->iocb_cmpl = lpfc_sli4_mds_loopback_cmpl; |
| 19306 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocbq, 0); |
| 19307 | if (rc == IOCB_ERROR) |
| 19308 | goto exit; |
| 19309 | |
| 19310 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 19311 | return; |
| 19312 | |
| 19313 | exit: |
| 19314 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 19315 | "2023 Unable to process MDS loopback frame\n"); |
| 19316 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 19317 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 19318 | kfree(pcmd); |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 19319 | if (iocbq) |
| 19320 | lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 19321 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 19322 | } |
| 19323 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 19324 | /** |
| 19325 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware |
| 19326 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 19327 | * @dmabuf: Pointer to a dmabuf that describes the FC sequence. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 19328 | * |
| 19329 | * This function is called with no lock held. This function processes all |
| 19330 | * the received buffers and gives it to upper layers when a received buffer |
| 19331 | * indicates that it is the final frame in the sequence. The interrupt |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19332 | * service routine processes received buffers at interrupt contexts. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 19333 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the |
| 19334 | * appropriate receive function when the final frame in a sequence is received. |
| 19335 | **/ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 19336 | void |
| 19337 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, |
| 19338 | struct hbq_dmabuf *dmabuf) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 19339 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 19340 | struct hbq_dmabuf *seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 19341 | struct fc_frame_header *fc_hdr; |
| 19342 | struct lpfc_vport *vport; |
| 19343 | uint32_t fcfi; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 19344 | uint32_t did; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 19345 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 19346 | /* Process each received buffer */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 19347 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 19348 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 19349 | if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS || |
| 19350 | fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) { |
| 19351 | vport = phba->pport; |
| 19352 | /* Handle MDS Loopback frames */ |
Dick Kennedy | 24411fc | 2020-08-03 14:02:25 -0700 | [diff] [blame] | 19353 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 19354 | lpfc_sli4_handle_mds_loopback(vport, dmabuf); |
| 19355 | else |
| 19356 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 19357 | return; |
| 19358 | } |
| 19359 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 19360 | /* check to see if this a valid type of frame */ |
| 19361 | if (lpfc_fc_frame_check(phba, fc_hdr)) { |
| 19362 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 19363 | return; |
| 19364 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 19365 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 19366 | if ((bf_get(lpfc_cqe_code, |
| 19367 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) |
| 19368 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, |
| 19369 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 19370 | else |
| 19371 | fcfi = bf_get(lpfc_rcqe_fcf_id, |
| 19372 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 19373 | |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 19374 | if (fc_hdr->fh_r_ctl == 0xF4 && fc_hdr->fh_type == 0xFF) { |
| 19375 | vport = phba->pport; |
| 19376 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 19377 | "2023 MDS Loopback %d bytes\n", |
| 19378 | bf_get(lpfc_rcqe_length, |
| 19379 | &dmabuf->cq_event.cqe.rcqe_cmpl)); |
| 19380 | /* Handle MDS Loopback frames */ |
| 19381 | lpfc_sli4_handle_mds_loopback(vport, dmabuf); |
| 19382 | return; |
| 19383 | } |
| 19384 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19385 | /* d_id this frame is directed to */ |
| 19386 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 19387 | |
| 19388 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi, did); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 19389 | if (!vport) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 19390 | /* throw out the frame */ |
| 19391 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 19392 | return; |
| 19393 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 19394 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 19395 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ |
| 19396 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && |
| 19397 | (did != Fabric_DID)) { |
| 19398 | /* |
| 19399 | * Throw out the frame if we are not pt2pt. |
| 19400 | * The pt2pt protocol allows for discovery frames |
| 19401 | * to be received without a registered VPI. |
| 19402 | */ |
| 19403 | if (!(vport->fc_flag & FC_PT2PT) || |
| 19404 | (phba->link_state == LPFC_HBA_READY)) { |
| 19405 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 19406 | return; |
| 19407 | } |
| 19408 | } |
| 19409 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 19410 | /* Handle the basic abort sequence (BA_ABTS) event */ |
| 19411 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 19412 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); |
| 19413 | return; |
| 19414 | } |
| 19415 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 19416 | /* Link this frame */ |
| 19417 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); |
| 19418 | if (!seq_dmabuf) { |
| 19419 | /* unable to add frame to vport - throw it out */ |
| 19420 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 19421 | return; |
| 19422 | } |
| 19423 | /* If not last frame in sequence continue processing frames. */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 19424 | if (!lpfc_seq_complete(seq_dmabuf)) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 19425 | return; |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 19426 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 19427 | /* Send the complete sequence to the upper layer protocol */ |
| 19428 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 19429 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19430 | |
| 19431 | /** |
| 19432 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port |
| 19433 | * @phba: pointer to lpfc hba data structure. |
| 19434 | * |
| 19435 | * This routine is invoked to post rpi header templates to the |
| 19436 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 19437 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 19438 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19439 | * |
| 19440 | * This routine does not require any locks. It's usage is expected |
| 19441 | * to be driver load or reset recovery when the driver is |
| 19442 | * sequential. |
| 19443 | * |
| 19444 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 19445 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19446 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19447 | * When this error occurs, the driver is not guaranteed |
| 19448 | * to have any rpi regions posted to the device and |
| 19449 | * must either attempt to repost the regions or take a |
| 19450 | * fatal error. |
| 19451 | **/ |
| 19452 | int |
| 19453 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) |
| 19454 | { |
| 19455 | struct lpfc_rpi_hdr *rpi_page; |
| 19456 | uint32_t rc = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 19457 | uint16_t lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19458 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 19459 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 19460 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 19461 | goto exit; |
| 19462 | if (phba->sli4_hba.extents_in_use) |
| 19463 | return -EIO; |
| 19464 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19465 | 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] | 19466 | /* |
| 19467 | * Assign the rpi headers a physical rpi only if the driver |
| 19468 | * has not initialized those resources. A port reset only |
| 19469 | * needs the headers posted. |
| 19470 | */ |
| 19471 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != |
| 19472 | LPFC_RPI_RSRC_RDY) |
| 19473 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
| 19474 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19475 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
| 19476 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 19477 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19478 | "2008 Error %d posting all rpi " |
| 19479 | "headers\n", rc); |
| 19480 | rc = -EIO; |
| 19481 | break; |
| 19482 | } |
| 19483 | } |
| 19484 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 19485 | exit: |
| 19486 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 19487 | LPFC_RPI_RSRC_RDY); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19488 | return rc; |
| 19489 | } |
| 19490 | |
| 19491 | /** |
| 19492 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port |
| 19493 | * @phba: pointer to lpfc hba data structure. |
| 19494 | * @rpi_page: pointer to the rpi memory region. |
| 19495 | * |
| 19496 | * This routine is invoked to post a single rpi header to the |
| 19497 | * HBA consistent with the SLI-4 interface spec. This memory region |
| 19498 | * maps up to 64 rpi context regions. |
| 19499 | * |
| 19500 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 19501 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19502 | * -ENOMEM - No available memory |
| 19503 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19504 | **/ |
| 19505 | int |
| 19506 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) |
| 19507 | { |
| 19508 | LPFC_MBOXQ_t *mboxq; |
| 19509 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; |
| 19510 | uint32_t rc = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19511 | uint32_t shdr_status, shdr_add_status; |
| 19512 | union lpfc_sli4_cfg_shdr *shdr; |
| 19513 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 19514 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 19515 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 19516 | return rc; |
| 19517 | if (phba->sli4_hba.extents_in_use) |
| 19518 | return -EIO; |
| 19519 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19520 | /* The port is notified of the header region via a mailbox command. */ |
| 19521 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19522 | if (!mboxq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 19523 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19524 | "2001 Unable to allocate memory for issuing " |
| 19525 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 19526 | return -ENOMEM; |
| 19527 | } |
| 19528 | |
| 19529 | /* Post all rpi memory regions to the port. */ |
| 19530 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19531 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 19532 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, |
| 19533 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 19534 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 19535 | LPFC_SLI4_MBX_EMBED); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 19536 | |
| 19537 | |
| 19538 | /* Post the physical rpi to the port for this rpi header. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19539 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
| 19540 | rpi_page->start_rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 19541 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
| 19542 | hdr_tmpl, rpi_page->page_count); |
| 19543 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19544 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
| 19545 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 19546 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19547 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
| 19548 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 19549 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 304ee43 | 2021-04-11 18:31:17 -0700 | [diff] [blame] | 19550 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19551 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 19552 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19553 | "2514 POST_RPI_HDR mailbox failed with " |
| 19554 | "status x%x add_status x%x, mbx status x%x\n", |
| 19555 | shdr_status, shdr_add_status, rc); |
| 19556 | rc = -ENXIO; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 19557 | } else { |
| 19558 | /* |
| 19559 | * The next_rpi stores the next logical module-64 rpi value used |
| 19560 | * to post physical rpis in subsequent rpi postings. |
| 19561 | */ |
| 19562 | spin_lock_irq(&phba->hbalock); |
| 19563 | phba->sli4_hba.next_rpi = rpi_page->next_rpi; |
| 19564 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19565 | } |
| 19566 | return rc; |
| 19567 | } |
| 19568 | |
| 19569 | /** |
| 19570 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range |
| 19571 | * @phba: pointer to lpfc hba data structure. |
| 19572 | * |
| 19573 | * This routine is invoked to post rpi header templates to the |
| 19574 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 19575 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 19576 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19577 | * |
| 19578 | * Returns |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 19579 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19580 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 19581 | **/ |
| 19582 | int |
| 19583 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) |
| 19584 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 19585 | unsigned long rpi; |
| 19586 | uint16_t max_rpi, rpi_limit; |
| 19587 | uint16_t rpi_remaining, lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19588 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 19589 | unsigned long iflag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19590 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19591 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 19592 | * Fetch the next logical rpi. Because this index is logical, |
| 19593 | * the driver starts at 0 each time. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19594 | */ |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 19595 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 19596 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
| 19597 | rpi_limit = phba->sli4_hba.next_rpi; |
| 19598 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 19599 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
| 19600 | if (rpi >= rpi_limit) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19601 | rpi = LPFC_RPI_ALLOC_ERROR; |
| 19602 | else { |
| 19603 | set_bit(rpi, phba->sli4_hba.rpi_bmask); |
| 19604 | phba->sli4_hba.max_cfg_param.rpi_used++; |
| 19605 | phba->sli4_hba.rpi_count++; |
| 19606 | } |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 19607 | lpfc_printf_log(phba, KERN_INFO, |
| 19608 | LOG_NODE | LOG_DISCOVERY, |
| 19609 | "0001 Allocated rpi:x%x max:x%x lim:x%x\n", |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 19610 | (int) rpi, max_rpi, rpi_limit); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19611 | |
| 19612 | /* |
| 19613 | * 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] | 19614 | * has been exhausted. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19615 | */ |
| 19616 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && |
| 19617 | (phba->sli4_hba.rpi_count >= max_rpi)) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 19618 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19619 | return rpi; |
| 19620 | } |
| 19621 | |
| 19622 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 19623 | * RPI header postings are not required for SLI4 ports capable of |
| 19624 | * extents. |
| 19625 | */ |
| 19626 | if (!phba->sli4_hba.rpi_hdrs_in_use) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 19627 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 19628 | return rpi; |
| 19629 | } |
| 19630 | |
| 19631 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19632 | * If the driver is running low on rpi resources, allocate another |
| 19633 | * page now. Note that the next_rpi value is used because |
| 19634 | * it represents how many are actually in use whereas max_rpi notes |
| 19635 | * how many are supported max by the device. |
| 19636 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 19637 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 19638 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19639 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
| 19640 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 19641 | if (!rpi_hdr) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 19642 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19643 | "2002 Error Could not grow rpi " |
| 19644 | "count\n"); |
| 19645 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 19646 | lrpi = rpi_hdr->start_rpi; |
| 19647 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19648 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
| 19649 | } |
| 19650 | } |
| 19651 | |
| 19652 | return rpi; |
| 19653 | } |
| 19654 | |
| 19655 | /** |
Lee Jones | 8514e2f | 2021-03-03 14:46:18 +0000 | [diff] [blame] | 19656 | * __lpfc_sli4_free_rpi - Release an rpi for reuse. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19657 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 19658 | * @rpi: rpi to free |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19659 | * |
| 19660 | * This routine is invoked to release an rpi to the pool of |
| 19661 | * available rpis maintained by the driver. |
| 19662 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 19663 | static void |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 19664 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 19665 | { |
James Smart | 7cfd563 | 2019-11-04 16:56:58 -0800 | [diff] [blame] | 19666 | /* |
| 19667 | * if the rpi value indicates a prior unreg has already |
| 19668 | * been done, skip the unreg. |
| 19669 | */ |
| 19670 | if (rpi == LPFC_RPI_ALLOC_ERROR) |
| 19671 | return; |
| 19672 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 19673 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { |
| 19674 | phba->sli4_hba.rpi_count--; |
| 19675 | phba->sli4_hba.max_cfg_param.rpi_used--; |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 19676 | } else { |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 19677 | lpfc_printf_log(phba, KERN_INFO, |
| 19678 | LOG_NODE | LOG_DISCOVERY, |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 19679 | "2016 rpi %x not inuse\n", |
| 19680 | rpi); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 19681 | } |
| 19682 | } |
| 19683 | |
| 19684 | /** |
| 19685 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 19686 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 19687 | * @rpi: rpi to free |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 19688 | * |
| 19689 | * This routine is invoked to release an rpi to the pool of |
| 19690 | * available rpis maintained by the driver. |
| 19691 | **/ |
| 19692 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19693 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 19694 | { |
| 19695 | spin_lock_irq(&phba->hbalock); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 19696 | __lpfc_sli4_free_rpi(phba, rpi); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19697 | spin_unlock_irq(&phba->hbalock); |
| 19698 | } |
| 19699 | |
| 19700 | /** |
| 19701 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region |
| 19702 | * @phba: pointer to lpfc hba data structure. |
| 19703 | * |
| 19704 | * This routine is invoked to remove the memory region that |
| 19705 | * provided rpi via a bitmask. |
| 19706 | **/ |
| 19707 | void |
| 19708 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) |
| 19709 | { |
| 19710 | kfree(phba->sli4_hba.rpi_bmask); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 19711 | kfree(phba->sli4_hba.rpi_ids); |
| 19712 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19713 | } |
| 19714 | |
| 19715 | /** |
| 19716 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 19717 | * @ndlp: pointer to lpfc nodelist data structure. |
| 19718 | * @cmpl: completion call-back. |
| 19719 | * @arg: data to load as MBox 'caller buffer information' |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19720 | * |
| 19721 | * This routine is invoked to remove the memory region that |
| 19722 | * provided rpi via a bitmask. |
| 19723 | **/ |
| 19724 | int |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 19725 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
| 19726 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19727 | { |
| 19728 | LPFC_MBOXQ_t *mboxq; |
| 19729 | struct lpfc_hba *phba = ndlp->phba; |
| 19730 | int rc; |
| 19731 | |
| 19732 | /* The port is notified of the header region via a mailbox command. */ |
| 19733 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19734 | if (!mboxq) |
| 19735 | return -ENOMEM; |
| 19736 | |
James Smart | 1037e4b | 2021-05-14 12:55:52 -0700 | [diff] [blame] | 19737 | /* If cmpl assigned, then this nlp_get pairs with |
| 19738 | * lpfc_mbx_cmpl_resume_rpi. |
| 19739 | * |
| 19740 | * Else cmpl is NULL, then this nlp_get pairs with |
| 19741 | * lpfc_sli_def_mbox_cmpl. |
| 19742 | */ |
| 19743 | if (!lpfc_nlp_get(ndlp)) { |
| 19744 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 19745 | "2122 %s: Failed to get nlp ref\n", |
| 19746 | __func__); |
| 19747 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 19748 | return -EIO; |
| 19749 | } |
| 19750 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19751 | /* Post all rpi memory regions to the port. */ |
| 19752 | lpfc_resume_rpi(mboxq, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 19753 | if (cmpl) { |
| 19754 | mboxq->mbox_cmpl = cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19755 | mboxq->ctx_buf = arg; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 19756 | } else |
| 19757 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 1037e4b | 2021-05-14 12:55:52 -0700 | [diff] [blame] | 19758 | mboxq->ctx_ndlp = ndlp; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 19759 | mboxq->vport = ndlp->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19760 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 19761 | if (rc == MBX_NOT_FINISHED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 19762 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19763 | "2010 Resume RPI Mailbox failed " |
| 19764 | "status %d, mbxStatus x%x\n", rc, |
| 19765 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | 1037e4b | 2021-05-14 12:55:52 -0700 | [diff] [blame] | 19766 | lpfc_nlp_put(ndlp); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19767 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 19768 | return -EIO; |
| 19769 | } |
| 19770 | return 0; |
| 19771 | } |
| 19772 | |
| 19773 | /** |
| 19774 | * lpfc_sli4_init_vpi - Initialize a vpi with the port |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 19775 | * @vport: Pointer to the vport for which the vpi is being initialized |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19776 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 19777 | * This routine is invoked to activate a vpi with the port. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19778 | * |
| 19779 | * Returns: |
| 19780 | * 0 success |
| 19781 | * -Evalue otherwise |
| 19782 | **/ |
| 19783 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 19784 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19785 | { |
| 19786 | LPFC_MBOXQ_t *mboxq; |
| 19787 | int rc = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 19788 | int retval = MBX_SUCCESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19789 | uint32_t mbox_tmo; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 19790 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19791 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19792 | if (!mboxq) |
| 19793 | return -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 19794 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 19795 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19796 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19797 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 19798 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19799 | "2022 INIT VPI Mailbox failed " |
| 19800 | "status %d, mbxStatus x%x\n", rc, |
| 19801 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 19802 | retval = -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19803 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 19804 | if (rc != MBX_TIMEOUT) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 19805 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 19806 | |
| 19807 | return retval; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19808 | } |
| 19809 | |
| 19810 | /** |
| 19811 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. |
| 19812 | * @phba: pointer to lpfc hba data structure. |
| 19813 | * @mboxq: Pointer to mailbox object. |
| 19814 | * |
| 19815 | * This routine is invoked to manually add a single FCF record. The caller |
| 19816 | * must pass a completely initialized FCF_Record. This routine takes |
| 19817 | * care of the nonembedded mailbox operations. |
| 19818 | **/ |
| 19819 | static void |
| 19820 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 19821 | { |
| 19822 | void *virt_addr; |
| 19823 | union lpfc_sli4_cfg_shdr *shdr; |
| 19824 | uint32_t shdr_status, shdr_add_status; |
| 19825 | |
| 19826 | virt_addr = mboxq->sge_array->addr[0]; |
| 19827 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 19828 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; |
| 19829 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 19830 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 19831 | |
| 19832 | if ((shdr_status || shdr_add_status) && |
| 19833 | (shdr_status != STATUS_FCF_IN_USE)) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 19834 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19835 | "2558 ADD_FCF_RECORD mailbox failed with " |
| 19836 | "status x%x add_status x%x\n", |
| 19837 | shdr_status, shdr_add_status); |
| 19838 | |
| 19839 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 19840 | } |
| 19841 | |
| 19842 | /** |
| 19843 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. |
| 19844 | * @phba: pointer to lpfc hba data structure. |
| 19845 | * @fcf_record: pointer to the initialized fcf record to add. |
| 19846 | * |
| 19847 | * This routine is invoked to manually add a single FCF record. The caller |
| 19848 | * must pass a completely initialized FCF_Record. This routine takes |
| 19849 | * care of the nonembedded mailbox operations. |
| 19850 | **/ |
| 19851 | int |
| 19852 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) |
| 19853 | { |
| 19854 | int rc = 0; |
| 19855 | LPFC_MBOXQ_t *mboxq; |
| 19856 | uint8_t *bytep; |
| 19857 | void *virt_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19858 | struct lpfc_mbx_sge sge; |
| 19859 | uint32_t alloc_len, req_len; |
| 19860 | uint32_t fcfindex; |
| 19861 | |
| 19862 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19863 | if (!mboxq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 19864 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19865 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); |
| 19866 | return -ENOMEM; |
| 19867 | } |
| 19868 | |
| 19869 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + |
| 19870 | sizeof(uint32_t); |
| 19871 | |
| 19872 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 19873 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 19874 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, |
| 19875 | req_len, LPFC_SLI4_MBX_NEMBED); |
| 19876 | if (alloc_len < req_len) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 19877 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19878 | "2523 Allocated DMA memory size (x%x) is " |
| 19879 | "less than the requested DMA memory " |
| 19880 | "size (x%x)\n", alloc_len, req_len); |
| 19881 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 19882 | return -ENOMEM; |
| 19883 | } |
| 19884 | |
| 19885 | /* |
| 19886 | * Get the first SGE entry from the non-embedded DMA memory. This |
| 19887 | * routine only uses a single SGE. |
| 19888 | */ |
| 19889 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19890 | virt_addr = mboxq->sge_array->addr[0]; |
| 19891 | /* |
| 19892 | * Configure the FCF record for FCFI 0. This is the driver's |
| 19893 | * hardcoded default and gets used in nonFIP mode. |
| 19894 | */ |
| 19895 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); |
| 19896 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 19897 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); |
| 19898 | |
| 19899 | /* |
| 19900 | * Copy the fcf_index and the FCF Record Data. The data starts after |
| 19901 | * the FCoE header plus word10. The data copy needs to be endian |
| 19902 | * correct. |
| 19903 | */ |
| 19904 | bytep += sizeof(uint32_t); |
| 19905 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); |
| 19906 | mboxq->vport = phba->pport; |
| 19907 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; |
| 19908 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 19909 | if (rc == MBX_NOT_FINISHED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 19910 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19911 | "2515 ADD_FCF_RECORD mailbox failed with " |
| 19912 | "status 0x%x\n", rc); |
| 19913 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 19914 | rc = -EIO; |
| 19915 | } else |
| 19916 | rc = 0; |
| 19917 | |
| 19918 | return rc; |
| 19919 | } |
| 19920 | |
| 19921 | /** |
| 19922 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. |
| 19923 | * @phba: pointer to lpfc hba data structure. |
| 19924 | * @fcf_record: pointer to the fcf record to write the default data. |
| 19925 | * @fcf_index: FCF table entry index. |
| 19926 | * |
| 19927 | * This routine is invoked to build the driver's default FCF record. The |
| 19928 | * values used are hardcoded. This routine handles memory initialization. |
| 19929 | * |
| 19930 | **/ |
| 19931 | void |
| 19932 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, |
| 19933 | struct fcf_record *fcf_record, |
| 19934 | uint16_t fcf_index) |
| 19935 | { |
| 19936 | memset(fcf_record, 0, sizeof(struct fcf_record)); |
| 19937 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; |
| 19938 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; |
| 19939 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; |
| 19940 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); |
| 19941 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); |
| 19942 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); |
| 19943 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); |
| 19944 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); |
| 19945 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); |
| 19946 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); |
| 19947 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); |
| 19948 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); |
| 19949 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 19950 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19951 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
| 19952 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, |
| 19953 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); |
| 19954 | /* Set the VLAN bit map */ |
| 19955 | if (phba->valid_vlan) { |
| 19956 | fcf_record->vlan_bitmap[phba->vlan_id / 8] |
| 19957 | = 1 << (phba->vlan_id % 8); |
| 19958 | } |
| 19959 | } |
| 19960 | |
| 19961 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19962 | * 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] | 19963 | * @phba: pointer to lpfc hba data structure. |
| 19964 | * @fcf_index: FCF table entry offset. |
| 19965 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19966 | * This routine is invoked to scan the entire FCF table by reading FCF |
| 19967 | * record and processing it one at a time starting from the @fcf_index |
| 19968 | * for initial FCF discovery or fast FCF failover rediscovery. |
| 19969 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 19970 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19971 | * otherwise. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19972 | **/ |
| 19973 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19974 | 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] | 19975 | { |
| 19976 | int rc = 0, error; |
| 19977 | LPFC_MBOXQ_t *mboxq; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19978 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 19979 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 19980 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19981 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19982 | if (!mboxq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 19983 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19984 | "2000 Failed to allocate mbox for " |
| 19985 | "READ_FCF cmd\n"); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 19986 | error = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19987 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19988 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19989 | /* Construct the read FCF record mailbox command */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19990 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19991 | if (rc) { |
| 19992 | error = -EINVAL; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19993 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19994 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19995 | /* Issue the mailbox command asynchronously */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19996 | mboxq->vport = phba->pport; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19997 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19998 | |
| 19999 | spin_lock_irq(&phba->hbalock); |
| 20000 | phba->hba_flag |= FCF_TS_INPROG; |
| 20001 | spin_unlock_irq(&phba->hbalock); |
| 20002 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 20003 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 20004 | if (rc == MBX_NOT_FINISHED) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 20005 | error = -EIO; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 20006 | else { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 20007 | /* Reset eligible FCF count for new scan */ |
| 20008 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 20009 | phba->fcf.eligible_fcf_cnt = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 20010 | error = 0; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 20011 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20012 | fail_fcf_scan: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 20013 | if (error) { |
| 20014 | if (mboxq) |
| 20015 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 20016 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 20017 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 20018 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 20019 | spin_unlock_irq(&phba->hbalock); |
| 20020 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 20021 | return error; |
| 20022 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 20023 | |
| 20024 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 20025 | * 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] | 20026 | * @phba: pointer to lpfc hba data structure. |
| 20027 | * @fcf_index: FCF table entry offset. |
| 20028 | * |
| 20029 | * 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] | 20030 | * and to use it for FLOGI roundrobin FCF failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20031 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 20032 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20033 | * otherwise. |
| 20034 | **/ |
| 20035 | int |
| 20036 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 20037 | { |
| 20038 | int rc = 0, error; |
| 20039 | LPFC_MBOXQ_t *mboxq; |
| 20040 | |
| 20041 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 20042 | if (!mboxq) { |
| 20043 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 20044 | "2763 Failed to allocate mbox for " |
| 20045 | "READ_FCF cmd\n"); |
| 20046 | error = -ENOMEM; |
| 20047 | goto fail_fcf_read; |
| 20048 | } |
| 20049 | /* Construct the read FCF record mailbox command */ |
| 20050 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 20051 | if (rc) { |
| 20052 | error = -EINVAL; |
| 20053 | goto fail_fcf_read; |
| 20054 | } |
| 20055 | /* Issue the mailbox command asynchronously */ |
| 20056 | mboxq->vport = phba->pport; |
| 20057 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; |
| 20058 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 20059 | if (rc == MBX_NOT_FINISHED) |
| 20060 | error = -EIO; |
| 20061 | else |
| 20062 | error = 0; |
| 20063 | |
| 20064 | fail_fcf_read: |
| 20065 | if (error && mboxq) |
| 20066 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 20067 | return error; |
| 20068 | } |
| 20069 | |
| 20070 | /** |
| 20071 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. |
| 20072 | * @phba: pointer to lpfc hba data structure. |
| 20073 | * @fcf_index: FCF table entry offset. |
| 20074 | * |
| 20075 | * 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] | 20076 | * determine whether it's eligible for FLOGI roundrobin failover list. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20077 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 20078 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20079 | * otherwise. |
| 20080 | **/ |
| 20081 | int |
| 20082 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 20083 | { |
| 20084 | int rc = 0, error; |
| 20085 | LPFC_MBOXQ_t *mboxq; |
| 20086 | |
| 20087 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 20088 | if (!mboxq) { |
| 20089 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 20090 | "2758 Failed to allocate mbox for " |
| 20091 | "READ_FCF cmd\n"); |
| 20092 | error = -ENOMEM; |
| 20093 | goto fail_fcf_read; |
| 20094 | } |
| 20095 | /* Construct the read FCF record mailbox command */ |
| 20096 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 20097 | if (rc) { |
| 20098 | error = -EINVAL; |
| 20099 | goto fail_fcf_read; |
| 20100 | } |
| 20101 | /* Issue the mailbox command asynchronously */ |
| 20102 | mboxq->vport = phba->pport; |
| 20103 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; |
| 20104 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 20105 | if (rc == MBX_NOT_FINISHED) |
| 20106 | error = -EIO; |
| 20107 | else |
| 20108 | error = 0; |
| 20109 | |
| 20110 | fail_fcf_read: |
| 20111 | if (error && mboxq) |
| 20112 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 20113 | return error; |
| 20114 | } |
| 20115 | |
| 20116 | /** |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 20117 | * lpfc_check_next_fcf_pri_level |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 20118 | * @phba: pointer to the lpfc_hba struct for this port. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 20119 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get |
| 20120 | * routine when the rr_bmask is empty. The FCF indecies are put into the |
| 20121 | * rr_bmask based on their priority level. Starting from the highest priority |
| 20122 | * to the lowest. The most likely FCF candidate will be in the highest |
| 20123 | * priority group. When this routine is called it searches the fcf_pri list for |
| 20124 | * next lowest priority group and repopulates the rr_bmask with only those |
| 20125 | * fcf_indexes. |
| 20126 | * returns: |
| 20127 | * 1=success 0=failure |
| 20128 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 20129 | static int |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 20130 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
| 20131 | { |
| 20132 | uint16_t next_fcf_pri; |
| 20133 | uint16_t last_index; |
| 20134 | struct lpfc_fcf_pri *fcf_pri; |
| 20135 | int rc; |
| 20136 | int ret = 0; |
| 20137 | |
| 20138 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 20139 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 20140 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 20141 | "3060 Last IDX %d\n", last_index); |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 20142 | |
| 20143 | /* Verify the priority list has 2 or more entries */ |
| 20144 | spin_lock_irq(&phba->hbalock); |
| 20145 | if (list_empty(&phba->fcf.fcf_pri_list) || |
| 20146 | list_is_singular(&phba->fcf.fcf_pri_list)) { |
| 20147 | spin_unlock_irq(&phba->hbalock); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 20148 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 20149 | "3061 Last IDX %d\n", last_index); |
| 20150 | return 0; /* Empty rr list */ |
| 20151 | } |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 20152 | spin_unlock_irq(&phba->hbalock); |
| 20153 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 20154 | next_fcf_pri = 0; |
| 20155 | /* |
| 20156 | * Clear the rr_bmask and set all of the bits that are at this |
| 20157 | * priority. |
| 20158 | */ |
| 20159 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 20160 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 20161 | spin_lock_irq(&phba->hbalock); |
| 20162 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 20163 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) |
| 20164 | continue; |
| 20165 | /* |
| 20166 | * the 1st priority that has not FLOGI failed |
| 20167 | * will be the highest. |
| 20168 | */ |
| 20169 | if (!next_fcf_pri) |
| 20170 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 20171 | spin_unlock_irq(&phba->hbalock); |
| 20172 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 20173 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 20174 | fcf_pri->fcf_rec.fcf_index); |
| 20175 | if (rc) |
| 20176 | return 0; |
| 20177 | } |
| 20178 | spin_lock_irq(&phba->hbalock); |
| 20179 | } |
| 20180 | /* |
| 20181 | * if next_fcf_pri was not set above and the list is not empty then |
| 20182 | * we have failed flogis on all of them. So reset flogi failed |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 20183 | * and start at the beginning. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 20184 | */ |
| 20185 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { |
| 20186 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 20187 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; |
| 20188 | /* |
| 20189 | * the 1st priority that has not FLOGI failed |
| 20190 | * will be the highest. |
| 20191 | */ |
| 20192 | if (!next_fcf_pri) |
| 20193 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 20194 | spin_unlock_irq(&phba->hbalock); |
| 20195 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 20196 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 20197 | fcf_pri->fcf_rec.fcf_index); |
| 20198 | if (rc) |
| 20199 | return 0; |
| 20200 | } |
| 20201 | spin_lock_irq(&phba->hbalock); |
| 20202 | } |
| 20203 | } else |
| 20204 | ret = 1; |
| 20205 | spin_unlock_irq(&phba->hbalock); |
| 20206 | |
| 20207 | return ret; |
| 20208 | } |
| 20209 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20210 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index |
| 20211 | * @phba: pointer to lpfc hba data structure. |
| 20212 | * |
| 20213 | * This routine is to get the next eligible FCF record index in a round |
| 20214 | * robin fashion. If the next eligible FCF record index equals to the |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 20215 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20216 | * shall be returned, otherwise, the next eligible FCF record's index |
| 20217 | * shall be returned. |
| 20218 | **/ |
| 20219 | uint16_t |
| 20220 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) |
| 20221 | { |
| 20222 | uint16_t next_fcf_index; |
| 20223 | |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 20224 | initial_priority: |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 20225 | /* Search start from next bit of currently registered FCF index */ |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 20226 | next_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 20227 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 20228 | next_priority: |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 20229 | /* Determine the next fcf index to check */ |
| 20230 | 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] | 20231 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 20232 | LPFC_SLI4_FCF_TBL_INDX_MAX, |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 20233 | next_fcf_index); |
| 20234 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20235 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 20236 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 20237 | /* |
| 20238 | * If we have wrapped then we need to clear the bits that |
| 20239 | * have been tested so that we can detect when we should |
| 20240 | * change the priority level. |
| 20241 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20242 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 20243 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 20244 | } |
| 20245 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20246 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 20247 | /* Check roundrobin failover list empty condition */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 20248 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
| 20249 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 20250 | /* |
| 20251 | * If next fcf index is not found check if there are lower |
| 20252 | * Priority level fcf's in the fcf_priority list. |
| 20253 | * Set up the rr_bmask with all of the avaiable fcf bits |
| 20254 | * at that level and continue the selection process. |
| 20255 | */ |
| 20256 | if (lpfc_check_next_fcf_pri_level(phba)) |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 20257 | goto initial_priority; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 20258 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 20259 | "2844 No roundrobin failover FCF available\n"); |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 20260 | |
| 20261 | return LPFC_FCOE_FCF_NEXT_NONE; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 20262 | } |
| 20263 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 20264 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
| 20265 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 20266 | LPFC_FCF_FLOGI_FAILED) { |
| 20267 | if (list_is_singular(&phba->fcf.fcf_pri_list)) |
| 20268 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 20269 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 20270 | goto next_priority; |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 20271 | } |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 20272 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 20273 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 20274 | "2845 Get next roundrobin failover FCF (x%x)\n", |
| 20275 | next_fcf_index); |
| 20276 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20277 | return next_fcf_index; |
| 20278 | } |
| 20279 | |
| 20280 | /** |
| 20281 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index |
| 20282 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 20283 | * @fcf_index: index into the FCF table to 'set' |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20284 | * |
| 20285 | * 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] | 20286 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20287 | * does not go beyond the range of the driver allocated bmask dimension |
| 20288 | * before setting the bit. |
| 20289 | * |
| 20290 | * Returns 0 if the index bit successfully set, otherwise, it returns |
| 20291 | * -EINVAL. |
| 20292 | **/ |
| 20293 | int |
| 20294 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) |
| 20295 | { |
| 20296 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 20297 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 20298 | "2610 FCF (x%x) reached driver's book " |
| 20299 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20300 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 20301 | return -EINVAL; |
| 20302 | } |
| 20303 | /* Set the eligible FCF record index bmask */ |
| 20304 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
| 20305 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 20306 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 20307 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 20308 | "bmask\n", fcf_index); |
| 20309 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20310 | return 0; |
| 20311 | } |
| 20312 | |
| 20313 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 20314 | * 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] | 20315 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 20316 | * @fcf_index: index into the FCF table to 'clear' |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20317 | * |
| 20318 | * This routine clears the FCF record index from the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 20319 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20320 | * does not go beyond the range of the driver allocated bmask dimension |
| 20321 | * before clearing the bit. |
| 20322 | **/ |
| 20323 | void |
| 20324 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) |
| 20325 | { |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 20326 | struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20327 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 20328 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 20329 | "2762 FCF (x%x) reached driver's book " |
| 20330 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20331 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 20332 | return; |
| 20333 | } |
| 20334 | /* Clear the eligible FCF record index bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 20335 | spin_lock_irq(&phba->hbalock); |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 20336 | list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list, |
| 20337 | list) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 20338 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
| 20339 | list_del_init(&fcf_pri->list); |
| 20340 | break; |
| 20341 | } |
| 20342 | } |
| 20343 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20344 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 20345 | |
| 20346 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 20347 | "2791 Clear FCF (x%x) from roundrobin failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 20348 | "bmask\n", fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20349 | } |
| 20350 | |
| 20351 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 20352 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table |
| 20353 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 20354 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 20355 | * |
| 20356 | * This routine is the completion routine for the rediscover FCF table mailbox |
| 20357 | * command. If the mailbox command returned failure, it will try to stop the |
| 20358 | * FCF rediscover wait timer. |
| 20359 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 20360 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 20361 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 20362 | { |
| 20363 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 20364 | uint32_t shdr_status, shdr_add_status; |
| 20365 | |
| 20366 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 20367 | |
| 20368 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 20369 | &redisc_fcf->header.cfg_shdr.response); |
| 20370 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 20371 | &redisc_fcf->header.cfg_shdr.response); |
| 20372 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20373 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 20374 | "2746 Requesting for FCF rediscovery failed " |
| 20375 | "status x%x add_status x%x\n", |
| 20376 | shdr_status, shdr_add_status); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20377 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 20378 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20379 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 20380 | spin_unlock_irq(&phba->hbalock); |
| 20381 | /* |
| 20382 | * CVL event triggered FCF rediscover request failed, |
| 20383 | * last resort to re-try current registered FCF entry. |
| 20384 | */ |
| 20385 | lpfc_retry_pport_discovery(phba); |
| 20386 | } else { |
| 20387 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20388 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 20389 | spin_unlock_irq(&phba->hbalock); |
| 20390 | /* |
| 20391 | * DEAD FCF event triggered FCF rediscover request |
| 20392 | * failed, last resort to fail over as a link down |
| 20393 | * to FCF registration. |
| 20394 | */ |
| 20395 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 20396 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20397 | } else { |
| 20398 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 20399 | "2775 Start FCF rediscover quiescent timer\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 20400 | /* |
| 20401 | * Start FCF rediscovery wait timer for pending FCF |
| 20402 | * before rescan FCF record table. |
| 20403 | */ |
| 20404 | lpfc_fcf_redisc_wait_start_timer(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20405 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 20406 | |
| 20407 | mempool_free(mbox, phba->mbox_mem_pool); |
| 20408 | } |
| 20409 | |
| 20410 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 20411 | * 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] | 20412 | * @phba: pointer to lpfc hba data structure. |
| 20413 | * |
| 20414 | * This routine is invoked to request for rediscovery of the entire FCF table |
| 20415 | * by the port. |
| 20416 | **/ |
| 20417 | int |
| 20418 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) |
| 20419 | { |
| 20420 | LPFC_MBOXQ_t *mbox; |
| 20421 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 20422 | int rc, length; |
| 20423 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 20424 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
| 20425 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
| 20426 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 20427 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 20428 | if (!mbox) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 20429 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 20430 | "2745 Failed to allocate mbox for " |
| 20431 | "requesting FCF rediscover.\n"); |
| 20432 | return -ENOMEM; |
| 20433 | } |
| 20434 | |
| 20435 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - |
| 20436 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 20437 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 20438 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, |
| 20439 | length, LPFC_SLI4_MBX_EMBED); |
| 20440 | |
| 20441 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 20442 | /* Set count to 0 for invalidating the entire FCF database */ |
| 20443 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); |
| 20444 | |
| 20445 | /* Issue the mailbox command asynchronously */ |
| 20446 | mbox->vport = phba->pport; |
| 20447 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; |
| 20448 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 20449 | |
| 20450 | if (rc == MBX_NOT_FINISHED) { |
| 20451 | mempool_free(mbox, phba->mbox_mem_pool); |
| 20452 | return -EIO; |
| 20453 | } |
| 20454 | return 0; |
| 20455 | } |
| 20456 | |
| 20457 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 20458 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event |
| 20459 | * @phba: pointer to lpfc hba data structure. |
| 20460 | * |
| 20461 | * This function is the failover routine as a last resort to the FCF DEAD |
| 20462 | * event when driver failed to perform fast FCF failover. |
| 20463 | **/ |
| 20464 | void |
| 20465 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) |
| 20466 | { |
| 20467 | uint32_t link_state; |
| 20468 | |
| 20469 | /* |
| 20470 | * Last resort as FCF DEAD event failover will treat this as |
| 20471 | * a link down, but save the link state because we don't want |
| 20472 | * it to be changed to Link Down unless it is already down. |
| 20473 | */ |
| 20474 | link_state = phba->link_state; |
| 20475 | lpfc_linkdown(phba); |
| 20476 | phba->link_state = link_state; |
| 20477 | |
| 20478 | /* Unregister FCF if no devices connected to it */ |
| 20479 | lpfc_unregister_unused_fcf(phba); |
| 20480 | } |
| 20481 | |
| 20482 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 20483 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 20484 | * @phba: pointer to lpfc hba data structure. |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 20485 | * @rgn23_data: pointer to configure region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 20486 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 20487 | * This function gets SLI3 port configure region 23 data through memory dump |
| 20488 | * mailbox command. When it successfully retrieves data, the size of the data |
| 20489 | * will be returned, otherwise, 0 will be returned. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 20490 | **/ |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 20491 | static uint32_t |
| 20492 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 20493 | { |
| 20494 | LPFC_MBOXQ_t *pmb = NULL; |
| 20495 | MAILBOX_t *mb; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 20496 | uint32_t offset = 0; |
James Smart | e4ec102 | 2021-04-21 16:45:11 -0700 | [diff] [blame] | 20497 | int rc; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 20498 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 20499 | if (!rgn23_data) |
| 20500 | return 0; |
| 20501 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 20502 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 20503 | if (!pmb) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 20504 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 20505 | "2600 failed to allocate mailbox memory\n"); |
| 20506 | return 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 20507 | } |
| 20508 | mb = &pmb->u.mb; |
| 20509 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 20510 | do { |
| 20511 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); |
| 20512 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 20513 | |
| 20514 | if (rc != MBX_SUCCESS) { |
| 20515 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 20516 | "2601 failed to read config " |
| 20517 | "region 23, rc 0x%x Status 0x%x\n", |
| 20518 | rc, mb->mbxStatus); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 20519 | mb->un.varDmp.word_cnt = 0; |
| 20520 | } |
| 20521 | /* |
| 20522 | * dump mem may return a zero when finished or we got a |
| 20523 | * mailbox error, either way we are done. |
| 20524 | */ |
| 20525 | if (mb->un.varDmp.word_cnt == 0) |
| 20526 | break; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 20527 | |
James Smart | e4ec102 | 2021-04-21 16:45:11 -0700 | [diff] [blame] | 20528 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) |
| 20529 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; |
| 20530 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 20531 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
James Smart | e4ec102 | 2021-04-21 16:45:11 -0700 | [diff] [blame] | 20532 | rgn23_data + offset, |
| 20533 | mb->un.varDmp.word_cnt); |
| 20534 | offset += mb->un.varDmp.word_cnt; |
| 20535 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 20536 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 20537 | mempool_free(pmb, phba->mbox_mem_pool); |
| 20538 | return offset; |
| 20539 | } |
| 20540 | |
| 20541 | /** |
| 20542 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. |
| 20543 | * @phba: pointer to lpfc hba data structure. |
| 20544 | * @rgn23_data: pointer to configure region 23 data. |
| 20545 | * |
| 20546 | * This function gets SLI4 port configure region 23 data through memory dump |
| 20547 | * mailbox command. When it successfully retrieves data, the size of the data |
| 20548 | * will be returned, otherwise, 0 will be returned. |
| 20549 | **/ |
| 20550 | static uint32_t |
| 20551 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
| 20552 | { |
| 20553 | LPFC_MBOXQ_t *mboxq = NULL; |
| 20554 | struct lpfc_dmabuf *mp = NULL; |
| 20555 | struct lpfc_mqe *mqe; |
| 20556 | uint32_t data_length = 0; |
| 20557 | int rc; |
| 20558 | |
| 20559 | if (!rgn23_data) |
| 20560 | return 0; |
| 20561 | |
| 20562 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 20563 | if (!mboxq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 20564 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 20565 | "3105 failed to allocate mailbox memory\n"); |
| 20566 | return 0; |
| 20567 | } |
| 20568 | |
| 20569 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) |
| 20570 | goto out; |
| 20571 | mqe = &mboxq->u.mqe; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 20572 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 20573 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 20574 | if (rc) |
| 20575 | goto out; |
| 20576 | data_length = mqe->un.mb_words[5]; |
| 20577 | if (data_length == 0) |
| 20578 | goto out; |
| 20579 | if (data_length > DMP_RGN23_SIZE) { |
| 20580 | data_length = 0; |
| 20581 | goto out; |
| 20582 | } |
| 20583 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); |
| 20584 | out: |
| 20585 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 20586 | if (mp) { |
| 20587 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 20588 | kfree(mp); |
| 20589 | } |
| 20590 | return data_length; |
| 20591 | } |
| 20592 | |
| 20593 | /** |
| 20594 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. |
| 20595 | * @phba: pointer to lpfc hba data structure. |
| 20596 | * |
| 20597 | * This function read region 23 and parse TLV for port status to |
| 20598 | * decide if the user disaled the port. If the TLV indicates the |
| 20599 | * port is disabled, the hba_flag is set accordingly. |
| 20600 | **/ |
| 20601 | void |
| 20602 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) |
| 20603 | { |
| 20604 | uint8_t *rgn23_data = NULL; |
| 20605 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; |
| 20606 | uint32_t offset = 0; |
| 20607 | |
| 20608 | /* Get adapter Region 23 data */ |
| 20609 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); |
| 20610 | if (!rgn23_data) |
| 20611 | goto out; |
| 20612 | |
| 20613 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 20614 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); |
| 20615 | else { |
| 20616 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 20617 | &phba->sli4_hba.sli_intf); |
| 20618 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) |
| 20619 | goto out; |
| 20620 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); |
| 20621 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 20622 | |
| 20623 | if (!data_size) |
| 20624 | goto out; |
| 20625 | |
| 20626 | /* Check the region signature first */ |
| 20627 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 20628 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 20629 | "2619 Config region 23 has bad signature\n"); |
| 20630 | goto out; |
| 20631 | } |
| 20632 | offset += 4; |
| 20633 | |
| 20634 | /* Check the data structure version */ |
| 20635 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 20636 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 20637 | "2620 Config region 23 has bad version\n"); |
| 20638 | goto out; |
| 20639 | } |
| 20640 | offset += 4; |
| 20641 | |
| 20642 | /* Parse TLV entries in the region */ |
| 20643 | while (offset < data_size) { |
| 20644 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) |
| 20645 | break; |
| 20646 | /* |
| 20647 | * If the TLV is not driver specific TLV or driver id is |
| 20648 | * not linux driver id, skip the record. |
| 20649 | */ |
| 20650 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || |
| 20651 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || |
| 20652 | (rgn23_data[offset + 3] != 0)) { |
| 20653 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 20654 | continue; |
| 20655 | } |
| 20656 | |
| 20657 | /* Driver found a driver specific TLV in the config region */ |
| 20658 | sub_tlv_len = rgn23_data[offset + 1] * 4; |
| 20659 | offset += 4; |
| 20660 | tlv_offset = 0; |
| 20661 | |
| 20662 | /* |
| 20663 | * Search for configured port state sub-TLV. |
| 20664 | */ |
| 20665 | while ((offset < data_size) && |
| 20666 | (tlv_offset < sub_tlv_len)) { |
| 20667 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { |
| 20668 | offset += 4; |
| 20669 | tlv_offset += 4; |
| 20670 | break; |
| 20671 | } |
| 20672 | if (rgn23_data[offset] != PORT_STE_TYPE) { |
| 20673 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 20674 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; |
| 20675 | continue; |
| 20676 | } |
| 20677 | |
| 20678 | /* This HBA contains PORT_STE configured */ |
| 20679 | if (!rgn23_data[offset + 2]) |
| 20680 | phba->hba_flag |= LINK_DISABLED; |
| 20681 | |
| 20682 | goto out; |
| 20683 | } |
| 20684 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 20685 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 20686 | out: |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 20687 | kfree(rgn23_data); |
| 20688 | return; |
| 20689 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 20690 | |
| 20691 | /** |
James Smart | 16a93e8 | 2021-07-07 11:43:34 -0700 | [diff] [blame] | 20692 | * lpfc_log_fw_write_cmpl - logs firmware write completion status |
| 20693 | * @phba: pointer to lpfc hba data structure |
| 20694 | * @shdr_status: wr_object rsp's status field |
| 20695 | * @shdr_add_status: wr_object rsp's add_status field |
| 20696 | * @shdr_add_status_2: wr_object rsp's add_status_2 field |
| 20697 | * @shdr_change_status: wr_object rsp's change_status field |
| 20698 | * @shdr_csf: wr_object rsp's csf bit |
| 20699 | * |
| 20700 | * This routine is intended to be called after a firmware write completes. |
| 20701 | * It will log next action items to be performed by the user to instantiate |
| 20702 | * the newly downloaded firmware or reason for incompatibility. |
| 20703 | **/ |
| 20704 | static void |
| 20705 | lpfc_log_fw_write_cmpl(struct lpfc_hba *phba, u32 shdr_status, |
| 20706 | u32 shdr_add_status, u32 shdr_add_status_2, |
| 20707 | u32 shdr_change_status, u32 shdr_csf) |
| 20708 | { |
| 20709 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 20710 | "4198 %s: flash_id x%02x, asic_rev x%02x, " |
| 20711 | "status x%02x, add_status x%02x, add_status_2 x%02x, " |
| 20712 | "change_status x%02x, csf %01x\n", __func__, |
| 20713 | phba->sli4_hba.flash_id, phba->sli4_hba.asic_rev, |
| 20714 | shdr_status, shdr_add_status, shdr_add_status_2, |
| 20715 | shdr_change_status, shdr_csf); |
| 20716 | |
| 20717 | if (shdr_add_status == LPFC_ADD_STATUS_INCOMPAT_OBJ) { |
| 20718 | switch (shdr_add_status_2) { |
| 20719 | case LPFC_ADD_STATUS_2_INCOMPAT_FLASH: |
| 20720 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 20721 | "4199 Firmware write failed: " |
| 20722 | "image incompatible with flash x%02x\n", |
| 20723 | phba->sli4_hba.flash_id); |
| 20724 | break; |
| 20725 | case LPFC_ADD_STATUS_2_INCORRECT_ASIC: |
| 20726 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 20727 | "4200 Firmware write failed: " |
| 20728 | "image incompatible with ASIC " |
| 20729 | "architecture x%02x\n", |
| 20730 | phba->sli4_hba.asic_rev); |
| 20731 | break; |
| 20732 | default: |
| 20733 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 20734 | "4210 Firmware write failed: " |
| 20735 | "add_status_2 x%02x\n", |
| 20736 | shdr_add_status_2); |
| 20737 | break; |
| 20738 | } |
| 20739 | } else if (!shdr_status && !shdr_add_status) { |
| 20740 | if (shdr_change_status == LPFC_CHANGE_STATUS_FW_RESET || |
| 20741 | shdr_change_status == LPFC_CHANGE_STATUS_PORT_MIGRATION) { |
| 20742 | if (shdr_csf) |
| 20743 | shdr_change_status = |
| 20744 | LPFC_CHANGE_STATUS_PCI_RESET; |
| 20745 | } |
| 20746 | |
| 20747 | switch (shdr_change_status) { |
| 20748 | case (LPFC_CHANGE_STATUS_PHYS_DEV_RESET): |
| 20749 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 20750 | "3198 Firmware write complete: System " |
| 20751 | "reboot required to instantiate\n"); |
| 20752 | break; |
| 20753 | case (LPFC_CHANGE_STATUS_FW_RESET): |
| 20754 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 20755 | "3199 Firmware write complete: " |
| 20756 | "Firmware reset required to " |
| 20757 | "instantiate\n"); |
| 20758 | break; |
| 20759 | case (LPFC_CHANGE_STATUS_PORT_MIGRATION): |
| 20760 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 20761 | "3200 Firmware write complete: Port " |
| 20762 | "Migration or PCI Reset required to " |
| 20763 | "instantiate\n"); |
| 20764 | break; |
| 20765 | case (LPFC_CHANGE_STATUS_PCI_RESET): |
| 20766 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 20767 | "3201 Firmware write complete: PCI " |
| 20768 | "Reset required to instantiate\n"); |
| 20769 | break; |
| 20770 | default: |
| 20771 | break; |
| 20772 | } |
| 20773 | } |
| 20774 | } |
| 20775 | |
| 20776 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 20777 | * lpfc_wr_object - write an object to the firmware |
| 20778 | * @phba: HBA structure that indicates port to create a queue on. |
| 20779 | * @dmabuf_list: list of dmabufs to write to the port. |
| 20780 | * @size: the total byte value of the objects to write to the port. |
| 20781 | * @offset: the current offset to be used to start the transfer. |
| 20782 | * |
| 20783 | * This routine will create a wr_object mailbox command to send to the port. |
| 20784 | * the mailbox command will be constructed using the dma buffers described in |
| 20785 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many |
| 20786 | * BDEs that the imbedded mailbox can support. The @offset variable will be |
| 20787 | * used to indicate the starting offset of the transfer and will also return |
| 20788 | * the offset after the write object mailbox has completed. @size is used to |
| 20789 | * determine the end of the object and whether the eof bit should be set. |
| 20790 | * |
| 20791 | * Return 0 is successful and offset will contain the the new offset to use |
| 20792 | * for the next write. |
| 20793 | * Return negative value for error cases. |
| 20794 | **/ |
| 20795 | int |
| 20796 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, |
| 20797 | uint32_t size, uint32_t *offset) |
| 20798 | { |
| 20799 | struct lpfc_mbx_wr_object *wr_object; |
| 20800 | LPFC_MBOXQ_t *mbox; |
| 20801 | int rc = 0, i = 0; |
James Smart | 16a93e8 | 2021-07-07 11:43:34 -0700 | [diff] [blame] | 20802 | uint32_t shdr_status, shdr_add_status, shdr_add_status_2; |
| 20803 | uint32_t shdr_change_status = 0, shdr_csf = 0; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 20804 | uint32_t mbox_tmo; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 20805 | struct lpfc_dmabuf *dmabuf; |
| 20806 | uint32_t written = 0; |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 20807 | bool check_change_status = false; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 20808 | |
| 20809 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 20810 | if (!mbox) |
| 20811 | return -ENOMEM; |
| 20812 | |
| 20813 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 20814 | LPFC_MBOX_OPCODE_WRITE_OBJECT, |
| 20815 | sizeof(struct lpfc_mbx_wr_object) - |
| 20816 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
| 20817 | |
| 20818 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; |
| 20819 | wr_object->u.request.write_offset = *offset; |
| 20820 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); |
| 20821 | wr_object->u.request.object_name[0] = |
| 20822 | cpu_to_le32(wr_object->u.request.object_name[0]); |
| 20823 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); |
| 20824 | list_for_each_entry(dmabuf, dmabuf_list, list) { |
| 20825 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) |
| 20826 | break; |
| 20827 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); |
| 20828 | wr_object->u.request.bde[i].addrHigh = |
| 20829 | putPaddrHigh(dmabuf->phys); |
| 20830 | if (written + SLI4_PAGE_SIZE >= size) { |
| 20831 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 20832 | (size - written); |
| 20833 | written += (size - written); |
| 20834 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 20835 | bf_set(lpfc_wr_object_eas, &wr_object->u.request, 1); |
| 20836 | check_change_status = true; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 20837 | } else { |
| 20838 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 20839 | SLI4_PAGE_SIZE; |
| 20840 | written += SLI4_PAGE_SIZE; |
| 20841 | } |
| 20842 | i++; |
| 20843 | } |
| 20844 | wr_object->u.request.bde_count = i; |
| 20845 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); |
| 20846 | if (!phba->sli4_hba.intr_enable) |
| 20847 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 20848 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 20849 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 20850 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 20851 | } |
| 20852 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 20853 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 20854 | &wr_object->header.cfg_shdr.response); |
| 20855 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 20856 | &wr_object->header.cfg_shdr.response); |
James Smart | 16a93e8 | 2021-07-07 11:43:34 -0700 | [diff] [blame] | 20857 | shdr_add_status_2 = bf_get(lpfc_mbox_hdr_add_status_2, |
| 20858 | &wr_object->header.cfg_shdr.response); |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 20859 | if (check_change_status) { |
| 20860 | shdr_change_status = bf_get(lpfc_wr_object_change_status, |
| 20861 | &wr_object->u.response); |
James Smart | 16a93e8 | 2021-07-07 11:43:34 -0700 | [diff] [blame] | 20862 | shdr_csf = bf_get(lpfc_wr_object_csf, |
| 20863 | &wr_object->u.response); |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 20864 | } |
James Smart | 16a93e8 | 2021-07-07 11:43:34 -0700 | [diff] [blame] | 20865 | |
James Smart | 304ee43 | 2021-04-11 18:31:17 -0700 | [diff] [blame] | 20866 | if (!phba->sli4_hba.intr_enable) |
| 20867 | mempool_free(mbox, phba->mbox_mem_pool); |
| 20868 | else if (rc != MBX_TIMEOUT) |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 20869 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 16a93e8 | 2021-07-07 11:43:34 -0700 | [diff] [blame] | 20870 | if (shdr_status || shdr_add_status || shdr_add_status_2 || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 20871 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 20872 | "3025 Write Object mailbox failed with " |
James Smart | 16a93e8 | 2021-07-07 11:43:34 -0700 | [diff] [blame] | 20873 | "status x%x add_status x%x, add_status_2 x%x, " |
| 20874 | "mbx status x%x\n", |
| 20875 | shdr_status, shdr_add_status, shdr_add_status_2, |
| 20876 | rc); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 20877 | rc = -ENXIO; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 20878 | *offset = shdr_add_status; |
James Smart | 16a93e8 | 2021-07-07 11:43:34 -0700 | [diff] [blame] | 20879 | } else { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 20880 | *offset += wr_object->u.response.actual_write_length; |
James Smart | 16a93e8 | 2021-07-07 11:43:34 -0700 | [diff] [blame] | 20881 | } |
| 20882 | |
| 20883 | if (rc || check_change_status) |
| 20884 | lpfc_log_fw_write_cmpl(phba, shdr_status, shdr_add_status, |
| 20885 | shdr_add_status_2, shdr_change_status, |
| 20886 | shdr_csf); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 20887 | return rc; |
| 20888 | } |
| 20889 | |
| 20890 | /** |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 20891 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. |
| 20892 | * @vport: pointer to vport data structure. |
| 20893 | * |
| 20894 | * This function iterate through the mailboxq and clean up all REG_LOGIN |
| 20895 | * and REG_VPI mailbox commands associated with the vport. This function |
| 20896 | * is called when driver want to restart discovery of the vport due to |
| 20897 | * a Clear Virtual Link event. |
| 20898 | **/ |
| 20899 | void |
| 20900 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) |
| 20901 | { |
| 20902 | struct lpfc_hba *phba = vport->phba; |
| 20903 | LPFC_MBOXQ_t *mb, *nextmb; |
| 20904 | struct lpfc_dmabuf *mp; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 20905 | struct lpfc_nodelist *ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 20906 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 20907 | LIST_HEAD(mbox_cmd_list); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 20908 | uint8_t restart_loop; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 20909 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 20910 | /* Clean up internally queued mailbox commands with the vport */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 20911 | spin_lock_irq(&phba->hbalock); |
| 20912 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 20913 | if (mb->vport != vport) |
| 20914 | continue; |
| 20915 | |
| 20916 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 20917 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 20918 | continue; |
| 20919 | |
Zou Wei | 4701808 | 2021-06-08 08:51:33 +0800 | [diff] [blame] | 20920 | list_move_tail(&mb->list, &mbox_cmd_list); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 20921 | } |
| 20922 | /* Clean up active mailbox command with the vport */ |
| 20923 | mb = phba->sli.mbox_active; |
| 20924 | if (mb && (mb->vport == vport)) { |
| 20925 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || |
| 20926 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) |
| 20927 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 20928 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 20929 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 20930 | /* Put reference count for delayed processing */ |
| 20931 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); |
| 20932 | /* Unregister the RPI when mailbox complete */ |
| 20933 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 20934 | } |
| 20935 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 20936 | /* Cleanup any mailbox completions which are not yet processed */ |
| 20937 | do { |
| 20938 | restart_loop = 0; |
| 20939 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 20940 | /* |
| 20941 | * If this mailox is already processed or it is |
| 20942 | * for another vport ignore it. |
| 20943 | */ |
| 20944 | if ((mb->vport != vport) || |
| 20945 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) |
| 20946 | continue; |
| 20947 | |
| 20948 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 20949 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 20950 | continue; |
| 20951 | |
| 20952 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 20953 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 20954 | ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 20955 | /* Unregister the RPI when mailbox complete */ |
| 20956 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 20957 | restart_loop = 1; |
| 20958 | spin_unlock_irq(&phba->hbalock); |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 20959 | spin_lock(&ndlp->lock); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 20960 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 20961 | spin_unlock(&ndlp->lock); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 20962 | spin_lock_irq(&phba->hbalock); |
| 20963 | break; |
| 20964 | } |
| 20965 | } |
| 20966 | } while (restart_loop); |
| 20967 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 20968 | spin_unlock_irq(&phba->hbalock); |
| 20969 | |
| 20970 | /* Release the cleaned-up mailbox commands */ |
| 20971 | while (!list_empty(&mbox_cmd_list)) { |
| 20972 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 20973 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 20974 | mp = (struct lpfc_dmabuf *)(mb->ctx_buf); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 20975 | if (mp) { |
| 20976 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 20977 | kfree(mp); |
| 20978 | } |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 20979 | mb->ctx_buf = NULL; |
| 20980 | ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
| 20981 | mb->ctx_ndlp = NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 20982 | if (ndlp) { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 20983 | spin_lock(&ndlp->lock); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 20984 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 20985 | spin_unlock(&ndlp->lock); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 20986 | lpfc_nlp_put(ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 20987 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 20988 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 20989 | mempool_free(mb, phba->mbox_mem_pool); |
| 20990 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 20991 | |
| 20992 | /* Release the ndlp with the cleaned-up active mailbox command */ |
| 20993 | if (act_mbx_ndlp) { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 20994 | spin_lock(&act_mbx_ndlp->lock); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 20995 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 20996 | spin_unlock(&act_mbx_ndlp->lock); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 20997 | lpfc_nlp_put(act_mbx_ndlp); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 20998 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 20999 | } |
| 21000 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 21001 | /** |
| 21002 | * lpfc_drain_txq - Drain the txq |
| 21003 | * @phba: Pointer to HBA context object. |
| 21004 | * |
| 21005 | * This function attempt to submit IOCBs on the txq |
| 21006 | * to the adapter. For SLI4 adapters, the txq contains |
| 21007 | * ELS IOCBs that have been deferred because the there |
| 21008 | * are no SGLs. This congestion can occur with large |
| 21009 | * vport counts during node discovery. |
| 21010 | **/ |
| 21011 | |
| 21012 | uint32_t |
| 21013 | lpfc_drain_txq(struct lpfc_hba *phba) |
| 21014 | { |
| 21015 | LIST_HEAD(completions); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 21016 | struct lpfc_sli_ring *pring; |
Daeseok Youn | 2e70637 | 2014-02-21 09:03:32 +0900 | [diff] [blame] | 21017 | struct lpfc_iocbq *piocbq = NULL; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 21018 | unsigned long iflags = 0; |
| 21019 | char *fail_msg = NULL; |
| 21020 | struct lpfc_sglq *sglq; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 21021 | union lpfc_wqe128 wqe; |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 21022 | uint32_t txq_cnt = 0; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 21023 | struct lpfc_queue *wq; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 21024 | |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 21025 | if (phba->link_flag & LS_MDS_LOOPBACK) { |
| 21026 | /* MDS WQE are posted only to first WQ*/ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 21027 | wq = phba->sli4_hba.hdwq[0].io_wq; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 21028 | if (unlikely(!wq)) |
| 21029 | return 0; |
| 21030 | pring = wq->pring; |
| 21031 | } else { |
| 21032 | wq = phba->sli4_hba.els_wq; |
| 21033 | if (unlikely(!wq)) |
| 21034 | return 0; |
| 21035 | pring = lpfc_phba_elsring(phba); |
| 21036 | } |
| 21037 | |
| 21038 | if (unlikely(!pring) || list_empty(&pring->txq)) |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 21039 | return 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 21040 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 21041 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 21042 | list_for_each_entry(piocbq, &pring->txq, list) { |
| 21043 | txq_cnt++; |
| 21044 | } |
| 21045 | |
| 21046 | if (txq_cnt > pring->txq_max) |
| 21047 | pring->txq_max = txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 21048 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 21049 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 21050 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 21051 | while (!list_empty(&pring->txq)) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 21052 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 21053 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 21054 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 21055 | if (!piocbq) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 21056 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 21057 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 21058 | "2823 txq empty and txq_cnt is %d\n ", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 21059 | txq_cnt); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 21060 | break; |
| 21061 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 21062 | sglq = __lpfc_sli_get_els_sglq(phba, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 21063 | if (!sglq) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 21064 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 21065 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 21066 | break; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 21067 | } |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 21068 | txq_cnt--; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 21069 | |
| 21070 | /* The xri and iocb resources secured, |
| 21071 | * attempt to issue request |
| 21072 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 21073 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 21074 | piocbq->sli4_xritag = sglq->sli4_xritag; |
| 21075 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) |
| 21076 | fail_msg = "to convert bpl to sgl"; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 21077 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 21078 | fail_msg = "to convert iocb to wqe"; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 21079 | else if (lpfc_sli4_wq_put(wq, &wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 21080 | fail_msg = " - Wq is full"; |
| 21081 | else |
| 21082 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); |
| 21083 | |
| 21084 | if (fail_msg) { |
| 21085 | /* Failed means we can't issue and need to cancel */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 21086 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 21087 | "2822 IOCB failed %s iotag 0x%x " |
| 21088 | "xri 0x%x\n", |
| 21089 | fail_msg, |
| 21090 | piocbq->iotag, piocbq->sli4_xritag); |
| 21091 | list_add_tail(&piocbq->list, &completions); |
| 21092 | } |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 21093 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 21094 | } |
| 21095 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 21096 | /* Cancel all the IOCBs that cannot be issued */ |
| 21097 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 21098 | IOERR_SLI_ABORTED); |
| 21099 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 21100 | return txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 21101 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 21102 | |
| 21103 | /** |
| 21104 | * lpfc_wqe_bpl2sgl - Convert the bpl/bde to a sgl. |
| 21105 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 21106 | * @pwqeq: Pointer to command WQE. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 21107 | * @sglq: Pointer to the scatter gather queue object. |
| 21108 | * |
| 21109 | * This routine converts the bpl or bde that is in the WQE |
| 21110 | * to a sgl list for the sli4 hardware. The physical address |
| 21111 | * of the bpl/bde is converted back to a virtual address. |
| 21112 | * If the WQE contains a BPL then the list of BDE's is |
| 21113 | * converted to sli4_sge's. If the WQE contains a single |
| 21114 | * BDE then it is converted to a single sli_sge. |
| 21115 | * The WQE is still in cpu endianness so the contents of |
| 21116 | * the bpl can be used without byte swapping. |
| 21117 | * |
| 21118 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 21119 | */ |
| 21120 | static uint16_t |
| 21121 | lpfc_wqe_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeq, |
| 21122 | struct lpfc_sglq *sglq) |
| 21123 | { |
| 21124 | uint16_t xritag = NO_XRI; |
| 21125 | struct ulp_bde64 *bpl = NULL; |
| 21126 | struct ulp_bde64 bde; |
| 21127 | struct sli4_sge *sgl = NULL; |
| 21128 | struct lpfc_dmabuf *dmabuf; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 21129 | union lpfc_wqe128 *wqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 21130 | int numBdes = 0; |
| 21131 | int i = 0; |
| 21132 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 21133 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
| 21134 | uint32_t cmd; |
| 21135 | |
| 21136 | if (!pwqeq || !sglq) |
| 21137 | return xritag; |
| 21138 | |
| 21139 | sgl = (struct sli4_sge *)sglq->sgl; |
| 21140 | wqe = &pwqeq->wqe; |
| 21141 | pwqeq->iocb.ulpIoTag = pwqeq->iotag; |
| 21142 | |
| 21143 | cmd = bf_get(wqe_cmnd, &wqe->generic.wqe_com); |
| 21144 | if (cmd == CMD_XMIT_BLS_RSP64_WQE) |
| 21145 | return sglq->sli4_xritag; |
| 21146 | numBdes = pwqeq->rsvd2; |
| 21147 | if (numBdes) { |
| 21148 | /* The addrHigh and addrLow fields within the WQE |
| 21149 | * have not been byteswapped yet so there is no |
| 21150 | * need to swap them back. |
| 21151 | */ |
| 21152 | if (pwqeq->context3) |
| 21153 | dmabuf = (struct lpfc_dmabuf *)pwqeq->context3; |
| 21154 | else |
| 21155 | return xritag; |
| 21156 | |
| 21157 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 21158 | if (!bpl) |
| 21159 | return xritag; |
| 21160 | |
| 21161 | for (i = 0; i < numBdes; i++) { |
| 21162 | /* Should already be byte swapped. */ |
| 21163 | sgl->addr_hi = bpl->addrHigh; |
| 21164 | sgl->addr_lo = bpl->addrLow; |
| 21165 | |
| 21166 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 21167 | if ((i+1) == numBdes) |
| 21168 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 21169 | else |
| 21170 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 21171 | /* swap the size field back to the cpu so we |
| 21172 | * can assign it to the sgl. |
| 21173 | */ |
| 21174 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 21175 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
| 21176 | /* The offsets in the sgl need to be accumulated |
| 21177 | * separately for the request and reply lists. |
| 21178 | * The request is always first, the reply follows. |
| 21179 | */ |
| 21180 | switch (cmd) { |
| 21181 | case CMD_GEN_REQUEST64_WQE: |
| 21182 | /* add up the reply sg entries */ |
| 21183 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 21184 | inbound++; |
| 21185 | /* first inbound? reset the offset */ |
| 21186 | if (inbound == 1) |
| 21187 | offset = 0; |
| 21188 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 21189 | bf_set(lpfc_sli4_sge_type, sgl, |
| 21190 | LPFC_SGE_TYPE_DATA); |
| 21191 | offset += bde.tus.f.bdeSize; |
| 21192 | break; |
| 21193 | case CMD_FCP_TRSP64_WQE: |
| 21194 | bf_set(lpfc_sli4_sge_offset, sgl, 0); |
| 21195 | bf_set(lpfc_sli4_sge_type, sgl, |
| 21196 | LPFC_SGE_TYPE_DATA); |
| 21197 | break; |
| 21198 | case CMD_FCP_TSEND64_WQE: |
| 21199 | case CMD_FCP_TRECEIVE64_WQE: |
| 21200 | bf_set(lpfc_sli4_sge_type, sgl, |
| 21201 | bpl->tus.f.bdeFlags); |
| 21202 | if (i < 3) |
| 21203 | offset = 0; |
| 21204 | else |
| 21205 | offset += bde.tus.f.bdeSize; |
| 21206 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 21207 | break; |
| 21208 | } |
| 21209 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 21210 | bpl++; |
| 21211 | sgl++; |
| 21212 | } |
| 21213 | } else if (wqe->gen_req.bde.tus.f.bdeFlags == BUFF_TYPE_BDE_64) { |
| 21214 | /* The addrHigh and addrLow fields of the BDE have not |
| 21215 | * been byteswapped yet so they need to be swapped |
| 21216 | * before putting them in the sgl. |
| 21217 | */ |
| 21218 | sgl->addr_hi = cpu_to_le32(wqe->gen_req.bde.addrHigh); |
| 21219 | sgl->addr_lo = cpu_to_le32(wqe->gen_req.bde.addrLow); |
| 21220 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 21221 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 21222 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 21223 | sgl->sge_len = cpu_to_le32(wqe->gen_req.bde.tus.f.bdeSize); |
| 21224 | } |
| 21225 | return sglq->sli4_xritag; |
| 21226 | } |
| 21227 | |
| 21228 | /** |
| 21229 | * lpfc_sli4_issue_wqe - Issue an SLI4 Work Queue Entry (WQE) |
| 21230 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 21231 | * @qp: Pointer to HDW queue. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 21232 | * @pwqe: Pointer to command WQE. |
| 21233 | **/ |
| 21234 | int |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 21235 | 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] | 21236 | struct lpfc_iocbq *pwqe) |
| 21237 | { |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 21238 | union lpfc_wqe128 *wqe = &pwqe->wqe; |
James Smart | 7cacae2 | 2020-03-31 09:50:03 -0700 | [diff] [blame] | 21239 | struct lpfc_async_xchg_ctx *ctxp; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 21240 | struct lpfc_queue *wq; |
| 21241 | struct lpfc_sglq *sglq; |
| 21242 | struct lpfc_sli_ring *pring; |
| 21243 | unsigned long iflags; |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 21244 | uint32_t ret = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 21245 | |
| 21246 | /* NVME_LS and NVME_LS ABTS requests. */ |
| 21247 | if (pwqe->iocb_flag & LPFC_IO_NVME_LS) { |
| 21248 | pring = phba->sli4_hba.nvmels_wq->pring; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 21249 | lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags, |
| 21250 | qp, wq_access); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 21251 | sglq = __lpfc_sli_get_els_sglq(phba, pwqe); |
| 21252 | if (!sglq) { |
| 21253 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 21254 | return WQE_BUSY; |
| 21255 | } |
| 21256 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 21257 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 21258 | if (lpfc_wqe_bpl2sgl(phba, pwqe, sglq) == NO_XRI) { |
| 21259 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 21260 | return WQE_ERROR; |
| 21261 | } |
| 21262 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 21263 | pwqe->sli4_xritag); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 21264 | ret = lpfc_sli4_wq_put(phba->sli4_hba.nvmels_wq, wqe); |
| 21265 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 21266 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 21267 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 21268 | } |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 21269 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 21270 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 21271 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 21272 | |
| 21273 | lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 21274 | return 0; |
| 21275 | } |
| 21276 | |
| 21277 | /* NVME_FCREQ and NVME_ABTS requests */ |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 21278 | if (pwqe->iocb_flag & (LPFC_IO_NVME | LPFC_IO_FCP | LPFC_IO_CMF)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 21279 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 21280 | wq = qp->io_wq; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 21281 | pring = wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 21282 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 21283 | bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 21284 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 21285 | lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags, |
| 21286 | qp, wq_access); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 21287 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 21288 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 21289 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 21290 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 21291 | } |
| 21292 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 21293 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 21294 | |
| 21295 | lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 21296 | return 0; |
| 21297 | } |
| 21298 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 21299 | /* NVMET requests */ |
| 21300 | if (pwqe->iocb_flag & LPFC_IO_NVMET) { |
| 21301 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 21302 | wq = qp->io_wq; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 21303 | pring = wq->pring; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 21304 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 21305 | ctxp = pwqe->context2; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 21306 | sglq = ctxp->ctxbuf->sglq; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 21307 | if (pwqe->sli4_xritag == NO_XRI) { |
| 21308 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 21309 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 21310 | } |
| 21311 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 21312 | pwqe->sli4_xritag); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 21313 | bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map); |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 21314 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 21315 | lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags, |
| 21316 | qp, wq_access); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 21317 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 21318 | if (ret) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 21319 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 21320 | return ret; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 21321 | } |
| 21322 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 21323 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 21324 | |
| 21325 | lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 21326 | return 0; |
| 21327 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 21328 | return WQE_ERROR; |
| 21329 | } |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21330 | |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 21331 | /** |
| 21332 | * lpfc_sli4_issue_abort_iotag - SLI-4 WQE init & issue for the Abort |
| 21333 | * @phba: Pointer to HBA context object. |
| 21334 | * @cmdiocb: Pointer to driver command iocb object. |
| 21335 | * @cmpl: completion function. |
| 21336 | * |
| 21337 | * Fill the appropriate fields for the abort WQE and call |
| 21338 | * internal routine lpfc_sli4_issue_wqe to send the WQE |
| 21339 | * This function is called with hbalock held and no ring_lock held. |
| 21340 | * |
| 21341 | * RETURNS 0 - SUCCESS |
| 21342 | **/ |
| 21343 | |
| 21344 | int |
| 21345 | lpfc_sli4_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 21346 | void *cmpl) |
| 21347 | { |
| 21348 | struct lpfc_vport *vport = cmdiocb->vport; |
| 21349 | struct lpfc_iocbq *abtsiocb = NULL; |
| 21350 | union lpfc_wqe128 *abtswqe; |
| 21351 | struct lpfc_io_buf *lpfc_cmd; |
| 21352 | int retval = IOCB_ERROR; |
| 21353 | u16 xritag = cmdiocb->sli4_xritag; |
| 21354 | |
| 21355 | /* |
| 21356 | * The scsi command can not be in txq and it is in flight because the |
| 21357 | * pCmd is still pointing at the SCSI command we have to abort. There |
| 21358 | * is no need to search the txcmplq. Just send an abort to the FW. |
| 21359 | */ |
| 21360 | |
| 21361 | abtsiocb = __lpfc_sli_get_iocbq(phba); |
| 21362 | if (!abtsiocb) |
| 21363 | return WQE_NORESOURCE; |
| 21364 | |
| 21365 | /* Indicate the IO is being aborted by the driver. */ |
| 21366 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 21367 | |
| 21368 | abtswqe = &abtsiocb->wqe; |
| 21369 | memset(abtswqe, 0, sizeof(*abtswqe)); |
| 21370 | |
James Smart | 696770e | 2021-05-28 14:22:40 -0700 | [diff] [blame] | 21371 | if (!lpfc_is_link_up(phba)) |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 21372 | bf_set(abort_cmd_ia, &abtswqe->abort_cmd, 1); |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 21373 | bf_set(abort_cmd_criteria, &abtswqe->abort_cmd, T_XRI_TAG); |
| 21374 | abtswqe->abort_cmd.rsrvd5 = 0; |
| 21375 | abtswqe->abort_cmd.wqe_com.abort_tag = xritag; |
| 21376 | bf_set(wqe_reqtag, &abtswqe->abort_cmd.wqe_com, abtsiocb->iotag); |
| 21377 | bf_set(wqe_cmnd, &abtswqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 21378 | bf_set(wqe_xri_tag, &abtswqe->generic.wqe_com, 0); |
| 21379 | bf_set(wqe_qosd, &abtswqe->abort_cmd.wqe_com, 1); |
| 21380 | bf_set(wqe_lenloc, &abtswqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 21381 | bf_set(wqe_cmd_type, &abtswqe->abort_cmd.wqe_com, OTHER_COMMAND); |
| 21382 | |
| 21383 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 21384 | abtsiocb->hba_wqidx = cmdiocb->hba_wqidx; |
| 21385 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
| 21386 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
| 21387 | abtsiocb->iocb_flag |= LPFC_IO_FCP; |
| 21388 | if (cmdiocb->iocb_flag & LPFC_IO_NVME) |
| 21389 | abtsiocb->iocb_flag |= LPFC_IO_NVME; |
| 21390 | if (cmdiocb->iocb_flag & LPFC_IO_FOF) |
| 21391 | abtsiocb->iocb_flag |= LPFC_IO_FOF; |
| 21392 | abtsiocb->vport = vport; |
| 21393 | abtsiocb->wqe_cmpl = cmpl; |
| 21394 | |
| 21395 | lpfc_cmd = container_of(cmdiocb, struct lpfc_io_buf, cur_iocbq); |
| 21396 | retval = lpfc_sli4_issue_wqe(phba, lpfc_cmd->hdwq, abtsiocb); |
| 21397 | |
| 21398 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI | LOG_NVME_ABTS | LOG_FCP, |
| 21399 | "0359 Abort xri x%x, original iotag x%x, " |
| 21400 | "abort cmd iotag x%x retval x%x\n", |
| 21401 | xritag, cmdiocb->iotag, abtsiocb->iotag, retval); |
| 21402 | |
| 21403 | if (retval) { |
| 21404 | cmdiocb->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 21405 | __lpfc_sli_release_iocbq(phba, abtsiocb); |
| 21406 | } |
| 21407 | |
| 21408 | return retval; |
| 21409 | } |
| 21410 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21411 | #ifdef LPFC_MXP_STAT |
| 21412 | /** |
| 21413 | * lpfc_snapshot_mxp - Snapshot pbl, pvt and busy count |
| 21414 | * @phba: pointer to lpfc hba data structure. |
| 21415 | * @hwqid: belong to which HWQ. |
| 21416 | * |
| 21417 | * The purpose of this routine is to take a snapshot of pbl, pvt and busy count |
| 21418 | * 15 seconds after a test case is running. |
| 21419 | * |
| 21420 | * The user should call lpfc_debugfs_multixripools_write before running a test |
| 21421 | * case to clear stat_snapshot_taken. Then the user starts a test case. During |
| 21422 | * test case is running, stat_snapshot_taken is incremented by 1 every time when |
| 21423 | * this routine is called from heartbeat timer. When stat_snapshot_taken is |
| 21424 | * equal to LPFC_MXP_SNAPSHOT_TAKEN, a snapshot is taken. |
| 21425 | **/ |
| 21426 | void lpfc_snapshot_mxp(struct lpfc_hba *phba, u32 hwqid) |
| 21427 | { |
| 21428 | struct lpfc_sli4_hdw_queue *qp; |
| 21429 | struct lpfc_multixri_pool *multixri_pool; |
| 21430 | struct lpfc_pvt_pool *pvt_pool; |
| 21431 | struct lpfc_pbl_pool *pbl_pool; |
| 21432 | u32 txcmplq_cnt; |
| 21433 | |
| 21434 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 21435 | multixri_pool = qp->p_multixri_pool; |
| 21436 | if (!multixri_pool) |
| 21437 | return; |
| 21438 | |
| 21439 | if (multixri_pool->stat_snapshot_taken == LPFC_MXP_SNAPSHOT_TAKEN) { |
| 21440 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
| 21441 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 21442 | txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21443 | |
| 21444 | multixri_pool->stat_pbl_count = pbl_pool->count; |
| 21445 | multixri_pool->stat_pvt_count = pvt_pool->count; |
| 21446 | multixri_pool->stat_busy_count = txcmplq_cnt; |
| 21447 | } |
| 21448 | |
| 21449 | multixri_pool->stat_snapshot_taken++; |
| 21450 | } |
| 21451 | #endif |
| 21452 | |
| 21453 | /** |
| 21454 | * lpfc_adjust_pvt_pool_count - Adjust private pool count |
| 21455 | * @phba: pointer to lpfc hba data structure. |
| 21456 | * @hwqid: belong to which HWQ. |
| 21457 | * |
| 21458 | * This routine moves some XRIs from private to public pool when private pool |
| 21459 | * is not busy. |
| 21460 | **/ |
| 21461 | void lpfc_adjust_pvt_pool_count(struct lpfc_hba *phba, u32 hwqid) |
| 21462 | { |
| 21463 | struct lpfc_multixri_pool *multixri_pool; |
| 21464 | u32 io_req_count; |
| 21465 | u32 prev_io_req_count; |
| 21466 | |
| 21467 | multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool; |
| 21468 | if (!multixri_pool) |
| 21469 | return; |
| 21470 | io_req_count = multixri_pool->io_req_count; |
| 21471 | prev_io_req_count = multixri_pool->prev_io_req_count; |
| 21472 | |
| 21473 | if (prev_io_req_count != io_req_count) { |
| 21474 | /* Private pool is busy */ |
| 21475 | multixri_pool->prev_io_req_count = io_req_count; |
| 21476 | } else { |
| 21477 | /* Private pool is not busy. |
| 21478 | * Move XRIs from private to public pool. |
| 21479 | */ |
| 21480 | lpfc_move_xri_pvt_to_pbl(phba, hwqid); |
| 21481 | } |
| 21482 | } |
| 21483 | |
| 21484 | /** |
| 21485 | * lpfc_adjust_high_watermark - Adjust high watermark |
| 21486 | * @phba: pointer to lpfc hba data structure. |
| 21487 | * @hwqid: belong to which HWQ. |
| 21488 | * |
| 21489 | * This routine sets high watermark as number of outstanding XRIs, |
| 21490 | * but make sure the new value is between xri_limit/2 and xri_limit. |
| 21491 | **/ |
| 21492 | void lpfc_adjust_high_watermark(struct lpfc_hba *phba, u32 hwqid) |
| 21493 | { |
| 21494 | u32 new_watermark; |
| 21495 | u32 watermark_max; |
| 21496 | u32 watermark_min; |
| 21497 | u32 xri_limit; |
| 21498 | u32 txcmplq_cnt; |
| 21499 | u32 abts_io_bufs; |
| 21500 | struct lpfc_multixri_pool *multixri_pool; |
| 21501 | struct lpfc_sli4_hdw_queue *qp; |
| 21502 | |
| 21503 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 21504 | multixri_pool = qp->p_multixri_pool; |
| 21505 | if (!multixri_pool) |
| 21506 | return; |
| 21507 | xri_limit = multixri_pool->xri_limit; |
| 21508 | |
| 21509 | watermark_max = xri_limit; |
| 21510 | watermark_min = xri_limit / 2; |
| 21511 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 21512 | txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21513 | abts_io_bufs = qp->abts_scsi_io_bufs; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 21514 | abts_io_bufs += qp->abts_nvme_io_bufs; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21515 | |
| 21516 | new_watermark = txcmplq_cnt + abts_io_bufs; |
| 21517 | new_watermark = min(watermark_max, new_watermark); |
| 21518 | new_watermark = max(watermark_min, new_watermark); |
| 21519 | multixri_pool->pvt_pool.high_watermark = new_watermark; |
| 21520 | |
| 21521 | #ifdef LPFC_MXP_STAT |
| 21522 | multixri_pool->stat_max_hwm = max(multixri_pool->stat_max_hwm, |
| 21523 | new_watermark); |
| 21524 | #endif |
| 21525 | } |
| 21526 | |
| 21527 | /** |
| 21528 | * lpfc_move_xri_pvt_to_pbl - Move some XRIs from private to public pool |
| 21529 | * @phba: pointer to lpfc hba data structure. |
| 21530 | * @hwqid: belong to which HWQ. |
| 21531 | * |
| 21532 | * This routine is called from hearbeat timer when pvt_pool is idle. |
| 21533 | * All free XRIs are moved from private to public pool on hwqid with 2 steps. |
| 21534 | * The first step moves (all - low_watermark) amount of XRIs. |
| 21535 | * The second step moves the rest of XRIs. |
| 21536 | **/ |
| 21537 | void lpfc_move_xri_pvt_to_pbl(struct lpfc_hba *phba, u32 hwqid) |
| 21538 | { |
| 21539 | struct lpfc_pbl_pool *pbl_pool; |
| 21540 | struct lpfc_pvt_pool *pvt_pool; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 21541 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21542 | struct lpfc_io_buf *lpfc_ncmd; |
| 21543 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 21544 | unsigned long iflag; |
| 21545 | struct list_head tmp_list; |
| 21546 | u32 tmp_count; |
| 21547 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 21548 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 21549 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
| 21550 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21551 | tmp_count = 0; |
| 21552 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 21553 | lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag, qp, mv_to_pub_pool); |
| 21554 | lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_from_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21555 | |
| 21556 | if (pvt_pool->count > pvt_pool->low_watermark) { |
| 21557 | /* Step 1: move (all - low_watermark) from pvt_pool |
| 21558 | * to pbl_pool |
| 21559 | */ |
| 21560 | |
| 21561 | /* Move low watermark of bufs from pvt_pool to tmp_list */ |
| 21562 | INIT_LIST_HEAD(&tmp_list); |
| 21563 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 21564 | &pvt_pool->list, list) { |
| 21565 | list_move_tail(&lpfc_ncmd->list, &tmp_list); |
| 21566 | tmp_count++; |
| 21567 | if (tmp_count >= pvt_pool->low_watermark) |
| 21568 | break; |
| 21569 | } |
| 21570 | |
| 21571 | /* Move all bufs from pvt_pool to pbl_pool */ |
| 21572 | list_splice_init(&pvt_pool->list, &pbl_pool->list); |
| 21573 | |
| 21574 | /* Move all bufs from tmp_list to pvt_pool */ |
| 21575 | list_splice(&tmp_list, &pvt_pool->list); |
| 21576 | |
| 21577 | pbl_pool->count += (pvt_pool->count - tmp_count); |
| 21578 | pvt_pool->count = tmp_count; |
| 21579 | } else { |
| 21580 | /* Step 2: move the rest from pvt_pool to pbl_pool */ |
| 21581 | list_splice_init(&pvt_pool->list, &pbl_pool->list); |
| 21582 | pbl_pool->count += pvt_pool->count; |
| 21583 | pvt_pool->count = 0; |
| 21584 | } |
| 21585 | |
| 21586 | spin_unlock(&pvt_pool->lock); |
| 21587 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 21588 | } |
| 21589 | |
| 21590 | /** |
| 21591 | * _lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool |
| 21592 | * @phba: pointer to lpfc hba data structure |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 21593 | * @qp: pointer to HDW queue |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21594 | * @pbl_pool: specified public free XRI pool |
| 21595 | * @pvt_pool: specified private free XRI pool |
| 21596 | * @count: number of XRIs to move |
| 21597 | * |
| 21598 | * This routine tries to move some free common bufs from the specified pbl_pool |
| 21599 | * to the specified pvt_pool. It might move less than count XRIs if there's not |
| 21600 | * enough in public pool. |
| 21601 | * |
| 21602 | * Return: |
| 21603 | * true - if XRIs are successfully moved from the specified pbl_pool to the |
| 21604 | * specified pvt_pool |
| 21605 | * false - if the specified pbl_pool is empty or locked by someone else |
| 21606 | **/ |
| 21607 | static bool |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 21608 | _lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, struct lpfc_sli4_hdw_queue *qp, |
| 21609 | struct lpfc_pbl_pool *pbl_pool, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21610 | struct lpfc_pvt_pool *pvt_pool, u32 count) |
| 21611 | { |
| 21612 | struct lpfc_io_buf *lpfc_ncmd; |
| 21613 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 21614 | unsigned long iflag; |
| 21615 | int ret; |
| 21616 | |
| 21617 | ret = spin_trylock_irqsave(&pbl_pool->lock, iflag); |
| 21618 | if (ret) { |
| 21619 | if (pbl_pool->count) { |
| 21620 | /* Move a batch of XRIs from public to private pool */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 21621 | lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_to_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21622 | list_for_each_entry_safe(lpfc_ncmd, |
| 21623 | lpfc_ncmd_next, |
| 21624 | &pbl_pool->list, |
| 21625 | list) { |
| 21626 | list_move_tail(&lpfc_ncmd->list, |
| 21627 | &pvt_pool->list); |
| 21628 | pvt_pool->count++; |
| 21629 | pbl_pool->count--; |
| 21630 | count--; |
| 21631 | if (count == 0) |
| 21632 | break; |
| 21633 | } |
| 21634 | |
| 21635 | spin_unlock(&pvt_pool->lock); |
| 21636 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 21637 | return true; |
| 21638 | } |
| 21639 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 21640 | } |
| 21641 | |
| 21642 | return false; |
| 21643 | } |
| 21644 | |
| 21645 | /** |
| 21646 | * lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool |
| 21647 | * @phba: pointer to lpfc hba data structure. |
| 21648 | * @hwqid: belong to which HWQ. |
| 21649 | * @count: number of XRIs to move |
| 21650 | * |
| 21651 | * This routine tries to find some free common bufs in one of public pools with |
| 21652 | * Round Robin method. The search always starts from local hwqid, then the next |
| 21653 | * HWQ which was found last time (rrb_next_hwqid). Once a public pool is found, |
| 21654 | * a batch of free common bufs are moved to private pool on hwqid. |
| 21655 | * It might move less than count XRIs if there's not enough in public pool. |
| 21656 | **/ |
| 21657 | void lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, u32 hwqid, u32 count) |
| 21658 | { |
| 21659 | struct lpfc_multixri_pool *multixri_pool; |
| 21660 | struct lpfc_multixri_pool *next_multixri_pool; |
| 21661 | struct lpfc_pvt_pool *pvt_pool; |
| 21662 | struct lpfc_pbl_pool *pbl_pool; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 21663 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21664 | u32 next_hwqid; |
| 21665 | u32 hwq_count; |
| 21666 | int ret; |
| 21667 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 21668 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 21669 | multixri_pool = qp->p_multixri_pool; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21670 | pvt_pool = &multixri_pool->pvt_pool; |
| 21671 | pbl_pool = &multixri_pool->pbl_pool; |
| 21672 | |
| 21673 | /* Check if local pbl_pool is available */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 21674 | 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] | 21675 | if (ret) { |
| 21676 | #ifdef LPFC_MXP_STAT |
| 21677 | multixri_pool->local_pbl_hit_count++; |
| 21678 | #endif |
| 21679 | return; |
| 21680 | } |
| 21681 | |
| 21682 | hwq_count = phba->cfg_hdw_queue; |
| 21683 | |
| 21684 | /* Get the next hwqid which was found last time */ |
| 21685 | next_hwqid = multixri_pool->rrb_next_hwqid; |
| 21686 | |
| 21687 | do { |
| 21688 | /* Go to next hwq */ |
| 21689 | next_hwqid = (next_hwqid + 1) % hwq_count; |
| 21690 | |
| 21691 | next_multixri_pool = |
| 21692 | phba->sli4_hba.hdwq[next_hwqid].p_multixri_pool; |
| 21693 | pbl_pool = &next_multixri_pool->pbl_pool; |
| 21694 | |
| 21695 | /* Check if the public free xri pool is available */ |
| 21696 | ret = _lpfc_move_xri_pbl_to_pvt( |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 21697 | phba, qp, pbl_pool, pvt_pool, count); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21698 | |
| 21699 | /* Exit while-loop if success or all hwqid are checked */ |
| 21700 | } while (!ret && next_hwqid != multixri_pool->rrb_next_hwqid); |
| 21701 | |
| 21702 | /* Starting point for the next time */ |
| 21703 | multixri_pool->rrb_next_hwqid = next_hwqid; |
| 21704 | |
| 21705 | if (!ret) { |
| 21706 | /* stats: all public pools are empty*/ |
| 21707 | multixri_pool->pbl_empty_count++; |
| 21708 | } |
| 21709 | |
| 21710 | #ifdef LPFC_MXP_STAT |
| 21711 | if (ret) { |
| 21712 | if (next_hwqid == hwqid) |
| 21713 | multixri_pool->local_pbl_hit_count++; |
| 21714 | else |
| 21715 | multixri_pool->other_pbl_hit_count++; |
| 21716 | } |
| 21717 | #endif |
| 21718 | } |
| 21719 | |
| 21720 | /** |
| 21721 | * lpfc_keep_pvt_pool_above_lowwm - Keep pvt_pool above low watermark |
| 21722 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 21723 | * @hwqid: belong to which HWQ. |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21724 | * |
| 21725 | * This routine get a batch of XRIs from pbl_pool if pvt_pool is less than |
| 21726 | * low watermark. |
| 21727 | **/ |
| 21728 | void lpfc_keep_pvt_pool_above_lowwm(struct lpfc_hba *phba, u32 hwqid) |
| 21729 | { |
| 21730 | struct lpfc_multixri_pool *multixri_pool; |
| 21731 | struct lpfc_pvt_pool *pvt_pool; |
| 21732 | |
| 21733 | multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool; |
| 21734 | pvt_pool = &multixri_pool->pvt_pool; |
| 21735 | |
| 21736 | if (pvt_pool->count < pvt_pool->low_watermark) |
| 21737 | lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH); |
| 21738 | } |
| 21739 | |
| 21740 | /** |
| 21741 | * lpfc_release_io_buf - Return one IO buf back to free pool |
| 21742 | * @phba: pointer to lpfc hba data structure. |
| 21743 | * @lpfc_ncmd: IO buf to be returned. |
| 21744 | * @qp: belong to which HWQ. |
| 21745 | * |
| 21746 | * This routine returns one IO buf back to free pool. If this is an urgent IO, |
| 21747 | * the IO buf is returned to expedite pool. If cfg_xri_rebalancing==1, |
| 21748 | * the IO buf is returned to pbl_pool or pvt_pool based on watermark and |
| 21749 | * xri_limit. If cfg_xri_rebalancing==0, the IO buf is returned to |
| 21750 | * lpfc_io_buf_list_put. |
| 21751 | **/ |
| 21752 | void lpfc_release_io_buf(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_ncmd, |
| 21753 | struct lpfc_sli4_hdw_queue *qp) |
| 21754 | { |
| 21755 | unsigned long iflag; |
| 21756 | struct lpfc_pbl_pool *pbl_pool; |
| 21757 | struct lpfc_pvt_pool *pvt_pool; |
| 21758 | struct lpfc_epd_pool *epd_pool; |
| 21759 | u32 txcmplq_cnt; |
| 21760 | u32 xri_owned; |
| 21761 | u32 xri_limit; |
| 21762 | u32 abts_io_bufs; |
| 21763 | |
| 21764 | /* MUST zero fields if buffer is reused by another protocol */ |
| 21765 | lpfc_ncmd->nvmeCmd = NULL; |
| 21766 | lpfc_ncmd->cur_iocbq.wqe_cmpl = NULL; |
| 21767 | lpfc_ncmd->cur_iocbq.iocb_cmpl = NULL; |
| 21768 | |
James Smart | 35a635a | 2019-09-21 20:59:02 -0700 | [diff] [blame] | 21769 | if (phba->cfg_xpsgl && !phba->nvmet_support && |
| 21770 | !list_empty(&lpfc_ncmd->dma_sgl_xtra_list)) |
| 21771 | lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd); |
| 21772 | |
| 21773 | if (!list_empty(&lpfc_ncmd->dma_cmd_rsp_list)) |
| 21774 | lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd); |
| 21775 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21776 | if (phba->cfg_xri_rebalancing) { |
| 21777 | if (lpfc_ncmd->expedite) { |
| 21778 | /* Return to expedite pool */ |
| 21779 | epd_pool = &phba->epd_pool; |
| 21780 | spin_lock_irqsave(&epd_pool->lock, iflag); |
| 21781 | list_add_tail(&lpfc_ncmd->list, &epd_pool->list); |
| 21782 | epd_pool->count++; |
| 21783 | spin_unlock_irqrestore(&epd_pool->lock, iflag); |
| 21784 | return; |
| 21785 | } |
| 21786 | |
| 21787 | /* Avoid invalid access if an IO sneaks in and is being rejected |
| 21788 | * just _after_ xri pools are destroyed in lpfc_offline. |
| 21789 | * Nothing much can be done at this point. |
| 21790 | */ |
| 21791 | if (!qp->p_multixri_pool) |
| 21792 | return; |
| 21793 | |
| 21794 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
| 21795 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
| 21796 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 21797 | txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21798 | abts_io_bufs = qp->abts_scsi_io_bufs; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 21799 | abts_io_bufs += qp->abts_nvme_io_bufs; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21800 | |
| 21801 | xri_owned = pvt_pool->count + txcmplq_cnt + abts_io_bufs; |
| 21802 | xri_limit = qp->p_multixri_pool->xri_limit; |
| 21803 | |
| 21804 | #ifdef LPFC_MXP_STAT |
| 21805 | if (xri_owned <= xri_limit) |
| 21806 | qp->p_multixri_pool->below_limit_count++; |
| 21807 | else |
| 21808 | qp->p_multixri_pool->above_limit_count++; |
| 21809 | #endif |
| 21810 | |
| 21811 | /* XRI goes to either public or private free xri pool |
| 21812 | * based on watermark and xri_limit |
| 21813 | */ |
| 21814 | if ((pvt_pool->count < pvt_pool->low_watermark) || |
| 21815 | (xri_owned < xri_limit && |
| 21816 | pvt_pool->count < pvt_pool->high_watermark)) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 21817 | lpfc_qp_spin_lock_irqsave(&pvt_pool->lock, iflag, |
| 21818 | qp, free_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21819 | list_add_tail(&lpfc_ncmd->list, |
| 21820 | &pvt_pool->list); |
| 21821 | pvt_pool->count++; |
| 21822 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 21823 | } else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 21824 | lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag, |
| 21825 | qp, free_pub_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21826 | list_add_tail(&lpfc_ncmd->list, |
| 21827 | &pbl_pool->list); |
| 21828 | pbl_pool->count++; |
| 21829 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 21830 | } |
| 21831 | } else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 21832 | lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag, |
| 21833 | qp, free_xri); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21834 | list_add_tail(&lpfc_ncmd->list, |
| 21835 | &qp->lpfc_io_buf_list_put); |
| 21836 | qp->put_io_bufs++; |
| 21837 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, |
| 21838 | iflag); |
| 21839 | } |
| 21840 | } |
| 21841 | |
| 21842 | /** |
| 21843 | * lpfc_get_io_buf_from_private_pool - Get one free IO buf from private pool |
| 21844 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 21845 | * @qp: pointer to HDW queue |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21846 | * @pvt_pool: pointer to private pool data structure. |
| 21847 | * @ndlp: pointer to lpfc nodelist data structure. |
| 21848 | * |
| 21849 | * This routine tries to get one free IO buf from private pool. |
| 21850 | * |
| 21851 | * Return: |
| 21852 | * pointer to one free IO buf - if private pool is not empty |
| 21853 | * NULL - if private pool is empty |
| 21854 | **/ |
| 21855 | static struct lpfc_io_buf * |
| 21856 | lpfc_get_io_buf_from_private_pool(struct lpfc_hba *phba, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 21857 | struct lpfc_sli4_hdw_queue *qp, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21858 | struct lpfc_pvt_pool *pvt_pool, |
| 21859 | struct lpfc_nodelist *ndlp) |
| 21860 | { |
| 21861 | struct lpfc_io_buf *lpfc_ncmd; |
| 21862 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 21863 | unsigned long iflag; |
| 21864 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 21865 | 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] | 21866 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 21867 | &pvt_pool->list, list) { |
| 21868 | if (lpfc_test_rrq_active( |
| 21869 | phba, ndlp, lpfc_ncmd->cur_iocbq.sli4_lxritag)) |
| 21870 | continue; |
| 21871 | list_del(&lpfc_ncmd->list); |
| 21872 | pvt_pool->count--; |
| 21873 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 21874 | return lpfc_ncmd; |
| 21875 | } |
| 21876 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 21877 | |
| 21878 | return NULL; |
| 21879 | } |
| 21880 | |
| 21881 | /** |
| 21882 | * lpfc_get_io_buf_from_expedite_pool - Get one free IO buf from expedite pool |
| 21883 | * @phba: pointer to lpfc hba data structure. |
| 21884 | * |
| 21885 | * This routine tries to get one free IO buf from expedite pool. |
| 21886 | * |
| 21887 | * Return: |
| 21888 | * pointer to one free IO buf - if expedite pool is not empty |
| 21889 | * NULL - if expedite pool is empty |
| 21890 | **/ |
| 21891 | static struct lpfc_io_buf * |
| 21892 | lpfc_get_io_buf_from_expedite_pool(struct lpfc_hba *phba) |
| 21893 | { |
| 21894 | struct lpfc_io_buf *lpfc_ncmd; |
| 21895 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 21896 | unsigned long iflag; |
| 21897 | struct lpfc_epd_pool *epd_pool; |
| 21898 | |
| 21899 | epd_pool = &phba->epd_pool; |
| 21900 | lpfc_ncmd = NULL; |
| 21901 | |
| 21902 | spin_lock_irqsave(&epd_pool->lock, iflag); |
| 21903 | if (epd_pool->count > 0) { |
| 21904 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 21905 | &epd_pool->list, list) { |
| 21906 | list_del(&lpfc_ncmd->list); |
| 21907 | epd_pool->count--; |
| 21908 | break; |
| 21909 | } |
| 21910 | } |
| 21911 | spin_unlock_irqrestore(&epd_pool->lock, iflag); |
| 21912 | |
| 21913 | return lpfc_ncmd; |
| 21914 | } |
| 21915 | |
| 21916 | /** |
| 21917 | * lpfc_get_io_buf_from_multixri_pools - Get one free IO bufs |
| 21918 | * @phba: pointer to lpfc hba data structure. |
| 21919 | * @ndlp: pointer to lpfc nodelist data structure. |
| 21920 | * @hwqid: belong to which HWQ |
| 21921 | * @expedite: 1 means this request is urgent. |
| 21922 | * |
| 21923 | * This routine will do the following actions and then return a pointer to |
| 21924 | * one free IO buf. |
| 21925 | * |
| 21926 | * 1. If private free xri count is empty, move some XRIs from public to |
| 21927 | * private pool. |
| 21928 | * 2. Get one XRI from private free xri pool. |
| 21929 | * 3. If we fail to get one from pvt_pool and this is an expedite request, |
| 21930 | * get one free xri from expedite pool. |
| 21931 | * |
| 21932 | * Note: ndlp is only used on SCSI side for RRQ testing. |
| 21933 | * The caller should pass NULL for ndlp on NVME side. |
| 21934 | * |
| 21935 | * Return: |
| 21936 | * pointer to one free IO buf - if private pool is not empty |
| 21937 | * NULL - if private pool is empty |
| 21938 | **/ |
| 21939 | static struct lpfc_io_buf * |
| 21940 | lpfc_get_io_buf_from_multixri_pools(struct lpfc_hba *phba, |
| 21941 | struct lpfc_nodelist *ndlp, |
| 21942 | int hwqid, int expedite) |
| 21943 | { |
| 21944 | struct lpfc_sli4_hdw_queue *qp; |
| 21945 | struct lpfc_multixri_pool *multixri_pool; |
| 21946 | struct lpfc_pvt_pool *pvt_pool; |
| 21947 | struct lpfc_io_buf *lpfc_ncmd; |
| 21948 | |
| 21949 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 21950 | lpfc_ncmd = NULL; |
| 21951 | multixri_pool = qp->p_multixri_pool; |
| 21952 | pvt_pool = &multixri_pool->pvt_pool; |
| 21953 | multixri_pool->io_req_count++; |
| 21954 | |
| 21955 | /* If pvt_pool is empty, move some XRIs from public to private pool */ |
| 21956 | if (pvt_pool->count == 0) |
| 21957 | lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH); |
| 21958 | |
| 21959 | /* Get one XRI from private free xri pool */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 21960 | 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] | 21961 | |
| 21962 | if (lpfc_ncmd) { |
| 21963 | lpfc_ncmd->hdwq = qp; |
| 21964 | lpfc_ncmd->hdwq_no = hwqid; |
| 21965 | } else if (expedite) { |
| 21966 | /* If we fail to get one from pvt_pool and this is an expedite |
| 21967 | * request, get one free xri from expedite pool. |
| 21968 | */ |
| 21969 | lpfc_ncmd = lpfc_get_io_buf_from_expedite_pool(phba); |
| 21970 | } |
| 21971 | |
| 21972 | return lpfc_ncmd; |
| 21973 | } |
| 21974 | |
| 21975 | static inline struct lpfc_io_buf * |
| 21976 | lpfc_io_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, int idx) |
| 21977 | { |
| 21978 | struct lpfc_sli4_hdw_queue *qp; |
| 21979 | struct lpfc_io_buf *lpfc_cmd, *lpfc_cmd_next; |
| 21980 | |
| 21981 | qp = &phba->sli4_hba.hdwq[idx]; |
| 21982 | list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next, |
| 21983 | &qp->lpfc_io_buf_list_get, list) { |
| 21984 | if (lpfc_test_rrq_active(phba, ndlp, |
| 21985 | lpfc_cmd->cur_iocbq.sli4_lxritag)) |
| 21986 | continue; |
| 21987 | |
| 21988 | if (lpfc_cmd->flags & LPFC_SBUF_NOT_POSTED) |
| 21989 | continue; |
| 21990 | |
| 21991 | list_del_init(&lpfc_cmd->list); |
| 21992 | qp->get_io_bufs--; |
| 21993 | lpfc_cmd->hdwq = qp; |
| 21994 | lpfc_cmd->hdwq_no = idx; |
| 21995 | return lpfc_cmd; |
| 21996 | } |
| 21997 | return NULL; |
| 21998 | } |
| 21999 | |
| 22000 | /** |
| 22001 | * lpfc_get_io_buf - Get one IO buffer from free pool |
| 22002 | * @phba: The HBA for which this call is being executed. |
| 22003 | * @ndlp: pointer to lpfc nodelist data structure. |
| 22004 | * @hwqid: belong to which HWQ |
| 22005 | * @expedite: 1 means this request is urgent. |
| 22006 | * |
| 22007 | * This routine gets one IO buffer from free pool. If cfg_xri_rebalancing==1, |
| 22008 | * removes a IO buffer from multiXRI pools. If cfg_xri_rebalancing==0, removes |
| 22009 | * a IO buffer from head of @hdwq io_buf_list and returns to caller. |
| 22010 | * |
| 22011 | * Note: ndlp is only used on SCSI side for RRQ testing. |
| 22012 | * The caller should pass NULL for ndlp on NVME side. |
| 22013 | * |
| 22014 | * Return codes: |
| 22015 | * NULL - Error |
| 22016 | * Pointer to lpfc_io_buf - Success |
| 22017 | **/ |
| 22018 | struct lpfc_io_buf *lpfc_get_io_buf(struct lpfc_hba *phba, |
| 22019 | struct lpfc_nodelist *ndlp, |
| 22020 | u32 hwqid, int expedite) |
| 22021 | { |
| 22022 | struct lpfc_sli4_hdw_queue *qp; |
| 22023 | unsigned long iflag; |
| 22024 | struct lpfc_io_buf *lpfc_cmd; |
| 22025 | |
| 22026 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 22027 | lpfc_cmd = NULL; |
| 22028 | |
| 22029 | if (phba->cfg_xri_rebalancing) |
| 22030 | lpfc_cmd = lpfc_get_io_buf_from_multixri_pools( |
| 22031 | phba, ndlp, hwqid, expedite); |
| 22032 | else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 22033 | lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_get_lock, iflag, |
| 22034 | qp, alloc_xri_get); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 22035 | if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT || expedite) |
| 22036 | lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid); |
| 22037 | if (!lpfc_cmd) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 22038 | lpfc_qp_spin_lock(&qp->io_buf_list_put_lock, |
| 22039 | qp, alloc_xri_put); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 22040 | list_splice(&qp->lpfc_io_buf_list_put, |
| 22041 | &qp->lpfc_io_buf_list_get); |
| 22042 | qp->get_io_bufs += qp->put_io_bufs; |
| 22043 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put); |
| 22044 | qp->put_io_bufs = 0; |
| 22045 | spin_unlock(&qp->io_buf_list_put_lock); |
| 22046 | if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT || |
| 22047 | expedite) |
| 22048 | lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid); |
| 22049 | } |
| 22050 | spin_unlock_irqrestore(&qp->io_buf_list_get_lock, iflag); |
| 22051 | } |
| 22052 | |
| 22053 | return lpfc_cmd; |
| 22054 | } |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 22055 | |
| 22056 | /** |
James Smart | 72df8a45 | 2021-08-16 09:28:52 -0700 | [diff] [blame] | 22057 | * lpfc_read_object - Retrieve object data from HBA |
| 22058 | * @phba: The HBA for which this call is being executed. |
| 22059 | * @rdobject: Pathname of object data we want to read. |
| 22060 | * @datap: Pointer to where data will be copied to. |
| 22061 | * @datasz: size of data area |
| 22062 | * |
| 22063 | * This routine is limited to object sizes of LPFC_BPL_SIZE (1024) or less. |
| 22064 | * The data will be truncated if datasz is not large enough. |
| 22065 | * Version 1 is not supported with Embedded mbox cmd, so we must use version 0. |
| 22066 | * Returns the actual bytes read from the object. |
| 22067 | */ |
| 22068 | int |
| 22069 | lpfc_read_object(struct lpfc_hba *phba, char *rdobject, uint32_t *datap, |
| 22070 | uint32_t datasz) |
| 22071 | { |
| 22072 | struct lpfc_mbx_read_object *read_object; |
| 22073 | LPFC_MBOXQ_t *mbox; |
| 22074 | int rc, length, eof, j, byte_cnt = 0; |
| 22075 | uint32_t shdr_status, shdr_add_status; |
| 22076 | union lpfc_sli4_cfg_shdr *shdr; |
| 22077 | struct lpfc_dmabuf *pcmd; |
| 22078 | |
| 22079 | /* sanity check on queue memory */ |
| 22080 | if (!datap) |
| 22081 | return -ENODEV; |
| 22082 | |
| 22083 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 22084 | if (!mbox) |
| 22085 | return -ENOMEM; |
| 22086 | length = (sizeof(struct lpfc_mbx_read_object) - |
| 22087 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 22088 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 22089 | LPFC_MBOX_OPCODE_READ_OBJECT, |
| 22090 | length, LPFC_SLI4_MBX_EMBED); |
| 22091 | read_object = &mbox->u.mqe.un.read_object; |
| 22092 | shdr = (union lpfc_sli4_cfg_shdr *)&read_object->header.cfg_shdr; |
| 22093 | |
| 22094 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_Q_CREATE_VERSION_0); |
| 22095 | bf_set(lpfc_mbx_rd_object_rlen, &read_object->u.request, datasz); |
| 22096 | read_object->u.request.rd_object_offset = 0; |
| 22097 | read_object->u.request.rd_object_cnt = 1; |
| 22098 | |
| 22099 | memset((void *)read_object->u.request.rd_object_name, 0, |
| 22100 | LPFC_OBJ_NAME_SZ); |
| 22101 | sprintf((uint8_t *)read_object->u.request.rd_object_name, rdobject); |
| 22102 | for (j = 0; j < strlen(rdobject); j++) |
| 22103 | read_object->u.request.rd_object_name[j] = |
| 22104 | cpu_to_le32(read_object->u.request.rd_object_name[j]); |
| 22105 | |
| 22106 | pcmd = kmalloc(sizeof(*pcmd), GFP_KERNEL); |
| 22107 | if (pcmd) |
| 22108 | pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); |
| 22109 | if (!pcmd || !pcmd->virt) { |
| 22110 | kfree(pcmd); |
| 22111 | mempool_free(mbox, phba->mbox_mem_pool); |
| 22112 | return -ENOMEM; |
| 22113 | } |
| 22114 | memset((void *)pcmd->virt, 0, LPFC_BPL_SIZE); |
| 22115 | read_object->u.request.rd_object_hbuf[0].pa_lo = |
| 22116 | putPaddrLow(pcmd->phys); |
| 22117 | read_object->u.request.rd_object_hbuf[0].pa_hi = |
| 22118 | putPaddrHigh(pcmd->phys); |
| 22119 | read_object->u.request.rd_object_hbuf[0].length = LPFC_BPL_SIZE; |
| 22120 | |
| 22121 | mbox->vport = phba->pport; |
| 22122 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 22123 | mbox->ctx_buf = NULL; |
| 22124 | mbox->ctx_ndlp = NULL; |
| 22125 | |
| 22126 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 22127 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 22128 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 22129 | |
| 22130 | if (shdr_status == STATUS_FAILED && |
| 22131 | shdr_add_status == ADD_STATUS_INVALID_OBJECT_NAME) { |
| 22132 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_CGN_MGMT, |
| 22133 | "4674 No port cfg file in FW.\n"); |
| 22134 | byte_cnt = -ENOENT; |
| 22135 | } else if (shdr_status || shdr_add_status || rc) { |
| 22136 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_CGN_MGMT, |
| 22137 | "2625 READ_OBJECT mailbox failed with " |
| 22138 | "status x%x add_status x%x, mbx status x%x\n", |
| 22139 | shdr_status, shdr_add_status, rc); |
| 22140 | byte_cnt = -ENXIO; |
| 22141 | } else { |
| 22142 | /* Success */ |
| 22143 | length = read_object->u.response.rd_object_actual_rlen; |
| 22144 | eof = bf_get(lpfc_mbx_rd_object_eof, &read_object->u.response); |
| 22145 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_CGN_MGMT, |
| 22146 | "2626 READ_OBJECT Success len %d:%d, EOF %d\n", |
| 22147 | length, datasz, eof); |
| 22148 | |
| 22149 | /* Detect the port config file exists but is empty */ |
| 22150 | if (!length && eof) { |
| 22151 | byte_cnt = 0; |
| 22152 | goto exit; |
| 22153 | } |
| 22154 | |
| 22155 | byte_cnt = length; |
| 22156 | lpfc_sli_pcimem_bcopy(pcmd->virt, datap, byte_cnt); |
| 22157 | } |
| 22158 | |
| 22159 | exit: |
| 22160 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
| 22161 | kfree(pcmd); |
| 22162 | mempool_free(mbox, phba->mbox_mem_pool); |
| 22163 | return byte_cnt; |
| 22164 | } |
| 22165 | |
| 22166 | /** |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 22167 | * lpfc_get_sgl_per_hdwq - Get one SGL chunk from hdwq's pool |
| 22168 | * @phba: The HBA for which this call is being executed. |
| 22169 | * @lpfc_buf: IO buf structure to append the SGL chunk |
| 22170 | * |
| 22171 | * This routine gets one SGL chunk buffer from hdwq's SGL chunk pool, |
| 22172 | * and will allocate an SGL chunk if the pool is empty. |
| 22173 | * |
| 22174 | * Return codes: |
| 22175 | * NULL - Error |
| 22176 | * Pointer to sli4_hybrid_sgl - Success |
| 22177 | **/ |
| 22178 | struct sli4_hybrid_sgl * |
| 22179 | lpfc_get_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf) |
| 22180 | { |
| 22181 | struct sli4_hybrid_sgl *list_entry = NULL; |
| 22182 | struct sli4_hybrid_sgl *tmp = NULL; |
| 22183 | struct sli4_hybrid_sgl *allocated_sgl = NULL; |
| 22184 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 22185 | struct list_head *buf_list = &hdwq->sgl_list; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 22186 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 22187 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 22188 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 22189 | |
| 22190 | if (likely(!list_empty(buf_list))) { |
| 22191 | /* break off 1 chunk from the sgl_list */ |
| 22192 | list_for_each_entry_safe(list_entry, tmp, |
| 22193 | buf_list, list_node) { |
| 22194 | list_move_tail(&list_entry->list_node, |
| 22195 | &lpfc_buf->dma_sgl_xtra_list); |
| 22196 | break; |
| 22197 | } |
| 22198 | } else { |
| 22199 | /* allocate more */ |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 22200 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 22201 | tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC, |
James Smart | 4583a4f | 2019-11-15 16:38:47 -0800 | [diff] [blame] | 22202 | cpu_to_node(hdwq->io_wq->chann)); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 22203 | if (!tmp) { |
| 22204 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 22205 | "8353 error kmalloc memory for HDWQ " |
| 22206 | "%d %s\n", |
| 22207 | lpfc_buf->hdwq_no, __func__); |
| 22208 | return NULL; |
| 22209 | } |
| 22210 | |
| 22211 | tmp->dma_sgl = dma_pool_alloc(phba->lpfc_sg_dma_buf_pool, |
| 22212 | GFP_ATOMIC, &tmp->dma_phys_sgl); |
| 22213 | if (!tmp->dma_sgl) { |
| 22214 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 22215 | "8354 error pool_alloc memory for HDWQ " |
| 22216 | "%d %s\n", |
| 22217 | lpfc_buf->hdwq_no, __func__); |
| 22218 | kfree(tmp); |
| 22219 | return NULL; |
| 22220 | } |
| 22221 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 22222 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 22223 | list_add_tail(&tmp->list_node, &lpfc_buf->dma_sgl_xtra_list); |
| 22224 | } |
| 22225 | |
| 22226 | allocated_sgl = list_last_entry(&lpfc_buf->dma_sgl_xtra_list, |
| 22227 | struct sli4_hybrid_sgl, |
| 22228 | list_node); |
| 22229 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 22230 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 22231 | |
| 22232 | return allocated_sgl; |
| 22233 | } |
| 22234 | |
| 22235 | /** |
| 22236 | * lpfc_put_sgl_per_hdwq - Put one SGL chunk into hdwq pool |
| 22237 | * @phba: The HBA for which this call is being executed. |
| 22238 | * @lpfc_buf: IO buf structure with the SGL chunk |
| 22239 | * |
| 22240 | * This routine puts one SGL chunk buffer into hdwq's SGL chunk pool. |
| 22241 | * |
| 22242 | * Return codes: |
| 22243 | * 0 - Success |
| 22244 | * -EINVAL - Error |
| 22245 | **/ |
| 22246 | int |
| 22247 | lpfc_put_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf) |
| 22248 | { |
| 22249 | int rc = 0; |
| 22250 | struct sli4_hybrid_sgl *list_entry = NULL; |
| 22251 | struct sli4_hybrid_sgl *tmp = NULL; |
| 22252 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 22253 | struct list_head *buf_list = &hdwq->sgl_list; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 22254 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 22255 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 22256 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 22257 | |
| 22258 | if (likely(!list_empty(&lpfc_buf->dma_sgl_xtra_list))) { |
| 22259 | list_for_each_entry_safe(list_entry, tmp, |
| 22260 | &lpfc_buf->dma_sgl_xtra_list, |
| 22261 | list_node) { |
| 22262 | list_move_tail(&list_entry->list_node, |
| 22263 | buf_list); |
| 22264 | } |
| 22265 | } else { |
| 22266 | rc = -EINVAL; |
| 22267 | } |
| 22268 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 22269 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 22270 | return rc; |
| 22271 | } |
| 22272 | |
| 22273 | /** |
| 22274 | * lpfc_free_sgl_per_hdwq - Free all SGL chunks of hdwq pool |
| 22275 | * @phba: phba object |
| 22276 | * @hdwq: hdwq to cleanup sgl buff resources on |
| 22277 | * |
| 22278 | * This routine frees all SGL chunks of hdwq SGL chunk pool. |
| 22279 | * |
| 22280 | * Return codes: |
| 22281 | * None |
| 22282 | **/ |
| 22283 | void |
| 22284 | lpfc_free_sgl_per_hdwq(struct lpfc_hba *phba, |
| 22285 | struct lpfc_sli4_hdw_queue *hdwq) |
| 22286 | { |
| 22287 | struct list_head *buf_list = &hdwq->sgl_list; |
| 22288 | struct sli4_hybrid_sgl *list_entry = NULL; |
| 22289 | struct sli4_hybrid_sgl *tmp = NULL; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 22290 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 22291 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 22292 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 22293 | |
| 22294 | /* Free sgl pool */ |
| 22295 | list_for_each_entry_safe(list_entry, tmp, |
| 22296 | buf_list, list_node) { |
| 22297 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 22298 | list_entry->dma_sgl, |
| 22299 | list_entry->dma_phys_sgl); |
| 22300 | list_del(&list_entry->list_node); |
| 22301 | kfree(list_entry); |
| 22302 | } |
| 22303 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 22304 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 22305 | } |
| 22306 | |
| 22307 | /** |
| 22308 | * lpfc_get_cmd_rsp_buf_per_hdwq - Get one CMD/RSP buffer from hdwq |
| 22309 | * @phba: The HBA for which this call is being executed. |
| 22310 | * @lpfc_buf: IO buf structure to attach the CMD/RSP buffer |
| 22311 | * |
| 22312 | * This routine gets one CMD/RSP buffer from hdwq's CMD/RSP pool, |
| 22313 | * and will allocate an CMD/RSP buffer if the pool is empty. |
| 22314 | * |
| 22315 | * Return codes: |
| 22316 | * NULL - Error |
| 22317 | * Pointer to fcp_cmd_rsp_buf - Success |
| 22318 | **/ |
| 22319 | struct fcp_cmd_rsp_buf * |
| 22320 | lpfc_get_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba, |
| 22321 | struct lpfc_io_buf *lpfc_buf) |
| 22322 | { |
| 22323 | struct fcp_cmd_rsp_buf *list_entry = NULL; |
| 22324 | struct fcp_cmd_rsp_buf *tmp = NULL; |
| 22325 | struct fcp_cmd_rsp_buf *allocated_buf = NULL; |
| 22326 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 22327 | struct list_head *buf_list = &hdwq->cmd_rsp_buf_list; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 22328 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 22329 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 22330 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 22331 | |
| 22332 | if (likely(!list_empty(buf_list))) { |
| 22333 | /* break off 1 chunk from the list */ |
| 22334 | list_for_each_entry_safe(list_entry, tmp, |
| 22335 | buf_list, |
| 22336 | list_node) { |
| 22337 | list_move_tail(&list_entry->list_node, |
| 22338 | &lpfc_buf->dma_cmd_rsp_list); |
| 22339 | break; |
| 22340 | } |
| 22341 | } else { |
| 22342 | /* allocate more */ |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 22343 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 22344 | tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC, |
James Smart | 4583a4f | 2019-11-15 16:38:47 -0800 | [diff] [blame] | 22345 | cpu_to_node(hdwq->io_wq->chann)); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 22346 | if (!tmp) { |
| 22347 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 22348 | "8355 error kmalloc memory for HDWQ " |
| 22349 | "%d %s\n", |
| 22350 | lpfc_buf->hdwq_no, __func__); |
| 22351 | return NULL; |
| 22352 | } |
| 22353 | |
| 22354 | tmp->fcp_cmnd = dma_pool_alloc(phba->lpfc_cmd_rsp_buf_pool, |
| 22355 | GFP_ATOMIC, |
| 22356 | &tmp->fcp_cmd_rsp_dma_handle); |
| 22357 | |
| 22358 | if (!tmp->fcp_cmnd) { |
| 22359 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 22360 | "8356 error pool_alloc memory for HDWQ " |
| 22361 | "%d %s\n", |
| 22362 | lpfc_buf->hdwq_no, __func__); |
| 22363 | kfree(tmp); |
| 22364 | return NULL; |
| 22365 | } |
| 22366 | |
| 22367 | tmp->fcp_rsp = (struct fcp_rsp *)((uint8_t *)tmp->fcp_cmnd + |
| 22368 | sizeof(struct fcp_cmnd)); |
| 22369 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 22370 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 22371 | list_add_tail(&tmp->list_node, &lpfc_buf->dma_cmd_rsp_list); |
| 22372 | } |
| 22373 | |
| 22374 | allocated_buf = list_last_entry(&lpfc_buf->dma_cmd_rsp_list, |
| 22375 | struct fcp_cmd_rsp_buf, |
| 22376 | list_node); |
| 22377 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 22378 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 22379 | |
| 22380 | return allocated_buf; |
| 22381 | } |
| 22382 | |
| 22383 | /** |
| 22384 | * lpfc_put_cmd_rsp_buf_per_hdwq - Put one CMD/RSP buffer into hdwq pool |
| 22385 | * @phba: The HBA for which this call is being executed. |
| 22386 | * @lpfc_buf: IO buf structure with the CMD/RSP buf |
| 22387 | * |
| 22388 | * This routine puts one CMD/RSP buffer into executing CPU's CMD/RSP pool. |
| 22389 | * |
| 22390 | * Return codes: |
| 22391 | * 0 - Success |
| 22392 | * -EINVAL - Error |
| 22393 | **/ |
| 22394 | int |
| 22395 | lpfc_put_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba, |
| 22396 | struct lpfc_io_buf *lpfc_buf) |
| 22397 | { |
| 22398 | int rc = 0; |
| 22399 | struct fcp_cmd_rsp_buf *list_entry = NULL; |
| 22400 | struct fcp_cmd_rsp_buf *tmp = NULL; |
| 22401 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 22402 | struct list_head *buf_list = &hdwq->cmd_rsp_buf_list; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 22403 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 22404 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 22405 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 22406 | |
| 22407 | if (likely(!list_empty(&lpfc_buf->dma_cmd_rsp_list))) { |
| 22408 | list_for_each_entry_safe(list_entry, tmp, |
| 22409 | &lpfc_buf->dma_cmd_rsp_list, |
| 22410 | list_node) { |
| 22411 | list_move_tail(&list_entry->list_node, |
| 22412 | buf_list); |
| 22413 | } |
| 22414 | } else { |
| 22415 | rc = -EINVAL; |
| 22416 | } |
| 22417 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 22418 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 22419 | return rc; |
| 22420 | } |
| 22421 | |
| 22422 | /** |
| 22423 | * lpfc_free_cmd_rsp_buf_per_hdwq - Free all CMD/RSP chunks of hdwq pool |
| 22424 | * @phba: phba object |
| 22425 | * @hdwq: hdwq to cleanup cmd rsp buff resources on |
| 22426 | * |
| 22427 | * This routine frees all CMD/RSP buffers of hdwq's CMD/RSP buf pool. |
| 22428 | * |
| 22429 | * Return codes: |
| 22430 | * None |
| 22431 | **/ |
| 22432 | void |
| 22433 | lpfc_free_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba, |
| 22434 | struct lpfc_sli4_hdw_queue *hdwq) |
| 22435 | { |
| 22436 | struct list_head *buf_list = &hdwq->cmd_rsp_buf_list; |
| 22437 | struct fcp_cmd_rsp_buf *list_entry = NULL; |
| 22438 | struct fcp_cmd_rsp_buf *tmp = NULL; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 22439 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 22440 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 22441 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 22442 | |
| 22443 | /* Free cmd_rsp buf pool */ |
| 22444 | list_for_each_entry_safe(list_entry, tmp, |
| 22445 | buf_list, |
| 22446 | list_node) { |
| 22447 | dma_pool_free(phba->lpfc_cmd_rsp_buf_pool, |
| 22448 | list_entry->fcp_cmnd, |
| 22449 | list_entry->fcp_cmd_rsp_dma_handle); |
| 22450 | list_del(&list_entry->list_node); |
| 22451 | kfree(list_entry); |
| 22452 | } |
| 22453 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 22454 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 22455 | } |