| 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 | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1442 | iocbq->iocb_flag &= ~(LPFC_IO_NVME | LPFC_IO_NVMET | |
| 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 | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1772 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1773 | * @phba: Pointer to HBA context object. |
| 1774 | * @pring: Pointer to driver SLI ring object. |
| 1775 | * |
| 1776 | * This function is called with hbalock held and the caller must post the |
| 1777 | * iocb without releasing the lock. If the caller releases the lock, |
| 1778 | * iocb slot returned by the function is not guaranteed to be available. |
| 1779 | * The function returns pointer to the next available iocb slot if there |
| 1780 | * is available slot in the ring, else it returns NULL. |
| 1781 | * If the get index of the ring is ahead of the put index, the function |
| 1782 | * will post an error attention event to the worker thread to take the |
| 1783 | * HBA to offline state. |
| 1784 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1785 | static IOCB_t * |
| 1786 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 1787 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1788 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1789 | uint32_t max_cmd_idx = pring->sli.sli3.numCiocb; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1790 | |
| 1791 | lockdep_assert_held(&phba->hbalock); |
| 1792 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1793 | if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) && |
| 1794 | (++pring->sli.sli3.next_cmdidx >= max_cmd_idx)) |
| 1795 | pring->sli.sli3.next_cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1796 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1797 | if (unlikely(pring->sli.sli3.local_getidx == |
| 1798 | pring->sli.sli3.next_cmdidx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1799 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1800 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1801 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1802 | if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1803 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1804 | "0315 Ring %d issue: portCmdGet %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1805 | "is bigger than cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1806 | pring->ringno, |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1807 | pring->sli.sli3.local_getidx, |
| 1808 | max_cmd_idx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1809 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1810 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1811 | /* |
| 1812 | * All error attention handlers are posted to |
| 1813 | * worker thread |
| 1814 | */ |
| 1815 | phba->work_ha |= HA_ERATT; |
| 1816 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1817 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1818 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1819 | |
| 1820 | return NULL; |
| 1821 | } |
| 1822 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1823 | if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1824 | return NULL; |
| 1825 | } |
| 1826 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1827 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1828 | } |
| 1829 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1830 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1831 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1832 | * @phba: Pointer to HBA context object. |
| 1833 | * @iocbq: Pointer to driver iocb object. |
| 1834 | * |
| 1835 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 1836 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 1837 | * array and assigns a new iotag. |
| 1838 | * The function returns the allocated iotag if successful, else returns zero. |
| 1839 | * Zero is not a valid iotag. |
| 1840 | * The caller is not required to hold any lock. |
| 1841 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1842 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1843 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1844 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1845 | struct lpfc_iocbq **new_arr; |
| 1846 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1847 | size_t new_len; |
| 1848 | struct lpfc_sli *psli = &phba->sli; |
| 1849 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1850 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1851 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1852 | iotag = psli->last_iotag; |
| 1853 | if(++iotag < psli->iocbq_lookup_len) { |
| 1854 | psli->last_iotag = iotag; |
| 1855 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1856 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1857 | iocbq->iotag = iotag; |
| 1858 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1859 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1860 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 1861 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1862 | spin_unlock_irq(&phba->hbalock); |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 1863 | new_arr = kcalloc(new_len, sizeof(struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1864 | GFP_KERNEL); |
| 1865 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1866 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1867 | old_arr = psli->iocbq_lookup; |
| 1868 | if (new_len <= psli->iocbq_lookup_len) { |
| 1869 | /* highly unprobable case */ |
| 1870 | kfree(new_arr); |
| 1871 | iotag = psli->last_iotag; |
| 1872 | if(++iotag < psli->iocbq_lookup_len) { |
| 1873 | psli->last_iotag = iotag; |
| 1874 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1875 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1876 | iocbq->iotag = iotag; |
| 1877 | return iotag; |
| 1878 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1879 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1880 | return 0; |
| 1881 | } |
| 1882 | if (psli->iocbq_lookup) |
| 1883 | memcpy(new_arr, old_arr, |
| 1884 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1885 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1886 | psli->iocbq_lookup = new_arr; |
| 1887 | psli->iocbq_lookup_len = new_len; |
| 1888 | psli->last_iotag = iotag; |
| 1889 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1890 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1891 | iocbq->iotag = iotag; |
| 1892 | kfree(old_arr); |
| 1893 | return iotag; |
| 1894 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1895 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1896 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1897 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1898 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1899 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 1900 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1901 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1902 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1903 | } |
| 1904 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1905 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1906 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1907 | * @phba: Pointer to HBA context object. |
| 1908 | * @pring: Pointer to driver SLI ring object. |
| 1909 | * @iocb: Pointer to iocb slot in the ring. |
| 1910 | * @nextiocb: Pointer to driver iocb object which need to be |
| 1911 | * posted to firmware. |
| 1912 | * |
Dick Kennedy | 88acb4d | 2020-05-01 14:43:07 -0700 | [diff] [blame] | 1913 | * This function is called to post a new iocb to the firmware. This |
| 1914 | * function copies the new iocb to ring iocb slot and updates the |
| 1915 | * ring pointers. It adds the new iocb to txcmplq if there is |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1916 | * 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] | 1917 | * iocb object. The hbalock is asserted held in the code path calling |
| 1918 | * this routine. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1919 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1920 | static void |
| 1921 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1922 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 1923 | { |
| 1924 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1925 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1926 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1927 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1928 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1929 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1930 | if (pring->ringno == LPFC_ELS_RING) { |
| 1931 | lpfc_debugfs_slow_ring_trc(phba, |
| 1932 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 1933 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 1934 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 1935 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 1936 | } |
| 1937 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1938 | /* |
| 1939 | * Issue iocb command to adapter |
| 1940 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1941 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1942 | wmb(); |
| 1943 | pring->stats.iocb_cmd++; |
| 1944 | |
| 1945 | /* |
| 1946 | * If there is no completion routine to call, we can release the |
| 1947 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 1948 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 1949 | */ |
| 1950 | if (nextiocb->iocb_cmpl) |
| 1951 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1952 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1953 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1954 | |
| 1955 | /* |
| 1956 | * Let the HBA know what IOCB slot will be the next one the |
| 1957 | * driver will put a command into. |
| 1958 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1959 | pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx; |
| 1960 | writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1961 | } |
| 1962 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1963 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1964 | * lpfc_sli_update_full_ring - Update the chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1965 | * @phba: Pointer to HBA context object. |
| 1966 | * @pring: Pointer to driver SLI ring object. |
| 1967 | * |
| 1968 | * The caller is not required to hold any lock for calling this function. |
| 1969 | * This function updates the chip attention bits for the ring to inform firmware |
| 1970 | * that there are pending work to be done for this ring and requests an |
| 1971 | * interrupt when there is space available in the ring. This function is |
| 1972 | * called when the driver is unable to post more iocbs to the ring due |
| 1973 | * to unavailability of space in the ring. |
| 1974 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1975 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1976 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1977 | { |
| 1978 | int ringno = pring->ringno; |
| 1979 | |
| 1980 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 1981 | |
| 1982 | wmb(); |
| 1983 | |
| 1984 | /* |
| 1985 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 1986 | * The HBA will tell us when an IOCB entry is available. |
| 1987 | */ |
| 1988 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 1989 | readl(phba->CAregaddr); /* flush */ |
| 1990 | |
| 1991 | pring->stats.iocb_cmd_full++; |
| 1992 | } |
| 1993 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1994 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1995 | * lpfc_sli_update_ring - Update chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1996 | * @phba: Pointer to HBA context object. |
| 1997 | * @pring: Pointer to driver SLI ring object. |
| 1998 | * |
| 1999 | * This function updates the chip attention register bit for the |
| 2000 | * given ring to inform HBA that there is more work to be done |
| 2001 | * in this ring. The caller is not required to hold any lock. |
| 2002 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2003 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2004 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2005 | { |
| 2006 | int ringno = pring->ringno; |
| 2007 | |
| 2008 | /* |
| 2009 | * Tell the HBA that there is work to do in this ring. |
| 2010 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2011 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 2012 | wmb(); |
| 2013 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 2014 | readl(phba->CAregaddr); /* flush */ |
| 2015 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2016 | } |
| 2017 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2018 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2019 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2020 | * @phba: Pointer to HBA context object. |
| 2021 | * @pring: Pointer to driver SLI ring object. |
| 2022 | * |
| 2023 | * This function is called with hbalock held to post pending iocbs |
| 2024 | * in the txq to the firmware. This function is called when driver |
| 2025 | * detects space available in the ring. |
| 2026 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2027 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2028 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2029 | { |
| 2030 | IOCB_t *iocb; |
| 2031 | struct lpfc_iocbq *nextiocb; |
| 2032 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2033 | lockdep_assert_held(&phba->hbalock); |
| 2034 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2035 | /* |
| 2036 | * Check to see if: |
| 2037 | * (a) there is anything on the txq to send |
| 2038 | * (b) link is up |
| 2039 | * (c) link attention events can be processed (fcp ring only) |
| 2040 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 2041 | */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 2042 | |
| 2043 | if (lpfc_is_link_up(phba) && |
| 2044 | (!list_empty(&pring->txq)) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2045 | (pring->ringno != LPFC_FCP_RING || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2046 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2047 | |
| 2048 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 2049 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 2050 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 2051 | |
| 2052 | if (iocb) |
| 2053 | lpfc_sli_update_ring(phba, pring); |
| 2054 | else |
| 2055 | lpfc_sli_update_full_ring(phba, pring); |
| 2056 | } |
| 2057 | |
| 2058 | return; |
| 2059 | } |
| 2060 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2061 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2062 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2063 | * @phba: Pointer to HBA context object. |
| 2064 | * @hbqno: HBQ number. |
| 2065 | * |
| 2066 | * This function is called with hbalock held to get the next |
| 2067 | * available slot for the given HBQ. If there is free slot |
| 2068 | * available for the HBQ it will return pointer to the next available |
| 2069 | * HBQ entry else it will return NULL. |
| 2070 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2071 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2072 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 2073 | { |
| 2074 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 2075 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2076 | lockdep_assert_held(&phba->hbalock); |
| 2077 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2078 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 2079 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 2080 | hbqp->next_hbqPutIdx = 0; |
| 2081 | |
| 2082 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2083 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2084 | uint32_t getidx = le32_to_cpu(raw_index); |
| 2085 | |
| 2086 | hbqp->local_hbqGetIdx = getidx; |
| 2087 | |
| 2088 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2089 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2090 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2091 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2092 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2093 | hbqp->entry_count); |
| 2094 | |
| 2095 | phba->link_state = LPFC_HBA_ERROR; |
| 2096 | return NULL; |
| 2097 | } |
| 2098 | |
| 2099 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 2100 | return NULL; |
| 2101 | } |
| 2102 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2103 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 2104 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2105 | } |
| 2106 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2107 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2108 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2109 | * @phba: Pointer to HBA context object. |
| 2110 | * |
| 2111 | * This function is called with no lock held to free all the |
| 2112 | * hbq buffers while uninitializing the SLI interface. It also |
| 2113 | * frees the HBQ buffers returned by the firmware but not yet |
| 2114 | * processed by the upper layers. |
| 2115 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2116 | void |
| 2117 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 2118 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2119 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 2120 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2121 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2122 | int i, hbq_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2123 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2124 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2125 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2126 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2127 | for (i = 0; i < hbq_count; ++i) { |
| 2128 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 2129 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 2130 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 2131 | list_del(&hbq_buf->dbuf.list); |
| 2132 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 2133 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2134 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2135 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2136 | |
| 2137 | /* Mark the HBQs not in use */ |
| 2138 | phba->hbq_in_use = 0; |
| 2139 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2140 | } |
| 2141 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2142 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2143 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2144 | * @phba: Pointer to HBA context object. |
| 2145 | * @hbqno: HBQ number. |
| 2146 | * @hbq_buf: Pointer to HBQ buffer. |
| 2147 | * |
| 2148 | * This function is called with the hbalock held to post a |
| 2149 | * hbq buffer to the firmware. If the function finds an empty |
| 2150 | * slot in the HBQ, it will post the buffer. The function will return |
| 2151 | * pointer to the hbq entry if it successfully post the buffer |
| 2152 | * else it will return NULL. |
| 2153 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2154 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2155 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2156 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2157 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2158 | lockdep_assert_held(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2159 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); |
| 2160 | } |
| 2161 | |
| 2162 | /** |
| 2163 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware |
| 2164 | * @phba: Pointer to HBA context object. |
| 2165 | * @hbqno: HBQ number. |
| 2166 | * @hbq_buf: Pointer to HBQ buffer. |
| 2167 | * |
| 2168 | * This function is called with the hbalock held to post a hbq buffer to the |
| 2169 | * firmware. If the function finds an empty slot in the HBQ, it will post the |
| 2170 | * buffer and place it on the hbq_buffer_list. The function will return zero if |
| 2171 | * it successfully post the buffer else it will return an error. |
| 2172 | **/ |
| 2173 | static int |
| 2174 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, |
| 2175 | struct hbq_dmabuf *hbq_buf) |
| 2176 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2177 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2178 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2179 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2180 | lockdep_assert_held(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2181 | /* Get next HBQ entry slot to use */ |
| 2182 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 2183 | if (hbqe) { |
| 2184 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 2185 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2186 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 2187 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2188 | hbqe->bde.tus.f.bdeSize = hbq_buf->total_size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2189 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2190 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 2191 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 2192 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2193 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 2194 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2195 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2196 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2197 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2198 | return 0; |
| 2199 | } else |
| 2200 | return -ENOMEM; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2201 | } |
| 2202 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2203 | /** |
| 2204 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware |
| 2205 | * @phba: Pointer to HBA context object. |
| 2206 | * @hbqno: HBQ number. |
| 2207 | * @hbq_buf: Pointer to HBQ buffer. |
| 2208 | * |
| 2209 | * This function is called with the hbalock held to post an RQE to the SLI4 |
| 2210 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to |
| 2211 | * the hbq_buffer_list and return zero, otherwise it will return an error. |
| 2212 | **/ |
| 2213 | static int |
| 2214 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, |
| 2215 | struct hbq_dmabuf *hbq_buf) |
| 2216 | { |
| 2217 | int rc; |
| 2218 | struct lpfc_rqe hrqe; |
| 2219 | struct lpfc_rqe drqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2220 | struct lpfc_queue *hrq; |
| 2221 | struct lpfc_queue *drq; |
| 2222 | |
| 2223 | if (hbqno != LPFC_ELS_HBQ) |
| 2224 | return 1; |
| 2225 | hrq = phba->sli4_hba.hdr_rq; |
| 2226 | drq = phba->sli4_hba.dat_rq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2227 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2228 | lockdep_assert_held(&phba->hbalock); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2229 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); |
| 2230 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); |
| 2231 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); |
| 2232 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2233 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2234 | if (rc < 0) |
| 2235 | return rc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2236 | hbq_buf->tag = (rc | (hbqno << 16)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2237 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); |
| 2238 | return 0; |
| 2239 | } |
| 2240 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2241 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2242 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 2243 | .rn = 1, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2244 | .entry_count = 256, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2245 | .mask_count = 0, |
| 2246 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2247 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2248 | .buffer_count = 0, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2249 | .init_count = 40, |
| 2250 | .add_count = 40, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2251 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2252 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2253 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 2254 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2255 | &lpfc_els_hbq, |
| 2256 | }; |
| 2257 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2258 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2259 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2260 | * @phba: Pointer to HBA context object. |
| 2261 | * @hbqno: HBQ number. |
| 2262 | * @count: Number of HBQ buffers to be posted. |
| 2263 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2264 | * This function is called with no lock held to post more hbq buffers to the |
| 2265 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 2266 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2267 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 2268 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2269 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 2270 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2271 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2272 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2273 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2274 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 2275 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2276 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2277 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2278 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 2279 | lpfc_hbq_defs[hbqno]->entry_count) |
| 2280 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 2281 | phba->hbqs[hbqno].buffer_count; |
| 2282 | if (!count) |
| 2283 | return 0; |
| 2284 | /* Allocate HBQ entries */ |
| 2285 | for (i = 0; i < count; i++) { |
| 2286 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 2287 | if (!hbq_buffer) |
| 2288 | break; |
| 2289 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 2290 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2291 | /* Check whether HBQ is still in use */ |
| 2292 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 2293 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2294 | goto err; |
| 2295 | while (!list_empty(&hbq_buf_list)) { |
| 2296 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 2297 | dbuf.list); |
| 2298 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 2299 | (hbqno << 16)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2300 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2301 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2302 | posted++; |
| 2303 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2304 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2305 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2306 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2307 | return posted; |
| 2308 | err: |
| 2309 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 2310 | while (!list_empty(&hbq_buf_list)) { |
| 2311 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 2312 | dbuf.list); |
| 2313 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 2314 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2315 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2316 | } |
| 2317 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2318 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2319 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2320 | * @phba: Pointer to HBA context object. |
| 2321 | * @qno: HBQ number. |
| 2322 | * |
| 2323 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2324 | * is called with no lock held. The function returns the number of HBQ entries |
| 2325 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2326 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2327 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2328 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2329 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2330 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2331 | return 0; |
| 2332 | else |
| 2333 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 2334 | lpfc_hbq_defs[qno]->add_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2335 | } |
| 2336 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2337 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2338 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2339 | * @phba: Pointer to HBA context object. |
| 2340 | * @qno: HBQ queue number. |
| 2341 | * |
| 2342 | * This function is called from SLI initialization code path with |
| 2343 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2344 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2345 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2346 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2347 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2348 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2349 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2350 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 2351 | lpfc_hbq_defs[qno]->entry_count); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2352 | else |
| 2353 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 2354 | lpfc_hbq_defs[qno]->init_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2355 | } |
| 2356 | |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 2357 | /* |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2358 | * 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] | 2359 | * |
| 2360 | * This function removes the first hbq buffer on an hbq list and returns a |
| 2361 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 2362 | **/ |
| 2363 | static struct hbq_dmabuf * |
| 2364 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) |
| 2365 | { |
| 2366 | struct lpfc_dmabuf *d_buf; |
| 2367 | |
| 2368 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); |
| 2369 | if (!d_buf) |
| 2370 | return NULL; |
| 2371 | return container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 2372 | } |
| 2373 | |
| 2374 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 2375 | * lpfc_sli_rqbuf_get - Remove the first dma buffer off of an RQ list |
| 2376 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 2377 | * @hrq: HBQ number. |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 2378 | * |
| 2379 | * This function removes the first RQ buffer on an RQ buffer list and returns a |
| 2380 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 2381 | **/ |
| 2382 | static struct rqb_dmabuf * |
| 2383 | lpfc_sli_rqbuf_get(struct lpfc_hba *phba, struct lpfc_queue *hrq) |
| 2384 | { |
| 2385 | struct lpfc_dmabuf *h_buf; |
| 2386 | struct lpfc_rqb *rqbp; |
| 2387 | |
| 2388 | rqbp = hrq->rqbp; |
| 2389 | list_remove_head(&rqbp->rqb_buffer_list, h_buf, |
| 2390 | struct lpfc_dmabuf, list); |
| 2391 | if (!h_buf) |
| 2392 | return NULL; |
| 2393 | rqbp->buffer_count--; |
| 2394 | return container_of(h_buf, struct rqb_dmabuf, hbuf); |
| 2395 | } |
| 2396 | |
| 2397 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2398 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2399 | * @phba: Pointer to HBA context object. |
| 2400 | * @tag: Tag of the hbq buffer. |
| 2401 | * |
Sebastian Herbszt | 7189241 | 2016-04-17 13:27:27 +0200 | [diff] [blame] | 2402 | * This function searches for the hbq buffer associated with the given tag in |
| 2403 | * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer |
| 2404 | * otherwise it returns NULL. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2405 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2406 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2407 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 2408 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2409 | struct lpfc_dmabuf *d_buf; |
| 2410 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2411 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2412 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2413 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 2414 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2415 | return NULL; |
| 2416 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2417 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2418 | 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] | 2419 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2420 | if (hbq_buf->tag == tag) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2421 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2422 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2423 | } |
| 2424 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2425 | spin_unlock_irq(&phba->hbalock); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2426 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2427 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2428 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2429 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2430 | } |
| 2431 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2432 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2433 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2434 | * @phba: Pointer to HBA context object. |
| 2435 | * @hbq_buffer: Pointer to HBQ buffer. |
| 2436 | * |
| 2437 | * This function is called with hbalock. This function gives back |
| 2438 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 2439 | * post the buffer, it will free the buffer. |
| 2440 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2441 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2442 | 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] | 2443 | { |
| 2444 | uint32_t hbqno; |
| 2445 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2446 | if (hbq_buffer) { |
| 2447 | hbqno = hbq_buffer->tag >> 16; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2448 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2449 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2450 | } |
| 2451 | } |
| 2452 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2453 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2454 | * 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] | 2455 | * @mbxCommand: mailbox command code. |
| 2456 | * |
| 2457 | * This function is called by the mailbox event handler function to verify |
| 2458 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 2459 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 2460 | * and the mailbox event handler will take the HBA offline. |
| 2461 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2462 | static int |
| 2463 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 2464 | { |
| 2465 | uint8_t ret; |
| 2466 | |
| 2467 | switch (mbxCommand) { |
| 2468 | case MBX_LOAD_SM: |
| 2469 | case MBX_READ_NV: |
| 2470 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2471 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2472 | case MBX_RUN_BIU_DIAG: |
| 2473 | case MBX_INIT_LINK: |
| 2474 | case MBX_DOWN_LINK: |
| 2475 | case MBX_CONFIG_LINK: |
| 2476 | case MBX_CONFIG_RING: |
| 2477 | case MBX_RESET_RING: |
| 2478 | case MBX_READ_CONFIG: |
| 2479 | case MBX_READ_RCONFIG: |
| 2480 | case MBX_READ_SPARM: |
| 2481 | case MBX_READ_STATUS: |
| 2482 | case MBX_READ_RPI: |
| 2483 | case MBX_READ_XRI: |
| 2484 | case MBX_READ_REV: |
| 2485 | case MBX_READ_LNK_STAT: |
| 2486 | case MBX_REG_LOGIN: |
| 2487 | case MBX_UNREG_LOGIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2488 | case MBX_CLEAR_LA: |
| 2489 | case MBX_DUMP_MEMORY: |
| 2490 | case MBX_DUMP_CONTEXT: |
| 2491 | case MBX_RUN_DIAGS: |
| 2492 | case MBX_RESTART: |
| 2493 | case MBX_UPDATE_CFG: |
| 2494 | case MBX_DOWN_LOAD: |
| 2495 | case MBX_DEL_LD_ENTRY: |
| 2496 | case MBX_RUN_PROGRAM: |
| 2497 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2498 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2499 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2500 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2501 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2502 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2503 | case MBX_LOAD_AREA: |
| 2504 | case MBX_RUN_BIU_DIAG64: |
| 2505 | case MBX_CONFIG_PORT: |
| 2506 | case MBX_READ_SPARM64: |
| 2507 | case MBX_READ_RPI64: |
| 2508 | case MBX_REG_LOGIN64: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2509 | case MBX_READ_TOPOLOGY: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2510 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2511 | case MBX_SET_DEBUG: |
| 2512 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2513 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2514 | case MBX_REG_VPI: |
| 2515 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2516 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2517 | case MBX_PORT_CAPABILITIES: |
| 2518 | case MBX_PORT_IOV_CONTROL: |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2519 | case MBX_SLI4_CONFIG: |
| 2520 | case MBX_SLI4_REQ_FTRS: |
| 2521 | case MBX_REG_FCFI: |
| 2522 | case MBX_UNREG_FCFI: |
| 2523 | case MBX_REG_VFI: |
| 2524 | case MBX_UNREG_VFI: |
| 2525 | case MBX_INIT_VPI: |
| 2526 | case MBX_INIT_VFI: |
| 2527 | case MBX_RESUME_RPI: |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 2528 | case MBX_READ_EVENT_LOG_STATUS: |
| 2529 | case MBX_READ_EVENT_LOG: |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2530 | case MBX_SECURITY_MGMT: |
| 2531 | case MBX_AUTH_PORT: |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 2532 | case MBX_ACCESS_VDATA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2533 | ret = mbxCommand; |
| 2534 | break; |
| 2535 | default: |
| 2536 | ret = MBX_SHUTDOWN; |
| 2537 | break; |
| 2538 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2539 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2540 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2541 | |
| 2542 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2543 | * 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] | 2544 | * @phba: Pointer to HBA context object. |
| 2545 | * @pmboxq: Pointer to mailbox command. |
| 2546 | * |
| 2547 | * This is completion handler function for mailbox commands issued from |
| 2548 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 2549 | * mailbox event handler function with no lock held. This function |
| 2550 | * will wake up thread waiting on the wait queue pointed by context1 |
| 2551 | * of the mailbox. |
| 2552 | **/ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2553 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2554 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2555 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2556 | unsigned long drvr_flag; |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2557 | struct completion *pmbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2558 | |
| 2559 | /* |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2560 | * If pmbox_done is empty, the driver thread gave up waiting and |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2561 | * continued running. |
| 2562 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2563 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2564 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2565 | pmbox_done = (struct completion *)pmboxq->context3; |
| 2566 | if (pmbox_done) |
| 2567 | complete(pmbox_done); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2568 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2569 | return; |
| 2570 | } |
| 2571 | |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 2572 | static void |
| 2573 | __lpfc_sli_rpi_release(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 2574 | { |
| 2575 | unsigned long iflags; |
| 2576 | |
| 2577 | if (ndlp->nlp_flag & NLP_RELEASE_RPI) { |
| 2578 | lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi); |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2579 | spin_lock_irqsave(&ndlp->lock, iflags); |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 2580 | ndlp->nlp_flag &= ~NLP_RELEASE_RPI; |
| 2581 | ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 2582 | spin_unlock_irqrestore(&ndlp->lock, iflags); |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 2583 | } |
| 2584 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
| 2585 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2586 | |
| 2587 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2588 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2589 | * @phba: Pointer to HBA context object. |
| 2590 | * @pmb: Pointer to mailbox object. |
| 2591 | * |
| 2592 | * This function is the default mailbox completion handler. It |
| 2593 | * frees the memory resources associated with the completed mailbox |
| 2594 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 2595 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 2596 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2597 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2598 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2599 | { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2600 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2601 | struct lpfc_dmabuf *mp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2602 | struct lpfc_nodelist *ndlp; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2603 | struct Scsi_Host *shost; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2604 | uint16_t rpi, vpi; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2605 | int rc; |
| 2606 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2607 | mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2608 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2609 | if (mp) { |
| 2610 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2611 | kfree(mp); |
| 2612 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2613 | |
| 2614 | /* |
| 2615 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 2616 | * is in re-discovery driver need to cleanup the RPI. |
| 2617 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2618 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2619 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
| 2620 | !pmb->u.mb.mbxStatus) { |
| 2621 | rpi = pmb->u.mb.un.varWords[0]; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2622 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
James Smart | 3850394 | 2020-03-22 11:12:53 -0700 | [diff] [blame] | 2623 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2624 | vpi -= phba->sli4_hba.max_cfg_param.vpi_base; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2625 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
James Smart | de96e9c | 2016-03-31 14:12:27 -0700 | [diff] [blame] | 2626 | pmb->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2627 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2628 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2629 | if (rc != MBX_NOT_FINISHED) |
| 2630 | return; |
| 2631 | } |
| 2632 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2633 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
| 2634 | !(phba->pport->load_flag & FC_UNLOADING) && |
| 2635 | !pmb->u.mb.mbxStatus) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2636 | shost = lpfc_shost_from_vport(vport); |
| 2637 | spin_lock_irq(shost->host_lock); |
| 2638 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
| 2639 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 2640 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2641 | } |
| 2642 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2643 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2644 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2645 | lpfc_nlp_put(ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2646 | pmb->ctx_buf = NULL; |
| 2647 | pmb->ctx_ndlp = NULL; |
| 2648 | } |
| 2649 | |
| 2650 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { |
| 2651 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
| 2652 | |
| 2653 | /* Check to see if there are any deferred events to process */ |
| 2654 | if (ndlp) { |
| 2655 | lpfc_printf_vlog( |
| 2656 | vport, |
| 2657 | KERN_INFO, LOG_MBOX | LOG_DISCOVERY, |
| 2658 | "1438 UNREG cmpl deferred mbox x%x " |
James Smart | f115612 | 2021-04-11 18:31:24 -0700 | [diff] [blame] | 2659 | "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] | 2660 | ndlp->nlp_rpi, ndlp->nlp_DID, |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 2661 | ndlp->nlp_flag, ndlp->nlp_defer_did, |
| 2662 | ndlp, vport->load_flag, kref_read(&ndlp->kref)); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2663 | |
| 2664 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && |
| 2665 | (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) { |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2666 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2667 | ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING; |
| 2668 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2669 | } else { |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 2670 | __lpfc_sli_rpi_release(vport, ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2671 | } |
James Smart | a70e63e | 2020-11-15 11:26:38 -0800 | [diff] [blame] | 2672 | |
| 2673 | /* The unreg_login mailbox is complete and had a |
| 2674 | * reference that has to be released. The PLOGI |
| 2675 | * got its own ref. |
| 2676 | */ |
| 2677 | lpfc_nlp_put(ndlp); |
James Smart | 9b16406 | 2019-03-12 16:30:06 -0700 | [diff] [blame] | 2678 | pmb->ctx_ndlp = NULL; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2679 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2680 | } |
| 2681 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2682 | /* Check security permission status on INIT_LINK mailbox command */ |
| 2683 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && |
| 2684 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2685 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2686 | "2860 SLI authentication is required " |
| 2687 | "for INIT_LINK but has not done yet\n"); |
| 2688 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2689 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
| 2690 | lpfc_sli4_mbox_cmd_free(phba, pmb); |
| 2691 | else |
| 2692 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2693 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2694 | /** |
| 2695 | * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler |
| 2696 | * @phba: Pointer to HBA context object. |
| 2697 | * @pmb: Pointer to mailbox object. |
| 2698 | * |
| 2699 | * This function is the unreg rpi mailbox completion handler. It |
| 2700 | * frees the memory resources associated with the completed mailbox |
James Smart | a70e63e | 2020-11-15 11:26:38 -0800 | [diff] [blame] | 2701 | * command. An additional reference is put on the ndlp to prevent |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2702 | * lpfc_nlp_release from freeing the rpi bit in the bitmask before |
| 2703 | * the unreg mailbox command completes, this routine puts the |
| 2704 | * reference back. |
| 2705 | * |
| 2706 | **/ |
| 2707 | void |
| 2708 | lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2709 | { |
| 2710 | struct lpfc_vport *vport = pmb->vport; |
| 2711 | struct lpfc_nodelist *ndlp; |
| 2712 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2713 | ndlp = pmb->ctx_ndlp; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2714 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { |
| 2715 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 2716 | (bf_get(lpfc_sli_intf_if_type, |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 2717 | &phba->sli4_hba.sli_intf) >= |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2718 | LPFC_SLI_INTF_IF_TYPE_2)) { |
| 2719 | if (ndlp) { |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2720 | lpfc_printf_vlog( |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 2721 | vport, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2722 | "0010 UNREG_LOGIN vpi:%x " |
| 2723 | "rpi:%x DID:%x defer x%x flg x%x " |
James Smart | f115612 | 2021-04-11 18:31:24 -0700 | [diff] [blame] | 2724 | "x%px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2725 | vport->vpi, ndlp->nlp_rpi, |
| 2726 | ndlp->nlp_DID, ndlp->nlp_defer_did, |
| 2727 | ndlp->nlp_flag, |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 2728 | ndlp); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 2729 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2730 | |
| 2731 | /* Check to see if there are any deferred |
| 2732 | * events to process |
| 2733 | */ |
| 2734 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && |
| 2735 | (ndlp->nlp_defer_did != |
| 2736 | NLP_EVT_NOTHING_PENDING)) { |
| 2737 | lpfc_printf_vlog( |
| 2738 | vport, KERN_INFO, LOG_DISCOVERY, |
| 2739 | "4111 UNREG cmpl deferred " |
| 2740 | "clr x%x on " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 2741 | "NPort x%x Data: x%x x%px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2742 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 2743 | ndlp->nlp_defer_did, ndlp); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2744 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2745 | ndlp->nlp_defer_did = |
| 2746 | NLP_EVT_NOTHING_PENDING; |
| 2747 | lpfc_issue_els_plogi( |
| 2748 | vport, ndlp->nlp_DID, 0); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2749 | } else { |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 2750 | __lpfc_sli_rpi_release(vport, ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2751 | } |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 2752 | |
| 2753 | lpfc_nlp_put(ndlp); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2754 | } |
| 2755 | } |
| 2756 | } |
| 2757 | |
| 2758 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2759 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2760 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2761 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2762 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2763 | * @phba: Pointer to HBA context object. |
| 2764 | * |
| 2765 | * This function is called with no lock held. This function processes all |
| 2766 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 2767 | * service routine processes mailbox completion interrupt and adds completed |
| 2768 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 2769 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 2770 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 2771 | * function returns the mailbox commands to the upper layer by calling the |
| 2772 | * completion handler function of each mailbox. |
| 2773 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2774 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2775 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2776 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2777 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2778 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2779 | int rc; |
| 2780 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2781 | |
| 2782 | phba->sli.slistat.mbox_event++; |
| 2783 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2784 | /* Get all completed mailboxe buffers into the cmplq */ |
| 2785 | spin_lock_irq(&phba->hbalock); |
| 2786 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 2787 | spin_unlock_irq(&phba->hbalock); |
| 2788 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2789 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2790 | do { |
| 2791 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 2792 | if (pmb == NULL) |
| 2793 | break; |
| 2794 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2795 | pmbox = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2796 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2797 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 2798 | if (pmb->vport) { |
| 2799 | lpfc_debugfs_disc_trc(pmb->vport, |
| 2800 | LPFC_DISC_TRC_MBOX_VPORT, |
| 2801 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 2802 | (uint32_t)pmbox->mbxCommand, |
| 2803 | pmbox->un.varWords[0], |
| 2804 | pmbox->un.varWords[1]); |
| 2805 | } |
| 2806 | else { |
| 2807 | lpfc_debugfs_disc_trc(phba->pport, |
| 2808 | LPFC_DISC_TRC_MBOX, |
| 2809 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 2810 | (uint32_t)pmbox->mbxCommand, |
| 2811 | pmbox->un.varWords[0], |
| 2812 | pmbox->un.varWords[1]); |
| 2813 | } |
| 2814 | } |
| 2815 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2816 | /* |
| 2817 | * It is a fatal error if unknown mbox command completion. |
| 2818 | */ |
| 2819 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 2820 | MBX_SHUTDOWN) { |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2821 | /* Unknown mailbox command compl */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2822 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2823 | "(%d):0323 Unknown Mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2824 | "x%x (x%x/x%x) Cmpl\n", |
James Smart | 43bfea1 | 2019-09-21 20:58:57 -0700 | [diff] [blame] | 2825 | pmb->vport ? pmb->vport->vpi : |
| 2826 | LPFC_VPORT_UNKNOWN, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2827 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2828 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2829 | pmb), |
| 2830 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2831 | pmb)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2832 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2833 | phba->work_hs = HS_FFER3; |
| 2834 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2835 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2836 | } |
| 2837 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2838 | if (pmbox->mbxStatus) { |
| 2839 | phba->sli.slistat.mbox_stat_err++; |
| 2840 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 2841 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2842 | lpfc_printf_log(phba, KERN_INFO, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2843 | LOG_MBOX | LOG_SLI, |
| 2844 | "(%d):0305 Mbox cmd cmpl " |
| 2845 | "error - RETRYing Data: x%x " |
| 2846 | "(x%x/x%x) x%x x%x x%x\n", |
James Smart | 43bfea1 | 2019-09-21 20:58:57 -0700 | [diff] [blame] | 2847 | pmb->vport ? pmb->vport->vpi : |
| 2848 | LPFC_VPORT_UNKNOWN, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2849 | pmbox->mbxCommand, |
| 2850 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2851 | pmb), |
| 2852 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2853 | pmb), |
| 2854 | pmbox->mbxStatus, |
| 2855 | pmbox->un.varWords[0], |
James Smart | 43bfea1 | 2019-09-21 20:58:57 -0700 | [diff] [blame] | 2856 | pmb->vport ? pmb->vport->port_state : |
| 2857 | LPFC_VPORT_UNKNOWN); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2858 | pmbox->mbxStatus = 0; |
| 2859 | pmbox->mbxOwner = OWN_HOST; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2860 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2861 | if (rc != MBX_NOT_FINISHED) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2862 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2863 | } |
| 2864 | } |
| 2865 | |
| 2866 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2867 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
Sakari Ailus | 2d44d16 | 2019-09-04 19:04:23 +0300 | [diff] [blame] | 2868 | "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl %ps " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2869 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 2870 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2871 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2872 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2873 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
| 2874 | lpfc_sli_config_mbox_opcode_get(phba, pmb), |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2875 | pmb->mbox_cmpl, |
| 2876 | *((uint32_t *) pmbox), |
| 2877 | pmbox->un.varWords[0], |
| 2878 | pmbox->un.varWords[1], |
| 2879 | pmbox->un.varWords[2], |
| 2880 | pmbox->un.varWords[3], |
| 2881 | pmbox->un.varWords[4], |
| 2882 | pmbox->un.varWords[5], |
| 2883 | pmbox->un.varWords[6], |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2884 | pmbox->un.varWords[7], |
| 2885 | pmbox->un.varWords[8], |
| 2886 | pmbox->un.varWords[9], |
| 2887 | pmbox->un.varWords[10]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2888 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2889 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2890 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2891 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2892 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2893 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2894 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2895 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2896 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2897 | * @phba: Pointer to HBA context object. |
| 2898 | * @pring: Pointer to driver SLI ring object. |
| 2899 | * @tag: buffer tag. |
| 2900 | * |
| 2901 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 2902 | * is set in the tag the buffer is posted for a particular exchange, |
| 2903 | * the function will return the buffer without replacing the buffer. |
| 2904 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 2905 | * returns the buffer and also posts another buffer to the firmware. |
| 2906 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2907 | static struct lpfc_dmabuf * |
| 2908 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2909 | struct lpfc_sli_ring *pring, |
| 2910 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2911 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2912 | struct hbq_dmabuf *hbq_entry; |
| 2913 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2914 | if (tag & QUE_BUFTAG_BIT) |
| 2915 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2916 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 2917 | if (!hbq_entry) |
| 2918 | return NULL; |
| 2919 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2920 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2921 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2922 | /** |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 2923 | * lpfc_nvme_unsol_ls_handler - Process an unsolicited event data buffer |
| 2924 | * containing a NVME LS request. |
| 2925 | * @phba: pointer to lpfc hba data structure. |
| 2926 | * @piocb: pointer to the iocbq struct representing the sequence starting |
| 2927 | * frame. |
| 2928 | * |
| 2929 | * This routine initially validates the NVME LS, validates there is a login |
| 2930 | * with the port that sent the LS, and then calls the appropriate nvme host |
| 2931 | * or target LS request handler. |
| 2932 | **/ |
| 2933 | static void |
| 2934 | lpfc_nvme_unsol_ls_handler(struct lpfc_hba *phba, struct lpfc_iocbq *piocb) |
| 2935 | { |
| 2936 | struct lpfc_nodelist *ndlp; |
| 2937 | struct lpfc_dmabuf *d_buf; |
| 2938 | struct hbq_dmabuf *nvmebuf; |
| 2939 | struct fc_frame_header *fc_hdr; |
| 2940 | struct lpfc_async_xchg_ctx *axchg = NULL; |
| 2941 | char *failwhy = NULL; |
| 2942 | uint32_t oxid, sid, did, fctl, size; |
James Smart | 4e57e0b | 2020-05-20 11:59:28 -0700 | [diff] [blame] | 2943 | int ret = 1; |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 2944 | |
| 2945 | d_buf = piocb->context2; |
| 2946 | |
| 2947 | nvmebuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 2948 | fc_hdr = nvmebuf->hbuf.virt; |
| 2949 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
| 2950 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 2951 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 2952 | fctl = (fc_hdr->fh_f_ctl[0] << 16 | |
| 2953 | fc_hdr->fh_f_ctl[1] << 8 | |
| 2954 | fc_hdr->fh_f_ctl[2]); |
| 2955 | size = bf_get(lpfc_rcqe_length, &nvmebuf->cq_event.cqe.rcqe_cmpl); |
| 2956 | |
| 2957 | lpfc_nvmeio_data(phba, "NVME LS RCV: xri x%x sz %d from %06x\n", |
| 2958 | oxid, size, sid); |
| 2959 | |
| 2960 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 2961 | failwhy = "Driver Unloading"; |
| 2962 | } else if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) { |
| 2963 | failwhy = "NVME FC4 Disabled"; |
| 2964 | } else if (!phba->nvmet_support && !phba->pport->localport) { |
| 2965 | failwhy = "No Localport"; |
| 2966 | } else if (phba->nvmet_support && !phba->targetport) { |
| 2967 | failwhy = "No Targetport"; |
| 2968 | } else if (unlikely(fc_hdr->fh_r_ctl != FC_RCTL_ELS4_REQ)) { |
| 2969 | failwhy = "Bad NVME LS R_CTL"; |
| 2970 | } else if (unlikely((fctl & 0x00FF0000) != |
| 2971 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT))) { |
| 2972 | failwhy = "Bad NVME LS F_CTL"; |
| 2973 | } else { |
| 2974 | axchg = kzalloc(sizeof(*axchg), GFP_ATOMIC); |
| 2975 | if (!axchg) |
| 2976 | failwhy = "No CTX memory"; |
| 2977 | } |
| 2978 | |
| 2979 | if (unlikely(failwhy)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2980 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 2981 | "6154 Drop NVME LS: SID %06X OXID x%X: %s\n", |
| 2982 | sid, oxid, failwhy); |
| 2983 | goto out_fail; |
| 2984 | } |
| 2985 | |
| 2986 | /* validate the source of the LS is logged in */ |
| 2987 | ndlp = lpfc_findnode_did(phba->pport, sid); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 2988 | if (!ndlp || |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 2989 | ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 2990 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) { |
| 2991 | lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC, |
| 2992 | "6216 NVME Unsol rcv: No ndlp: " |
| 2993 | "NPort_ID x%x oxid x%x\n", |
| 2994 | sid, oxid); |
| 2995 | goto out_fail; |
| 2996 | } |
| 2997 | |
| 2998 | axchg->phba = phba; |
| 2999 | axchg->ndlp = ndlp; |
| 3000 | axchg->size = size; |
| 3001 | axchg->oxid = oxid; |
| 3002 | axchg->sid = sid; |
| 3003 | axchg->wqeq = NULL; |
| 3004 | axchg->state = LPFC_NVME_STE_LS_RCV; |
| 3005 | axchg->entry_cnt = 1; |
| 3006 | axchg->rqb_buffer = (void *)nvmebuf; |
| 3007 | axchg->hdwq = &phba->sli4_hba.hdwq[0]; |
| 3008 | axchg->payload = nvmebuf->dbuf.virt; |
| 3009 | INIT_LIST_HEAD(&axchg->list); |
| 3010 | |
James Smart | 243156c | 2021-01-04 10:02:37 -0800 | [diff] [blame] | 3011 | if (phba->nvmet_support) { |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 3012 | ret = lpfc_nvmet_handle_lsreq(phba, axchg); |
James Smart | 243156c | 2021-01-04 10:02:37 -0800 | [diff] [blame] | 3013 | spin_lock_irq(&ndlp->lock); |
| 3014 | if (!ret && !(ndlp->fc4_xpt_flags & NLP_XPT_HAS_HH)) { |
| 3015 | ndlp->fc4_xpt_flags |= NLP_XPT_HAS_HH; |
| 3016 | spin_unlock_irq(&ndlp->lock); |
| 3017 | |
| 3018 | /* This reference is a single occurrence to hold the |
| 3019 | * node valid until the nvmet transport calls |
| 3020 | * host_release. |
| 3021 | */ |
| 3022 | if (!lpfc_nlp_get(ndlp)) |
| 3023 | goto out_fail; |
| 3024 | |
| 3025 | lpfc_printf_log(phba, KERN_ERR, LOG_NODE, |
James Smart | f115612 | 2021-04-11 18:31:24 -0700 | [diff] [blame] | 3026 | "6206 NVMET unsol ls_req ndlp x%px " |
James Smart | 243156c | 2021-01-04 10:02:37 -0800 | [diff] [blame] | 3027 | "DID x%x xflags x%x refcnt %d\n", |
| 3028 | ndlp, ndlp->nlp_DID, |
| 3029 | ndlp->fc4_xpt_flags, |
| 3030 | kref_read(&ndlp->kref)); |
| 3031 | } else { |
| 3032 | spin_unlock_irq(&ndlp->lock); |
| 3033 | } |
| 3034 | } else { |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 3035 | ret = lpfc_nvme_handle_lsreq(phba, axchg); |
James Smart | 243156c | 2021-01-04 10:02:37 -0800 | [diff] [blame] | 3036 | } |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 3037 | |
| 3038 | /* if zero, LS was successfully handled. If non-zero, LS not handled */ |
| 3039 | if (!ret) |
| 3040 | return; |
| 3041 | |
James Smart | 243156c | 2021-01-04 10:02:37 -0800 | [diff] [blame] | 3042 | out_fail: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3043 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 3044 | "6155 Drop NVME LS from DID %06X: SID %06X OXID x%X " |
| 3045 | "NVMe%s handler failed %d\n", |
| 3046 | did, sid, oxid, |
| 3047 | (phba->nvmet_support) ? "T" : "I", ret); |
| 3048 | |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 3049 | /* recycle receive buffer */ |
| 3050 | lpfc_in_buf_free(phba, &nvmebuf->dbuf); |
| 3051 | |
| 3052 | /* If start of new exchange, abort it */ |
James Smart | 4e57e0b | 2020-05-20 11:59:28 -0700 | [diff] [blame] | 3053 | if (axchg && (fctl & FC_FC_FIRST_SEQ && !(fctl & FC_FC_EX_CTX))) |
| 3054 | ret = lpfc_nvme_unsol_ls_issue_abort(phba, axchg, sid, oxid); |
| 3055 | |
| 3056 | if (ret) |
| 3057 | kfree(axchg); |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 3058 | } |
| 3059 | |
| 3060 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3061 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence |
| 3062 | * @phba: Pointer to HBA context object. |
| 3063 | * @pring: Pointer to driver SLI ring object. |
| 3064 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. |
| 3065 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. |
| 3066 | * @fch_type: the type for the first frame of the sequence. |
| 3067 | * |
| 3068 | * This function is called with no lock held. This function uses the r_ctl and |
| 3069 | * type of the received sequence to find the correct callback function to call |
| 3070 | * to process the sequence. |
| 3071 | **/ |
| 3072 | static int |
| 3073 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3074 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, |
| 3075 | uint32_t fch_type) |
| 3076 | { |
| 3077 | int i; |
| 3078 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3079 | switch (fch_type) { |
| 3080 | case FC_TYPE_NVME: |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 3081 | lpfc_nvme_unsol_ls_handler(phba, saveq); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3082 | return 1; |
| 3083 | default: |
| 3084 | break; |
| 3085 | } |
| 3086 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3087 | /* unSolicited Responses */ |
| 3088 | if (pring->prt[0].profile) { |
| 3089 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 3090 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 3091 | saveq); |
| 3092 | return 1; |
| 3093 | } |
| 3094 | /* We must search, based on rctl / type |
| 3095 | for the right routine */ |
| 3096 | for (i = 0; i < pring->num_mask; i++) { |
| 3097 | if ((pring->prt[i].rctl == fch_r_ctl) && |
| 3098 | (pring->prt[i].type == fch_type)) { |
| 3099 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 3100 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 3101 | (phba, pring, saveq); |
| 3102 | return 1; |
| 3103 | } |
| 3104 | } |
| 3105 | return 0; |
| 3106 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3107 | |
| 3108 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3109 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3110 | * @phba: Pointer to HBA context object. |
| 3111 | * @pring: Pointer to driver SLI ring object. |
| 3112 | * @saveq: Pointer to the unsolicited iocb. |
| 3113 | * |
| 3114 | * This function is called with no lock held by the ring event handler |
| 3115 | * when there is an unsolicited iocb posted to the response ring by the |
| 3116 | * firmware. This function gets the buffer associated with the iocbs |
| 3117 | * and calls the event handler for the ring. This function handles both |
| 3118 | * qring buffers and hbq buffers. |
| 3119 | * When the function returns 1 the caller can free the iocb object otherwise |
| 3120 | * upper layer functions will free the iocb objects. |
| 3121 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3122 | static int |
| 3123 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3124 | struct lpfc_iocbq *saveq) |
| 3125 | { |
| 3126 | IOCB_t * irsp; |
| 3127 | WORD5 * w5p; |
| 3128 | uint32_t Rctl, Type; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3129 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3130 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3131 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3132 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3133 | |
| 3134 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 3135 | if (pring->lpfc_sli_rcv_async_status) |
| 3136 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 3137 | else |
| 3138 | lpfc_printf_log(phba, |
| 3139 | KERN_WARNING, |
| 3140 | LOG_SLI, |
| 3141 | "0316 Ring %d handler: unexpected " |
| 3142 | "ASYNC_STATUS iocb received evt_code " |
| 3143 | "0x%x\n", |
| 3144 | pring->ringno, |
| 3145 | irsp->un.asyncstat.evt_code); |
| 3146 | return 1; |
| 3147 | } |
| 3148 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3149 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 3150 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 3151 | if (irsp->ulpBdeCount > 0) { |
| 3152 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 3153 | irsp->un.ulpWord[3]); |
| 3154 | lpfc_in_buf_free(phba, dmzbuf); |
| 3155 | } |
| 3156 | |
| 3157 | if (irsp->ulpBdeCount > 1) { |
| 3158 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 3159 | irsp->unsli3.sli3Words[3]); |
| 3160 | lpfc_in_buf_free(phba, dmzbuf); |
| 3161 | } |
| 3162 | |
| 3163 | if (irsp->ulpBdeCount > 2) { |
| 3164 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 3165 | irsp->unsli3.sli3Words[7]); |
| 3166 | lpfc_in_buf_free(phba, dmzbuf); |
| 3167 | } |
| 3168 | |
| 3169 | return 1; |
| 3170 | } |
| 3171 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3172 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3173 | if (irsp->ulpBdeCount != 0) { |
| 3174 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3175 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3176 | if (!saveq->context2) |
| 3177 | lpfc_printf_log(phba, |
| 3178 | KERN_ERR, |
| 3179 | LOG_SLI, |
| 3180 | "0341 Ring %d Cannot find buffer for " |
| 3181 | "an unsolicited iocb. tag 0x%x\n", |
| 3182 | pring->ringno, |
| 3183 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3184 | } |
| 3185 | if (irsp->ulpBdeCount == 2) { |
| 3186 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3187 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3188 | if (!saveq->context3) |
| 3189 | lpfc_printf_log(phba, |
| 3190 | KERN_ERR, |
| 3191 | LOG_SLI, |
| 3192 | "0342 Ring %d Cannot find buffer for an" |
| 3193 | " unsolicited iocb. tag 0x%x\n", |
| 3194 | pring->ringno, |
| 3195 | irsp->unsli3.sli3Words[7]); |
| 3196 | } |
| 3197 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3198 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3199 | if (irsp->ulpBdeCount != 0) { |
| 3200 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 3201 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 3202 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3203 | lpfc_printf_log(phba, |
| 3204 | KERN_ERR, |
| 3205 | LOG_SLI, |
| 3206 | "0343 Ring %d Cannot find " |
| 3207 | "buffer for an unsolicited iocb" |
| 3208 | ". tag 0x%x\n", pring->ringno, |
| 3209 | irsp->un.ulpWord[3]); |
| 3210 | } |
| 3211 | if (irsp->ulpBdeCount == 2) { |
| 3212 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 3213 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 3214 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3215 | lpfc_printf_log(phba, |
| 3216 | KERN_ERR, |
| 3217 | LOG_SLI, |
| 3218 | "0344 Ring %d Cannot find " |
| 3219 | "buffer for an unsolicited " |
| 3220 | "iocb. tag 0x%x\n", |
| 3221 | pring->ringno, |
| 3222 | irsp->unsli3.sli3Words[7]); |
| 3223 | } |
| 3224 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3225 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 3226 | if (irsp->ulpBdeCount != 0 && |
| 3227 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 3228 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 3229 | int found = 0; |
| 3230 | |
| 3231 | /* search continue save q for same XRI */ |
| 3232 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3233 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
| 3234 | saveq->iocb.unsli3.rcvsli3.ox_id) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 3235 | list_add_tail(&saveq->list, &iocbq->list); |
| 3236 | found = 1; |
| 3237 | break; |
| 3238 | } |
| 3239 | } |
| 3240 | if (!found) |
| 3241 | list_add_tail(&saveq->clist, |
| 3242 | &pring->iocb_continue_saveq); |
| 3243 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 3244 | list_del_init(&iocbq->clist); |
| 3245 | saveq = iocbq; |
| 3246 | irsp = &(saveq->iocb); |
| 3247 | } else |
| 3248 | return 0; |
| 3249 | } |
| 3250 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 3251 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 3252 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3253 | Rctl = FC_RCTL_ELS_REQ; |
| 3254 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 3255 | } else { |
| 3256 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 3257 | Rctl = w5p->hcsw.Rctl; |
| 3258 | Type = w5p->hcsw.Type; |
| 3259 | |
| 3260 | /* Firmware Workaround */ |
| 3261 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 3262 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 3263 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3264 | Rctl = FC_RCTL_ELS_REQ; |
| 3265 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 3266 | w5p->hcsw.Rctl = Rctl; |
| 3267 | w5p->hcsw.Type = Type; |
| 3268 | } |
| 3269 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3270 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3271 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3272 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3273 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3274 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3275 | pring->ringno, Rctl, Type); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3276 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3277 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3278 | } |
| 3279 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3280 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3281 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3282 | * @phba: Pointer to HBA context object. |
| 3283 | * @pring: Pointer to driver SLI ring object. |
| 3284 | * @prspiocb: Pointer to response iocb object. |
| 3285 | * |
| 3286 | * This function looks up the iocb_lookup table to get the command iocb |
| 3287 | * corresponding to the given response iocb using the iotag of the |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3288 | * response iocb. The driver calls this function with the hbalock held |
| 3289 | * for SLI3 ports or the ring lock held for SLI4 ports. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3290 | * This function returns the command iocb object if it finds the command |
| 3291 | * iocb else returns NULL. |
| 3292 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3293 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3294 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 3295 | struct lpfc_sli_ring *pring, |
| 3296 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3297 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3298 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 3299 | uint16_t iotag; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3300 | spinlock_t *temp_lock = NULL; |
| 3301 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3302 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3303 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3304 | temp_lock = &pring->ring_lock; |
| 3305 | else |
| 3306 | temp_lock = &phba->hbalock; |
| 3307 | |
| 3308 | spin_lock_irqsave(temp_lock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3309 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3310 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3311 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 3312 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3313 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3314 | /* remove from txcmpl queue list */ |
| 3315 | list_del_init(&cmd_iocb->list); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3316 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3317 | pring->txcmplq_cnt--; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3318 | spin_unlock_irqrestore(temp_lock, iflag); |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3319 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 3320 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3321 | } |
| 3322 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3323 | spin_unlock_irqrestore(temp_lock, iflag); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3324 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3325 | "0317 iotag x%x is out of " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3326 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3327 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3328 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3329 | return NULL; |
| 3330 | } |
| 3331 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3332 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3333 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag |
| 3334 | * @phba: Pointer to HBA context object. |
| 3335 | * @pring: Pointer to driver SLI ring object. |
| 3336 | * @iotag: IOCB tag. |
| 3337 | * |
| 3338 | * 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] | 3339 | * corresponding to the given iotag. The driver calls this function with |
| 3340 | * 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] | 3341 | * This function returns the command iocb object if it finds the command |
| 3342 | * iocb else returns NULL. |
| 3343 | **/ |
| 3344 | static struct lpfc_iocbq * |
| 3345 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, |
| 3346 | struct lpfc_sli_ring *pring, uint16_t iotag) |
| 3347 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3348 | struct lpfc_iocbq *cmd_iocb = NULL; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3349 | spinlock_t *temp_lock = NULL; |
| 3350 | unsigned long iflag = 0; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3351 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3352 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3353 | temp_lock = &pring->ring_lock; |
| 3354 | else |
| 3355 | temp_lock = &phba->hbalock; |
| 3356 | |
| 3357 | spin_lock_irqsave(temp_lock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3358 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 3359 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3360 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
| 3361 | /* remove from txcmpl queue list */ |
| 3362 | list_del_init(&cmd_iocb->list); |
| 3363 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3364 | pring->txcmplq_cnt--; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3365 | spin_unlock_irqrestore(temp_lock, iflag); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3366 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 3367 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3368 | } |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3369 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3370 | spin_unlock_irqrestore(temp_lock, iflag); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3371 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3372 | "0372 iotag x%x lookup error: max iotag (x%x) " |
| 3373 | "iocb_flag x%x\n", |
| 3374 | iotag, phba->sli.last_iotag, |
| 3375 | cmd_iocb ? cmd_iocb->iocb_flag : 0xffff); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3376 | return NULL; |
| 3377 | } |
| 3378 | |
| 3379 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3380 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3381 | * @phba: Pointer to HBA context object. |
| 3382 | * @pring: Pointer to driver SLI ring object. |
| 3383 | * @saveq: Pointer to the response iocb to be processed. |
| 3384 | * |
| 3385 | * This function is called by the ring event handler for non-fcp |
| 3386 | * rings when there is a new response iocb in the response ring. |
| 3387 | * The caller is not required to hold any locks. This function |
| 3388 | * gets the command iocb associated with the response iocb and |
| 3389 | * calls the completion handler for the command iocb. If there |
| 3390 | * is no completion handler, the function will free the resources |
| 3391 | * associated with command iocb. If the response iocb is for |
| 3392 | * an already aborted command iocb, the status of the completion |
| 3393 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 3394 | * This function always returns 1. |
| 3395 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3396 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3397 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3398 | struct lpfc_iocbq *saveq) |
| 3399 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3400 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3401 | int rc = 1; |
| 3402 | unsigned long iflag; |
| 3403 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3404 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3405 | if (cmdiocbp) { |
| 3406 | if (cmdiocbp->iocb_cmpl) { |
| 3407 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3408 | * If an ELS command failed send an event to mgmt |
| 3409 | * application. |
| 3410 | */ |
| 3411 | if (saveq->iocb.ulpStatus && |
| 3412 | (pring->ringno == LPFC_ELS_RING) && |
| 3413 | (cmdiocbp->iocb.ulpCommand == |
| 3414 | CMD_ELS_REQUEST64_CR)) |
| 3415 | lpfc_send_els_failure_event(phba, |
| 3416 | cmdiocbp, saveq); |
| 3417 | |
| 3418 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3419 | * Post all ELS completions to the worker thread. |
| 3420 | * All other are passed to the completion callback. |
| 3421 | */ |
| 3422 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3423 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 3424 | (cmdiocbp->iocb_flag & |
| 3425 | LPFC_DRIVER_ABORTED)) { |
| 3426 | spin_lock_irqsave(&phba->hbalock, |
| 3427 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3428 | cmdiocbp->iocb_flag &= |
| 3429 | ~LPFC_DRIVER_ABORTED; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3430 | spin_unlock_irqrestore(&phba->hbalock, |
| 3431 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3432 | saveq->iocb.ulpStatus = |
| 3433 | IOSTAT_LOCAL_REJECT; |
| 3434 | saveq->iocb.un.ulpWord[4] = |
| 3435 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3436 | |
| 3437 | /* Firmware could still be in progress |
| 3438 | * of DMAing payload, so don't free data |
| 3439 | * buffer till after a hbeat. |
| 3440 | */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3441 | spin_lock_irqsave(&phba->hbalock, |
| 3442 | iflag); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3443 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3444 | spin_unlock_irqrestore(&phba->hbalock, |
| 3445 | iflag); |
| 3446 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3447 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3448 | if (saveq->iocb_flag & |
| 3449 | LPFC_EXCHANGE_BUSY) { |
| 3450 | /* Set cmdiocb flag for the |
| 3451 | * exchange busy so sgl (xri) |
| 3452 | * will not be released until |
| 3453 | * the abort xri is received |
| 3454 | * from hba. |
| 3455 | */ |
| 3456 | spin_lock_irqsave( |
| 3457 | &phba->hbalock, iflag); |
| 3458 | cmdiocbp->iocb_flag |= |
| 3459 | LPFC_EXCHANGE_BUSY; |
| 3460 | spin_unlock_irqrestore( |
| 3461 | &phba->hbalock, iflag); |
| 3462 | } |
| 3463 | if (cmdiocbp->iocb_flag & |
| 3464 | LPFC_DRIVER_ABORTED) { |
| 3465 | /* |
| 3466 | * Clear LPFC_DRIVER_ABORTED |
| 3467 | * bit in case it was driver |
| 3468 | * initiated abort. |
| 3469 | */ |
| 3470 | spin_lock_irqsave( |
| 3471 | &phba->hbalock, iflag); |
| 3472 | cmdiocbp->iocb_flag &= |
| 3473 | ~LPFC_DRIVER_ABORTED; |
| 3474 | spin_unlock_irqrestore( |
| 3475 | &phba->hbalock, iflag); |
| 3476 | cmdiocbp->iocb.ulpStatus = |
| 3477 | IOSTAT_LOCAL_REJECT; |
| 3478 | cmdiocbp->iocb.un.ulpWord[4] = |
| 3479 | IOERR_ABORT_REQUESTED; |
| 3480 | /* |
| 3481 | * For SLI4, irsiocb contains |
| 3482 | * NO_XRI in sli_xritag, it |
| 3483 | * shall not affect releasing |
| 3484 | * sgl (xri) process. |
| 3485 | */ |
| 3486 | saveq->iocb.ulpStatus = |
| 3487 | IOSTAT_LOCAL_REJECT; |
| 3488 | saveq->iocb.un.ulpWord[4] = |
| 3489 | IOERR_SLI_ABORTED; |
| 3490 | spin_lock_irqsave( |
| 3491 | &phba->hbalock, iflag); |
| 3492 | saveq->iocb_flag |= |
| 3493 | LPFC_DELAY_MEM_FREE; |
| 3494 | spin_unlock_irqrestore( |
| 3495 | &phba->hbalock, iflag); |
| 3496 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3497 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3498 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3499 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3500 | } else |
| 3501 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3502 | } else { |
| 3503 | /* |
| 3504 | * Unknown initiating command based on the response iotag. |
| 3505 | * This could be the case on the ELS ring because of |
| 3506 | * lpfc_els_abort(). |
| 3507 | */ |
| 3508 | if (pring->ringno != LPFC_ELS_RING) { |
| 3509 | /* |
| 3510 | * Ring <ringno> handler: unexpected completion IoTag |
| 3511 | * <IoTag> |
| 3512 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3513 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3514 | "0322 Ring %d handler: " |
| 3515 | "unexpected completion IoTag x%x " |
| 3516 | "Data: x%x x%x x%x x%x\n", |
| 3517 | pring->ringno, |
| 3518 | saveq->iocb.ulpIoTag, |
| 3519 | saveq->iocb.ulpStatus, |
| 3520 | saveq->iocb.un.ulpWord[4], |
| 3521 | saveq->iocb.ulpCommand, |
| 3522 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3523 | } |
| 3524 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3525 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3526 | return rc; |
| 3527 | } |
| 3528 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3529 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3530 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3531 | * @phba: Pointer to HBA context object. |
| 3532 | * @pring: Pointer to driver SLI ring object. |
| 3533 | * |
| 3534 | * This function is called from the iocb ring event handlers when |
| 3535 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 3536 | * an error attention condition to the worker thread and the worker |
| 3537 | * thread will transition the HBA to offline state. |
| 3538 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3539 | static void |
| 3540 | 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] | 3541 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3542 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3543 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3544 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3545 | * rsp ring <portRspMax> |
| 3546 | */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3547 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3548 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3549 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3550 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3551 | pring->sli.sli3.numRiocb); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3552 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3553 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3554 | |
| 3555 | /* |
| 3556 | * All error attention handlers are posted to |
| 3557 | * worker thread |
| 3558 | */ |
| 3559 | phba->work_ha |= HA_ERATT; |
| 3560 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3561 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3562 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3563 | |
| 3564 | return; |
| 3565 | } |
| 3566 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3567 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3568 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 3569 | * @t: Context to fetch pointer to address of HBA context object from. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3570 | * |
| 3571 | * This function is invoked by the Error Attention polling timer when the |
| 3572 | * timer times out. It will check the SLI Error Attention register for |
| 3573 | * possible attention events. If so, it will post an Error Attention event |
| 3574 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 3575 | * Error Attention polling timer for the next poll. |
| 3576 | **/ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3577 | void lpfc_poll_eratt(struct timer_list *t) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3578 | { |
| 3579 | struct lpfc_hba *phba; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 3580 | uint32_t eratt = 0; |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3581 | uint64_t sli_intr, cnt; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3582 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3583 | phba = from_timer(phba, t, eratt_poll); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3584 | |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3585 | /* Here we will also keep track of interrupts per sec of the hba */ |
| 3586 | sli_intr = phba->sli.slistat.sli_intr; |
| 3587 | |
| 3588 | if (phba->sli.slistat.sli_prev_intr > sli_intr) |
| 3589 | cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) + |
| 3590 | sli_intr); |
| 3591 | else |
| 3592 | cnt = (sli_intr - phba->sli.slistat.sli_prev_intr); |
| 3593 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 3594 | /* 64-bit integer division not supported on 32-bit x86 - use do_div */ |
| 3595 | do_div(cnt, phba->eratt_poll_interval); |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3596 | phba->sli.slistat.sli_ips = cnt; |
| 3597 | |
| 3598 | phba->sli.slistat.sli_prev_intr = sli_intr; |
| 3599 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3600 | /* Check chip HA register for error event */ |
| 3601 | eratt = lpfc_sli_check_eratt(phba); |
| 3602 | |
| 3603 | if (eratt) |
| 3604 | /* Tell the worker thread there is work to do */ |
| 3605 | lpfc_worker_wake_up(phba); |
| 3606 | else |
| 3607 | /* Restart the timer for next eratt poll */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3608 | mod_timer(&phba->eratt_poll, |
| 3609 | jiffies + |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 3610 | msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3611 | return; |
| 3612 | } |
| 3613 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3614 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3615 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3616 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3617 | * @phba: Pointer to HBA context object. |
| 3618 | * @pring: Pointer to driver SLI ring object. |
| 3619 | * @mask: Host attention register mask for this ring. |
| 3620 | * |
| 3621 | * This function is called from the interrupt context when there is a ring |
| 3622 | * event for the fcp ring. The caller does not hold any lock. |
| 3623 | * 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] | 3624 | * 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] | 3625 | * LE bit set. The function will call the completion handler of the command iocb |
| 3626 | * if the response iocb indicates a completion for a command iocb or it is |
| 3627 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 3628 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3629 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3630 | * to check it explicitly. |
| 3631 | */ |
| 3632 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3633 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 3634 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3635 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3636 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3637 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3638 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3639 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 3640 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3641 | uint32_t status; |
| 3642 | uint32_t portRspPut, portRspMax; |
| 3643 | int rc = 1; |
| 3644 | lpfc_iocb_type type; |
| 3645 | unsigned long iflag; |
| 3646 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3647 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3648 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3649 | pring->stats.iocb_event++; |
| 3650 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3651 | /* |
| 3652 | * The next available response entry should never exceed the maximum |
| 3653 | * entries. If it does, treat it as an adapter hardware error. |
| 3654 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3655 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3656 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3657 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3658 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3659 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3660 | return 1; |
| 3661 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3662 | if (phba->fcp_ring_in_use) { |
| 3663 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3664 | return 1; |
| 3665 | } else |
| 3666 | phba->fcp_ring_in_use = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3667 | |
| 3668 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3669 | while (pring->sli.sli3.rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3670 | /* |
| 3671 | * Fetch an entry off the ring and copy it into a local data |
| 3672 | * structure. The copy involves a byte-swap since the |
| 3673 | * network byte order and pci byte orders are different. |
| 3674 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3675 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3676 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3677 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3678 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3679 | pring->sli.sli3.rspidx = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3680 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3681 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 3682 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3683 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3684 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3685 | irsp = &rspiocbq.iocb; |
| 3686 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3687 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 3688 | pring->stats.iocb_rsp++; |
| 3689 | rsp_cmpl++; |
| 3690 | |
| 3691 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3692 | /* |
| 3693 | * If resource errors reported from HBA, reduce |
| 3694 | * queuedepths of the SCSI device. |
| 3695 | */ |
| 3696 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3697 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3698 | IOERR_NO_RESOURCES)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3699 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3700 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3701 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3702 | } |
| 3703 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3704 | /* Rsp ring <ringno> error: IOCB */ |
| 3705 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3706 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3707 | "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] | 3708 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3709 | irsp->un.ulpWord[0], |
| 3710 | irsp->un.ulpWord[1], |
| 3711 | irsp->un.ulpWord[2], |
| 3712 | irsp->un.ulpWord[3], |
| 3713 | irsp->un.ulpWord[4], |
| 3714 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3715 | *(uint32_t *)&irsp->un1, |
| 3716 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3717 | } |
| 3718 | |
| 3719 | switch (type) { |
| 3720 | case LPFC_ABORT_IOCB: |
| 3721 | case LPFC_SOL_IOCB: |
| 3722 | /* |
| 3723 | * Idle exchange closed via ABTS from port. No iocb |
| 3724 | * resources need to be recovered. |
| 3725 | */ |
| 3726 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3727 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3728 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3729 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3730 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3731 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3732 | break; |
| 3733 | } |
| 3734 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3735 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3736 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 3737 | &rspiocbq); |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3738 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3739 | if (unlikely(!cmdiocbq)) |
| 3740 | break; |
| 3741 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 3742 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 3743 | if (cmdiocbq->iocb_cmpl) { |
| 3744 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3745 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 3746 | &rspiocbq); |
| 3747 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3748 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3749 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3750 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3751 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3752 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3753 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3754 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3755 | default: |
| 3756 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3757 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3758 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3759 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 3760 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 3761 | dev_warn(&((phba->pcidev)->dev), |
| 3762 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3763 | phba->brd_no, adaptermsg); |
| 3764 | } else { |
| 3765 | /* Unknown IOCB command */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3766 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3767 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3768 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3769 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3770 | irsp->ulpStatus, |
| 3771 | irsp->ulpIoTag, |
| 3772 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3773 | } |
| 3774 | break; |
| 3775 | } |
| 3776 | |
| 3777 | /* |
| 3778 | * The response IOCB has been processed. Update the ring |
| 3779 | * pointer in SLIM. If the port response put pointer has not |
| 3780 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 3781 | * response put pointer. |
| 3782 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3783 | writel(pring->sli.sli3.rspidx, |
| 3784 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3785 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3786 | if (pring->sli.sli3.rspidx == portRspPut) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3787 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3788 | } |
| 3789 | |
| 3790 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 3791 | pring->stats.iocb_rsp_full++; |
| 3792 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3793 | writel(status, phba->CAregaddr); |
| 3794 | readl(phba->CAregaddr); |
| 3795 | } |
| 3796 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3797 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3798 | pring->stats.iocb_cmd_empty++; |
| 3799 | |
| 3800 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3801 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3802 | lpfc_sli_resume_iocb(phba, pring); |
| 3803 | |
| 3804 | if ((pring->lpfc_sli_cmd_available)) |
| 3805 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3806 | |
| 3807 | } |
| 3808 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3809 | phba->fcp_ring_in_use = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3810 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3811 | return rc; |
| 3812 | } |
| 3813 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3814 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3815 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
| 3816 | * @phba: Pointer to HBA context object. |
| 3817 | * @pring: Pointer to driver SLI ring object. |
| 3818 | * @rspiocbp: Pointer to driver response IOCB object. |
| 3819 | * |
| 3820 | * This function is called from the worker thread when there is a slow-path |
| 3821 | * response IOCB to process. This function chains all the response iocbs until |
| 3822 | * seeing the iocb with the LE bit set. The function will call |
| 3823 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a |
| 3824 | * completion of a command iocb. The function will call the |
| 3825 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. |
| 3826 | * The function frees the resources or calls the completion handler if this |
| 3827 | * iocb is an abort completion. The function returns NULL when the response |
| 3828 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise |
| 3829 | * this function shall chain the iocb on to the iocb_continueq and return the |
| 3830 | * response iocb passed in. |
| 3831 | **/ |
| 3832 | static struct lpfc_iocbq * |
| 3833 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3834 | struct lpfc_iocbq *rspiocbp) |
| 3835 | { |
| 3836 | struct lpfc_iocbq *saveq; |
| 3837 | struct lpfc_iocbq *cmdiocbp; |
| 3838 | struct lpfc_iocbq *next_iocb; |
| 3839 | IOCB_t *irsp = NULL; |
| 3840 | uint32_t free_saveq; |
| 3841 | uint8_t iocb_cmd_type; |
| 3842 | lpfc_iocb_type type; |
| 3843 | unsigned long iflag; |
| 3844 | int rc; |
| 3845 | |
| 3846 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3847 | /* First add the response iocb to the countinueq list */ |
| 3848 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| 3849 | pring->iocb_continueq_cnt++; |
| 3850 | |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 3851 | /* Now, determine whether the list is completed for processing */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3852 | irsp = &rspiocbp->iocb; |
| 3853 | if (irsp->ulpLe) { |
| 3854 | /* |
| 3855 | * By default, the driver expects to free all resources |
| 3856 | * associated with this iocb completion. |
| 3857 | */ |
| 3858 | free_saveq = 1; |
| 3859 | saveq = list_get_first(&pring->iocb_continueq, |
| 3860 | struct lpfc_iocbq, list); |
| 3861 | irsp = &(saveq->iocb); |
| 3862 | list_del_init(&pring->iocb_continueq); |
| 3863 | pring->iocb_continueq_cnt = 0; |
| 3864 | |
| 3865 | pring->stats.iocb_rsp++; |
| 3866 | |
| 3867 | /* |
| 3868 | * If resource errors reported from HBA, reduce |
| 3869 | * queuedepths of the SCSI device. |
| 3870 | */ |
| 3871 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3872 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3873 | IOERR_NO_RESOURCES)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3874 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3875 | phba->lpfc_rampdown_queue_depth(phba); |
| 3876 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3877 | } |
| 3878 | |
| 3879 | if (irsp->ulpStatus) { |
| 3880 | /* Rsp ring <ringno> error: IOCB */ |
| 3881 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3882 | "0328 Rsp Ring %d error: " |
| 3883 | "IOCB Data: " |
| 3884 | "x%x x%x x%x x%x " |
| 3885 | "x%x x%x x%x x%x " |
| 3886 | "x%x x%x x%x x%x " |
| 3887 | "x%x x%x x%x x%x\n", |
| 3888 | pring->ringno, |
| 3889 | irsp->un.ulpWord[0], |
| 3890 | irsp->un.ulpWord[1], |
| 3891 | irsp->un.ulpWord[2], |
| 3892 | irsp->un.ulpWord[3], |
| 3893 | irsp->un.ulpWord[4], |
| 3894 | irsp->un.ulpWord[5], |
| 3895 | *(((uint32_t *) irsp) + 6), |
| 3896 | *(((uint32_t *) irsp) + 7), |
| 3897 | *(((uint32_t *) irsp) + 8), |
| 3898 | *(((uint32_t *) irsp) + 9), |
| 3899 | *(((uint32_t *) irsp) + 10), |
| 3900 | *(((uint32_t *) irsp) + 11), |
| 3901 | *(((uint32_t *) irsp) + 12), |
| 3902 | *(((uint32_t *) irsp) + 13), |
| 3903 | *(((uint32_t *) irsp) + 14), |
| 3904 | *(((uint32_t *) irsp) + 15)); |
| 3905 | } |
| 3906 | |
| 3907 | /* |
| 3908 | * Fetch the IOCB command type and call the correct completion |
| 3909 | * routine. Solicited and Unsolicited IOCBs on the ELS ring |
| 3910 | * get freed back to the lpfc_iocb_list by the discovery |
| 3911 | * kernel thread. |
| 3912 | */ |
| 3913 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 3914 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 3915 | switch (type) { |
| 3916 | case LPFC_SOL_IOCB: |
| 3917 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3918 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); |
| 3919 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3920 | break; |
| 3921 | |
| 3922 | case LPFC_UNSOL_IOCB: |
| 3923 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3924 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); |
| 3925 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3926 | if (!rc) |
| 3927 | free_saveq = 0; |
| 3928 | break; |
| 3929 | |
| 3930 | case LPFC_ABORT_IOCB: |
| 3931 | cmdiocbp = NULL; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3932 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) { |
| 3933 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3934 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, |
| 3935 | saveq); |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3936 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3937 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3938 | if (cmdiocbp) { |
| 3939 | /* Call the specified completion routine */ |
| 3940 | if (cmdiocbp->iocb_cmpl) { |
| 3941 | spin_unlock_irqrestore(&phba->hbalock, |
| 3942 | iflag); |
| 3943 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, |
| 3944 | saveq); |
| 3945 | spin_lock_irqsave(&phba->hbalock, |
| 3946 | iflag); |
| 3947 | } else |
| 3948 | __lpfc_sli_release_iocbq(phba, |
| 3949 | cmdiocbp); |
| 3950 | } |
| 3951 | break; |
| 3952 | |
| 3953 | case LPFC_UNKNOWN_IOCB: |
| 3954 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3955 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3956 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3957 | memcpy(&adaptermsg[0], (uint8_t *)irsp, |
| 3958 | MAX_MSG_DATA); |
| 3959 | dev_warn(&((phba->pcidev)->dev), |
| 3960 | "lpfc%d: %s\n", |
| 3961 | phba->brd_no, adaptermsg); |
| 3962 | } else { |
| 3963 | /* Unknown IOCB command */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3964 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3965 | "0335 Unknown IOCB " |
| 3966 | "command Data: x%x " |
| 3967 | "x%x x%x x%x\n", |
| 3968 | irsp->ulpCommand, |
| 3969 | irsp->ulpStatus, |
| 3970 | irsp->ulpIoTag, |
| 3971 | irsp->ulpContext); |
| 3972 | } |
| 3973 | break; |
| 3974 | } |
| 3975 | |
| 3976 | if (free_saveq) { |
| 3977 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 3978 | &saveq->list, list) { |
James Smart | 61f35bf | 2013-05-31 17:03:48 -0400 | [diff] [blame] | 3979 | list_del_init(&rspiocbp->list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3980 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
| 3981 | } |
| 3982 | __lpfc_sli_release_iocbq(phba, saveq); |
| 3983 | } |
| 3984 | rspiocbp = NULL; |
| 3985 | } |
| 3986 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3987 | return rspiocbp; |
| 3988 | } |
| 3989 | |
| 3990 | /** |
| 3991 | * 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] | 3992 | * @phba: Pointer to HBA context object. |
| 3993 | * @pring: Pointer to driver SLI ring object. |
| 3994 | * @mask: Host attention register mask for this ring. |
| 3995 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3996 | * This routine wraps the actual slow_ring event process routine from the |
| 3997 | * API jump table function pointer from the lpfc_hba struct. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3998 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3999 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4000 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 4001 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4002 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4003 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); |
| 4004 | } |
| 4005 | |
| 4006 | /** |
| 4007 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings |
| 4008 | * @phba: Pointer to HBA context object. |
| 4009 | * @pring: Pointer to driver SLI ring object. |
| 4010 | * @mask: Host attention register mask for this ring. |
| 4011 | * |
| 4012 | * This function is called from the worker thread when there is a ring event |
| 4013 | * for non-fcp rings. The caller does not hold any lock. The function will |
| 4014 | * remove each response iocb in the response ring and calls the handle |
| 4015 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 4016 | **/ |
| 4017 | static void |
| 4018 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, |
| 4019 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 4020 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4021 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4022 | IOCB_t *entry; |
| 4023 | IOCB_t *irsp = NULL; |
| 4024 | struct lpfc_iocbq *rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4025 | uint32_t portRspPut, portRspMax; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4026 | unsigned long iflag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4027 | uint32_t status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4028 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4029 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4030 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4031 | pring->stats.iocb_event++; |
| 4032 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4033 | /* |
| 4034 | * The next available response entry should never exceed the maximum |
| 4035 | * entries. If it does, treat it as an adapter hardware error. |
| 4036 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4037 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4038 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 4039 | if (portRspPut >= portRspMax) { |
| 4040 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4041 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4042 | * rsp ring <portRspMax> |
| 4043 | */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4044 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4045 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4046 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4047 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4048 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4049 | phba->link_state = LPFC_HBA_ERROR; |
| 4050 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4051 | |
| 4052 | phba->work_hs = HS_FFER3; |
| 4053 | lpfc_handle_eratt(phba); |
| 4054 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4055 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4056 | } |
| 4057 | |
| 4058 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4059 | while (pring->sli.sli3.rspidx != portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4060 | /* |
| 4061 | * Build a completion list and call the appropriate handler. |
| 4062 | * The process is to get the next available response iocb, get |
| 4063 | * a free iocb from the list, copy the response data into the |
| 4064 | * free iocb, insert to the continuation list, and update the |
| 4065 | * next response index to slim. This process makes response |
| 4066 | * iocb's in the ring available to DMA as fast as possible but |
| 4067 | * pays a penalty for a copy operation. Since the iocb is |
| 4068 | * only 32 bytes, this penalty is considered small relative to |
| 4069 | * the PCI reads for register values and a slim write. When |
| 4070 | * the ulpLe field is set, the entire Command has been |
| 4071 | * received. |
| 4072 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4073 | entry = lpfc_resp_iocb(phba, pring); |
| 4074 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4075 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4076 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4077 | if (rspiocbp == NULL) { |
| 4078 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 4079 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4080 | break; |
| 4081 | } |
| 4082 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4083 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 4084 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4085 | irsp = &rspiocbp->iocb; |
| 4086 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4087 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 4088 | pring->sli.sli3.rspidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4089 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 4090 | if (pring->ringno == LPFC_ELS_RING) { |
| 4091 | lpfc_debugfs_slow_ring_trc(phba, |
| 4092 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 4093 | *(((uint32_t *) irsp) + 4), |
| 4094 | *(((uint32_t *) irsp) + 6), |
| 4095 | *(((uint32_t *) irsp) + 7)); |
| 4096 | } |
| 4097 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4098 | writel(pring->sli.sli3.rspidx, |
| 4099 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4100 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4101 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 4102 | /* Handle the response IOCB */ |
| 4103 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); |
| 4104 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4105 | |
| 4106 | /* |
| 4107 | * If the port response put pointer has not been updated, sync |
| 4108 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 4109 | * response put pointer. |
| 4110 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4111 | if (pring->sli.sli3.rspidx == portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4112 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 4113 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4114 | } /* while (pring->sli.sli3.rspidx != portRspPut) */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4115 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4116 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4117 | /* At least one response entry has been freed */ |
| 4118 | pring->stats.iocb_rsp_full++; |
| 4119 | /* SET RxRE_RSP in Chip Att register */ |
| 4120 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 4121 | writel(status, phba->CAregaddr); |
| 4122 | readl(phba->CAregaddr); /* flush */ |
| 4123 | } |
| 4124 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 4125 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 4126 | pring->stats.iocb_cmd_empty++; |
| 4127 | |
| 4128 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4129 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4130 | lpfc_sli_resume_iocb(phba, pring); |
| 4131 | |
| 4132 | if ((pring->lpfc_sli_cmd_available)) |
| 4133 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 4134 | |
| 4135 | } |
| 4136 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4137 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4138 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4139 | } |
| 4140 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4141 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4142 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events |
| 4143 | * @phba: Pointer to HBA context object. |
| 4144 | * @pring: Pointer to driver SLI ring object. |
| 4145 | * @mask: Host attention register mask for this ring. |
| 4146 | * |
| 4147 | * This function is called from the worker thread when there is a pending |
| 4148 | * ELS response iocb on the driver internal slow-path response iocb worker |
| 4149 | * queue. The caller does not hold any lock. The function will remove each |
| 4150 | * response iocb from the response worker queue and calls the handle |
| 4151 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 4152 | **/ |
| 4153 | static void |
| 4154 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, |
| 4155 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 4156 | { |
| 4157 | struct lpfc_iocbq *irspiocbq; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4158 | struct hbq_dmabuf *dmabuf; |
| 4159 | struct lpfc_cq_event *cq_event; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4160 | unsigned long iflag; |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 4161 | int count = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4162 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4163 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 4164 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 4165 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 4166 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4167 | /* Get the response iocb from the head of work queue */ |
| 4168 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4169 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4170 | cq_event, struct lpfc_cq_event, list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4171 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4172 | |
| 4173 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 4174 | case CQE_CODE_COMPL_WQE: |
| 4175 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 4176 | cq_event); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4177 | /* Translate ELS WCQE to response IOCBQ */ |
| 4178 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, |
| 4179 | irspiocbq); |
| 4180 | if (irspiocbq) |
| 4181 | lpfc_sli_sp_handle_rspiocb(phba, pring, |
| 4182 | irspiocbq); |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 4183 | count++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4184 | break; |
| 4185 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4186 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4187 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 4188 | cq_event); |
| 4189 | lpfc_sli4_handle_received_buffer(phba, dmabuf); |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 4190 | count++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4191 | break; |
| 4192 | default: |
| 4193 | break; |
| 4194 | } |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 4195 | |
| 4196 | /* Limit the number of events to 64 to avoid soft lockups */ |
| 4197 | if (count == 64) |
| 4198 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4199 | } |
| 4200 | } |
| 4201 | |
| 4202 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4203 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4204 | * @phba: Pointer to HBA context object. |
| 4205 | * @pring: Pointer to driver SLI ring object. |
| 4206 | * |
| 4207 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 4208 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 4209 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 4210 | * the return of this function. The caller is not required to hold any locks. |
| 4211 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4212 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4213 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 4214 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4215 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4216 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4217 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4218 | if (pring->ringno == LPFC_ELS_RING) { |
| 4219 | lpfc_fabric_abort_hba(phba); |
| 4220 | } |
| 4221 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4222 | /* Error everything on txq and txcmplq |
| 4223 | * First do the txq. |
| 4224 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4225 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 4226 | spin_lock_irq(&pring->ring_lock); |
| 4227 | list_splice_init(&pring->txq, &completions); |
| 4228 | pring->txq_cnt = 0; |
| 4229 | spin_unlock_irq(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4230 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4231 | spin_lock_irq(&phba->hbalock); |
| 4232 | /* Next issue ABTS for everything on the txcmplq */ |
| 4233 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 4234 | lpfc_sli_issue_abort_iotag(phba, pring, iocb, NULL); |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4235 | spin_unlock_irq(&phba->hbalock); |
| 4236 | } else { |
| 4237 | spin_lock_irq(&phba->hbalock); |
| 4238 | list_splice_init(&pring->txq, &completions); |
| 4239 | pring->txq_cnt = 0; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4240 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4241 | /* Next issue ABTS for everything on the txcmplq */ |
| 4242 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 4243 | lpfc_sli_issue_abort_iotag(phba, pring, iocb, NULL); |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4244 | spin_unlock_irq(&phba->hbalock); |
| 4245 | } |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 4246 | /* Make sure HBA is alive */ |
| 4247 | lpfc_issue_hb_tmo(phba); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4248 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4249 | /* Cancel all the IOCBs from the completions list */ |
| 4250 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 4251 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4252 | } |
| 4253 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4254 | /** |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4255 | * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings |
| 4256 | * @phba: Pointer to HBA context object. |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4257 | * |
| 4258 | * This function aborts all iocbs in FCP rings and frees all the iocb |
| 4259 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 4260 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 4261 | * the return of this function. The caller is not required to hold any locks. |
| 4262 | **/ |
| 4263 | void |
| 4264 | lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba) |
| 4265 | { |
| 4266 | struct lpfc_sli *psli = &phba->sli; |
| 4267 | struct lpfc_sli_ring *pring; |
| 4268 | uint32_t i; |
| 4269 | |
| 4270 | /* Look on all the FCP Rings for the iotag */ |
| 4271 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4272 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4273 | pring = phba->sli4_hba.hdwq[i].io_wq->pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4274 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 4275 | } |
| 4276 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4277 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4278 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 4279 | } |
| 4280 | } |
| 4281 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4282 | /** |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4283 | * lpfc_sli_flush_io_rings - flush all iocbs in the IO ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4284 | * @phba: Pointer to HBA context object. |
| 4285 | * |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4286 | * 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] | 4287 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 4288 | * for all the iocb commands in txcmplq, they will just be returned with |
| 4289 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 4290 | * slot has been permanently disabled. |
| 4291 | **/ |
| 4292 | void |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4293 | lpfc_sli_flush_io_rings(struct lpfc_hba *phba) |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4294 | { |
| 4295 | LIST_HEAD(txq); |
| 4296 | LIST_HEAD(txcmplq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4297 | struct lpfc_sli *psli = &phba->sli; |
| 4298 | struct lpfc_sli_ring *pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4299 | uint32_t i; |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4300 | struct lpfc_iocbq *piocb, *next_iocb; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4301 | |
| 4302 | spin_lock_irq(&phba->hbalock); |
James Smart | 4cd7089 | 2020-03-22 11:12:57 -0700 | [diff] [blame] | 4303 | if (phba->hba_flag & HBA_IOQ_FLUSH || |
| 4304 | !phba->sli4_hba.hdwq) { |
| 4305 | spin_unlock_irq(&phba->hbalock); |
| 4306 | return; |
| 4307 | } |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4308 | /* Indicate the I/O queues are flushed */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4309 | phba->hba_flag |= HBA_IOQ_FLUSH; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4310 | spin_unlock_irq(&phba->hbalock); |
| 4311 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4312 | /* Look on all the FCP Rings for the iotag */ |
| 4313 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4314 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4315 | pring = phba->sli4_hba.hdwq[i].io_wq->pring; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4316 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4317 | spin_lock_irq(&pring->ring_lock); |
| 4318 | /* Retrieve everything on txq */ |
| 4319 | list_splice_init(&pring->txq, &txq); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4320 | list_for_each_entry_safe(piocb, next_iocb, |
| 4321 | &pring->txcmplq, list) |
| 4322 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4323 | /* Retrieve everything on the txcmplq */ |
| 4324 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 4325 | pring->txq_cnt = 0; |
| 4326 | pring->txcmplq_cnt = 0; |
| 4327 | spin_unlock_irq(&pring->ring_lock); |
| 4328 | |
| 4329 | /* Flush the txq */ |
| 4330 | lpfc_sli_cancel_iocbs(phba, &txq, |
| 4331 | IOSTAT_LOCAL_REJECT, |
| 4332 | IOERR_SLI_DOWN); |
| 4333 | /* Flush the txcmpq */ |
| 4334 | lpfc_sli_cancel_iocbs(phba, &txcmplq, |
| 4335 | IOSTAT_LOCAL_REJECT, |
| 4336 | IOERR_SLI_DOWN); |
| 4337 | } |
| 4338 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4339 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4340 | |
| 4341 | spin_lock_irq(&phba->hbalock); |
| 4342 | /* Retrieve everything on txq */ |
| 4343 | list_splice_init(&pring->txq, &txq); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4344 | list_for_each_entry_safe(piocb, next_iocb, |
| 4345 | &pring->txcmplq, list) |
| 4346 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4347 | /* Retrieve everything on the txcmplq */ |
| 4348 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 4349 | pring->txq_cnt = 0; |
| 4350 | pring->txcmplq_cnt = 0; |
| 4351 | spin_unlock_irq(&phba->hbalock); |
| 4352 | |
| 4353 | /* Flush the txq */ |
| 4354 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
| 4355 | IOERR_SLI_DOWN); |
| 4356 | /* Flush the txcmpq */ |
| 4357 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
| 4358 | IOERR_SLI_DOWN); |
| 4359 | } |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4360 | } |
| 4361 | |
| 4362 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4363 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4364 | * @phba: Pointer to HBA context object. |
| 4365 | * @mask: Bit mask to be checked. |
| 4366 | * |
| 4367 | * This function reads the host status register and compares |
| 4368 | * with the provided bit mask to check if HBA completed |
| 4369 | * the restart. This function will wait in a loop for the |
| 4370 | * HBA to complete restart. If the HBA does not restart within |
| 4371 | * 15 iterations, the function will reset the HBA again. The |
| 4372 | * function returns 1 when HBA fail to restart otherwise returns |
| 4373 | * zero. |
| 4374 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4375 | static int |
| 4376 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4377 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4378 | uint32_t status; |
| 4379 | int i = 0; |
| 4380 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4381 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4382 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4383 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4384 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4385 | |
James Smart | d2f2547 | 2021-01-04 10:02:27 -0800 | [diff] [blame] | 4386 | phba->hba_flag |= HBA_NEEDS_CFG_PORT; |
| 4387 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4388 | /* |
| 4389 | * Check status register every 100ms for 5 retries, then every |
| 4390 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 4391 | * every 2.5 sec for 4. |
| 4392 | * Break our of the loop if errors occurred during init. |
| 4393 | */ |
| 4394 | while (((status & mask) != mask) && |
| 4395 | !(status & HS_FFERM) && |
| 4396 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4397 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4398 | if (i <= 5) |
| 4399 | msleep(10); |
| 4400 | else if (i <= 10) |
| 4401 | msleep(500); |
| 4402 | else |
| 4403 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4404 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4405 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4406 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4407 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4408 | lpfc_sli_brdrestart(phba); |
| 4409 | } |
| 4410 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4411 | if (lpfc_readl(phba->HSregaddr, &status)) { |
| 4412 | retval = 1; |
| 4413 | break; |
| 4414 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4415 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4416 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4417 | /* Check to see if any errors occurred during init */ |
| 4418 | if ((status & HS_FFERM) || (i >= 20)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4419 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4420 | "2751 Adapter failed to restart, " |
| 4421 | "status reg x%x, FW Data: A8 x%x AC x%x\n", |
| 4422 | status, |
| 4423 | readl(phba->MBslimaddr + 0xa8), |
| 4424 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4425 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4426 | retval = 1; |
| 4427 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4428 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4429 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4430 | } |
| 4431 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4432 | /** |
| 4433 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status |
| 4434 | * @phba: Pointer to HBA context object. |
| 4435 | * @mask: Bit mask to be checked. |
| 4436 | * |
| 4437 | * This function checks the host status register to check if HBA is |
| 4438 | * ready. This function will wait in a loop for the HBA to be ready |
| 4439 | * If the HBA is not ready , the function will will reset the HBA PCI |
| 4440 | * function again. The function returns 1 when HBA fail to be ready |
| 4441 | * otherwise returns zero. |
| 4442 | **/ |
| 4443 | static int |
| 4444 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) |
| 4445 | { |
| 4446 | uint32_t status; |
| 4447 | int retval = 0; |
| 4448 | |
| 4449 | /* Read the HBA Host Status Register */ |
| 4450 | status = lpfc_sli4_post_status_check(phba); |
| 4451 | |
| 4452 | if (status) { |
| 4453 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 4454 | lpfc_sli_brdrestart(phba); |
| 4455 | status = lpfc_sli4_post_status_check(phba); |
| 4456 | } |
| 4457 | |
| 4458 | /* Check to see if any errors occurred during init */ |
| 4459 | if (status) { |
| 4460 | phba->link_state = LPFC_HBA_ERROR; |
| 4461 | retval = 1; |
| 4462 | } else |
| 4463 | phba->sli4_hba.intr_enable = 0; |
| 4464 | |
| 4465 | return retval; |
| 4466 | } |
| 4467 | |
| 4468 | /** |
| 4469 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness |
| 4470 | * @phba: Pointer to HBA context object. |
| 4471 | * @mask: Bit mask to be checked. |
| 4472 | * |
| 4473 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine |
| 4474 | * from the API jump table function pointer from the lpfc_hba struct. |
| 4475 | **/ |
| 4476 | int |
| 4477 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| 4478 | { |
| 4479 | return phba->lpfc_sli_brdready(phba, mask); |
| 4480 | } |
| 4481 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4482 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 4483 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4484 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4485 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4486 | * @phba: Pointer to HBA context object. |
| 4487 | * |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 4488 | * This function is called before resetting an HBA. This function is called |
| 4489 | * with hbalock held and requests HBA to quiesce DMAs before a reset. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4490 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4491 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4492 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4493 | uint32_t __iomem *resp_buf; |
| 4494 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4495 | volatile uint32_t mbox; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4496 | uint32_t hc_copy, ha_copy, resp_data; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4497 | int i; |
| 4498 | uint8_t hdrtype; |
| 4499 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 4500 | lockdep_assert_held(&phba->hbalock); |
| 4501 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4502 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 4503 | if (hdrtype != 0x80 || |
| 4504 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 4505 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 4506 | return; |
| 4507 | |
| 4508 | /* |
| 4509 | * Tell the other part of the chip to suspend temporarily all |
| 4510 | * its DMA activity. |
| 4511 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4512 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4513 | |
| 4514 | /* Disable the error attention */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4515 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 4516 | return; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4517 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 4518 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4519 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4520 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4521 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4522 | return; |
| 4523 | if (ha_copy & HA_ERATT) { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4524 | /* Clear Chip error bit */ |
| 4525 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4526 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4527 | } |
| 4528 | |
| 4529 | mbox = 0; |
| 4530 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 4531 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 4532 | |
| 4533 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4534 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4535 | writel(mbox, mbox_buf); |
| 4536 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4537 | for (i = 0; i < 50; i++) { |
| 4538 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 4539 | return; |
| 4540 | if (resp_data != ~(BARRIER_TEST_PATTERN)) |
| 4541 | mdelay(1); |
| 4542 | else |
| 4543 | break; |
| 4544 | } |
| 4545 | resp_data = 0; |
| 4546 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 4547 | return; |
| 4548 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4549 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4550 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4551 | goto restore_hc; |
| 4552 | else |
| 4553 | goto clear_errat; |
| 4554 | } |
| 4555 | |
| 4556 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4557 | resp_data = 0; |
| 4558 | for (i = 0; i < 500; i++) { |
| 4559 | if (lpfc_readl(resp_buf, &resp_data)) |
| 4560 | return; |
| 4561 | if (resp_data != mbox) |
| 4562 | mdelay(1); |
| 4563 | else |
| 4564 | break; |
| 4565 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4566 | |
| 4567 | clear_errat: |
| 4568 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4569 | while (++i < 500) { |
| 4570 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4571 | return; |
| 4572 | if (!(ha_copy & HA_ERATT)) |
| 4573 | mdelay(1); |
| 4574 | else |
| 4575 | break; |
| 4576 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4577 | |
| 4578 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 4579 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4580 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4581 | } |
| 4582 | |
| 4583 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4584 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4585 | writel(hc_copy, phba->HCregaddr); |
| 4586 | readl(phba->HCregaddr); /* flush */ |
| 4587 | } |
| 4588 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4589 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4590 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4591 | * @phba: Pointer to HBA context object. |
| 4592 | * |
| 4593 | * This function issues a kill_board mailbox command and waits for |
| 4594 | * the error attention interrupt. This function is called for stopping |
| 4595 | * the firmware processing. The caller is not required to hold any |
| 4596 | * locks. This function calls lpfc_hba_down_post function to free |
| 4597 | * any pending commands after the kill. The function will return 1 when it |
| 4598 | * fails to kill the board else will return 0. |
| 4599 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4600 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4601 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4602 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4603 | struct lpfc_sli *psli; |
| 4604 | LPFC_MBOXQ_t *pmb; |
| 4605 | uint32_t status; |
| 4606 | uint32_t ha_copy; |
| 4607 | int retval; |
| 4608 | int i = 0; |
| 4609 | |
| 4610 | psli = &phba->sli; |
| 4611 | |
| 4612 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4613 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4614 | "0329 Kill HBA Data: x%x x%x\n", |
| 4615 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4616 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4617 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4618 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4619 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4620 | |
| 4621 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4622 | spin_lock_irq(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4623 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 4624 | spin_unlock_irq(&phba->hbalock); |
| 4625 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4626 | return 1; |
| 4627 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4628 | status &= ~HC_ERINT_ENA; |
| 4629 | writel(status, phba->HCregaddr); |
| 4630 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4631 | phba->link_flag |= LS_IGNORE_ERATT; |
| 4632 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4633 | |
| 4634 | lpfc_kill_board(phba, pmb); |
| 4635 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4636 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 4637 | |
| 4638 | if (retval != MBX_SUCCESS) { |
| 4639 | if (retval != MBX_BUSY) |
| 4640 | mempool_free(pmb, phba->mbox_mem_pool); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4641 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4642 | "2752 KILL_BOARD command failed retval %d\n", |
| 4643 | retval); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4644 | spin_lock_irq(&phba->hbalock); |
| 4645 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4646 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4647 | return 1; |
| 4648 | } |
| 4649 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4650 | spin_lock_irq(&phba->hbalock); |
| 4651 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 4652 | spin_unlock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4653 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4654 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4655 | |
| 4656 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 4657 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 4658 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 4659 | * board is now undefined. |
| 4660 | */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4661 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4662 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4663 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 4664 | mdelay(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4665 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4666 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4667 | } |
| 4668 | |
| 4669 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4670 | if (ha_copy & HA_ERATT) { |
| 4671 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4672 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4673 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4674 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4675 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4676 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4677 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4678 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4679 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4680 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4681 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4682 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4683 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4684 | } |
| 4685 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4686 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4687 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4688 | * @phba: Pointer to HBA context object. |
| 4689 | * |
| 4690 | * This function resets the HBA by writing HC_INITFF to the control |
| 4691 | * register. After the HBA resets, this function resets all the iocb ring |
| 4692 | * indices. This function disables PCI layer parity checking during |
| 4693 | * the reset. |
| 4694 | * This function returns 0 always. |
| 4695 | * The caller is not required to hold any locks. |
| 4696 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4697 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4698 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4699 | { |
| 4700 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4701 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4702 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4703 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4704 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4705 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4706 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4707 | /* Reset HBA */ |
| 4708 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4709 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4710 | (phba->pport) ? phba->pport->port_state : 0, |
| 4711 | psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4712 | |
| 4713 | /* perform board reset */ |
| 4714 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4715 | phba->link_events = 0; |
James Smart | d2f2547 | 2021-01-04 10:02:27 -0800 | [diff] [blame] | 4716 | phba->hba_flag |= HBA_NEEDS_CFG_PORT; |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4717 | if (phba->pport) { |
| 4718 | phba->pport->fc_myDID = 0; |
| 4719 | phba->pport->fc_prevDID = 0; |
| 4720 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4721 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4722 | /* Turn off parity checking and serr during the physical reset */ |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 4723 | if (pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value)) |
| 4724 | return -EIO; |
| 4725 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4726 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 4727 | (cfg_value & |
| 4728 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4729 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4730 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
| 4731 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4732 | /* Now toggle INITFF bit in the Host Control Register */ |
| 4733 | writel(HC_INITFF, phba->HCregaddr); |
| 4734 | mdelay(1); |
| 4735 | readl(phba->HCregaddr); /* flush */ |
| 4736 | writel(0, phba->HCregaddr); |
| 4737 | readl(phba->HCregaddr); /* flush */ |
| 4738 | |
| 4739 | /* Restore PCI cmd register */ |
| 4740 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4741 | |
| 4742 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4743 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4744 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4745 | pring->flag = 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4746 | pring->sli.sli3.rspidx = 0; |
| 4747 | pring->sli.sli3.next_cmdidx = 0; |
| 4748 | pring->sli.sli3.local_getidx = 0; |
| 4749 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4750 | pring->missbufcnt = 0; |
| 4751 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4752 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4753 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4754 | return 0; |
| 4755 | } |
| 4756 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4757 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4758 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
| 4759 | * @phba: Pointer to HBA context object. |
| 4760 | * |
| 4761 | * This function resets a SLI4 HBA. This function disables PCI layer parity |
| 4762 | * checking during resets the device. The caller is not required to hold |
| 4763 | * any locks. |
| 4764 | * |
James Smart | 8c24a4f | 2019-08-14 16:56:53 -0700 | [diff] [blame] | 4765 | * This function returns 0 on success else returns negative error code. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4766 | **/ |
| 4767 | int |
| 4768 | lpfc_sli4_brdreset(struct lpfc_hba *phba) |
| 4769 | { |
| 4770 | struct lpfc_sli *psli = &phba->sli; |
| 4771 | uint16_t cfg_value; |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4772 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4773 | |
| 4774 | /* Reset HBA */ |
| 4775 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4776 | "0295 Reset HBA Data: x%x x%x x%x\n", |
| 4777 | phba->pport->port_state, psli->sli_flag, |
| 4778 | phba->hba_flag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4779 | |
| 4780 | /* perform board reset */ |
| 4781 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4782 | phba->link_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4783 | phba->pport->fc_myDID = 0; |
| 4784 | phba->pport->fc_prevDID = 0; |
| 4785 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4786 | spin_lock_irq(&phba->hbalock); |
| 4787 | psli->sli_flag &= ~(LPFC_PROCESS_LA); |
| 4788 | phba->fcf.fcf_flag = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4789 | spin_unlock_irq(&phba->hbalock); |
| 4790 | |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4791 | /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */ |
| 4792 | if (phba->hba_flag & HBA_FW_DUMP_OP) { |
| 4793 | phba->hba_flag &= ~HBA_FW_DUMP_OP; |
| 4794 | return rc; |
| 4795 | } |
| 4796 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4797 | /* Now physically reset the device */ |
| 4798 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4799 | "0389 Performing PCI function reset!\n"); |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4800 | |
| 4801 | /* Turn off parity checking and serr during the physical reset */ |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 4802 | if (pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value)) { |
| 4803 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4804 | "3205 PCI read Config failed\n"); |
| 4805 | return -EIO; |
| 4806 | } |
| 4807 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4808 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & |
| 4809 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4810 | |
James Smart | 8831881 | 2012-09-29 11:29:29 -0400 | [diff] [blame] | 4811 | /* Perform FCoE PCI function reset before freeing queue memory */ |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4812 | rc = lpfc_pci_function_reset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4813 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4814 | /* Restore PCI cmd register */ |
| 4815 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| 4816 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4817 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4818 | } |
| 4819 | |
| 4820 | /** |
| 4821 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4822 | * @phba: Pointer to HBA context object. |
| 4823 | * |
| 4824 | * This function is called in the SLI initialization code path to |
| 4825 | * restart the HBA. The caller is not required to hold any lock. |
| 4826 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 4827 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 4828 | * function to free any pending commands. The function enables |
| 4829 | * POST only during the first initialization. The function returns zero. |
| 4830 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 4831 | * command before the return of this function. |
| 4832 | **/ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4833 | static int |
| 4834 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4835 | { |
| 4836 | MAILBOX_t *mb; |
| 4837 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4838 | volatile uint32_t word0; |
| 4839 | void __iomem *to_slim; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4840 | uint32_t hba_aer_enabled; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4841 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4842 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4843 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4844 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4845 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4846 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4847 | psli = &phba->sli; |
| 4848 | |
| 4849 | /* Restart HBA */ |
| 4850 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4851 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4852 | (phba->pport) ? phba->pport->port_state : 0, |
| 4853 | psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4854 | |
| 4855 | word0 = 0; |
| 4856 | mb = (MAILBOX_t *) &word0; |
| 4857 | mb->mbxCommand = MBX_RESTART; |
| 4858 | mb->mbxHc = 1; |
| 4859 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4860 | lpfc_reset_barrier(phba); |
| 4861 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4862 | to_slim = phba->MBslimaddr; |
| 4863 | writel(*(uint32_t *) mb, to_slim); |
| 4864 | readl(to_slim); /* flush */ |
| 4865 | |
| 4866 | /* Only skip post after fc_ffinit is completed */ |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4867 | if (phba->pport && phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4868 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4869 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4870 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4871 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4872 | writel(*(uint32_t *) mb, to_slim); |
| 4873 | readl(to_slim); /* flush */ |
| 4874 | |
| 4875 | lpfc_sli_brdreset(phba); |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4876 | if (phba->pport) |
| 4877 | phba->pport->stopped = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4878 | phba->link_state = LPFC_INIT_START; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4879 | phba->hba_flag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4880 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4881 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4882 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
Arnd Bergmann | c4d6204d | 2018-06-18 17:28:23 +0200 | [diff] [blame] | 4883 | psli->stats_start = ktime_get_seconds(); |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4884 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4885 | /* Give the INITFF and Post time to settle. */ |
| 4886 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4887 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4888 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4889 | if (hba_aer_enabled) |
| 4890 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4891 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4892 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4893 | |
| 4894 | return 0; |
| 4895 | } |
| 4896 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4897 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4898 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba |
| 4899 | * @phba: Pointer to HBA context object. |
| 4900 | * |
| 4901 | * This function is called in the SLI initialization code path to restart |
| 4902 | * a SLI4 HBA. The caller is not required to hold any lock. |
| 4903 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 4904 | * free any pending commands. |
| 4905 | **/ |
| 4906 | static int |
| 4907 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) |
| 4908 | { |
| 4909 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4910 | uint32_t hba_aer_enabled; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4911 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4912 | |
| 4913 | /* Restart HBA */ |
| 4914 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4915 | "0296 Restart HBA Data: x%x x%x\n", |
| 4916 | phba->pport->port_state, psli->sli_flag); |
| 4917 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4918 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4919 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4920 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4921 | rc = lpfc_sli4_brdreset(phba); |
James Smart | 4fb86a6 | 2019-09-03 14:54:41 -0700 | [diff] [blame] | 4922 | if (rc) { |
| 4923 | phba->link_state = LPFC_HBA_ERROR; |
| 4924 | goto hba_down_queue; |
| 4925 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4926 | |
| 4927 | spin_lock_irq(&phba->hbalock); |
| 4928 | phba->pport->stopped = 0; |
| 4929 | phba->link_state = LPFC_INIT_START; |
| 4930 | phba->hba_flag = 0; |
| 4931 | spin_unlock_irq(&phba->hbalock); |
| 4932 | |
| 4933 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
Arnd Bergmann | c4d6204d | 2018-06-18 17:28:23 +0200 | [diff] [blame] | 4934 | psli->stats_start = ktime_get_seconds(); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4935 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4936 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4937 | if (hba_aer_enabled) |
| 4938 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4939 | |
James Smart | 4fb86a6 | 2019-09-03 14:54:41 -0700 | [diff] [blame] | 4940 | hba_down_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4941 | lpfc_hba_down_post(phba); |
James Smart | 569dbe8 | 2017-06-15 22:56:47 -0700 | [diff] [blame] | 4942 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4943 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4944 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4945 | } |
| 4946 | |
| 4947 | /** |
| 4948 | * lpfc_sli_brdrestart - Wrapper func for restarting hba |
| 4949 | * @phba: Pointer to HBA context object. |
| 4950 | * |
| 4951 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the |
| 4952 | * API jump table function pointer from the lpfc_hba struct. |
| 4953 | **/ |
| 4954 | int |
| 4955 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
| 4956 | { |
| 4957 | return phba->lpfc_sli_brdrestart(phba); |
| 4958 | } |
| 4959 | |
| 4960 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4961 | * 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] | 4962 | * @phba: Pointer to HBA context object. |
| 4963 | * |
| 4964 | * This function is called after a HBA restart to wait for successful |
| 4965 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 4966 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 4967 | * iteration, the function will restart the HBA again. The function returns |
| 4968 | * zero if HBA successfully restarted else returns negative error code. |
| 4969 | **/ |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4970 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4971 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 4972 | { |
| 4973 | uint32_t status, i = 0; |
| 4974 | |
| 4975 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4976 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4977 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4978 | |
| 4979 | /* Check status register to see what current state is */ |
| 4980 | i = 0; |
| 4981 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 4982 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4983 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
| 4984 | * retries, then every 1 sec for 50 retires for a total of |
| 4985 | * ~60 seconds before reset the board again and check every |
| 4986 | * 1 sec for 50 retries. The up to 60 seconds before the |
| 4987 | * board ready is required by the Falcon FIPS zeroization |
| 4988 | * complete, and any reset the board in between shall cause |
| 4989 | * restart of zeroization, further delay the board ready. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4990 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4991 | if (i++ >= 200) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4992 | /* Adapter failed to init, timeout, status reg |
| 4993 | <status> */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4994 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4995 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4996 | "timeout, status reg x%x, " |
| 4997 | "FW Data: A8 x%x AC x%x\n", status, |
| 4998 | readl(phba->MBslimaddr + 0xa8), |
| 4999 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5000 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5001 | return -ETIMEDOUT; |
| 5002 | } |
| 5003 | |
| 5004 | /* Check to see if any errors occurred during init */ |
| 5005 | if (status & HS_FFERM) { |
| 5006 | /* ERROR: During chipset initialization */ |
| 5007 | /* Adapter failed to init, chipset, status reg |
| 5008 | <status> */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5009 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5010 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5011 | "chipset, status reg x%x, " |
| 5012 | "FW Data: A8 x%x AC x%x\n", status, |
| 5013 | readl(phba->MBslimaddr + 0xa8), |
| 5014 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5015 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5016 | return -EIO; |
| 5017 | } |
| 5018 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 5019 | if (i <= 10) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5020 | msleep(10); |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 5021 | else if (i <= 100) |
| 5022 | msleep(100); |
| 5023 | else |
| 5024 | msleep(1000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5025 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 5026 | if (i == 150) { |
| 5027 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5028 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 5029 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5030 | } |
| 5031 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 5032 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 5033 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5034 | } |
| 5035 | |
| 5036 | /* Check to see if any errors occurred during init */ |
| 5037 | if (status & HS_FFERM) { |
| 5038 | /* ERROR: During chipset initialization */ |
| 5039 | /* Adapter failed to init, chipset, status reg <status> */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5040 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5041 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5042 | "status reg x%x, " |
| 5043 | "FW Data: A8 x%x AC x%x\n", status, |
| 5044 | readl(phba->MBslimaddr + 0xa8), |
| 5045 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5046 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5047 | return -EIO; |
| 5048 | } |
| 5049 | |
James Smart | d2f2547 | 2021-01-04 10:02:27 -0800 | [diff] [blame] | 5050 | phba->hba_flag |= HBA_NEEDS_CFG_PORT; |
| 5051 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5052 | /* Clear all interrupt enable conditions */ |
| 5053 | writel(0, phba->HCregaddr); |
| 5054 | readl(phba->HCregaddr); /* flush */ |
| 5055 | |
| 5056 | /* setup host attn register */ |
| 5057 | writel(0xffffffff, phba->HAregaddr); |
| 5058 | readl(phba->HAregaddr); /* flush */ |
| 5059 | return 0; |
| 5060 | } |
| 5061 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5062 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5063 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5064 | * |
| 5065 | * This function calculates and returns the number of HBQs required to be |
| 5066 | * configured. |
| 5067 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 5068 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5069 | lpfc_sli_hbq_count(void) |
| 5070 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5071 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5072 | } |
| 5073 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5074 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5075 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5076 | * |
| 5077 | * This function adds the number of hbq entries in every HBQ to get |
| 5078 | * the total number of hbq entries required for the HBA and returns |
| 5079 | * the total count. |
| 5080 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5081 | static int |
| 5082 | lpfc_sli_hbq_entry_count(void) |
| 5083 | { |
| 5084 | int hbq_count = lpfc_sli_hbq_count(); |
| 5085 | int count = 0; |
| 5086 | int i; |
| 5087 | |
| 5088 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5089 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5090 | return count; |
| 5091 | } |
| 5092 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5093 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5094 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5095 | * |
| 5096 | * This function calculates amount of memory required for all hbq entries |
| 5097 | * to be configured and returns the total memory required. |
| 5098 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5099 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5100 | lpfc_sli_hbq_size(void) |
| 5101 | { |
| 5102 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 5103 | } |
| 5104 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5105 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5106 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5107 | * @phba: Pointer to HBA context object. |
| 5108 | * |
| 5109 | * This function is called during the SLI initialization to configure |
| 5110 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 5111 | * required to hold any locks. This function will return zero if successful |
| 5112 | * else it will return negative error code. |
| 5113 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5114 | static int |
| 5115 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 5116 | { |
| 5117 | int hbq_count = lpfc_sli_hbq_count(); |
| 5118 | LPFC_MBOXQ_t *pmb; |
| 5119 | MAILBOX_t *pmbox; |
| 5120 | uint32_t hbqno; |
| 5121 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5122 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5123 | /* Get a Mailbox buffer to setup mailbox |
| 5124 | * commands for HBA initialization |
| 5125 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5126 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5127 | |
| 5128 | if (!pmb) |
| 5129 | return -ENOMEM; |
| 5130 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5131 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5132 | |
| 5133 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 5134 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 5135 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5136 | |
| 5137 | hbq_entry_index = 0; |
| 5138 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 5139 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 5140 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 5141 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 5142 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5143 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5144 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 5145 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5146 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 5147 | |
| 5148 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 5149 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 5150 | mbxStatus <status>, ring <num> */ |
| 5151 | |
| 5152 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5153 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5154 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5155 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5156 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5157 | pmbox->mbxStatus, hbqno); |
| 5158 | |
| 5159 | phba->link_state = LPFC_HBA_ERROR; |
| 5160 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 5161 | return -ENXIO; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5162 | } |
| 5163 | } |
| 5164 | phba->hbq_count = hbq_count; |
| 5165 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5166 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5167 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5168 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5169 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 5170 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5171 | return 0; |
| 5172 | } |
| 5173 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5174 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 5175 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA |
| 5176 | * @phba: Pointer to HBA context object. |
| 5177 | * |
| 5178 | * This function is called during the SLI initialization to configure |
| 5179 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 5180 | * required to hold any locks. This function will return zero if successful |
| 5181 | * else it will return negative error code. |
| 5182 | **/ |
| 5183 | static int |
| 5184 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) |
| 5185 | { |
| 5186 | phba->hbq_in_use = 1; |
James Smart | 999fbbc | 2019-12-18 15:58:06 -0800 | [diff] [blame] | 5187 | /** |
| 5188 | * Specific case when the MDS diagnostics is enabled and supported. |
| 5189 | * The receive buffer count is truncated to manage the incoming |
| 5190 | * traffic. |
| 5191 | **/ |
| 5192 | if (phba->cfg_enable_mds_diags && phba->mds_diags_support) |
| 5193 | phba->hbqs[LPFC_ELS_HBQ].entry_count = |
| 5194 | lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count >> 1; |
| 5195 | else |
| 5196 | phba->hbqs[LPFC_ELS_HBQ].entry_count = |
| 5197 | lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 5198 | phba->hbq_count = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5199 | lpfc_sli_hbqbuf_init_hbqs(phba, LPFC_ELS_HBQ); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 5200 | /* Initially populate or replenish the HBQs */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 5201 | return 0; |
| 5202 | } |
| 5203 | |
| 5204 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5205 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5206 | * @phba: Pointer to HBA context object. |
| 5207 | * @sli_mode: sli mode - 2/3 |
| 5208 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 5209 | * This function is called by the sli initialization code path |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5210 | * to issue config_port mailbox command. This function restarts the |
| 5211 | * HBA firmware and issues a config_port mailbox command to configure |
| 5212 | * the SLI interface in the sli mode specified by sli_mode |
| 5213 | * variable. The caller is not required to hold any locks. |
| 5214 | * The function returns 0 if successful, else returns negative error |
| 5215 | * code. |
| 5216 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5217 | int |
| 5218 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5219 | { |
| 5220 | LPFC_MBOXQ_t *pmb; |
| 5221 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 5222 | |
| 5223 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5224 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5225 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5226 | return -ENOMEM; |
| 5227 | } |
| 5228 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5229 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5230 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5231 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 5232 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5233 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5234 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 5235 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5236 | rc = lpfc_sli_chipset_init(phba); |
| 5237 | if (rc) |
| 5238 | break; |
| 5239 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5240 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 5241 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5242 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5243 | resetcount++; |
| 5244 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5245 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 5246 | * value of 0 means the call was successful. Any other |
| 5247 | * nonzero value is a failure, but if ERESTART is returned, |
| 5248 | * the driver may reset the HBA and try again. |
| 5249 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5250 | rc = lpfc_config_port_prep(phba); |
| 5251 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5252 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5253 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5254 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5255 | break; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5256 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5257 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5258 | lpfc_config_port(phba, pmb); |
| 5259 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5260 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 5261 | LPFC_SLI3_HBQ_ENABLED | |
| 5262 | LPFC_SLI3_CRP_ENABLED | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 5263 | LPFC_SLI3_DSS_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5264 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5265 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5266 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5267 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5268 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5269 | spin_lock_irq(&phba->hbalock); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5270 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5271 | spin_unlock_irq(&phba->hbalock); |
| 5272 | rc = -ENXIO; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5273 | } else { |
| 5274 | /* Allow asynchronous mailbox command to go through */ |
| 5275 | spin_lock_irq(&phba->hbalock); |
| 5276 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 5277 | spin_unlock_irq(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5278 | done = 1; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 5279 | |
| 5280 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && |
| 5281 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) |
| 5282 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 5283 | "3110 Port did not grant ASABT\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5284 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5285 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5286 | if (!done) { |
| 5287 | rc = -EINVAL; |
| 5288 | goto do_prep_failed; |
| 5289 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5290 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
| 5291 | if (!pmb->u.mb.un.varCfgPort.cMA) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5292 | rc = -ENXIO; |
| 5293 | goto do_prep_failed; |
| 5294 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5295 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5296 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5297 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
| 5298 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? |
| 5299 | phba->max_vpi : phba->max_vports; |
| 5300 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5301 | } else |
| 5302 | phba->max_vpi = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5303 | if (pmb->u.mb.un.varCfgPort.gerbm) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5304 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5305 | if (pmb->u.mb.un.varCfgPort.gcrp) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5306 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 5307 | |
| 5308 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
| 5309 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5310 | |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 5311 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
| 5312 | if (pmb->u.mb.un.varCfgPort.gbg == 0) { |
| 5313 | phba->cfg_enable_bg = 0; |
| 5314 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5315 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5316 | "0443 Adapter did not grant " |
| 5317 | "BlockGuard\n"); |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 5318 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5319 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5320 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 5321 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5322 | phba->port_gp = phba->mbox->us.s2.port; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5323 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5324 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5325 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5326 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5327 | return rc; |
| 5328 | } |
| 5329 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5330 | |
| 5331 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 5332 | * lpfc_sli_hba_setup - SLI initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5333 | * @phba: Pointer to HBA context object. |
| 5334 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 5335 | * This function is the main SLI initialization function. This function |
| 5336 | * is called by the HBA initialization code, HBA reset code and HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5337 | * error attention handler code. Caller is not required to hold any |
| 5338 | * locks. This function issues config_port mailbox command to configure |
| 5339 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 5340 | * calls the config_port_post function to issue init_link mailbox |
| 5341 | * command and to start the discovery. The function will return zero |
| 5342 | * if successful, else it will return negative error code. |
| 5343 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5344 | int |
| 5345 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 5346 | { |
| 5347 | uint32_t rc; |
James Smart | d2f2547 | 2021-01-04 10:02:27 -0800 | [diff] [blame] | 5348 | int i; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5349 | int longs; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5350 | |
James Smart | d2f2547 | 2021-01-04 10:02:27 -0800 | [diff] [blame] | 5351 | /* Enable ISR already does config_port because of config_msi mbx */ |
| 5352 | if (phba->hba_flag & HBA_NEEDS_CFG_PORT) { |
| 5353 | rc = lpfc_sli_config_port(phba, LPFC_SLI_REV3); |
| 5354 | if (rc) |
| 5355 | return -EIO; |
| 5356 | phba->hba_flag &= ~HBA_NEEDS_CFG_PORT; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5357 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 5358 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5359 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 5360 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 5361 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 5362 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 5363 | if (!rc) { |
| 5364 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5365 | "2709 This device supports " |
| 5366 | "Advanced Error Reporting (AER)\n"); |
| 5367 | spin_lock_irq(&phba->hbalock); |
| 5368 | phba->hba_flag |= HBA_AER_ENABLED; |
| 5369 | spin_unlock_irq(&phba->hbalock); |
| 5370 | } else { |
| 5371 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5372 | "2708 This device does not support " |
James Smart | b069d7e | 2013-05-31 17:04:36 -0400 | [diff] [blame] | 5373 | "Advanced Error Reporting (AER): %d\n", |
| 5374 | rc); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 5375 | phba->cfg_aer_support = 0; |
| 5376 | } |
| 5377 | } |
| 5378 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5379 | if (phba->sli_rev == 3) { |
| 5380 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 5381 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5382 | } else { |
| 5383 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 5384 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5385 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5386 | } |
| 5387 | |
| 5388 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5389 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 5390 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5391 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5392 | |
| 5393 | if (rc) |
| 5394 | goto lpfc_sli_hba_setup_error; |
| 5395 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5396 | /* Initialize VPIs. */ |
| 5397 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 5398 | /* |
| 5399 | * The VPI bitmask and physical ID array are allocated |
| 5400 | * and initialized once only - at driver load. A port |
| 5401 | * reset doesn't need to reinitialize this memory. |
| 5402 | */ |
| 5403 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { |
| 5404 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5405 | phba->vpi_bmask = kcalloc(longs, |
| 5406 | sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5407 | GFP_KERNEL); |
| 5408 | if (!phba->vpi_bmask) { |
| 5409 | rc = -ENOMEM; |
| 5410 | goto lpfc_sli_hba_setup_error; |
| 5411 | } |
| 5412 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5413 | phba->vpi_ids = kcalloc(phba->max_vpi + 1, |
| 5414 | sizeof(uint16_t), |
| 5415 | GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5416 | if (!phba->vpi_ids) { |
| 5417 | kfree(phba->vpi_bmask); |
| 5418 | rc = -ENOMEM; |
| 5419 | goto lpfc_sli_hba_setup_error; |
| 5420 | } |
| 5421 | for (i = 0; i < phba->max_vpi; i++) |
| 5422 | phba->vpi_ids[i] = i; |
| 5423 | } |
| 5424 | } |
| 5425 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5426 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5427 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 5428 | rc = lpfc_sli_hbq_setup(phba); |
| 5429 | if (rc) |
| 5430 | goto lpfc_sli_hba_setup_error; |
| 5431 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5432 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5433 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5434 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5435 | |
| 5436 | rc = lpfc_config_port_post(phba); |
| 5437 | if (rc) |
| 5438 | goto lpfc_sli_hba_setup_error; |
| 5439 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5440 | return rc; |
| 5441 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5442 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5443 | phba->link_state = LPFC_HBA_ERROR; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5444 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5445 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5446 | return rc; |
| 5447 | } |
| 5448 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5449 | /** |
| 5450 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
| 5451 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 5452 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5453 | * This function issue a dump mailbox command to read config region |
| 5454 | * 23 and parse the records in the region and populate driver |
| 5455 | * data structure. |
| 5456 | **/ |
| 5457 | static int |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5458 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5459 | { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5460 | LPFC_MBOXQ_t *mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5461 | struct lpfc_dmabuf *mp; |
| 5462 | struct lpfc_mqe *mqe; |
| 5463 | uint32_t data_length; |
| 5464 | int rc; |
| 5465 | |
| 5466 | /* Program the default value of vlan_id and fc_map */ |
| 5467 | phba->valid_vlan = 0; |
| 5468 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 5469 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 5470 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 5471 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5472 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5473 | if (!mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5474 | return -ENOMEM; |
| 5475 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5476 | mqe = &mboxq->u.mqe; |
| 5477 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { |
| 5478 | rc = -ENOMEM; |
| 5479 | goto out_free_mboxq; |
| 5480 | } |
| 5481 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5482 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5483 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5484 | |
| 5485 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 5486 | "(%d):2571 Mailbox cmd x%x Status x%x " |
| 5487 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 5488 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 5489 | "CQ: x%x x%x x%x x%x\n", |
| 5490 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 5491 | bf_get(lpfc_mqe_command, mqe), |
| 5492 | bf_get(lpfc_mqe_status, mqe), |
| 5493 | mqe->un.mb_words[0], mqe->un.mb_words[1], |
| 5494 | mqe->un.mb_words[2], mqe->un.mb_words[3], |
| 5495 | mqe->un.mb_words[4], mqe->un.mb_words[5], |
| 5496 | mqe->un.mb_words[6], mqe->un.mb_words[7], |
| 5497 | mqe->un.mb_words[8], mqe->un.mb_words[9], |
| 5498 | mqe->un.mb_words[10], mqe->un.mb_words[11], |
| 5499 | mqe->un.mb_words[12], mqe->un.mb_words[13], |
| 5500 | mqe->un.mb_words[14], mqe->un.mb_words[15], |
| 5501 | mqe->un.mb_words[16], mqe->un.mb_words[50], |
| 5502 | mboxq->mcqe.word0, |
| 5503 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 5504 | mboxq->mcqe.trailer); |
| 5505 | |
| 5506 | if (rc) { |
| 5507 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5508 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5509 | rc = -EIO; |
| 5510 | goto out_free_mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5511 | } |
| 5512 | data_length = mqe->un.mb_words[5]; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 5513 | if (data_length > DMP_RGN23_SIZE) { |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5514 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5515 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5516 | rc = -EIO; |
| 5517 | goto out_free_mboxq; |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5518 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5519 | |
| 5520 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
| 5521 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5522 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5523 | rc = 0; |
| 5524 | |
| 5525 | out_free_mboxq: |
| 5526 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5527 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5528 | } |
| 5529 | |
| 5530 | /** |
| 5531 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
| 5532 | * @phba: pointer to lpfc hba data structure. |
| 5533 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. |
| 5534 | * @vpd: pointer to the memory to hold resulting port vpd data. |
| 5535 | * @vpd_size: On input, the number of bytes allocated to @vpd. |
| 5536 | * On output, the number of data bytes in @vpd. |
| 5537 | * |
| 5538 | * This routine executes a READ_REV SLI4 mailbox command. In |
| 5539 | * addition, this routine gets the port vpd data. |
| 5540 | * |
| 5541 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5542 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 5543 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5544 | **/ |
| 5545 | static int |
| 5546 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 5547 | uint8_t *vpd, uint32_t *vpd_size) |
| 5548 | { |
| 5549 | int rc = 0; |
| 5550 | uint32_t dma_size; |
| 5551 | struct lpfc_dmabuf *dmabuf; |
| 5552 | struct lpfc_mqe *mqe; |
| 5553 | |
| 5554 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5555 | if (!dmabuf) |
| 5556 | return -ENOMEM; |
| 5557 | |
| 5558 | /* |
| 5559 | * Get a DMA buffer for the vpd data resulting from the READ_REV |
| 5560 | * mailbox command. |
| 5561 | */ |
| 5562 | dma_size = *vpd_size; |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 5563 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, dma_size, |
| 5564 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5565 | if (!dmabuf->virt) { |
| 5566 | kfree(dmabuf); |
| 5567 | return -ENOMEM; |
| 5568 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5569 | |
| 5570 | /* |
| 5571 | * The SLI4 implementation of READ_REV conflicts at word1, |
| 5572 | * bits 31:16 and SLI4 adds vpd functionality not present |
| 5573 | * in SLI3. This code corrects the conflicts. |
| 5574 | */ |
| 5575 | lpfc_read_rev(phba, mboxq); |
| 5576 | mqe = &mboxq->u.mqe; |
| 5577 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); |
| 5578 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); |
| 5579 | mqe->un.read_rev.word1 &= 0x0000FFFF; |
| 5580 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); |
| 5581 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); |
| 5582 | |
| 5583 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5584 | if (rc) { |
| 5585 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 5586 | dmabuf->virt, dmabuf->phys); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 5587 | kfree(dmabuf); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5588 | return -EIO; |
| 5589 | } |
| 5590 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5591 | /* |
| 5592 | * The available vpd length cannot be bigger than the |
| 5593 | * DMA buffer passed to the port. Catch the less than |
| 5594 | * case and update the caller's size. |
| 5595 | */ |
| 5596 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) |
| 5597 | *vpd_size = mqe->un.read_rev.avail_vpd_len; |
| 5598 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5599 | memcpy(vpd, dmabuf->virt, *vpd_size); |
| 5600 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5601 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 5602 | dmabuf->virt, dmabuf->phys); |
| 5603 | kfree(dmabuf); |
| 5604 | return 0; |
| 5605 | } |
| 5606 | |
| 5607 | /** |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5608 | * lpfc_sli4_get_ctl_attr - Retrieve SLI4 device controller attributes |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5609 | * @phba: pointer to lpfc hba data structure. |
| 5610 | * |
| 5611 | * This routine retrieves SLI4 device physical port name this PCI function |
| 5612 | * is attached to. |
| 5613 | * |
| 5614 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 5615 | * 0 - successful |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5616 | * otherwise - failed to retrieve controller attributes |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5617 | **/ |
| 5618 | static int |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5619 | lpfc_sli4_get_ctl_attr(struct lpfc_hba *phba) |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5620 | { |
| 5621 | LPFC_MBOXQ_t *mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5622 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
| 5623 | struct lpfc_controller_attribute *cntl_attr; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5624 | void *virtaddr = NULL; |
| 5625 | uint32_t alloclen, reqlen; |
| 5626 | uint32_t shdr_status, shdr_add_status; |
| 5627 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5628 | int rc; |
| 5629 | |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5630 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5631 | if (!mboxq) |
| 5632 | return -ENOMEM; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5633 | |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5634 | /* Send COMMON_GET_CNTL_ATTRIBUTES mbox cmd */ |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5635 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); |
| 5636 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5637 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, |
| 5638 | LPFC_SLI4_MBX_NEMBED); |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5639 | |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5640 | if (alloclen < reqlen) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5641 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5642 | "3084 Allocated DMA memory size (%d) is " |
| 5643 | "less than the requested DMA memory size " |
| 5644 | "(%d)\n", alloclen, reqlen); |
| 5645 | rc = -ENOMEM; |
| 5646 | goto out_free_mboxq; |
| 5647 | } |
| 5648 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5649 | virtaddr = mboxq->sge_array->addr[0]; |
| 5650 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; |
| 5651 | shdr = &mbx_cntl_attr->cfg_shdr; |
| 5652 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5653 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5654 | if (shdr_status || shdr_add_status || rc) { |
| 5655 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5656 | "3085 Mailbox x%x (x%x/x%x) failed, " |
| 5657 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5658 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5659 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5660 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5661 | rc, shdr_status, shdr_add_status); |
| 5662 | rc = -ENXIO; |
| 5663 | goto out_free_mboxq; |
| 5664 | } |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5665 | |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5666 | cntl_attr = &mbx_cntl_attr->cntl_attr; |
| 5667 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 5668 | phba->sli4_hba.lnk_info.lnk_tp = |
| 5669 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); |
| 5670 | phba->sli4_hba.lnk_info.lnk_no = |
| 5671 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5672 | |
| 5673 | memset(phba->BIOSVersion, 0, sizeof(phba->BIOSVersion)); |
| 5674 | strlcat(phba->BIOSVersion, (char *)cntl_attr->bios_ver_str, |
| 5675 | sizeof(phba->BIOSVersion)); |
| 5676 | |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5677 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5678 | "3086 lnk_type:%d, lnk_numb:%d, bios_ver:%s\n", |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5679 | phba->sli4_hba.lnk_info.lnk_tp, |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5680 | phba->sli4_hba.lnk_info.lnk_no, |
| 5681 | phba->BIOSVersion); |
| 5682 | out_free_mboxq: |
James Smart | 304ee43 | 2021-04-11 18:31:17 -0700 | [diff] [blame] | 5683 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 5684 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 5685 | else |
| 5686 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5687 | return rc; |
| 5688 | } |
| 5689 | |
| 5690 | /** |
| 5691 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name |
| 5692 | * @phba: pointer to lpfc hba data structure. |
| 5693 | * |
| 5694 | * This routine retrieves SLI4 device physical port name this PCI function |
| 5695 | * is attached to. |
| 5696 | * |
| 5697 | * Return codes |
| 5698 | * 0 - successful |
| 5699 | * otherwise - failed to retrieve physical port name |
| 5700 | **/ |
| 5701 | static int |
| 5702 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) |
| 5703 | { |
| 5704 | LPFC_MBOXQ_t *mboxq; |
| 5705 | struct lpfc_mbx_get_port_name *get_port_name; |
| 5706 | uint32_t shdr_status, shdr_add_status; |
| 5707 | union lpfc_sli4_cfg_shdr *shdr; |
| 5708 | char cport_name = 0; |
| 5709 | int rc; |
| 5710 | |
| 5711 | /* We assume nothing at this point */ |
| 5712 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 5713 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; |
| 5714 | |
| 5715 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5716 | if (!mboxq) |
| 5717 | return -ENOMEM; |
| 5718 | /* obtain link type and link number via READ_CONFIG */ |
| 5719 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 5720 | lpfc_sli4_read_config(phba); |
| 5721 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) |
| 5722 | goto retrieve_ppname; |
| 5723 | |
| 5724 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ |
| 5725 | rc = lpfc_sli4_get_ctl_attr(phba); |
| 5726 | if (rc) |
| 5727 | goto out_free_mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5728 | |
| 5729 | retrieve_ppname: |
| 5730 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5731 | LPFC_MBOX_OPCODE_GET_PORT_NAME, |
| 5732 | sizeof(struct lpfc_mbx_get_port_name) - |
| 5733 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 5734 | LPFC_SLI4_MBX_EMBED); |
| 5735 | get_port_name = &mboxq->u.mqe.un.get_port_name; |
| 5736 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; |
| 5737 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); |
| 5738 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, |
| 5739 | phba->sli4_hba.lnk_info.lnk_tp); |
| 5740 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5741 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5742 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5743 | if (shdr_status || shdr_add_status || rc) { |
| 5744 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5745 | "3087 Mailbox x%x (x%x/x%x) failed: " |
| 5746 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5747 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5748 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5749 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5750 | rc, shdr_status, shdr_add_status); |
| 5751 | rc = -ENXIO; |
| 5752 | goto out_free_mboxq; |
| 5753 | } |
| 5754 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 5755 | case LPFC_LINK_NUMBER_0: |
| 5756 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, |
| 5757 | &get_port_name->u.response); |
| 5758 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5759 | break; |
| 5760 | case LPFC_LINK_NUMBER_1: |
| 5761 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, |
| 5762 | &get_port_name->u.response); |
| 5763 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5764 | break; |
| 5765 | case LPFC_LINK_NUMBER_2: |
| 5766 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, |
| 5767 | &get_port_name->u.response); |
| 5768 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5769 | break; |
| 5770 | case LPFC_LINK_NUMBER_3: |
| 5771 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, |
| 5772 | &get_port_name->u.response); |
| 5773 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5774 | break; |
| 5775 | default: |
| 5776 | break; |
| 5777 | } |
| 5778 | |
| 5779 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { |
| 5780 | phba->Port[0] = cport_name; |
| 5781 | phba->Port[1] = '\0'; |
| 5782 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5783 | "3091 SLI get port name: %s\n", phba->Port); |
| 5784 | } |
| 5785 | |
| 5786 | out_free_mboxq: |
James Smart | 304ee43 | 2021-04-11 18:31:17 -0700 | [diff] [blame] | 5787 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 5788 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 5789 | else |
| 5790 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5791 | return rc; |
| 5792 | } |
| 5793 | |
| 5794 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5795 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
| 5796 | * @phba: pointer to lpfc hba data structure. |
| 5797 | * |
| 5798 | * This routine is called to explicitly arm the SLI4 device's completion and |
| 5799 | * event queues |
| 5800 | **/ |
| 5801 | static void |
| 5802 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) |
| 5803 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5804 | int qidx; |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5805 | struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5806 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 5807 | struct lpfc_queue *eq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5808 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 5809 | sli4_hba->sli4_write_cq_db(phba, sli4_hba->mbx_cq, 0, LPFC_QUEUE_REARM); |
| 5810 | 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] | 5811 | if (sli4_hba->nvmels_cq) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 5812 | sli4_hba->sli4_write_cq_db(phba, sli4_hba->nvmels_cq, 0, |
| 5813 | LPFC_QUEUE_REARM); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5814 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5815 | if (sli4_hba->hdwq) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 5816 | /* Loop thru all Hardware Queues */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5817 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 5818 | qp = &sli4_hba->hdwq[qidx]; |
| 5819 | /* ARM the corresponding CQ */ |
James Smart | 01f2ef6 | 2019-08-28 16:19:11 -0700 | [diff] [blame] | 5820 | sli4_hba->sli4_write_cq_db(phba, qp->io_cq, 0, |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 5821 | LPFC_QUEUE_REARM); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5822 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5823 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 5824 | /* Loop thru all IRQ vectors */ |
| 5825 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
| 5826 | eq = sli4_hba->hba_eq_hdl[qidx].eq; |
| 5827 | /* ARM the corresponding EQ */ |
| 5828 | sli4_hba->sli4_write_eq_db(phba, eq, |
| 5829 | 0, LPFC_QUEUE_REARM); |
| 5830 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5831 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5832 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 5833 | if (phba->nvmet_support) { |
| 5834 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 5835 | sli4_hba->sli4_write_cq_db(phba, |
| 5836 | sli4_hba->nvmet_cqset[qidx], 0, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 5837 | LPFC_QUEUE_REARM); |
| 5838 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5839 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5840 | } |
| 5841 | |
| 5842 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5843 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. |
| 5844 | * @phba: Pointer to HBA context object. |
| 5845 | * @type: The resource extent type. |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5846 | * @extnt_count: buffer to hold port available extent count. |
| 5847 | * @extnt_size: buffer to hold element count per extent. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5848 | * |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5849 | * This function calls the port and retrievs the number of available |
| 5850 | * extents and their size for a particular extent type. |
| 5851 | * |
| 5852 | * Returns: 0 if successful. Nonzero otherwise. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5853 | **/ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5854 | int |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5855 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
| 5856 | uint16_t *extnt_count, uint16_t *extnt_size) |
| 5857 | { |
| 5858 | int rc = 0; |
| 5859 | uint32_t length; |
| 5860 | uint32_t mbox_tmo; |
| 5861 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; |
| 5862 | LPFC_MBOXQ_t *mbox; |
| 5863 | |
| 5864 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5865 | if (!mbox) |
| 5866 | return -ENOMEM; |
| 5867 | |
| 5868 | /* Find out how many extents are available for this resource type */ |
| 5869 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - |
| 5870 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5871 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5872 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, |
| 5873 | length, LPFC_SLI4_MBX_EMBED); |
| 5874 | |
| 5875 | /* Send an extents count of 0 - the GET doesn't use it. */ |
| 5876 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5877 | LPFC_SLI4_MBX_EMBED); |
| 5878 | if (unlikely(rc)) { |
| 5879 | rc = -EIO; |
| 5880 | goto err_exit; |
| 5881 | } |
| 5882 | |
| 5883 | if (!phba->sli4_hba.intr_enable) |
| 5884 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5885 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5886 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5887 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5888 | } |
| 5889 | if (unlikely(rc)) { |
| 5890 | rc = -EIO; |
| 5891 | goto err_exit; |
| 5892 | } |
| 5893 | |
| 5894 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; |
| 5895 | if (bf_get(lpfc_mbox_hdr_status, |
| 5896 | &rsrc_info->header.cfg_shdr.response)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5897 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5898 | "2930 Failed to get resource extents " |
| 5899 | "Status 0x%x Add'l Status 0x%x\n", |
| 5900 | bf_get(lpfc_mbox_hdr_status, |
| 5901 | &rsrc_info->header.cfg_shdr.response), |
| 5902 | bf_get(lpfc_mbox_hdr_add_status, |
| 5903 | &rsrc_info->header.cfg_shdr.response)); |
| 5904 | rc = -EIO; |
| 5905 | goto err_exit; |
| 5906 | } |
| 5907 | |
| 5908 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, |
| 5909 | &rsrc_info->u.rsp); |
| 5910 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, |
| 5911 | &rsrc_info->u.rsp); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5912 | |
| 5913 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5914 | "3162 Retrieved extents type-%d from port: count:%d, " |
| 5915 | "size:%d\n", type, *extnt_count, *extnt_size); |
| 5916 | |
| 5917 | err_exit: |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5918 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5919 | return rc; |
| 5920 | } |
| 5921 | |
| 5922 | /** |
| 5923 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. |
| 5924 | * @phba: Pointer to HBA context object. |
| 5925 | * @type: The extent type to check. |
| 5926 | * |
| 5927 | * This function reads the current available extents from the port and checks |
| 5928 | * if the extent count or extent size has changed since the last access. |
| 5929 | * Callers use this routine post port reset to understand if there is a |
| 5930 | * extent reprovisioning requirement. |
| 5931 | * |
| 5932 | * Returns: |
| 5933 | * -Error: error indicates problem. |
| 5934 | * 1: Extent count or size has changed. |
| 5935 | * 0: No changes. |
| 5936 | **/ |
| 5937 | static int |
| 5938 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) |
| 5939 | { |
| 5940 | uint16_t curr_ext_cnt, rsrc_ext_cnt; |
| 5941 | uint16_t size_diff, rsrc_ext_size; |
| 5942 | int rc = 0; |
| 5943 | struct lpfc_rsrc_blks *rsrc_entry; |
| 5944 | struct list_head *rsrc_blk_list = NULL; |
| 5945 | |
| 5946 | size_diff = 0; |
| 5947 | curr_ext_cnt = 0; |
| 5948 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5949 | &rsrc_ext_cnt, |
| 5950 | &rsrc_ext_size); |
| 5951 | if (unlikely(rc)) |
| 5952 | return -EIO; |
| 5953 | |
| 5954 | switch (type) { |
| 5955 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5956 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5957 | break; |
| 5958 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5959 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; |
| 5960 | break; |
| 5961 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5962 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5963 | break; |
| 5964 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5965 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5966 | break; |
| 5967 | default: |
| 5968 | break; |
| 5969 | } |
| 5970 | |
| 5971 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { |
| 5972 | curr_ext_cnt++; |
| 5973 | if (rsrc_entry->rsrc_size != rsrc_ext_size) |
| 5974 | size_diff++; |
| 5975 | } |
| 5976 | |
| 5977 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) |
| 5978 | rc = 1; |
| 5979 | |
| 5980 | return rc; |
| 5981 | } |
| 5982 | |
| 5983 | /** |
| 5984 | * lpfc_sli4_cfg_post_extnts - |
| 5985 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 5986 | * @extnt_cnt: number of available extents. |
| 5987 | * @type: the extent type (rpi, xri, vfi, vpi). |
| 5988 | * @emb: buffer to hold either MBX_EMBED or MBX_NEMBED operation. |
| 5989 | * @mbox: pointer to the caller's allocated mailbox structure. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5990 | * |
| 5991 | * This function executes the extents allocation request. It also |
| 5992 | * takes care of the amount of memory needed to allocate or get the |
| 5993 | * allocated extents. It is the caller's responsibility to evaluate |
| 5994 | * the response. |
| 5995 | * |
| 5996 | * Returns: |
| 5997 | * -Error: Error value describes the condition found. |
| 5998 | * 0: if successful |
| 5999 | **/ |
| 6000 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6001 | 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] | 6002 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
| 6003 | { |
| 6004 | int rc = 0; |
| 6005 | uint32_t req_len; |
| 6006 | uint32_t emb_len; |
| 6007 | uint32_t alloc_len, mbox_tmo; |
| 6008 | |
| 6009 | /* Calculate the total requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6010 | req_len = extnt_cnt * sizeof(uint16_t); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6011 | |
| 6012 | /* |
| 6013 | * Calculate the size of an embedded mailbox. The uint32_t |
| 6014 | * accounts for extents-specific word. |
| 6015 | */ |
| 6016 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 6017 | sizeof(uint32_t); |
| 6018 | |
| 6019 | /* |
| 6020 | * Presume the allocation and response will fit into an embedded |
| 6021 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 6022 | */ |
| 6023 | *emb = LPFC_SLI4_MBX_EMBED; |
| 6024 | if (req_len > emb_len) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6025 | req_len = extnt_cnt * sizeof(uint16_t) + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6026 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 6027 | sizeof(uint32_t); |
| 6028 | *emb = LPFC_SLI4_MBX_NEMBED; |
| 6029 | } |
| 6030 | |
| 6031 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6032 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, |
| 6033 | req_len, *emb); |
| 6034 | if (alloc_len < req_len) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6035 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6036 | "2982 Allocated DMA memory size (x%x) is " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6037 | "less than the requested DMA memory " |
| 6038 | "size (x%x)\n", alloc_len, req_len); |
| 6039 | return -ENOMEM; |
| 6040 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6041 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6042 | if (unlikely(rc)) |
| 6043 | return -EIO; |
| 6044 | |
| 6045 | if (!phba->sli4_hba.intr_enable) |
| 6046 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 6047 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6048 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6049 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 6050 | } |
| 6051 | |
| 6052 | if (unlikely(rc)) |
| 6053 | rc = -EIO; |
| 6054 | return rc; |
| 6055 | } |
| 6056 | |
| 6057 | /** |
| 6058 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. |
| 6059 | * @phba: Pointer to HBA context object. |
| 6060 | * @type: The resource extent type to allocate. |
| 6061 | * |
| 6062 | * This function allocates the number of elements for the specified |
| 6063 | * resource type. |
| 6064 | **/ |
| 6065 | static int |
| 6066 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 6067 | { |
| 6068 | bool emb = false; |
| 6069 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; |
| 6070 | uint16_t rsrc_id, rsrc_start, j, k; |
| 6071 | uint16_t *ids; |
| 6072 | int i, rc; |
| 6073 | unsigned long longs; |
| 6074 | unsigned long *bmask; |
| 6075 | struct lpfc_rsrc_blks *rsrc_blks; |
| 6076 | LPFC_MBOXQ_t *mbox; |
| 6077 | uint32_t length; |
| 6078 | struct lpfc_id_range *id_array = NULL; |
| 6079 | void *virtaddr = NULL; |
| 6080 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 6081 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 6082 | struct list_head *ext_blk_list; |
| 6083 | |
| 6084 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 6085 | &rsrc_cnt, |
| 6086 | &rsrc_size); |
| 6087 | if (unlikely(rc)) |
| 6088 | return -EIO; |
| 6089 | |
| 6090 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6091 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6092 | "3009 No available Resource Extents " |
| 6093 | "for resource type 0x%x: Count: 0x%x, " |
| 6094 | "Size 0x%x\n", type, rsrc_cnt, |
| 6095 | rsrc_size); |
| 6096 | return -ENOMEM; |
| 6097 | } |
| 6098 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6099 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
| 6100 | "2903 Post resource extents type-0x%x: " |
| 6101 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6102 | |
| 6103 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6104 | if (!mbox) |
| 6105 | return -ENOMEM; |
| 6106 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6107 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6108 | if (unlikely(rc)) { |
| 6109 | rc = -EIO; |
| 6110 | goto err_exit; |
| 6111 | } |
| 6112 | |
| 6113 | /* |
| 6114 | * Figure out where the response is located. Then get local pointers |
| 6115 | * to the response data. The port does not guarantee to respond to |
| 6116 | * all extents counts request so update the local variable with the |
| 6117 | * allocated count from the port. |
| 6118 | */ |
| 6119 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 6120 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 6121 | id_array = &rsrc_ext->u.rsp.id[0]; |
| 6122 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 6123 | } else { |
| 6124 | virtaddr = mbox->sge_array->addr[0]; |
| 6125 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 6126 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 6127 | id_array = &n_rsrc->id; |
| 6128 | } |
| 6129 | |
| 6130 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 6131 | rsrc_id_cnt = rsrc_cnt * rsrc_size; |
| 6132 | |
| 6133 | /* |
| 6134 | * Based on the resource size and count, correct the base and max |
| 6135 | * resource values. |
| 6136 | */ |
| 6137 | length = sizeof(struct lpfc_rsrc_blks); |
| 6138 | switch (type) { |
| 6139 | case LPFC_RSC_TYPE_FCOE_RPI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6140 | phba->sli4_hba.rpi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6141 | sizeof(unsigned long), |
| 6142 | GFP_KERNEL); |
| 6143 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 6144 | rc = -ENOMEM; |
| 6145 | goto err_exit; |
| 6146 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6147 | phba->sli4_hba.rpi_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6148 | sizeof(uint16_t), |
| 6149 | GFP_KERNEL); |
| 6150 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 6151 | kfree(phba->sli4_hba.rpi_bmask); |
| 6152 | rc = -ENOMEM; |
| 6153 | goto err_exit; |
| 6154 | } |
| 6155 | |
| 6156 | /* |
| 6157 | * The next_rpi was initialized with the maximum available |
| 6158 | * count but the port may allocate a smaller number. Catch |
| 6159 | * that case and update the next_rpi. |
| 6160 | */ |
| 6161 | phba->sli4_hba.next_rpi = rsrc_id_cnt; |
| 6162 | |
| 6163 | /* Initialize local ptrs for common extent processing later. */ |
| 6164 | bmask = phba->sli4_hba.rpi_bmask; |
| 6165 | ids = phba->sli4_hba.rpi_ids; |
| 6166 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 6167 | break; |
| 6168 | case LPFC_RSC_TYPE_FCOE_VPI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6169 | phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6170 | GFP_KERNEL); |
| 6171 | if (unlikely(!phba->vpi_bmask)) { |
| 6172 | rc = -ENOMEM; |
| 6173 | goto err_exit; |
| 6174 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6175 | phba->vpi_ids = kcalloc(rsrc_id_cnt, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6176 | GFP_KERNEL); |
| 6177 | if (unlikely(!phba->vpi_ids)) { |
| 6178 | kfree(phba->vpi_bmask); |
| 6179 | rc = -ENOMEM; |
| 6180 | goto err_exit; |
| 6181 | } |
| 6182 | |
| 6183 | /* Initialize local ptrs for common extent processing later. */ |
| 6184 | bmask = phba->vpi_bmask; |
| 6185 | ids = phba->vpi_ids; |
| 6186 | ext_blk_list = &phba->lpfc_vpi_blk_list; |
| 6187 | break; |
| 6188 | case LPFC_RSC_TYPE_FCOE_XRI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6189 | phba->sli4_hba.xri_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6190 | sizeof(unsigned long), |
| 6191 | GFP_KERNEL); |
| 6192 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 6193 | rc = -ENOMEM; |
| 6194 | goto err_exit; |
| 6195 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6196 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6197 | phba->sli4_hba.xri_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6198 | sizeof(uint16_t), |
| 6199 | GFP_KERNEL); |
| 6200 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 6201 | kfree(phba->sli4_hba.xri_bmask); |
| 6202 | rc = -ENOMEM; |
| 6203 | goto err_exit; |
| 6204 | } |
| 6205 | |
| 6206 | /* Initialize local ptrs for common extent processing later. */ |
| 6207 | bmask = phba->sli4_hba.xri_bmask; |
| 6208 | ids = phba->sli4_hba.xri_ids; |
| 6209 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 6210 | break; |
| 6211 | case LPFC_RSC_TYPE_FCOE_VFI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6212 | phba->sli4_hba.vfi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6213 | sizeof(unsigned long), |
| 6214 | GFP_KERNEL); |
| 6215 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 6216 | rc = -ENOMEM; |
| 6217 | goto err_exit; |
| 6218 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6219 | phba->sli4_hba.vfi_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6220 | sizeof(uint16_t), |
| 6221 | GFP_KERNEL); |
| 6222 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 6223 | kfree(phba->sli4_hba.vfi_bmask); |
| 6224 | rc = -ENOMEM; |
| 6225 | goto err_exit; |
| 6226 | } |
| 6227 | |
| 6228 | /* Initialize local ptrs for common extent processing later. */ |
| 6229 | bmask = phba->sli4_hba.vfi_bmask; |
| 6230 | ids = phba->sli4_hba.vfi_ids; |
| 6231 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 6232 | break; |
| 6233 | default: |
| 6234 | /* Unsupported Opcode. Fail call. */ |
| 6235 | id_array = NULL; |
| 6236 | bmask = NULL; |
| 6237 | ids = NULL; |
| 6238 | ext_blk_list = NULL; |
| 6239 | goto err_exit; |
| 6240 | } |
| 6241 | |
| 6242 | /* |
| 6243 | * Complete initializing the extent configuration with the |
| 6244 | * allocated ids assigned to this function. The bitmask serves |
| 6245 | * as an index into the array and manages the available ids. The |
| 6246 | * array just stores the ids communicated to the port via the wqes. |
| 6247 | */ |
| 6248 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { |
| 6249 | if ((i % 2) == 0) |
| 6250 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, |
| 6251 | &id_array[k]); |
| 6252 | else |
| 6253 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, |
| 6254 | &id_array[k]); |
| 6255 | |
| 6256 | rsrc_blks = kzalloc(length, GFP_KERNEL); |
| 6257 | if (unlikely(!rsrc_blks)) { |
| 6258 | rc = -ENOMEM; |
| 6259 | kfree(bmask); |
| 6260 | kfree(ids); |
| 6261 | goto err_exit; |
| 6262 | } |
| 6263 | rsrc_blks->rsrc_start = rsrc_id; |
| 6264 | rsrc_blks->rsrc_size = rsrc_size; |
| 6265 | list_add_tail(&rsrc_blks->list, ext_blk_list); |
| 6266 | rsrc_start = rsrc_id; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6267 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 6268 | phba->sli4_hba.io_xri_start = rsrc_start + |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6269 | lpfc_sli4_get_iocb_cnt(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6270 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6271 | |
| 6272 | while (rsrc_id < (rsrc_start + rsrc_size)) { |
| 6273 | ids[j] = rsrc_id; |
| 6274 | rsrc_id++; |
| 6275 | j++; |
| 6276 | } |
| 6277 | /* Entire word processed. Get next word.*/ |
| 6278 | if ((i % 2) == 1) |
| 6279 | k++; |
| 6280 | } |
| 6281 | err_exit: |
| 6282 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 6283 | return rc; |
| 6284 | } |
| 6285 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6286 | |
| 6287 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6288 | /** |
| 6289 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. |
| 6290 | * @phba: Pointer to HBA context object. |
| 6291 | * @type: the extent's type. |
| 6292 | * |
| 6293 | * This function deallocates all extents of a particular resource type. |
| 6294 | * SLI4 does not allow for deallocating a particular extent range. It |
| 6295 | * is the caller's responsibility to release all kernel memory resources. |
| 6296 | **/ |
| 6297 | static int |
| 6298 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 6299 | { |
| 6300 | int rc; |
| 6301 | uint32_t length, mbox_tmo = 0; |
| 6302 | LPFC_MBOXQ_t *mbox; |
| 6303 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; |
| 6304 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; |
| 6305 | |
| 6306 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6307 | if (!mbox) |
| 6308 | return -ENOMEM; |
| 6309 | |
| 6310 | /* |
| 6311 | * This function sends an embedded mailbox because it only sends the |
| 6312 | * the resource type. All extents of this type are released by the |
| 6313 | * port. |
| 6314 | */ |
| 6315 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - |
| 6316 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6317 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6318 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, |
| 6319 | length, LPFC_SLI4_MBX_EMBED); |
| 6320 | |
| 6321 | /* Send an extents count of 0 - the dealloc doesn't use it. */ |
| 6322 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 6323 | LPFC_SLI4_MBX_EMBED); |
| 6324 | if (unlikely(rc)) { |
| 6325 | rc = -EIO; |
| 6326 | goto out_free_mbox; |
| 6327 | } |
| 6328 | if (!phba->sli4_hba.intr_enable) |
| 6329 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 6330 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6331 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6332 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 6333 | } |
| 6334 | if (unlikely(rc)) { |
| 6335 | rc = -EIO; |
| 6336 | goto out_free_mbox; |
| 6337 | } |
| 6338 | |
| 6339 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; |
| 6340 | if (bf_get(lpfc_mbox_hdr_status, |
| 6341 | &dealloc_rsrc->header.cfg_shdr.response)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6342 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6343 | "2919 Failed to release resource extents " |
| 6344 | "for type %d - Status 0x%x Add'l Status 0x%x. " |
| 6345 | "Resource memory not released.\n", |
| 6346 | type, |
| 6347 | bf_get(lpfc_mbox_hdr_status, |
| 6348 | &dealloc_rsrc->header.cfg_shdr.response), |
| 6349 | bf_get(lpfc_mbox_hdr_add_status, |
| 6350 | &dealloc_rsrc->header.cfg_shdr.response)); |
| 6351 | rc = -EIO; |
| 6352 | goto out_free_mbox; |
| 6353 | } |
| 6354 | |
| 6355 | /* Release kernel memory resources for the specific type. */ |
| 6356 | switch (type) { |
| 6357 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 6358 | kfree(phba->vpi_bmask); |
| 6359 | kfree(phba->vpi_ids); |
| 6360 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6361 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6362 | &phba->lpfc_vpi_blk_list, list) { |
| 6363 | list_del_init(&rsrc_blk->list); |
| 6364 | kfree(rsrc_blk); |
| 6365 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 6366 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6367 | break; |
| 6368 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 6369 | kfree(phba->sli4_hba.xri_bmask); |
| 6370 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6371 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6372 | &phba->sli4_hba.lpfc_xri_blk_list, list) { |
| 6373 | list_del_init(&rsrc_blk->list); |
| 6374 | kfree(rsrc_blk); |
| 6375 | } |
| 6376 | break; |
| 6377 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 6378 | kfree(phba->sli4_hba.vfi_bmask); |
| 6379 | kfree(phba->sli4_hba.vfi_ids); |
| 6380 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6381 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6382 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { |
| 6383 | list_del_init(&rsrc_blk->list); |
| 6384 | kfree(rsrc_blk); |
| 6385 | } |
| 6386 | break; |
| 6387 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 6388 | /* RPI bitmask and physical id array are cleaned up earlier. */ |
| 6389 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6390 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { |
| 6391 | list_del_init(&rsrc_blk->list); |
| 6392 | kfree(rsrc_blk); |
| 6393 | } |
| 6394 | break; |
| 6395 | default: |
| 6396 | break; |
| 6397 | } |
| 6398 | |
| 6399 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6400 | |
| 6401 | out_free_mbox: |
| 6402 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6403 | return rc; |
| 6404 | } |
| 6405 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 6406 | static void |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6407 | lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox, |
| 6408 | uint32_t feature) |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6409 | { |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6410 | uint32_t len; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6411 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6412 | len = sizeof(struct lpfc_mbx_set_feature) - |
| 6413 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 6414 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6415 | LPFC_MBOX_OPCODE_SET_FEATURES, len, |
| 6416 | LPFC_SLI4_MBX_EMBED); |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6417 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6418 | switch (feature) { |
| 6419 | case LPFC_SET_UE_RECOVERY: |
| 6420 | bf_set(lpfc_mbx_set_feature_UER, |
| 6421 | &mbox->u.mqe.un.set_feature, 1); |
| 6422 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY; |
| 6423 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 6424 | break; |
| 6425 | case LPFC_SET_MDS_DIAGS: |
| 6426 | bf_set(lpfc_mbx_set_feature_mds, |
| 6427 | &mbox->u.mqe.un.set_feature, 1); |
| 6428 | bf_set(lpfc_mbx_set_feature_mds_deep_loopbk, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 6429 | &mbox->u.mqe.un.set_feature, 1); |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6430 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS; |
| 6431 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 6432 | break; |
James Smart | 171f6c4 | 2019-11-04 16:57:07 -0800 | [diff] [blame] | 6433 | case LPFC_SET_DUAL_DUMP: |
| 6434 | bf_set(lpfc_mbx_set_feature_dd, |
| 6435 | &mbox->u.mqe.un.set_feature, LPFC_ENABLE_DUAL_DUMP); |
| 6436 | bf_set(lpfc_mbx_set_feature_ddquery, |
| 6437 | &mbox->u.mqe.un.set_feature, 0); |
| 6438 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_DUAL_DUMP; |
| 6439 | mbox->u.mqe.un.set_feature.param_len = 4; |
| 6440 | break; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6441 | } |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6442 | |
| 6443 | return; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6444 | } |
| 6445 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6446 | /** |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 6447 | * lpfc_ras_stop_fwlog: Disable FW logging by the adapter |
| 6448 | * @phba: Pointer to HBA context object. |
| 6449 | * |
| 6450 | * Disable FW logging into host memory on the adapter. To |
| 6451 | * be done before reading logs from the host memory. |
| 6452 | **/ |
| 6453 | void |
| 6454 | lpfc_ras_stop_fwlog(struct lpfc_hba *phba) |
| 6455 | { |
| 6456 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6457 | |
James Smart | 95bfc6d | 2019-10-18 14:18:27 -0700 | [diff] [blame] | 6458 | spin_lock_irq(&phba->hbalock); |
| 6459 | ras_fwlog->state = INACTIVE; |
| 6460 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 6461 | |
| 6462 | /* Disable FW logging to host memory */ |
| 6463 | writel(LPFC_CTL_PDEV_CTL_DDL_RAS, |
| 6464 | phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET); |
James Smart | 95bfc6d | 2019-10-18 14:18:27 -0700 | [diff] [blame] | 6465 | |
| 6466 | /* Wait 10ms for firmware to stop using DMA buffer */ |
| 6467 | usleep_range(10 * 1000, 20 * 1000); |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 6468 | } |
| 6469 | |
| 6470 | /** |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6471 | * lpfc_sli4_ras_dma_free - Free memory allocated for FW logging. |
| 6472 | * @phba: Pointer to HBA context object. |
| 6473 | * |
| 6474 | * This function is called to free memory allocated for RAS FW logging |
| 6475 | * support in the driver. |
| 6476 | **/ |
| 6477 | void |
| 6478 | lpfc_sli4_ras_dma_free(struct lpfc_hba *phba) |
| 6479 | { |
| 6480 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6481 | struct lpfc_dmabuf *dmabuf, *next; |
| 6482 | |
| 6483 | if (!list_empty(&ras_fwlog->fwlog_buff_list)) { |
| 6484 | list_for_each_entry_safe(dmabuf, next, |
| 6485 | &ras_fwlog->fwlog_buff_list, |
| 6486 | list) { |
| 6487 | list_del(&dmabuf->list); |
| 6488 | dma_free_coherent(&phba->pcidev->dev, |
| 6489 | LPFC_RAS_MAX_ENTRY_SIZE, |
| 6490 | dmabuf->virt, dmabuf->phys); |
| 6491 | kfree(dmabuf); |
| 6492 | } |
| 6493 | } |
| 6494 | |
| 6495 | if (ras_fwlog->lwpd.virt) { |
| 6496 | dma_free_coherent(&phba->pcidev->dev, |
| 6497 | sizeof(uint32_t) * 2, |
| 6498 | ras_fwlog->lwpd.virt, |
| 6499 | ras_fwlog->lwpd.phys); |
| 6500 | ras_fwlog->lwpd.virt = NULL; |
| 6501 | } |
| 6502 | |
James Smart | 95bfc6d | 2019-10-18 14:18:27 -0700 | [diff] [blame] | 6503 | spin_lock_irq(&phba->hbalock); |
| 6504 | ras_fwlog->state = INACTIVE; |
| 6505 | spin_unlock_irq(&phba->hbalock); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6506 | } |
| 6507 | |
| 6508 | /** |
| 6509 | * lpfc_sli4_ras_dma_alloc: Allocate memory for FW support |
| 6510 | * @phba: Pointer to HBA context object. |
| 6511 | * @fwlog_buff_count: Count of buffers to be created. |
| 6512 | * |
| 6513 | * This routine DMA memory for Log Write Position Data[LPWD] and buffer |
| 6514 | * to update FW log is posted to the adapter. |
| 6515 | * Buffer count is calculated based on module param ras_fwlog_buffsize |
| 6516 | * Size of each buffer posted to FW is 64K. |
| 6517 | **/ |
| 6518 | |
| 6519 | static int |
| 6520 | lpfc_sli4_ras_dma_alloc(struct lpfc_hba *phba, |
| 6521 | uint32_t fwlog_buff_count) |
| 6522 | { |
| 6523 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6524 | struct lpfc_dmabuf *dmabuf; |
| 6525 | int rc = 0, i = 0; |
| 6526 | |
| 6527 | /* Initialize List */ |
| 6528 | INIT_LIST_HEAD(&ras_fwlog->fwlog_buff_list); |
| 6529 | |
| 6530 | /* Allocate memory for the LWPD */ |
| 6531 | ras_fwlog->lwpd.virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 6532 | sizeof(uint32_t) * 2, |
| 6533 | &ras_fwlog->lwpd.phys, |
| 6534 | GFP_KERNEL); |
| 6535 | if (!ras_fwlog->lwpd.virt) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6536 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6537 | "6185 LWPD Memory Alloc Failed\n"); |
| 6538 | |
| 6539 | return -ENOMEM; |
| 6540 | } |
| 6541 | |
| 6542 | ras_fwlog->fw_buffcount = fwlog_buff_count; |
| 6543 | for (i = 0; i < ras_fwlog->fw_buffcount; i++) { |
| 6544 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 6545 | GFP_KERNEL); |
| 6546 | if (!dmabuf) { |
| 6547 | rc = -ENOMEM; |
| 6548 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6549 | "6186 Memory Alloc failed FW logging"); |
| 6550 | goto free_mem; |
| 6551 | } |
| 6552 | |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 6553 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6554 | LPFC_RAS_MAX_ENTRY_SIZE, |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 6555 | &dmabuf->phys, GFP_KERNEL); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6556 | if (!dmabuf->virt) { |
| 6557 | kfree(dmabuf); |
| 6558 | rc = -ENOMEM; |
| 6559 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6560 | "6187 DMA Alloc Failed FW logging"); |
| 6561 | goto free_mem; |
| 6562 | } |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6563 | dmabuf->buffer_tag = i; |
| 6564 | list_add_tail(&dmabuf->list, &ras_fwlog->fwlog_buff_list); |
| 6565 | } |
| 6566 | |
| 6567 | free_mem: |
| 6568 | if (rc) |
| 6569 | lpfc_sli4_ras_dma_free(phba); |
| 6570 | |
| 6571 | return rc; |
| 6572 | } |
| 6573 | |
| 6574 | /** |
| 6575 | * lpfc_sli4_ras_mbox_cmpl: Completion handler for RAS MBX command |
| 6576 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 6577 | * @pmb: pointer to the driver internal queue element for mailbox command. |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6578 | * |
| 6579 | * Completion handler for driver's RAS MBX command to the device. |
| 6580 | **/ |
| 6581 | static void |
| 6582 | lpfc_sli4_ras_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6583 | { |
| 6584 | MAILBOX_t *mb; |
| 6585 | union lpfc_sli4_cfg_shdr *shdr; |
| 6586 | uint32_t shdr_status, shdr_add_status; |
| 6587 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6588 | |
| 6589 | mb = &pmb->u.mb; |
| 6590 | |
| 6591 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 6592 | &pmb->u.mqe.un.ras_fwlog.header.cfg_shdr; |
| 6593 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 6594 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 6595 | |
| 6596 | if (mb->mbxStatus != MBX_SUCCESS || shdr_status) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6597 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6598 | "6188 FW LOG mailbox " |
| 6599 | "completed with status x%x add_status x%x," |
| 6600 | " mbx status x%x\n", |
| 6601 | shdr_status, shdr_add_status, mb->mbxStatus); |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6602 | |
| 6603 | ras_fwlog->ras_hwsupport = false; |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6604 | goto disable_ras; |
| 6605 | } |
| 6606 | |
James Smart | 95bfc6d | 2019-10-18 14:18:27 -0700 | [diff] [blame] | 6607 | spin_lock_irq(&phba->hbalock); |
| 6608 | ras_fwlog->state = ACTIVE; |
| 6609 | spin_unlock_irq(&phba->hbalock); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6610 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6611 | |
| 6612 | return; |
| 6613 | |
| 6614 | disable_ras: |
| 6615 | /* Free RAS DMA memory */ |
| 6616 | lpfc_sli4_ras_dma_free(phba); |
| 6617 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6618 | } |
| 6619 | |
| 6620 | /** |
| 6621 | * lpfc_sli4_ras_fwlog_init: Initialize memory and post RAS MBX command |
| 6622 | * @phba: pointer to lpfc hba data structure. |
| 6623 | * @fwlog_level: Logging verbosity level. |
| 6624 | * @fwlog_enable: Enable/Disable logging. |
| 6625 | * |
| 6626 | * Initialize memory and post mailbox command to enable FW logging in host |
| 6627 | * memory. |
| 6628 | **/ |
| 6629 | int |
| 6630 | lpfc_sli4_ras_fwlog_init(struct lpfc_hba *phba, |
| 6631 | uint32_t fwlog_level, |
| 6632 | uint32_t fwlog_enable) |
| 6633 | { |
| 6634 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6635 | struct lpfc_mbx_set_ras_fwlog *mbx_fwlog = NULL; |
| 6636 | struct lpfc_dmabuf *dmabuf; |
| 6637 | LPFC_MBOXQ_t *mbox; |
| 6638 | uint32_t len = 0, fwlog_buffsize, fwlog_entry_count; |
| 6639 | int rc = 0; |
| 6640 | |
James Smart | 95bfc6d | 2019-10-18 14:18:27 -0700 | [diff] [blame] | 6641 | spin_lock_irq(&phba->hbalock); |
| 6642 | ras_fwlog->state = INACTIVE; |
| 6643 | spin_unlock_irq(&phba->hbalock); |
| 6644 | |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6645 | fwlog_buffsize = (LPFC_RAS_MIN_BUFF_POST_SIZE * |
| 6646 | phba->cfg_ras_fwlog_buffsize); |
| 6647 | fwlog_entry_count = (fwlog_buffsize/LPFC_RAS_MAX_ENTRY_SIZE); |
| 6648 | |
| 6649 | /* |
| 6650 | * If re-enabling FW logging support use earlier allocated |
| 6651 | * DMA buffers while posting MBX command. |
| 6652 | **/ |
| 6653 | if (!ras_fwlog->lwpd.virt) { |
| 6654 | rc = lpfc_sli4_ras_dma_alloc(phba, fwlog_entry_count); |
| 6655 | if (rc) { |
| 6656 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6657 | "6189 FW Log Memory Allocation Failed"); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6658 | return rc; |
| 6659 | } |
| 6660 | } |
| 6661 | |
| 6662 | /* Setup Mailbox command */ |
| 6663 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6664 | if (!mbox) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6665 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6666 | "6190 RAS MBX Alloc Failed"); |
| 6667 | rc = -ENOMEM; |
| 6668 | goto mem_free; |
| 6669 | } |
| 6670 | |
| 6671 | ras_fwlog->fw_loglevel = fwlog_level; |
| 6672 | len = (sizeof(struct lpfc_mbx_set_ras_fwlog) - |
| 6673 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6674 | |
| 6675 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_LOWLEVEL, |
| 6676 | LPFC_MBOX_OPCODE_SET_DIAG_LOG_OPTION, |
| 6677 | len, LPFC_SLI4_MBX_EMBED); |
| 6678 | |
| 6679 | mbx_fwlog = (struct lpfc_mbx_set_ras_fwlog *)&mbox->u.mqe.un.ras_fwlog; |
| 6680 | bf_set(lpfc_fwlog_enable, &mbx_fwlog->u.request, |
| 6681 | fwlog_enable); |
| 6682 | bf_set(lpfc_fwlog_loglvl, &mbx_fwlog->u.request, |
| 6683 | ras_fwlog->fw_loglevel); |
| 6684 | bf_set(lpfc_fwlog_buffcnt, &mbx_fwlog->u.request, |
| 6685 | ras_fwlog->fw_buffcount); |
| 6686 | bf_set(lpfc_fwlog_buffsz, &mbx_fwlog->u.request, |
| 6687 | LPFC_RAS_MAX_ENTRY_SIZE/SLI4_PAGE_SIZE); |
| 6688 | |
| 6689 | /* Update DMA buffer address */ |
| 6690 | list_for_each_entry(dmabuf, &ras_fwlog->fwlog_buff_list, list) { |
| 6691 | memset(dmabuf->virt, 0, LPFC_RAS_MAX_ENTRY_SIZE); |
| 6692 | |
| 6693 | mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_lo = |
| 6694 | putPaddrLow(dmabuf->phys); |
| 6695 | |
| 6696 | mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_hi = |
| 6697 | putPaddrHigh(dmabuf->phys); |
| 6698 | } |
| 6699 | |
| 6700 | /* Update LPWD address */ |
| 6701 | mbx_fwlog->u.request.lwpd.addr_lo = putPaddrLow(ras_fwlog->lwpd.phys); |
| 6702 | mbx_fwlog->u.request.lwpd.addr_hi = putPaddrHigh(ras_fwlog->lwpd.phys); |
| 6703 | |
James Smart | 95bfc6d | 2019-10-18 14:18:27 -0700 | [diff] [blame] | 6704 | spin_lock_irq(&phba->hbalock); |
| 6705 | ras_fwlog->state = REG_INPROGRESS; |
| 6706 | spin_unlock_irq(&phba->hbalock); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6707 | mbox->vport = phba->pport; |
| 6708 | mbox->mbox_cmpl = lpfc_sli4_ras_mbox_cmpl; |
| 6709 | |
| 6710 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 6711 | |
| 6712 | if (rc == MBX_NOT_FINISHED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6713 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6714 | "6191 FW-Log Mailbox failed. " |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6715 | "status %d mbxStatus : x%x", rc, |
| 6716 | bf_get(lpfc_mqe_status, &mbox->u.mqe)); |
| 6717 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6718 | rc = -EIO; |
| 6719 | goto mem_free; |
| 6720 | } else |
| 6721 | rc = 0; |
| 6722 | mem_free: |
| 6723 | if (rc) |
| 6724 | lpfc_sli4_ras_dma_free(phba); |
| 6725 | |
| 6726 | return rc; |
| 6727 | } |
| 6728 | |
| 6729 | /** |
| 6730 | * lpfc_sli4_ras_setup - Check if RAS supported on the adapter |
| 6731 | * @phba: Pointer to HBA context object. |
| 6732 | * |
| 6733 | * Check if RAS is supported on the adapter and initialize it. |
| 6734 | **/ |
| 6735 | void |
| 6736 | lpfc_sli4_ras_setup(struct lpfc_hba *phba) |
| 6737 | { |
| 6738 | /* Check RAS FW Log needs to be enabled or not */ |
| 6739 | if (lpfc_check_fwlog_support(phba)) |
| 6740 | return; |
| 6741 | |
| 6742 | lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level, |
| 6743 | LPFC_RAS_ENABLE_LOGGING); |
| 6744 | } |
| 6745 | |
| 6746 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6747 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. |
| 6748 | * @phba: Pointer to HBA context object. |
| 6749 | * |
| 6750 | * This function allocates all SLI4 resource identifiers. |
| 6751 | **/ |
| 6752 | int |
| 6753 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) |
| 6754 | { |
| 6755 | int i, rc, error = 0; |
| 6756 | uint16_t count, base; |
| 6757 | unsigned long longs; |
| 6758 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6759 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 6760 | 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] | 6761 | if (phba->sli4_hba.extents_in_use) { |
| 6762 | /* |
| 6763 | * The port supports resource extents. The XRI, VPI, VFI, RPI |
| 6764 | * resource extent count must be read and allocated before |
| 6765 | * provisioning the resource id arrays. |
| 6766 | */ |
| 6767 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
| 6768 | LPFC_IDX_RSRC_RDY) { |
| 6769 | /* |
| 6770 | * Extent-based resources are set - the driver could |
| 6771 | * be in a port reset. Figure out if any corrective |
| 6772 | * actions need to be taken. |
| 6773 | */ |
| 6774 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6775 | LPFC_RSC_TYPE_FCOE_VFI); |
| 6776 | if (rc != 0) |
| 6777 | error++; |
| 6778 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6779 | LPFC_RSC_TYPE_FCOE_VPI); |
| 6780 | if (rc != 0) |
| 6781 | error++; |
| 6782 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6783 | LPFC_RSC_TYPE_FCOE_XRI); |
| 6784 | if (rc != 0) |
| 6785 | error++; |
| 6786 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6787 | LPFC_RSC_TYPE_FCOE_RPI); |
| 6788 | if (rc != 0) |
| 6789 | error++; |
| 6790 | |
| 6791 | /* |
| 6792 | * It's possible that the number of resources |
| 6793 | * provided to this port instance changed between |
| 6794 | * resets. Detect this condition and reallocate |
| 6795 | * resources. Otherwise, there is no action. |
| 6796 | */ |
| 6797 | if (error) { |
| 6798 | lpfc_printf_log(phba, KERN_INFO, |
| 6799 | LOG_MBOX | LOG_INIT, |
| 6800 | "2931 Detected extent resource " |
| 6801 | "change. Reallocating all " |
| 6802 | "extents.\n"); |
| 6803 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6804 | LPFC_RSC_TYPE_FCOE_VFI); |
| 6805 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6806 | LPFC_RSC_TYPE_FCOE_VPI); |
| 6807 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6808 | LPFC_RSC_TYPE_FCOE_XRI); |
| 6809 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6810 | LPFC_RSC_TYPE_FCOE_RPI); |
| 6811 | } else |
| 6812 | return 0; |
| 6813 | } |
| 6814 | |
| 6815 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 6816 | if (unlikely(rc)) |
| 6817 | goto err_exit; |
| 6818 | |
| 6819 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 6820 | if (unlikely(rc)) |
| 6821 | goto err_exit; |
| 6822 | |
| 6823 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 6824 | if (unlikely(rc)) |
| 6825 | goto err_exit; |
| 6826 | |
| 6827 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 6828 | if (unlikely(rc)) |
| 6829 | goto err_exit; |
| 6830 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 6831 | LPFC_IDX_RSRC_RDY); |
| 6832 | return rc; |
| 6833 | } else { |
| 6834 | /* |
| 6835 | * The port does not support resource extents. The XRI, VPI, |
| 6836 | * VFI, RPI resource ids were determined from READ_CONFIG. |
| 6837 | * Just allocate the bitmasks and provision the resource id |
| 6838 | * arrays. If a port reset is active, the resources don't |
| 6839 | * need any action - just exit. |
| 6840 | */ |
| 6841 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6842 | LPFC_IDX_RSRC_RDY) { |
| 6843 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 6844 | lpfc_sli4_remove_rpis(phba); |
| 6845 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6846 | /* RPIs. */ |
| 6847 | count = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6848 | if (count <= 0) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6849 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6850 | "3279 Invalid provisioning of " |
| 6851 | "rpi:%d\n", count); |
| 6852 | rc = -EINVAL; |
| 6853 | goto err_exit; |
| 6854 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6855 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
| 6856 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6857 | phba->sli4_hba.rpi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6858 | sizeof(unsigned long), |
| 6859 | GFP_KERNEL); |
| 6860 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 6861 | rc = -ENOMEM; |
| 6862 | goto err_exit; |
| 6863 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6864 | phba->sli4_hba.rpi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6865 | GFP_KERNEL); |
| 6866 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 6867 | rc = -ENOMEM; |
| 6868 | goto free_rpi_bmask; |
| 6869 | } |
| 6870 | |
| 6871 | for (i = 0; i < count; i++) |
| 6872 | phba->sli4_hba.rpi_ids[i] = base + i; |
| 6873 | |
| 6874 | /* VPIs. */ |
| 6875 | count = phba->sli4_hba.max_cfg_param.max_vpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6876 | if (count <= 0) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6877 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6878 | "3280 Invalid provisioning of " |
| 6879 | "vpi:%d\n", count); |
| 6880 | rc = -EINVAL; |
| 6881 | goto free_rpi_ids; |
| 6882 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6883 | base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 6884 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6885 | phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6886 | GFP_KERNEL); |
| 6887 | if (unlikely(!phba->vpi_bmask)) { |
| 6888 | rc = -ENOMEM; |
| 6889 | goto free_rpi_ids; |
| 6890 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6891 | phba->vpi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6892 | GFP_KERNEL); |
| 6893 | if (unlikely(!phba->vpi_ids)) { |
| 6894 | rc = -ENOMEM; |
| 6895 | goto free_vpi_bmask; |
| 6896 | } |
| 6897 | |
| 6898 | for (i = 0; i < count; i++) |
| 6899 | phba->vpi_ids[i] = base + i; |
| 6900 | |
| 6901 | /* XRIs. */ |
| 6902 | count = phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6903 | if (count <= 0) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6904 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6905 | "3281 Invalid provisioning of " |
| 6906 | "xri:%d\n", count); |
| 6907 | rc = -EINVAL; |
| 6908 | goto free_vpi_ids; |
| 6909 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6910 | base = phba->sli4_hba.max_cfg_param.xri_base; |
| 6911 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6912 | phba->sli4_hba.xri_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6913 | sizeof(unsigned long), |
| 6914 | GFP_KERNEL); |
| 6915 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 6916 | rc = -ENOMEM; |
| 6917 | goto free_vpi_ids; |
| 6918 | } |
James Smart | 41899be | 2012-03-01 22:34:19 -0500 | [diff] [blame] | 6919 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6920 | phba->sli4_hba.xri_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6921 | GFP_KERNEL); |
| 6922 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 6923 | rc = -ENOMEM; |
| 6924 | goto free_xri_bmask; |
| 6925 | } |
| 6926 | |
| 6927 | for (i = 0; i < count; i++) |
| 6928 | phba->sli4_hba.xri_ids[i] = base + i; |
| 6929 | |
| 6930 | /* VFIs. */ |
| 6931 | count = phba->sli4_hba.max_cfg_param.max_vfi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6932 | if (count <= 0) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6933 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6934 | "3282 Invalid provisioning of " |
| 6935 | "vfi:%d\n", count); |
| 6936 | rc = -EINVAL; |
| 6937 | goto free_xri_ids; |
| 6938 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6939 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
| 6940 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6941 | phba->sli4_hba.vfi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6942 | sizeof(unsigned long), |
| 6943 | GFP_KERNEL); |
| 6944 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 6945 | rc = -ENOMEM; |
| 6946 | goto free_xri_ids; |
| 6947 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6948 | phba->sli4_hba.vfi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6949 | GFP_KERNEL); |
| 6950 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 6951 | rc = -ENOMEM; |
| 6952 | goto free_vfi_bmask; |
| 6953 | } |
| 6954 | |
| 6955 | for (i = 0; i < count; i++) |
| 6956 | phba->sli4_hba.vfi_ids[i] = base + i; |
| 6957 | |
| 6958 | /* |
| 6959 | * Mark all resources ready. An HBA reset doesn't need |
| 6960 | * to reset the initialization. |
| 6961 | */ |
| 6962 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 6963 | LPFC_IDX_RSRC_RDY); |
| 6964 | return 0; |
| 6965 | } |
| 6966 | |
| 6967 | free_vfi_bmask: |
| 6968 | kfree(phba->sli4_hba.vfi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6969 | phba->sli4_hba.vfi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6970 | free_xri_ids: |
| 6971 | kfree(phba->sli4_hba.xri_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6972 | phba->sli4_hba.xri_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6973 | free_xri_bmask: |
| 6974 | kfree(phba->sli4_hba.xri_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6975 | phba->sli4_hba.xri_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6976 | free_vpi_ids: |
| 6977 | kfree(phba->vpi_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6978 | phba->vpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6979 | free_vpi_bmask: |
| 6980 | kfree(phba->vpi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6981 | phba->vpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6982 | free_rpi_ids: |
| 6983 | kfree(phba->sli4_hba.rpi_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6984 | phba->sli4_hba.rpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6985 | free_rpi_bmask: |
| 6986 | kfree(phba->sli4_hba.rpi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6987 | phba->sli4_hba.rpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6988 | err_exit: |
| 6989 | return rc; |
| 6990 | } |
| 6991 | |
| 6992 | /** |
| 6993 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. |
| 6994 | * @phba: Pointer to HBA context object. |
| 6995 | * |
| 6996 | * This function allocates the number of elements for the specified |
| 6997 | * resource type. |
| 6998 | **/ |
| 6999 | int |
| 7000 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) |
| 7001 | { |
| 7002 | if (phba->sli4_hba.extents_in_use) { |
| 7003 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 7004 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 7005 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 7006 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 7007 | } else { |
| 7008 | kfree(phba->vpi_bmask); |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 7009 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7010 | kfree(phba->vpi_ids); |
| 7011 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 7012 | kfree(phba->sli4_hba.xri_bmask); |
| 7013 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7014 | kfree(phba->sli4_hba.vfi_bmask); |
| 7015 | kfree(phba->sli4_hba.vfi_ids); |
| 7016 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 7017 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 7018 | } |
| 7019 | |
| 7020 | return 0; |
| 7021 | } |
| 7022 | |
| 7023 | /** |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 7024 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. |
| 7025 | * @phba: Pointer to HBA context object. |
| 7026 | * @type: The resource extent type. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 7027 | * @extnt_cnt: buffer to hold port extent count response |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 7028 | * @extnt_size: buffer to hold port extent size response. |
| 7029 | * |
| 7030 | * This function calls the port to read the host allocated extents |
| 7031 | * for a particular type. |
| 7032 | **/ |
| 7033 | int |
| 7034 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, |
| 7035 | uint16_t *extnt_cnt, uint16_t *extnt_size) |
| 7036 | { |
| 7037 | bool emb; |
| 7038 | int rc = 0; |
| 7039 | uint16_t curr_blks = 0; |
| 7040 | uint32_t req_len, emb_len; |
| 7041 | uint32_t alloc_len, mbox_tmo; |
| 7042 | struct list_head *blk_list_head; |
| 7043 | struct lpfc_rsrc_blks *rsrc_blk; |
| 7044 | LPFC_MBOXQ_t *mbox; |
| 7045 | void *virtaddr = NULL; |
| 7046 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 7047 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 7048 | union lpfc_sli4_cfg_shdr *shdr; |
| 7049 | |
| 7050 | switch (type) { |
| 7051 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 7052 | blk_list_head = &phba->lpfc_vpi_blk_list; |
| 7053 | break; |
| 7054 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 7055 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; |
| 7056 | break; |
| 7057 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 7058 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 7059 | break; |
| 7060 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 7061 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 7062 | break; |
| 7063 | default: |
| 7064 | return -EIO; |
| 7065 | } |
| 7066 | |
| 7067 | /* Count the number of extents currently allocatd for this type. */ |
| 7068 | list_for_each_entry(rsrc_blk, blk_list_head, list) { |
| 7069 | if (curr_blks == 0) { |
| 7070 | /* |
| 7071 | * The GET_ALLOCATED mailbox does not return the size, |
| 7072 | * just the count. The size should be just the size |
| 7073 | * stored in the current allocated block and all sizes |
| 7074 | * for an extent type are the same so set the return |
| 7075 | * value now. |
| 7076 | */ |
| 7077 | *extnt_size = rsrc_blk->rsrc_size; |
| 7078 | } |
| 7079 | curr_blks++; |
| 7080 | } |
| 7081 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 7082 | /* |
| 7083 | * Calculate the size of an embedded mailbox. The uint32_t |
| 7084 | * accounts for extents-specific word. |
| 7085 | */ |
| 7086 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 7087 | sizeof(uint32_t); |
| 7088 | |
| 7089 | /* |
| 7090 | * Presume the allocation and response will fit into an embedded |
| 7091 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 7092 | */ |
| 7093 | emb = LPFC_SLI4_MBX_EMBED; |
| 7094 | req_len = emb_len; |
| 7095 | if (req_len > emb_len) { |
| 7096 | req_len = curr_blks * sizeof(uint16_t) + |
| 7097 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 7098 | sizeof(uint32_t); |
| 7099 | emb = LPFC_SLI4_MBX_NEMBED; |
| 7100 | } |
| 7101 | |
| 7102 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7103 | if (!mbox) |
| 7104 | return -ENOMEM; |
| 7105 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); |
| 7106 | |
| 7107 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7108 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, |
| 7109 | req_len, emb); |
| 7110 | if (alloc_len < req_len) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7111 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 7112 | "2983 Allocated DMA memory size (x%x) is " |
| 7113 | "less than the requested DMA memory " |
| 7114 | "size (x%x)\n", alloc_len, req_len); |
| 7115 | rc = -ENOMEM; |
| 7116 | goto err_exit; |
| 7117 | } |
| 7118 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); |
| 7119 | if (unlikely(rc)) { |
| 7120 | rc = -EIO; |
| 7121 | goto err_exit; |
| 7122 | } |
| 7123 | |
| 7124 | if (!phba->sli4_hba.intr_enable) |
| 7125 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 7126 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7127 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 7128 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 7129 | } |
| 7130 | |
| 7131 | if (unlikely(rc)) { |
| 7132 | rc = -EIO; |
| 7133 | goto err_exit; |
| 7134 | } |
| 7135 | |
| 7136 | /* |
| 7137 | * Figure out where the response is located. Then get local pointers |
| 7138 | * to the response data. The port does not guarantee to respond to |
| 7139 | * all extents counts request so update the local variable with the |
| 7140 | * allocated count from the port. |
| 7141 | */ |
| 7142 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 7143 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 7144 | shdr = &rsrc_ext->header.cfg_shdr; |
| 7145 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 7146 | } else { |
| 7147 | virtaddr = mbox->sge_array->addr[0]; |
| 7148 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 7149 | shdr = &n_rsrc->cfg_shdr; |
| 7150 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 7151 | } |
| 7152 | |
| 7153 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7154 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 7155 | "2984 Failed to read allocated resources " |
| 7156 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", |
| 7157 | type, |
| 7158 | bf_get(lpfc_mbox_hdr_status, &shdr->response), |
| 7159 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); |
| 7160 | rc = -EIO; |
| 7161 | goto err_exit; |
| 7162 | } |
| 7163 | err_exit: |
| 7164 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 7165 | return rc; |
| 7166 | } |
| 7167 | |
| 7168 | /** |
James Smart | 0ef6996 | 2017-04-21 16:04:50 -0700 | [diff] [blame] | 7169 | * lpfc_sli4_repost_sgl_list - Repost the buffers sgl pages as block |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7170 | * @phba: pointer to lpfc hba data structure. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7171 | * @sgl_list: linked link of sgl buffers to post |
| 7172 | * @cnt: number of linked list buffers |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7173 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7174 | * This routine walks the list of buffers that have been allocated and |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7175 | * repost them to the port by using SGL block post. This is needed after a |
| 7176 | * pci_function_reset/warm_start or start. It attempts to construct blocks |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7177 | * of buffer sgls which contains contiguous xris and uses the non-embedded |
| 7178 | * 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] | 7179 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post |
| 7180 | * mailbox command for posting. |
| 7181 | * |
| 7182 | * Returns: 0 = success, non-zero failure. |
| 7183 | **/ |
| 7184 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7185 | lpfc_sli4_repost_sgl_list(struct lpfc_hba *phba, |
| 7186 | struct list_head *sgl_list, int cnt) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7187 | { |
| 7188 | struct lpfc_sglq *sglq_entry = NULL; |
| 7189 | struct lpfc_sglq *sglq_entry_next = NULL; |
| 7190 | struct lpfc_sglq *sglq_entry_first = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7191 | int status, total_cnt; |
| 7192 | int post_cnt = 0, num_posted = 0, block_cnt = 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7193 | int last_xritag = NO_XRI; |
| 7194 | LIST_HEAD(prep_sgl_list); |
| 7195 | LIST_HEAD(blck_sgl_list); |
| 7196 | LIST_HEAD(allc_sgl_list); |
| 7197 | LIST_HEAD(post_sgl_list); |
| 7198 | LIST_HEAD(free_sgl_list); |
| 7199 | |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 7200 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7201 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 7202 | list_splice_init(sgl_list, &allc_sgl_list); |
| 7203 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 7204 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7205 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7206 | total_cnt = cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7207 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 7208 | &allc_sgl_list, list) { |
| 7209 | list_del_init(&sglq_entry->list); |
| 7210 | block_cnt++; |
| 7211 | if ((last_xritag != NO_XRI) && |
| 7212 | (sglq_entry->sli4_xritag != last_xritag + 1)) { |
| 7213 | /* a hole in xri block, form a sgl posting block */ |
| 7214 | list_splice_init(&prep_sgl_list, &blck_sgl_list); |
| 7215 | post_cnt = block_cnt - 1; |
| 7216 | /* prepare list for next posting block */ |
| 7217 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 7218 | block_cnt = 1; |
| 7219 | } else { |
| 7220 | /* prepare list for next posting block */ |
| 7221 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 7222 | /* enough sgls for non-embed sgl mbox command */ |
| 7223 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 7224 | list_splice_init(&prep_sgl_list, |
| 7225 | &blck_sgl_list); |
| 7226 | post_cnt = block_cnt; |
| 7227 | block_cnt = 0; |
| 7228 | } |
| 7229 | } |
| 7230 | num_posted++; |
| 7231 | |
| 7232 | /* keep track of last sgl's xritag */ |
| 7233 | last_xritag = sglq_entry->sli4_xritag; |
| 7234 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7235 | /* end of repost sgl list condition for buffers */ |
| 7236 | if (num_posted == total_cnt) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7237 | if (post_cnt == 0) { |
| 7238 | list_splice_init(&prep_sgl_list, |
| 7239 | &blck_sgl_list); |
| 7240 | post_cnt = block_cnt; |
| 7241 | } else if (block_cnt == 1) { |
| 7242 | status = lpfc_sli4_post_sgl(phba, |
| 7243 | sglq_entry->phys, 0, |
| 7244 | sglq_entry->sli4_xritag); |
| 7245 | if (!status) { |
| 7246 | /* successful, put sgl to posted list */ |
| 7247 | list_add_tail(&sglq_entry->list, |
| 7248 | &post_sgl_list); |
| 7249 | } else { |
| 7250 | /* Failure, put sgl to free list */ |
| 7251 | lpfc_printf_log(phba, KERN_WARNING, |
| 7252 | LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7253 | "3159 Failed to post " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7254 | "sgl, xritag:x%x\n", |
| 7255 | sglq_entry->sli4_xritag); |
| 7256 | list_add_tail(&sglq_entry->list, |
| 7257 | &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 7258 | total_cnt--; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7259 | } |
| 7260 | } |
| 7261 | } |
| 7262 | |
| 7263 | /* continue until a nembed page worth of sgls */ |
| 7264 | if (post_cnt == 0) |
| 7265 | continue; |
| 7266 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7267 | /* post the buffer list sgls as a block */ |
| 7268 | status = lpfc_sli4_post_sgl_list(phba, &blck_sgl_list, |
| 7269 | post_cnt); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7270 | |
| 7271 | if (!status) { |
| 7272 | /* success, put sgl list to posted sgl list */ |
| 7273 | list_splice_init(&blck_sgl_list, &post_sgl_list); |
| 7274 | } else { |
| 7275 | /* Failure, put sgl list to free sgl list */ |
| 7276 | sglq_entry_first = list_first_entry(&blck_sgl_list, |
| 7277 | struct lpfc_sglq, |
| 7278 | list); |
| 7279 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7280 | "3160 Failed to post sgl-list, " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7281 | "xritag:x%x-x%x\n", |
| 7282 | sglq_entry_first->sli4_xritag, |
| 7283 | (sglq_entry_first->sli4_xritag + |
| 7284 | post_cnt - 1)); |
| 7285 | list_splice_init(&blck_sgl_list, &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 7286 | total_cnt -= post_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7287 | } |
| 7288 | |
| 7289 | /* don't reset xirtag due to hole in xri block */ |
| 7290 | if (block_cnt == 0) |
| 7291 | last_xritag = NO_XRI; |
| 7292 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7293 | /* reset sgl post count for next round of posting */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7294 | post_cnt = 0; |
| 7295 | } |
| 7296 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7297 | /* free the sgls failed to post */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7298 | lpfc_free_sgl_list(phba, &free_sgl_list); |
| 7299 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7300 | /* push sgls posted to the available list */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7301 | if (!list_empty(&post_sgl_list)) { |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 7302 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7303 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 7304 | list_splice_init(&post_sgl_list, sgl_list); |
| 7305 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 7306 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7307 | } else { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7308 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7309 | "3161 Failure to post sgl to port.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7310 | return -EIO; |
| 7311 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7312 | |
| 7313 | /* return the number of XRIs actually posted */ |
| 7314 | return total_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7315 | } |
| 7316 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7317 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7318 | * 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] | 7319 | * @phba: pointer to lpfc hba data structure. |
| 7320 | * |
| 7321 | * This routine walks the list of nvme buffers that have been allocated and |
| 7322 | * repost them to the port by using SGL block post. This is needed after a |
| 7323 | * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine |
| 7324 | * 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] | 7325 | * 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] | 7326 | * |
| 7327 | * Returns: 0 = success, non-zero failure. |
| 7328 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 7329 | static int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7330 | lpfc_sli4_repost_io_sgl_list(struct lpfc_hba *phba) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7331 | { |
| 7332 | LIST_HEAD(post_nblist); |
| 7333 | int num_posted, rc = 0; |
| 7334 | |
| 7335 | /* get all NVME buffers need to repost to a local list */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7336 | lpfc_io_buf_flush(phba, &post_nblist); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7337 | |
| 7338 | /* post the list of nvme buffer sgls to port if available */ |
| 7339 | if (!list_empty(&post_nblist)) { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7340 | num_posted = lpfc_sli4_post_io_sgl_list( |
| 7341 | phba, &post_nblist, phba->sli4_hba.io_xri_cnt); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7342 | /* failed to post any nvme buffer, return error */ |
| 7343 | if (num_posted == 0) |
| 7344 | rc = -EIO; |
| 7345 | } |
| 7346 | return rc; |
| 7347 | } |
| 7348 | |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 7349 | static void |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7350 | lpfc_set_host_data(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 7351 | { |
| 7352 | uint32_t len; |
| 7353 | |
| 7354 | len = sizeof(struct lpfc_mbx_set_host_data) - |
| 7355 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 7356 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7357 | LPFC_MBOX_OPCODE_SET_HOST_DATA, len, |
| 7358 | LPFC_SLI4_MBX_EMBED); |
| 7359 | |
| 7360 | 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] | 7361 | mbox->u.mqe.un.set_host_data.param_len = |
| 7362 | LPFC_HOST_OS_DRIVER_VERSION_SIZE; |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7363 | snprintf(mbox->u.mqe.un.set_host_data.data, |
| 7364 | LPFC_HOST_OS_DRIVER_VERSION_SIZE, |
| 7365 | "Linux %s v"LPFC_DRIVER_VERSION, |
| 7366 | (phba->hba_flag & HBA_FCOE_MODE) ? "FCoE" : "FC"); |
| 7367 | } |
| 7368 | |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7369 | int |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7370 | lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7371 | struct lpfc_queue *drq, int count, int idx) |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7372 | { |
| 7373 | int rc, i; |
| 7374 | struct lpfc_rqe hrqe; |
| 7375 | struct lpfc_rqe drqe; |
| 7376 | struct lpfc_rqb *rqbp; |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7377 | unsigned long flags; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7378 | struct rqb_dmabuf *rqb_buffer; |
| 7379 | LIST_HEAD(rqb_buf_list); |
| 7380 | |
| 7381 | rqbp = hrq->rqbp; |
| 7382 | for (i = 0; i < count; i++) { |
James Smart | 62e3a931d | 2020-10-20 13:27:11 -0700 | [diff] [blame] | 7383 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7384 | /* IF RQ is already full, don't bother */ |
James Smart | 62e3a931d | 2020-10-20 13:27:11 -0700 | [diff] [blame] | 7385 | if (rqbp->buffer_count + i >= rqbp->entry_count - 1) { |
| 7386 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7387 | break; |
James Smart | 62e3a931d | 2020-10-20 13:27:11 -0700 | [diff] [blame] | 7388 | } |
| 7389 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 7390 | |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7391 | rqb_buffer = rqbp->rqb_alloc_buffer(phba); |
| 7392 | if (!rqb_buffer) |
| 7393 | break; |
| 7394 | rqb_buffer->hrq = hrq; |
| 7395 | rqb_buffer->drq = drq; |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7396 | rqb_buffer->idx = idx; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7397 | list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list); |
| 7398 | } |
James Smart | 62e3a931d | 2020-10-20 13:27:11 -0700 | [diff] [blame] | 7399 | |
| 7400 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7401 | while (!list_empty(&rqb_buf_list)) { |
| 7402 | list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf, |
| 7403 | hbuf.list); |
| 7404 | |
| 7405 | hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys); |
| 7406 | hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys); |
| 7407 | drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys); |
| 7408 | drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys); |
| 7409 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
| 7410 | if (rc < 0) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7411 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7412 | "6421 Cannot post to HRQ %d: %x %x %x " |
| 7413 | "DRQ %x %x\n", |
| 7414 | hrq->queue_id, |
| 7415 | hrq->host_index, |
| 7416 | hrq->hba_index, |
| 7417 | hrq->entry_count, |
| 7418 | drq->host_index, |
| 7419 | drq->hba_index); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7420 | rqbp->rqb_free_buffer(phba, rqb_buffer); |
| 7421 | } else { |
| 7422 | list_add_tail(&rqb_buffer->hbuf.list, |
| 7423 | &rqbp->rqb_buffer_list); |
| 7424 | rqbp->buffer_count++; |
| 7425 | } |
| 7426 | } |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7427 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7428 | return 1; |
| 7429 | } |
| 7430 | |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 7431 | /** |
| 7432 | * lpfc_init_idle_stat_hb - Initialize idle_stat tracking |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 7433 | * @phba: pointer to lpfc hba data structure. |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 7434 | * |
| 7435 | * This routine initializes the per-cq idle_stat to dynamically dictate |
| 7436 | * polling decisions. |
| 7437 | * |
| 7438 | * Return codes: |
| 7439 | * None |
| 7440 | **/ |
| 7441 | static void lpfc_init_idle_stat_hb(struct lpfc_hba *phba) |
| 7442 | { |
| 7443 | int i; |
| 7444 | struct lpfc_sli4_hdw_queue *hdwq; |
| 7445 | struct lpfc_queue *cq; |
| 7446 | struct lpfc_idle_stat *idle_stat; |
| 7447 | u64 wall; |
| 7448 | |
| 7449 | for_each_present_cpu(i) { |
| 7450 | hdwq = &phba->sli4_hba.hdwq[phba->sli4_hba.cpu_map[i].hdwq]; |
| 7451 | cq = hdwq->io_cq; |
| 7452 | |
| 7453 | /* Skip if we've already handled this cq's primary CPU */ |
| 7454 | if (cq->chann != i) |
| 7455 | continue; |
| 7456 | |
| 7457 | idle_stat = &phba->sli4_hba.idle_stat[i]; |
| 7458 | |
| 7459 | idle_stat->prev_idle = get_cpu_idle_time(i, &wall, 1); |
| 7460 | idle_stat->prev_wall = wall; |
| 7461 | |
| 7462 | if (phba->nvmet_support) |
| 7463 | cq->poll_mode = LPFC_QUEUE_WORK; |
| 7464 | else |
| 7465 | cq->poll_mode = LPFC_IRQ_POLL; |
| 7466 | } |
| 7467 | |
| 7468 | if (!phba->nvmet_support) |
| 7469 | schedule_delayed_work(&phba->idle_stat_delay_work, |
| 7470 | msecs_to_jiffies(LPFC_IDLE_STAT_DELAY)); |
| 7471 | } |
| 7472 | |
Dick Kennedy | f0020e4 | 2020-06-30 14:49:58 -0700 | [diff] [blame] | 7473 | static void lpfc_sli4_dip(struct lpfc_hba *phba) |
| 7474 | { |
| 7475 | uint32_t if_type; |
| 7476 | |
| 7477 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 7478 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2 || |
| 7479 | if_type == LPFC_SLI_INTF_IF_TYPE_6) { |
| 7480 | struct lpfc_register reg_data; |
| 7481 | |
| 7482 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 7483 | ®_data.word0)) |
| 7484 | return; |
| 7485 | |
| 7486 | if (bf_get(lpfc_sliport_status_dip, ®_data)) |
James Smart | 0b3ad32 | 2021-01-04 10:02:39 -0800 | [diff] [blame] | 7487 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
Dick Kennedy | f0020e4 | 2020-06-30 14:49:58 -0700 | [diff] [blame] | 7488 | "2904 Firmware Dump Image Present" |
| 7489 | " on Adapter"); |
| 7490 | } |
| 7491 | } |
| 7492 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7493 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 7494 | * lpfc_sli4_hba_setup - SLI4 device initialization PCI function |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7495 | * @phba: Pointer to HBA context object. |
| 7496 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 7497 | * This function is the main SLI4 device initialization PCI function. This |
| 7498 | * function is called by the HBA initialization code, HBA reset code and |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7499 | * HBA error attention handler code. Caller is not required to hold any |
| 7500 | * locks. |
| 7501 | **/ |
| 7502 | int |
| 7503 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) |
| 7504 | { |
James Smart | 171f6c4 | 2019-11-04 16:57:07 -0800 | [diff] [blame] | 7505 | int rc, i, cnt, len, dd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7506 | LPFC_MBOXQ_t *mboxq; |
| 7507 | struct lpfc_mqe *mqe; |
| 7508 | uint8_t *vpd; |
| 7509 | uint32_t vpd_size; |
| 7510 | uint32_t ftr_rsp = 0; |
| 7511 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
| 7512 | struct lpfc_vport *vport = phba->pport; |
| 7513 | struct lpfc_dmabuf *mp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7514 | struct lpfc_rqb *rqbp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7515 | |
| 7516 | /* Perform a PCI function reset to start from clean */ |
| 7517 | rc = lpfc_pci_function_reset(phba); |
| 7518 | if (unlikely(rc)) |
| 7519 | return -ENODEV; |
| 7520 | |
| 7521 | /* Check the HBA Host Status Register for readyness */ |
| 7522 | rc = lpfc_sli4_post_status_check(phba); |
| 7523 | if (unlikely(rc)) |
| 7524 | return -ENODEV; |
| 7525 | else { |
| 7526 | spin_lock_irq(&phba->hbalock); |
| 7527 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; |
| 7528 | spin_unlock_irq(&phba->hbalock); |
| 7529 | } |
| 7530 | |
Dick Kennedy | f0020e4 | 2020-06-30 14:49:58 -0700 | [diff] [blame] | 7531 | lpfc_sli4_dip(phba); |
| 7532 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7533 | /* |
| 7534 | * Allocate a single mailbox container for initializing the |
| 7535 | * port. |
| 7536 | */ |
| 7537 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7538 | if (!mboxq) |
| 7539 | return -ENOMEM; |
| 7540 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7541 | /* Issue READ_REV to collect vpd and FW information. */ |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 7542 | vpd_size = SLI4_PAGE_SIZE; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7543 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
| 7544 | if (!vpd) { |
| 7545 | rc = -ENOMEM; |
| 7546 | goto out_free_mbox; |
| 7547 | } |
| 7548 | |
| 7549 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7550 | if (unlikely(rc)) { |
| 7551 | kfree(vpd); |
| 7552 | goto out_free_mbox; |
| 7553 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 7554 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7555 | mqe = &mboxq->u.mqe; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7556 | 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] | 7557 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7558 | phba->hba_flag |= HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 7559 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
| 7560 | } else { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7561 | phba->hba_flag &= ~HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 7562 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 7563 | |
| 7564 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == |
| 7565 | LPFC_DCBX_CEE_MODE) |
| 7566 | phba->hba_flag |= HBA_FIP_SUPPORT; |
| 7567 | else |
| 7568 | phba->hba_flag &= ~HBA_FIP_SUPPORT; |
| 7569 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 7570 | phba->hba_flag &= ~HBA_IOQ_FLUSH; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 7571 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7572 | if (phba->sli_rev != LPFC_SLI_REV4) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7573 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7574 | "0376 READ_REV Error. SLI Level %d " |
| 7575 | "FCoE enabled %d\n", |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7576 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7577 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7578 | kfree(vpd); |
| 7579 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7580 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 7581 | |
| 7582 | /* |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7583 | * Continue initialization with default values even if driver failed |
| 7584 | * to read FCoE param config regions, only read parameters if the |
| 7585 | * board is FCoE |
| 7586 | */ |
| 7587 | if (phba->hba_flag & HBA_FCOE_MODE && |
| 7588 | lpfc_sli4_read_fcoe_params(phba)) |
| 7589 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, |
| 7590 | "2570 Failed to read FCoE parameters\n"); |
| 7591 | |
| 7592 | /* |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 7593 | * Retrieve sli4 device physical port name, failure of doing it |
| 7594 | * is considered as non-fatal. |
| 7595 | */ |
| 7596 | rc = lpfc_sli4_retrieve_pport_name(phba); |
| 7597 | if (!rc) |
| 7598 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7599 | "3080 Successful retrieving SLI4 device " |
| 7600 | "physical port name: %s.\n", phba->Port); |
| 7601 | |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 7602 | rc = lpfc_sli4_get_ctl_attr(phba); |
| 7603 | if (!rc) |
| 7604 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7605 | "8351 Successful retrieving SLI4 device " |
| 7606 | "CTL ATTR\n"); |
| 7607 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7608 | /* |
| 7609 | * Evaluate the read rev and vpd data. Populate the driver |
| 7610 | * state with the results. If this routine fails, the failure |
| 7611 | * is not fatal as the driver will use generic values. |
| 7612 | */ |
| 7613 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); |
| 7614 | if (unlikely(!rc)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7615 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7616 | "0377 Error %d parsing vpd. " |
| 7617 | "Using defaults.\n", rc); |
| 7618 | rc = 0; |
| 7619 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7620 | kfree(vpd); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7621 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7622 | /* Save information as VPD data */ |
| 7623 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; |
| 7624 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; |
James Smart | 4e565cf | 2018-02-22 08:18:50 -0800 | [diff] [blame] | 7625 | |
| 7626 | /* |
| 7627 | * This is because first G7 ASIC doesn't support the standard |
| 7628 | * 0x5a NVME cmd descriptor type/subtype |
| 7629 | */ |
| 7630 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 7631 | LPFC_SLI_INTF_IF_TYPE_6) && |
| 7632 | (phba->vpd.rev.biuRev == LPFC_G7_ASIC_1) && |
| 7633 | (phba->vpd.rev.smRev == 0) && |
| 7634 | (phba->cfg_nvme_embed_cmd == 1)) |
| 7635 | phba->cfg_nvme_embed_cmd = 0; |
| 7636 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7637 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; |
| 7638 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, |
| 7639 | &mqe->un.read_rev); |
| 7640 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, |
| 7641 | &mqe->un.read_rev); |
| 7642 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, |
| 7643 | &mqe->un.read_rev); |
| 7644 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, |
| 7645 | &mqe->un.read_rev); |
| 7646 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; |
| 7647 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); |
| 7648 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; |
| 7649 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); |
| 7650 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; |
| 7651 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); |
| 7652 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7653 | "(%d):0380 READ_REV Status x%x " |
| 7654 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", |
| 7655 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7656 | bf_get(lpfc_mqe_status, mqe), |
| 7657 | phba->vpd.rev.opFwName, |
| 7658 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, |
| 7659 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7660 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7661 | 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] | 7662 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 7663 | lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY); |
| 7664 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7665 | if (rc == MBX_SUCCESS) { |
| 7666 | phba->hba_flag |= HBA_RECOVERABLE_UE; |
| 7667 | /* Set 1Sec interval to detect UE */ |
| 7668 | phba->eratt_poll_interval = 1; |
| 7669 | phba->sli4_hba.ue_to_sr = bf_get( |
| 7670 | lpfc_mbx_set_feature_UESR, |
| 7671 | &mboxq->u.mqe.un.set_feature); |
| 7672 | phba->sli4_hba.ue_to_rp = bf_get( |
| 7673 | lpfc_mbx_set_feature_UERP, |
| 7674 | &mboxq->u.mqe.un.set_feature); |
| 7675 | } |
| 7676 | } |
| 7677 | |
| 7678 | if (phba->cfg_enable_mds_diags && phba->mds_diags_support) { |
| 7679 | /* Enable MDS Diagnostics only if the SLI Port supports it */ |
| 7680 | lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS); |
| 7681 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7682 | if (rc != MBX_SUCCESS) |
| 7683 | phba->mds_diags_support = 0; |
| 7684 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 7685 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7686 | /* |
| 7687 | * Discover the port's supported feature set and match it against the |
| 7688 | * hosts requests. |
| 7689 | */ |
| 7690 | lpfc_request_features(phba, mboxq); |
| 7691 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7692 | if (unlikely(rc)) { |
| 7693 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7694 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7695 | } |
| 7696 | |
| 7697 | /* |
| 7698 | * The port must support FCP initiator mode as this is the |
| 7699 | * only mode running in the host. |
| 7700 | */ |
| 7701 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { |
| 7702 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7703 | "0378 No support for fcpi mode.\n"); |
| 7704 | ftr_rsp++; |
| 7705 | } |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 7706 | |
| 7707 | /* Performance Hints are ONLY for FCoE */ |
| 7708 | if (phba->hba_flag & HBA_FCOE_MODE) { |
| 7709 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
| 7710 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; |
| 7711 | else |
| 7712 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; |
| 7713 | } |
| 7714 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7715 | /* |
| 7716 | * If the port cannot support the host's requested features |
| 7717 | * then turn off the global config parameters to disable the |
| 7718 | * feature in the driver. This is not a fatal error. |
| 7719 | */ |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 7720 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
| 7721 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) { |
| 7722 | phba->cfg_enable_bg = 0; |
| 7723 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 7724 | ftr_rsp++; |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 7725 | } |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 7726 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7727 | |
| 7728 | if (phba->max_vpi && phba->cfg_enable_npiv && |
| 7729 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 7730 | ftr_rsp++; |
| 7731 | |
| 7732 | if (ftr_rsp) { |
| 7733 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7734 | "0379 Feature Mismatch Data: x%08x %08x " |
| 7735 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, |
| 7736 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, |
| 7737 | phba->cfg_enable_npiv, phba->max_vpi); |
| 7738 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 7739 | phba->cfg_enable_bg = 0; |
| 7740 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 7741 | phba->cfg_enable_npiv = 0; |
| 7742 | } |
| 7743 | |
| 7744 | /* These SLI3 features are assumed in SLI4 */ |
| 7745 | spin_lock_irq(&phba->hbalock); |
| 7746 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); |
| 7747 | spin_unlock_irq(&phba->hbalock); |
| 7748 | |
James Smart | 171f6c4 | 2019-11-04 16:57:07 -0800 | [diff] [blame] | 7749 | /* Always try to enable dual dump feature if we can */ |
| 7750 | lpfc_set_features(phba, mboxq, LPFC_SET_DUAL_DUMP); |
| 7751 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7752 | dd = bf_get(lpfc_mbx_set_feature_dd, &mboxq->u.mqe.un.set_feature); |
| 7753 | if ((rc == MBX_SUCCESS) && (dd == LPFC_ENABLE_DUAL_DUMP)) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7754 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 171f6c4 | 2019-11-04 16:57:07 -0800 | [diff] [blame] | 7755 | "6448 Dual Dump is enabled\n"); |
| 7756 | else |
| 7757 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI | LOG_INIT, |
| 7758 | "6447 Dual Dump Mailbox x%x (x%x/x%x) failed, " |
| 7759 | "rc:x%x dd:x%x\n", |
| 7760 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 7761 | lpfc_sli_config_mbox_subsys_get( |
| 7762 | phba, mboxq), |
| 7763 | lpfc_sli_config_mbox_opcode_get( |
| 7764 | phba, mboxq), |
| 7765 | rc, dd); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7766 | /* |
| 7767 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent |
| 7768 | * calls depends on these resources to complete port setup. |
| 7769 | */ |
| 7770 | rc = lpfc_sli4_alloc_resource_identifiers(phba); |
| 7771 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7772 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7773 | "2920 Failed to alloc Resource IDs " |
| 7774 | "rc = x%x\n", rc); |
| 7775 | goto out_free_mbox; |
| 7776 | } |
| 7777 | |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7778 | lpfc_set_host_data(phba, mboxq); |
| 7779 | |
| 7780 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7781 | if (rc) { |
| 7782 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7783 | "2134 Failed to set host os driver version %x", |
| 7784 | rc); |
| 7785 | } |
| 7786 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7787 | /* Read the port's service parameters. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 7788 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
| 7789 | if (rc) { |
| 7790 | phba->link_state = LPFC_HBA_ERROR; |
| 7791 | rc = -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7792 | goto out_free_mbox; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 7793 | } |
| 7794 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7795 | mboxq->vport = vport; |
| 7796 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7797 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7798 | if (rc == MBX_SUCCESS) { |
| 7799 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); |
| 7800 | rc = 0; |
| 7801 | } |
| 7802 | |
| 7803 | /* |
| 7804 | * This memory was allocated by the lpfc_read_sparam routine. Release |
| 7805 | * it to the mbuf pool. |
| 7806 | */ |
| 7807 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 7808 | kfree(mp); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7809 | mboxq->ctx_buf = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7810 | if (unlikely(rc)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7811 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7812 | "0382 READ_SPARAM command failed " |
| 7813 | "status %d, mbxStatus x%x\n", |
| 7814 | rc, bf_get(lpfc_mqe_status, mqe)); |
| 7815 | phba->link_state = LPFC_HBA_ERROR; |
| 7816 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7817 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7818 | } |
| 7819 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7820 | lpfc_update_vport_wwn(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7821 | |
| 7822 | /* Update the fc_host data structures with new wwn. */ |
| 7823 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 7824 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
| 7825 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7826 | /* Create all the SLI4 queues */ |
| 7827 | rc = lpfc_sli4_queue_create(phba); |
| 7828 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7829 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7830 | "3089 Failed to allocate queues\n"); |
| 7831 | rc = -ENODEV; |
| 7832 | goto out_free_mbox; |
| 7833 | } |
| 7834 | /* Set up all the queues to the device */ |
| 7835 | rc = lpfc_sli4_queue_setup(phba); |
| 7836 | if (unlikely(rc)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7837 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7838 | "0381 Error %d during queue setup.\n ", rc); |
| 7839 | goto out_stop_timers; |
| 7840 | } |
| 7841 | /* Initialize the driver internal SLI layer lists. */ |
| 7842 | lpfc_sli4_setup(phba); |
| 7843 | lpfc_sli4_queue_init(phba); |
| 7844 | |
| 7845 | /* update host els xri-sgl sizes and mappings */ |
| 7846 | rc = lpfc_sli4_els_sgl_update(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7847 | if (unlikely(rc)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7848 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7849 | "1400 Failed to update xri-sgl size and " |
| 7850 | "mapping: %d\n", rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7851 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7852 | } |
| 7853 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7854 | /* register the els sgl pool to the port */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7855 | rc = lpfc_sli4_repost_sgl_list(phba, &phba->sli4_hba.lpfc_els_sgl_list, |
| 7856 | phba->sli4_hba.els_xri_cnt); |
| 7857 | if (unlikely(rc < 0)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7858 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7859 | "0582 Error %d during els sgl post " |
| 7860 | "operation\n", rc); |
| 7861 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7862 | goto out_destroy_queue; |
| 7863 | } |
| 7864 | phba->sli4_hba.els_xri_cnt = rc; |
| 7865 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7866 | if (phba->nvmet_support) { |
| 7867 | /* update host nvmet xri-sgl sizes and mappings */ |
| 7868 | rc = lpfc_sli4_nvmet_sgl_update(phba); |
| 7869 | if (unlikely(rc)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7870 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7871 | "6308 Failed to update nvmet-sgl size " |
| 7872 | "and mapping: %d\n", rc); |
| 7873 | goto out_destroy_queue; |
| 7874 | } |
| 7875 | |
| 7876 | /* register the nvmet sgl pool to the port */ |
| 7877 | rc = lpfc_sli4_repost_sgl_list( |
| 7878 | phba, |
| 7879 | &phba->sli4_hba.lpfc_nvmet_sgl_list, |
| 7880 | phba->sli4_hba.nvmet_xri_cnt); |
| 7881 | if (unlikely(rc < 0)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7882 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7883 | "3117 Error %d during nvmet " |
| 7884 | "sgl post\n", rc); |
| 7885 | rc = -ENODEV; |
| 7886 | goto out_destroy_queue; |
| 7887 | } |
| 7888 | phba->sli4_hba.nvmet_xri_cnt = rc; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7889 | |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 7890 | /* We allocate an iocbq for every receive context SGL. |
| 7891 | * The additional allocation is for abort and ls handling. |
| 7892 | */ |
| 7893 | cnt = phba->sli4_hba.nvmet_xri_cnt + |
| 7894 | phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7895 | } else { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7896 | /* update host common xri-sgl sizes and mappings */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7897 | rc = lpfc_sli4_io_sgl_update(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7898 | if (unlikely(rc)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7899 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7900 | "6082 Failed to update nvme-sgl size " |
| 7901 | "and mapping: %d\n", rc); |
| 7902 | goto out_destroy_queue; |
| 7903 | } |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7904 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7905 | /* register the allocated common sgl pool to the port */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7906 | rc = lpfc_sli4_repost_io_sgl_list(phba); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7907 | if (unlikely(rc)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7908 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7909 | "6116 Error %d during nvme sgl post " |
| 7910 | "operation\n", rc); |
| 7911 | /* Some NVME buffers were moved to abort nvme list */ |
| 7912 | /* A pci function reset will repost them */ |
| 7913 | rc = -ENODEV; |
| 7914 | goto out_destroy_queue; |
| 7915 | } |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 7916 | /* Each lpfc_io_buf job structure has an iocbq element. |
| 7917 | * This cnt provides for abort, els, ct and ls requests. |
| 7918 | */ |
| 7919 | cnt = phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7920 | } |
| 7921 | |
| 7922 | if (!phba->sli.iocbq_lookup) { |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7923 | /* Initialize and populate the iocb list per host */ |
| 7924 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 7925 | "2821 initialize iocb list with %d entries\n", |
| 7926 | cnt); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7927 | rc = lpfc_init_iocb_list(phba, cnt); |
| 7928 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7929 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7930 | "1413 Failed to init iocb list.\n"); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7931 | goto out_destroy_queue; |
| 7932 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7933 | } |
| 7934 | |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7935 | if (phba->nvmet_support) |
| 7936 | lpfc_nvmet_create_targetport(phba); |
| 7937 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7938 | if (phba->nvmet_support && phba->cfg_nvmet_mrq) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7939 | /* Post initial buffers to all RQs created */ |
| 7940 | for (i = 0; i < phba->cfg_nvmet_mrq; i++) { |
| 7941 | rqbp = phba->sli4_hba.nvmet_mrq_hdr[i]->rqbp; |
| 7942 | INIT_LIST_HEAD(&rqbp->rqb_buffer_list); |
| 7943 | rqbp->rqb_alloc_buffer = lpfc_sli4_nvmet_alloc; |
| 7944 | rqbp->rqb_free_buffer = lpfc_sli4_nvmet_free; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 7945 | rqbp->entry_count = LPFC_NVMET_RQE_DEF_COUNT; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7946 | rqbp->buffer_count = 0; |
| 7947 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7948 | lpfc_post_rq_buffer( |
| 7949 | phba, phba->sli4_hba.nvmet_mrq_hdr[i], |
| 7950 | phba->sli4_hba.nvmet_mrq_data[i], |
James Smart | 2448e48 | 2018-04-09 14:24:24 -0700 | [diff] [blame] | 7951 | phba->cfg_nvmet_mrq_post, i); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7952 | } |
| 7953 | } |
| 7954 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7955 | /* Post the rpi header region to the device. */ |
| 7956 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); |
| 7957 | if (unlikely(rc)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7958 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7959 | "0393 Error %d during rpi post operation\n", |
| 7960 | rc); |
| 7961 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7962 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7963 | } |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 7964 | lpfc_sli4_node_prep(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7965 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7966 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7967 | if ((phba->nvmet_support == 0) || (phba->cfg_nvmet_mrq == 1)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7968 | /* |
| 7969 | * The FC Port needs to register FCFI (index 0) |
| 7970 | */ |
| 7971 | lpfc_reg_fcfi(phba, mboxq); |
| 7972 | mboxq->vport = phba->pport; |
| 7973 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7974 | if (rc != MBX_SUCCESS) |
| 7975 | goto out_unset_queue; |
| 7976 | rc = 0; |
| 7977 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, |
| 7978 | &mboxq->u.mqe.un.reg_fcfi); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7979 | } else { |
| 7980 | /* We are a NVME Target mode with MRQ > 1 */ |
| 7981 | |
| 7982 | /* First register the FCFI */ |
| 7983 | lpfc_reg_fcfi_mrq(phba, mboxq, 0); |
| 7984 | mboxq->vport = phba->pport; |
| 7985 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7986 | if (rc != MBX_SUCCESS) |
| 7987 | goto out_unset_queue; |
| 7988 | rc = 0; |
| 7989 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_mrq_fcfi, |
| 7990 | &mboxq->u.mqe.un.reg_fcfi_mrq); |
| 7991 | |
| 7992 | /* Next register the MRQs */ |
| 7993 | lpfc_reg_fcfi_mrq(phba, mboxq, 1); |
| 7994 | mboxq->vport = phba->pport; |
| 7995 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7996 | if (rc != MBX_SUCCESS) |
| 7997 | goto out_unset_queue; |
| 7998 | rc = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7999 | } |
| 8000 | /* Check if the port is configured to be disabled */ |
| 8001 | lpfc_sli_read_link_ste(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8002 | } |
| 8003 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 8004 | /* Don't post more new bufs if repost already recovered |
| 8005 | * the nvme sgls. |
| 8006 | */ |
| 8007 | if (phba->nvmet_support == 0) { |
| 8008 | if (phba->sli4_hba.io_xri_cnt == 0) { |
| 8009 | len = lpfc_new_io_buf( |
| 8010 | phba, phba->sli4_hba.io_xri_max); |
| 8011 | if (len == 0) { |
| 8012 | rc = -ENOMEM; |
| 8013 | goto out_unset_queue; |
| 8014 | } |
| 8015 | |
| 8016 | if (phba->cfg_xri_rebalancing) |
| 8017 | lpfc_create_multixri_pools(phba); |
| 8018 | } |
| 8019 | } else { |
| 8020 | phba->cfg_xri_rebalancing = 0; |
| 8021 | } |
| 8022 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8023 | /* Allow asynchronous mailbox command to go through */ |
| 8024 | spin_lock_irq(&phba->hbalock); |
| 8025 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 8026 | spin_unlock_irq(&phba->hbalock); |
| 8027 | |
| 8028 | /* Post receive buffers to the device */ |
| 8029 | lpfc_sli4_rb_setup(phba); |
| 8030 | |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 8031 | /* Reset HBA FCF states after HBA reset */ |
| 8032 | phba->fcf.fcf_flag = 0; |
| 8033 | phba->fcf.current_rec.flag = 0; |
| 8034 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8035 | /* Start the ELS watchdog timer */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8036 | mod_timer(&vport->els_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8037 | jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8038 | |
| 8039 | /* Start heart beat timer */ |
| 8040 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8041 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 8042 | phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8043 | phba->last_completion_time = jiffies; |
| 8044 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8045 | /* start eq_delay heartbeat */ |
| 8046 | if (phba->cfg_auto_imax) |
| 8047 | queue_delayed_work(phba->wq, &phba->eq_delay_work, |
| 8048 | msecs_to_jiffies(LPFC_EQ_DELAY_MSECS)); |
| 8049 | |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 8050 | /* start per phba idle_stat_delay heartbeat */ |
| 8051 | lpfc_init_idle_stat_hb(phba); |
| 8052 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8053 | /* Start error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8054 | mod_timer(&phba->eratt_poll, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 8055 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8056 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8057 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 8058 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 8059 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 8060 | if (!rc) { |
| 8061 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8062 | "2829 This device supports " |
| 8063 | "Advanced Error Reporting (AER)\n"); |
| 8064 | spin_lock_irq(&phba->hbalock); |
| 8065 | phba->hba_flag |= HBA_AER_ENABLED; |
| 8066 | spin_unlock_irq(&phba->hbalock); |
| 8067 | } else { |
| 8068 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8069 | "2830 This device does not support " |
| 8070 | "Advanced Error Reporting (AER)\n"); |
| 8071 | phba->cfg_aer_support = 0; |
| 8072 | } |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 8073 | rc = 0; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8074 | } |
| 8075 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8076 | /* |
| 8077 | * The port is ready, set the host's link state to LINK_DOWN |
| 8078 | * in preparation for link interrupts. |
| 8079 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8080 | spin_lock_irq(&phba->hbalock); |
| 8081 | phba->link_state = LPFC_LINK_DOWN; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 8082 | |
| 8083 | /* Check if physical ports are trunked */ |
| 8084 | if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba)) |
| 8085 | phba->trunk_link.link0.state = LPFC_LINK_DOWN; |
| 8086 | if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba)) |
| 8087 | phba->trunk_link.link1.state = LPFC_LINK_DOWN; |
| 8088 | if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba)) |
| 8089 | phba->trunk_link.link2.state = LPFC_LINK_DOWN; |
| 8090 | if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba)) |
| 8091 | phba->trunk_link.link3.state = LPFC_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8092 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 8093 | |
James Smart | e8869f5 | 2019-03-12 16:30:18 -0700 | [diff] [blame] | 8094 | /* Arm the CQs and then EQs on device */ |
| 8095 | lpfc_sli4_arm_cqeq_intr(phba); |
| 8096 | |
| 8097 | /* Indicate device interrupt mode */ |
| 8098 | phba->sli4_hba.intr_enable = 1; |
| 8099 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 8100 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 8101 | (phba->hba_flag & LINK_DISABLED)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8102 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 8103 | "3103 Adapter Link is disabled.\n"); |
| 8104 | lpfc_down_link(phba, mboxq); |
| 8105 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8106 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8107 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 8108 | "3104 Adapter failed to issue " |
| 8109 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 8110 | goto out_io_buff_free; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 8111 | } |
| 8112 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8113 | /* don't perform init_link on SLI4 FC port loopback test */ |
| 8114 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 8115 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 8116 | if (rc) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 8117 | goto out_io_buff_free; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8118 | } |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8119 | } |
| 8120 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 8121 | return rc; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 8122 | out_io_buff_free: |
| 8123 | /* Free allocated IO Buffers */ |
| 8124 | lpfc_io_free(phba); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 8125 | out_unset_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8126 | /* Unset all the queues set up in this routine when error out */ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8127 | lpfc_sli4_queue_unset(phba); |
| 8128 | out_destroy_queue: |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 8129 | lpfc_free_iocb_list(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8130 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8131 | out_stop_timers: |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8132 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8133 | out_free_mbox: |
| 8134 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 8135 | return rc; |
| 8136 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8137 | |
| 8138 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8139 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 8140 | * @t: Context to fetch pointer to hba structure from. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8141 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8142 | * This is the callback function for mailbox timer. The mailbox |
| 8143 | * timer is armed when a new mailbox command is issued and the timer |
| 8144 | * is deleted when the mailbox complete. The function is called by |
| 8145 | * the kernel timer code when a mailbox does not complete within |
| 8146 | * expected time. This function wakes up the worker thread to |
| 8147 | * process the mailbox timeout and returns. All the processing is |
| 8148 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 8149 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8150 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 8151 | lpfc_mbox_timeout(struct timer_list *t) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8152 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 8153 | struct lpfc_hba *phba = from_timer(phba, t, sli.mbox_tmo); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8154 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8155 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8156 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8157 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8158 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8159 | if (!tmo_posted) |
| 8160 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 8161 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 8162 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8163 | if (!tmo_posted) |
| 8164 | lpfc_worker_wake_up(phba); |
| 8165 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8166 | } |
| 8167 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8168 | /** |
| 8169 | * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions |
| 8170 | * are pending |
| 8171 | * @phba: Pointer to HBA context object. |
| 8172 | * |
| 8173 | * This function checks if any mailbox completions are present on the mailbox |
| 8174 | * completion queue. |
| 8175 | **/ |
Nicholas Krause | 3bb11fc | 2015-08-31 16:48:13 -0400 | [diff] [blame] | 8176 | static bool |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8177 | lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba) |
| 8178 | { |
| 8179 | |
| 8180 | uint32_t idx; |
| 8181 | struct lpfc_queue *mcq; |
| 8182 | struct lpfc_mcqe *mcqe; |
| 8183 | bool pending_completions = false; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8184 | uint8_t qe_valid; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8185 | |
| 8186 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 8187 | return false; |
| 8188 | |
| 8189 | /* Check for completions on mailbox completion queue */ |
| 8190 | |
| 8191 | mcq = phba->sli4_hba.mbx_cq; |
| 8192 | idx = mcq->hba_index; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8193 | qe_valid = mcq->qe_valid; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 8194 | while (bf_get_le32(lpfc_cqe_valid, |
| 8195 | (struct lpfc_cqe *)lpfc_sli4_qe(mcq, idx)) == qe_valid) { |
| 8196 | mcqe = (struct lpfc_mcqe *)(lpfc_sli4_qe(mcq, idx)); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8197 | if (bf_get_le32(lpfc_trailer_completed, mcqe) && |
| 8198 | (!bf_get_le32(lpfc_trailer_async, mcqe))) { |
| 8199 | pending_completions = true; |
| 8200 | break; |
| 8201 | } |
| 8202 | idx = (idx + 1) % mcq->entry_count; |
| 8203 | if (mcq->hba_index == idx) |
| 8204 | break; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8205 | |
| 8206 | /* if the index wrapped around, toggle the valid bit */ |
| 8207 | if (phba->sli4_hba.pc_sli4_params.cqav && !idx) |
| 8208 | qe_valid = (qe_valid) ? 0 : 1; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8209 | } |
| 8210 | return pending_completions; |
| 8211 | |
| 8212 | } |
| 8213 | |
| 8214 | /** |
| 8215 | * lpfc_sli4_process_missed_mbox_completions - process mbox completions |
| 8216 | * that were missed. |
| 8217 | * @phba: Pointer to HBA context object. |
| 8218 | * |
| 8219 | * For sli4, it is possible to miss an interrupt. As such mbox completions |
| 8220 | * maybe missed causing erroneous mailbox timeouts to occur. This function |
| 8221 | * checks to see if mbox completions are on the mailbox completion queue |
| 8222 | * and will process all the completions associated with the eq for the |
| 8223 | * mailbox completion queue. |
| 8224 | **/ |
YueHaibing | d7b761b | 2019-05-31 23:28:41 +0800 | [diff] [blame] | 8225 | static bool |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8226 | lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba) |
| 8227 | { |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 8228 | struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8229 | uint32_t eqidx; |
| 8230 | struct lpfc_queue *fpeq = NULL; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8231 | struct lpfc_queue *eq; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8232 | bool mbox_pending; |
| 8233 | |
| 8234 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 8235 | return false; |
| 8236 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8237 | /* Find the EQ associated with the mbox CQ */ |
| 8238 | if (sli4_hba->hdwq) { |
| 8239 | for (eqidx = 0; eqidx < phba->cfg_irq_chann; eqidx++) { |
| 8240 | eq = phba->sli4_hba.hba_eq_hdl[eqidx].eq; |
Daniel Wagner | 535fb49 | 2019-10-18 18:21:11 +0200 | [diff] [blame] | 8241 | if (eq && eq->queue_id == sli4_hba->mbx_cq->assoc_qid) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8242 | fpeq = eq; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8243 | break; |
| 8244 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8245 | } |
| 8246 | } |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8247 | if (!fpeq) |
| 8248 | return false; |
| 8249 | |
| 8250 | /* Turn off interrupts from this EQ */ |
| 8251 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 8252 | sli4_hba->sli4_eq_clr_intr(fpeq); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8253 | |
| 8254 | /* Check to see if a mbox completion is pending */ |
| 8255 | |
| 8256 | mbox_pending = lpfc_sli4_mbox_completions_pending(phba); |
| 8257 | |
| 8258 | /* |
| 8259 | * If a mbox completion is pending, process all the events on EQ |
| 8260 | * associated with the mbox completion queue (this could include |
| 8261 | * mailbox commands, async events, els commands, receive queue data |
| 8262 | * and fcp commands) |
| 8263 | */ |
| 8264 | |
| 8265 | if (mbox_pending) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8266 | /* process and rearm the EQ */ |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 8267 | lpfc_sli4_process_eq(phba, fpeq, LPFC_QUEUE_REARM); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8268 | else |
| 8269 | /* Always clear and re-arm the EQ */ |
| 8270 | sli4_hba->sli4_write_eq_db(phba, fpeq, 0, LPFC_QUEUE_REARM); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8271 | |
| 8272 | return mbox_pending; |
| 8273 | |
| 8274 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8275 | |
| 8276 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8277 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8278 | * @phba: Pointer to HBA context object. |
| 8279 | * |
| 8280 | * This function is called from worker thread when a mailbox command times out. |
| 8281 | * The caller is not required to hold any locks. This function will reset the |
| 8282 | * HBA and recover all the pending commands. |
| 8283 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8284 | void |
| 8285 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 8286 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8287 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 8288 | MAILBOX_t *mb = NULL; |
| 8289 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 8290 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8291 | |
James Smart | 9ec58ec | 2021-01-04 10:02:35 -0800 | [diff] [blame] | 8292 | /* If the mailbox completed, process the completion */ |
| 8293 | lpfc_sli4_process_missed_mbox_completions(phba); |
| 8294 | |
| 8295 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8296 | return; |
| 8297 | |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 8298 | if (pmbox != NULL) |
| 8299 | mb = &pmbox->u.mb; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8300 | /* Check the pmbox pointer first. There is a race condition |
| 8301 | * between the mbox timeout handler getting executed in the |
| 8302 | * worklist and the mailbox actually completing. When this |
| 8303 | * race condition occurs, the mbox_active will be NULL. |
| 8304 | */ |
| 8305 | spin_lock_irq(&phba->hbalock); |
| 8306 | if (pmbox == NULL) { |
| 8307 | lpfc_printf_log(phba, KERN_WARNING, |
| 8308 | LOG_MBOX | LOG_SLI, |
| 8309 | "0353 Active Mailbox cleared - mailbox timeout " |
| 8310 | "exiting\n"); |
| 8311 | spin_unlock_irq(&phba->hbalock); |
| 8312 | return; |
| 8313 | } |
| 8314 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8315 | /* Mbox cmd <mbxCommand> timeout */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8316 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 8317 | "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] | 8318 | mb->mbxCommand, |
| 8319 | phba->pport->port_state, |
| 8320 | phba->sli.sli_flag, |
| 8321 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8322 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8323 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 8324 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 8325 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8326 | * it to fail all outstanding SCSI IO. |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 8327 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8328 | spin_lock_irq(&phba->pport->work_port_lock); |
| 8329 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 8330 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 8331 | spin_lock_irq(&phba->hbalock); |
| 8332 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 8333 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8334 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 8335 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8336 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 8337 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8338 | |
| 8339 | /* Reset the HBA device */ |
| 8340 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8341 | } |
| 8342 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8343 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8344 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8345 | * @phba: Pointer to HBA context object. |
| 8346 | * @pmbox: Pointer to mailbox object. |
| 8347 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8348 | * |
| 8349 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8350 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 8351 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8352 | * The mailbox command can be submitted in polling mode, in which case |
| 8353 | * this function will wait in a polling loop for the completion of the |
| 8354 | * mailbox. |
| 8355 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 8356 | * function will submit the command and returns immediately without waiting |
| 8357 | * for the mailbox completion. The no_wait is supported only when HBA |
| 8358 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 8359 | * The SLI interface allows only one mailbox pending at a time. If the |
| 8360 | * mailbox is issued in polling mode and there is already a mailbox |
| 8361 | * pending, then the function will return an error. If the mailbox is issued |
| 8362 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 8363 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 8364 | * The sli layer owns the mailbox object until the completion of mailbox |
| 8365 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 8366 | * return codes the caller owns the mailbox command after the return of |
| 8367 | * the function. |
| 8368 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8369 | static int |
| 8370 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 8371 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8372 | { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8373 | MAILBOX_t *mbx; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8374 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8375 | uint32_t status, evtctr; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8376 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8377 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8378 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8379 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8380 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8381 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8382 | int processing_queue = 0; |
| 8383 | |
| 8384 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 8385 | if (!pmbox) { |
James Smart | 8568a4d | 2009-07-19 10:01:16 -0400 | [diff] [blame] | 8386 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8387 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8388 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8389 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8390 | return MBX_SUCCESS; |
| 8391 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8392 | processing_queue = 1; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8393 | pmbox = lpfc_mbox_get(phba); |
| 8394 | if (!pmbox) { |
| 8395 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8396 | return MBX_SUCCESS; |
| 8397 | } |
| 8398 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8399 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8400 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8401 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8402 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8403 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8404 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8405 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8406 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8407 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8408 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8409 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8410 | } |
| 8411 | } |
| 8412 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8413 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8414 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 8415 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8416 | goto out_not_finished; |
| 8417 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8418 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8419 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 8420 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 8421 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8422 | goto out_not_finished; |
| 8423 | } |
| 8424 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8425 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8426 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8427 | mbx = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8428 | status = MBX_SUCCESS; |
| 8429 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8430 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 8431 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8432 | |
| 8433 | /* Mbox command <mbxCommand> cannot issue */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8434 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8435 | "(%d):0311 Mailbox command x%x cannot " |
| 8436 | "issue Data: x%x x%x\n", |
| 8437 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8438 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8439 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8440 | } |
| 8441 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8442 | if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8443 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
| 8444 | !(hc_copy & HC_MBINT_ENA)) { |
| 8445 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8446 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8447 | "(%d):2528 Mailbox command x%x cannot " |
| 8448 | "issue Data: x%x x%x\n", |
| 8449 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8450 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8451 | goto out_not_finished; |
| 8452 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 8453 | } |
| 8454 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8455 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8456 | /* Polling for a mbox command when another one is already active |
| 8457 | * is not allowed in SLI. Also, the driver must have established |
| 8458 | * SLI2 mode to queue and process multiple mbox commands. |
| 8459 | */ |
| 8460 | |
| 8461 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8462 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8463 | |
| 8464 | /* Mbox command <mbxCommand> cannot issue */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8465 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8466 | "(%d):2529 Mailbox command x%x " |
| 8467 | "cannot issue Data: x%x x%x\n", |
| 8468 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8469 | pmbox->u.mb.mbxCommand, |
| 8470 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8471 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8472 | } |
| 8473 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8474 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8475 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8476 | /* Mbox command <mbxCommand> cannot issue */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8477 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8478 | "(%d):2530 Mailbox command x%x " |
| 8479 | "cannot issue Data: x%x x%x\n", |
| 8480 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8481 | pmbox->u.mb.mbxCommand, |
| 8482 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8483 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8484 | } |
| 8485 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8486 | /* Another mailbox command is still being processed, queue this |
| 8487 | * command to be processed later. |
| 8488 | */ |
| 8489 | lpfc_mbox_put(phba, pmbox); |
| 8490 | |
| 8491 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8492 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8493 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8494 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8495 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 8496 | mbx->mbxCommand, |
| 8497 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8498 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8499 | |
| 8500 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8501 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8502 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8503 | if (pmbox->vport) { |
| 8504 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 8505 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8506 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8507 | (uint32_t)mbx->mbxCommand, |
| 8508 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8509 | } |
| 8510 | else { |
| 8511 | lpfc_debugfs_disc_trc(phba->pport, |
| 8512 | LPFC_DISC_TRC_MBOX, |
| 8513 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8514 | (uint32_t)mbx->mbxCommand, |
| 8515 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8516 | } |
| 8517 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8518 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8519 | } |
| 8520 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8521 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8522 | |
| 8523 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 8524 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8525 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8526 | (mbx->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8527 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8528 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8529 | /* Mbox command <mbxCommand> cannot issue */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8530 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8531 | "(%d):2531 Mailbox command x%x " |
| 8532 | "cannot issue Data: x%x x%x\n", |
| 8533 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8534 | pmbox->u.mb.mbxCommand, |
| 8535 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8536 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8537 | } |
| 8538 | /* timeout active mbox command */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8539 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 8540 | 1000); |
| 8541 | mod_timer(&psli->mbox_tmo, jiffies + timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8542 | } |
| 8543 | |
| 8544 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8545 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8546 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8547 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8548 | pmbox->vport ? pmbox->vport->vpi : 0, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 8549 | mbx->mbxCommand, |
| 8550 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8551 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8552 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8553 | if (mbx->mbxCommand != MBX_HEARTBEAT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8554 | if (pmbox->vport) { |
| 8555 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 8556 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8557 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8558 | (uint32_t)mbx->mbxCommand, |
| 8559 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8560 | } |
| 8561 | else { |
| 8562 | lpfc_debugfs_disc_trc(phba->pport, |
| 8563 | LPFC_DISC_TRC_MBOX, |
| 8564 | "MBOX Send: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8565 | (uint32_t)mbx->mbxCommand, |
| 8566 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8567 | } |
| 8568 | } |
| 8569 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8570 | psli->slistat.mbox_cmd++; |
| 8571 | evtctr = psli->slistat.mbox_event; |
| 8572 | |
| 8573 | /* next set own bit for the adapter and copy over command word */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8574 | mbx->mbxOwner = OWN_CHIP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8575 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8576 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8577 | /* Populate mbox extension offset word. */ |
| 8578 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8579 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8580 | = (uint8_t *)phba->mbox_ext |
| 8581 | - (uint8_t *)phba->mbox; |
| 8582 | } |
| 8583 | |
| 8584 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8585 | if (pmbox->in_ext_byte_len && pmbox->ctx_buf) { |
| 8586 | lpfc_sli_pcimem_bcopy(pmbox->ctx_buf, |
| 8587 | (uint8_t *)phba->mbox_ext, |
| 8588 | pmbox->in_ext_byte_len); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8589 | } |
| 8590 | /* Copy command data to host SLIM area */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8591 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8592 | } else { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8593 | /* Populate mbox extension offset word. */ |
| 8594 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8595 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8596 | = MAILBOX_HBA_EXT_OFFSET; |
| 8597 | |
| 8598 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8599 | if (pmbox->in_ext_byte_len && pmbox->ctx_buf) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8600 | lpfc_memcpy_to_slim(phba->MBslimaddr + |
| 8601 | MAILBOX_HBA_EXT_OFFSET, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8602 | pmbox->ctx_buf, pmbox->in_ext_byte_len); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8603 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8604 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8605 | /* copy command data into host mbox for cmpl */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8606 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, |
| 8607 | MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8608 | |
| 8609 | /* First copy mbox command data to HBA SLIM, skip past first |
| 8610 | word */ |
| 8611 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8612 | lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0], |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8613 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 8614 | |
| 8615 | /* Next copy over first word, with mbxOwner set */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8616 | ldata = *((uint32_t *)mbx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8617 | to_slim = phba->MBslimaddr; |
| 8618 | writel(ldata, to_slim); |
| 8619 | readl(to_slim); /* flush */ |
| 8620 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8621 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8622 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8623 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8624 | } |
| 8625 | |
| 8626 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8627 | |
| 8628 | switch (flag) { |
| 8629 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8630 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8631 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8632 | /* Interrupt board to do it */ |
| 8633 | writel(CA_MBATT, phba->CAregaddr); |
| 8634 | readl(phba->CAregaddr); /* flush */ |
| 8635 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8636 | break; |
| 8637 | |
| 8638 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8639 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8640 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8641 | /* Interrupt board to do it */ |
| 8642 | writel(CA_MBATT, phba->CAregaddr); |
| 8643 | readl(phba->CAregaddr); /* flush */ |
| 8644 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8645 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8646 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8647 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8648 | word0 = le32_to_cpu(word0); |
| 8649 | } else { |
| 8650 | /* First read mbox status word */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8651 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
| 8652 | spin_unlock_irqrestore(&phba->hbalock, |
| 8653 | drvr_flag); |
| 8654 | goto out_not_finished; |
| 8655 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8656 | } |
| 8657 | |
| 8658 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8659 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 8660 | spin_unlock_irqrestore(&phba->hbalock, |
| 8661 | drvr_flag); |
| 8662 | goto out_not_finished; |
| 8663 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8664 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 8665 | 1000) + jiffies; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8666 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8667 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8668 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 8669 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8670 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8671 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8672 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8673 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8674 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8675 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8676 | } |
| 8677 | |
| 8678 | /* Check if we took a mbox interrupt while we were |
| 8679 | polling */ |
| 8680 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 8681 | && (evtctr != psli->slistat.mbox_event)) |
| 8682 | break; |
| 8683 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8684 | if (i++ > 10) { |
| 8685 | spin_unlock_irqrestore(&phba->hbalock, |
| 8686 | drvr_flag); |
| 8687 | msleep(1); |
| 8688 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 8689 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8690 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8691 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8692 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8693 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8694 | word0 = le32_to_cpu(word0); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8695 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8696 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8697 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8698 | /* Check real SLIM for any errors */ |
| 8699 | slimword0 = readl(phba->MBslimaddr); |
| 8700 | slimmb = (MAILBOX_t *) & slimword0; |
| 8701 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 8702 | && slimmb->mbxStatus) { |
| 8703 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8704 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8705 | word0 = slimword0; |
| 8706 | } |
| 8707 | } |
| 8708 | } else { |
| 8709 | /* First copy command data */ |
| 8710 | word0 = readl(phba->MBslimaddr); |
| 8711 | } |
| 8712 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8713 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 8714 | spin_unlock_irqrestore(&phba->hbalock, |
| 8715 | drvr_flag); |
| 8716 | goto out_not_finished; |
| 8717 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8718 | } |
| 8719 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8720 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8721 | /* copy results back to user */ |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8722 | lpfc_sli_pcimem_bcopy(phba->mbox, mbx, |
| 8723 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8724 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8725 | if (pmbox->out_ext_byte_len && pmbox->ctx_buf) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8726 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8727 | pmbox->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8728 | pmbox->out_ext_byte_len); |
| 8729 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8730 | } else { |
| 8731 | /* First copy command data */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8732 | lpfc_memcpy_from_slim(mbx, phba->MBslimaddr, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8733 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8734 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8735 | if (pmbox->out_ext_byte_len && pmbox->ctx_buf) { |
| 8736 | lpfc_memcpy_from_slim( |
| 8737 | pmbox->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8738 | phba->MBslimaddr + |
| 8739 | MAILBOX_HBA_EXT_OFFSET, |
| 8740 | pmbox->out_ext_byte_len); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8741 | } |
| 8742 | } |
| 8743 | |
| 8744 | writel(HA_MBATT, phba->HAregaddr); |
| 8745 | readl(phba->HAregaddr); /* flush */ |
| 8746 | |
| 8747 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8748 | status = mbx->mbxStatus; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8749 | } |
| 8750 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8751 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8752 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8753 | |
| 8754 | out_not_finished: |
| 8755 | if (processing_queue) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8756 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8757 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 8758 | } |
| 8759 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8760 | } |
| 8761 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8762 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8763 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command |
| 8764 | * @phba: Pointer to HBA context object. |
| 8765 | * |
| 8766 | * The function blocks the posting of SLI4 asynchronous mailbox commands from |
| 8767 | * the driver internal pending mailbox queue. It will then try to wait out the |
| 8768 | * possible outstanding mailbox command before return. |
| 8769 | * |
| 8770 | * Returns: |
| 8771 | * 0 - the outstanding mailbox command completed; otherwise, the wait for |
| 8772 | * the outstanding mailbox command timed out. |
| 8773 | **/ |
| 8774 | static int |
| 8775 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) |
| 8776 | { |
| 8777 | struct lpfc_sli *psli = &phba->sli; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8778 | int rc = 0; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8779 | unsigned long timeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8780 | |
| 8781 | /* Mark the asynchronous mailbox command posting as blocked */ |
| 8782 | spin_lock_irq(&phba->hbalock); |
| 8783 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8784 | /* Determine how long we might wait for the active mailbox |
| 8785 | * command to be gracefully completed by firmware. |
| 8786 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8787 | if (phba->sli.mbox_active) |
| 8788 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 8789 | phba->sli.mbox_active) * |
| 8790 | 1000) + jiffies; |
| 8791 | spin_unlock_irq(&phba->hbalock); |
| 8792 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8793 | /* Make sure the mailbox is really active */ |
| 8794 | if (timeout) |
| 8795 | lpfc_sli4_process_missed_mbox_completions(phba); |
| 8796 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8797 | /* Wait for the outstnading mailbox command to complete */ |
| 8798 | while (phba->sli.mbox_active) { |
| 8799 | /* Check active mailbox complete status every 2ms */ |
| 8800 | msleep(2); |
| 8801 | if (time_after(jiffies, timeout)) { |
| 8802 | /* Timeout, marked the outstanding cmd not complete */ |
| 8803 | rc = 1; |
| 8804 | break; |
| 8805 | } |
| 8806 | } |
| 8807 | |
| 8808 | /* Can not cleanly block async mailbox command, fails it */ |
| 8809 | if (rc) { |
| 8810 | spin_lock_irq(&phba->hbalock); |
| 8811 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 8812 | spin_unlock_irq(&phba->hbalock); |
| 8813 | } |
| 8814 | return rc; |
| 8815 | } |
| 8816 | |
| 8817 | /** |
| 8818 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command |
| 8819 | * @phba: Pointer to HBA context object. |
| 8820 | * |
| 8821 | * The function unblocks and resume posting of SLI4 asynchronous mailbox |
| 8822 | * commands from the driver internal pending mailbox queue. It makes sure |
| 8823 | * that there is no outstanding mailbox command before resuming posting |
| 8824 | * asynchronous mailbox commands. If, for any reason, there is outstanding |
| 8825 | * mailbox command, it will try to wait it out before resuming asynchronous |
| 8826 | * mailbox command posting. |
| 8827 | **/ |
| 8828 | static void |
| 8829 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) |
| 8830 | { |
| 8831 | struct lpfc_sli *psli = &phba->sli; |
| 8832 | |
| 8833 | spin_lock_irq(&phba->hbalock); |
| 8834 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8835 | /* Asynchronous mailbox posting is not blocked, do nothing */ |
| 8836 | spin_unlock_irq(&phba->hbalock); |
| 8837 | return; |
| 8838 | } |
| 8839 | |
| 8840 | /* Outstanding synchronous mailbox command is guaranteed to be done, |
| 8841 | * successful or timeout, after timing-out the outstanding mailbox |
| 8842 | * command shall always be removed, so just unblock posting async |
| 8843 | * mailbox command and resume |
| 8844 | */ |
| 8845 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 8846 | spin_unlock_irq(&phba->hbalock); |
| 8847 | |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 8848 | /* wake up worker thread to post asynchronous mailbox command */ |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8849 | lpfc_worker_wake_up(phba); |
| 8850 | } |
| 8851 | |
| 8852 | /** |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8853 | * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready |
| 8854 | * @phba: Pointer to HBA context object. |
| 8855 | * @mboxq: Pointer to mailbox object. |
| 8856 | * |
| 8857 | * The function waits for the bootstrap mailbox register ready bit from |
| 8858 | * port for twice the regular mailbox command timeout value. |
| 8859 | * |
| 8860 | * 0 - no timeout on waiting for bootstrap mailbox register ready. |
| 8861 | * MBXERR_ERROR - wait for bootstrap mailbox register timed out. |
| 8862 | **/ |
| 8863 | static int |
| 8864 | lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8865 | { |
| 8866 | uint32_t db_ready; |
| 8867 | unsigned long timeout; |
| 8868 | struct lpfc_register bmbx_reg; |
| 8869 | |
| 8870 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
| 8871 | * 1000) + jiffies; |
| 8872 | |
| 8873 | do { |
| 8874 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 8875 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 8876 | if (!db_ready) |
James Smart | e2ffe4d | 2019-03-12 16:30:15 -0700 | [diff] [blame] | 8877 | mdelay(2); |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8878 | |
| 8879 | if (time_after(jiffies, timeout)) |
| 8880 | return MBXERR_ERROR; |
| 8881 | } while (!db_ready); |
| 8882 | |
| 8883 | return 0; |
| 8884 | } |
| 8885 | |
| 8886 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8887 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox |
| 8888 | * @phba: Pointer to HBA context object. |
| 8889 | * @mboxq: Pointer to mailbox object. |
| 8890 | * |
| 8891 | * The function posts a mailbox to the port. The mailbox is expected |
| 8892 | * to be comletely filled in and ready for the port to operate on it. |
| 8893 | * This routine executes a synchronous completion operation on the |
| 8894 | * mailbox by polling for its completion. |
| 8895 | * |
| 8896 | * The caller must not be holding any locks when calling this routine. |
| 8897 | * |
| 8898 | * Returns: |
| 8899 | * MBX_SUCCESS - mailbox posted successfully |
| 8900 | * Any of the MBX error values. |
| 8901 | **/ |
| 8902 | static int |
| 8903 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8904 | { |
| 8905 | int rc = MBX_SUCCESS; |
| 8906 | unsigned long iflag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8907 | uint32_t mcqe_status; |
| 8908 | uint32_t mbx_cmnd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8909 | struct lpfc_sli *psli = &phba->sli; |
| 8910 | struct lpfc_mqe *mb = &mboxq->u.mqe; |
| 8911 | struct lpfc_bmbx_create *mbox_rgn; |
| 8912 | struct dma_address *dma_address; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8913 | |
| 8914 | /* |
| 8915 | * Only one mailbox can be active to the bootstrap mailbox region |
| 8916 | * at a time and there is no queueing provided. |
| 8917 | */ |
| 8918 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8919 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8920 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8921 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8922 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8923 | "cannot issue Data: x%x x%x\n", |
| 8924 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8925 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8926 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8927 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8928 | psli->sli_flag, MBX_POLL); |
| 8929 | return MBXERR_ERROR; |
| 8930 | } |
| 8931 | /* The server grabs the token and owns it until release */ |
| 8932 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8933 | phba->sli.mbox_active = mboxq; |
| 8934 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8935 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8936 | /* wait for bootstrap mbox register for readyness */ |
| 8937 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8938 | if (rc) |
| 8939 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8940 | /* |
| 8941 | * Initialize the bootstrap memory region to avoid stale data areas |
| 8942 | * in the mailbox post. Then copy the caller's mailbox contents to |
| 8943 | * the bmbx mailbox region. |
| 8944 | */ |
| 8945 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); |
| 8946 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8947 | lpfc_sli4_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
| 8948 | sizeof(struct lpfc_mqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8949 | |
| 8950 | /* Post the high mailbox dma address to the port and wait for ready. */ |
| 8951 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 8952 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); |
| 8953 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8954 | /* wait for bootstrap mbox register for hi-address write done */ |
| 8955 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8956 | if (rc) |
| 8957 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8958 | |
| 8959 | /* Post the low mailbox dma address to the port. */ |
| 8960 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8961 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8962 | /* wait for bootstrap mbox register for low address write done */ |
| 8963 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8964 | if (rc) |
| 8965 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8966 | |
| 8967 | /* |
| 8968 | * Read the CQ to ensure the mailbox has completed. |
| 8969 | * If so, update the mailbox status so that the upper layers |
| 8970 | * can complete the request normally. |
| 8971 | */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8972 | lpfc_sli4_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
| 8973 | sizeof(struct lpfc_mqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8974 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8975 | lpfc_sli4_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
| 8976 | sizeof(struct lpfc_mcqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8977 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8978 | /* |
| 8979 | * When the CQE status indicates a failure and the mailbox status |
| 8980 | * indicates success then copy the CQE status into the mailbox status |
| 8981 | * (and prefix it with x4000). |
| 8982 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8983 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8984 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
| 8985 | bf_set(lpfc_mqe_status, mb, |
| 8986 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8987 | rc = MBXERR_ERROR; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 8988 | } else |
| 8989 | lpfc_sli4_swap_str(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8990 | |
| 8991 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8992 | "(%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] | 8993 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
| 8994 | " 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] | 8995 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
| 8996 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8997 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8998 | bf_get(lpfc_mqe_status, mb), |
| 8999 | mb->un.mb_words[0], mb->un.mb_words[1], |
| 9000 | mb->un.mb_words[2], mb->un.mb_words[3], |
| 9001 | mb->un.mb_words[4], mb->un.mb_words[5], |
| 9002 | mb->un.mb_words[6], mb->un.mb_words[7], |
| 9003 | mb->un.mb_words[8], mb->un.mb_words[9], |
| 9004 | mb->un.mb_words[10], mb->un.mb_words[11], |
| 9005 | mb->un.mb_words[12], mboxq->mcqe.word0, |
| 9006 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 9007 | mboxq->mcqe.trailer); |
| 9008 | exit: |
| 9009 | /* We are holding the token, no needed for lock when release */ |
| 9010 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 9011 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 9012 | phba->sli.mbox_active = NULL; |
| 9013 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 9014 | return rc; |
| 9015 | } |
| 9016 | |
| 9017 | /** |
| 9018 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware |
| 9019 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 9020 | * @mboxq: Pointer to mailbox object. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9021 | * @flag: Flag indicating how the mailbox need to be processed. |
| 9022 | * |
| 9023 | * This function is called by discovery code and HBA management code to submit |
| 9024 | * a mailbox command to firmware with SLI-4 interface spec. |
| 9025 | * |
| 9026 | * Return codes the caller owns the mailbox command after the return of the |
| 9027 | * function. |
| 9028 | **/ |
| 9029 | static int |
| 9030 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 9031 | uint32_t flag) |
| 9032 | { |
| 9033 | struct lpfc_sli *psli = &phba->sli; |
| 9034 | unsigned long iflags; |
| 9035 | int rc; |
| 9036 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 9037 | /* dump from issue mailbox command if setup */ |
| 9038 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); |
| 9039 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 9040 | rc = lpfc_mbox_dev_check(phba); |
| 9041 | if (unlikely(rc)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9042 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9043 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 9044 | "cannot issue Data: x%x x%x\n", |
| 9045 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 9046 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9047 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 9048 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 9049 | psli->sli_flag, flag); |
| 9050 | goto out_not_finished; |
| 9051 | } |
| 9052 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9053 | /* Detect polling mode and jump to a handler */ |
| 9054 | if (!phba->sli4_hba.intr_enable) { |
| 9055 | if (flag == MBX_POLL) |
| 9056 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 9057 | else |
| 9058 | rc = -EIO; |
| 9059 | if (rc != MBX_SUCCESS) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9060 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9061 | "(%d):2541 Mailbox command x%x " |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 9062 | "(x%x/x%x) failure: " |
| 9063 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 9064 | "Data: x%x x%x\n,", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9065 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 9066 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9067 | lpfc_sli_config_mbox_subsys_get(phba, |
| 9068 | mboxq), |
| 9069 | lpfc_sli_config_mbox_opcode_get(phba, |
| 9070 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 9071 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 9072 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 9073 | bf_get(lpfc_mcqe_ext_status, |
| 9074 | &mboxq->mcqe), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9075 | psli->sli_flag, flag); |
| 9076 | return rc; |
| 9077 | } else if (flag == MBX_POLL) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9078 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 9079 | "(%d):2542 Try to issue mailbox command " |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 9080 | "x%x (x%x/x%x) synchronously ahead of async " |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9081 | "mailbox command queue: x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9082 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 9083 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9084 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 9085 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9086 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9087 | /* Try to block the asynchronous mailbox posting */ |
| 9088 | rc = lpfc_sli4_async_mbox_block(phba); |
| 9089 | if (!rc) { |
| 9090 | /* Successfully blocked, now issue sync mbox cmd */ |
| 9091 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 9092 | if (rc != MBX_SUCCESS) |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 9093 | lpfc_printf_log(phba, KERN_WARNING, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9094 | LOG_MBOX | LOG_SLI, |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 9095 | "(%d):2597 Sync Mailbox command " |
| 9096 | "x%x (x%x/x%x) failure: " |
| 9097 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 9098 | "Data: x%x x%x\n,", |
| 9099 | mboxq->vport ? mboxq->vport->vpi : 0, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9100 | mboxq->u.mb.mbxCommand, |
| 9101 | lpfc_sli_config_mbox_subsys_get(phba, |
| 9102 | mboxq), |
| 9103 | lpfc_sli_config_mbox_opcode_get(phba, |
| 9104 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 9105 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 9106 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 9107 | bf_get(lpfc_mcqe_ext_status, |
| 9108 | &mboxq->mcqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9109 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9110 | /* Unblock the async mailbox posting afterward */ |
| 9111 | lpfc_sli4_async_mbox_unblock(phba); |
| 9112 | } |
| 9113 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9114 | } |
| 9115 | |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 9116 | /* Now, interrupt mode asynchronous mailbox command */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9117 | rc = lpfc_mbox_cmd_check(phba, mboxq); |
| 9118 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9119 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9120 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9121 | "cannot issue Data: x%x x%x\n", |
| 9122 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 9123 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9124 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 9125 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9126 | psli->sli_flag, flag); |
| 9127 | goto out_not_finished; |
| 9128 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9129 | |
| 9130 | /* Put the mailbox command to the driver internal FIFO */ |
| 9131 | psli->slistat.mbox_busy++; |
| 9132 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9133 | lpfc_mbox_put(phba, mboxq); |
| 9134 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9135 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 9136 | "(%d):0354 Mbox cmd issue - Enqueue Data: " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9137 | "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] | 9138 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
| 9139 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9140 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 9141 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9142 | phba->pport->port_state, |
| 9143 | psli->sli_flag, MBX_NOWAIT); |
| 9144 | /* Wake up worker thread to transport mailbox command from head */ |
| 9145 | lpfc_worker_wake_up(phba); |
| 9146 | |
| 9147 | return MBX_BUSY; |
| 9148 | |
| 9149 | out_not_finished: |
| 9150 | return MBX_NOT_FINISHED; |
| 9151 | } |
| 9152 | |
| 9153 | /** |
| 9154 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device |
| 9155 | * @phba: Pointer to HBA context object. |
| 9156 | * |
| 9157 | * This function is called by worker thread to send a mailbox command to |
| 9158 | * SLI4 HBA firmware. |
| 9159 | * |
| 9160 | **/ |
| 9161 | int |
| 9162 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) |
| 9163 | { |
| 9164 | struct lpfc_sli *psli = &phba->sli; |
| 9165 | LPFC_MBOXQ_t *mboxq; |
| 9166 | int rc = MBX_SUCCESS; |
| 9167 | unsigned long iflags; |
| 9168 | struct lpfc_mqe *mqe; |
| 9169 | uint32_t mbx_cmnd; |
| 9170 | |
| 9171 | /* Check interrupt mode before post async mailbox command */ |
| 9172 | if (unlikely(!phba->sli4_hba.intr_enable)) |
| 9173 | return MBX_NOT_FINISHED; |
| 9174 | |
| 9175 | /* Check for mailbox command service token */ |
| 9176 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9177 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 9178 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9179 | return MBX_NOT_FINISHED; |
| 9180 | } |
| 9181 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 9182 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9183 | return MBX_NOT_FINISHED; |
| 9184 | } |
| 9185 | if (unlikely(phba->sli.mbox_active)) { |
| 9186 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9187 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9188 | "0384 There is pending active mailbox cmd\n"); |
| 9189 | return MBX_NOT_FINISHED; |
| 9190 | } |
| 9191 | /* Take the mailbox command service token */ |
| 9192 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 9193 | |
| 9194 | /* Get the next mailbox command from head of queue */ |
| 9195 | mboxq = lpfc_mbox_get(phba); |
| 9196 | |
| 9197 | /* If no more mailbox command waiting for post, we're done */ |
| 9198 | if (!mboxq) { |
| 9199 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 9200 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9201 | return MBX_SUCCESS; |
| 9202 | } |
| 9203 | phba->sli.mbox_active = mboxq; |
| 9204 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9205 | |
| 9206 | /* Check device readiness for posting mailbox command */ |
| 9207 | rc = lpfc_mbox_dev_check(phba); |
| 9208 | if (unlikely(rc)) |
| 9209 | /* Driver clean routine will clean up pending mailbox */ |
| 9210 | goto out_not_finished; |
| 9211 | |
| 9212 | /* Prepare the mbox command to be posted */ |
| 9213 | mqe = &mboxq->u.mqe; |
| 9214 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); |
| 9215 | |
| 9216 | /* Start timer for the mbox_tmo and log some mailbox post messages */ |
| 9217 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 9218 | msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq)))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9219 | |
| 9220 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9221 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9222 | "x%x x%x\n", |
| 9223 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9224 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 9225 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9226 | phba->pport->port_state, psli->sli_flag); |
| 9227 | |
| 9228 | if (mbx_cmnd != MBX_HEARTBEAT) { |
| 9229 | if (mboxq->vport) { |
| 9230 | lpfc_debugfs_disc_trc(mboxq->vport, |
| 9231 | LPFC_DISC_TRC_MBOX_VPORT, |
| 9232 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 9233 | mbx_cmnd, mqe->un.mb_words[0], |
| 9234 | mqe->un.mb_words[1]); |
| 9235 | } else { |
| 9236 | lpfc_debugfs_disc_trc(phba->pport, |
| 9237 | LPFC_DISC_TRC_MBOX, |
| 9238 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 9239 | mbx_cmnd, mqe->un.mb_words[0], |
| 9240 | mqe->un.mb_words[1]); |
| 9241 | } |
| 9242 | } |
| 9243 | psli->slistat.mbox_cmd++; |
| 9244 | |
| 9245 | /* Post the mailbox command to the port */ |
| 9246 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); |
| 9247 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9248 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9249 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9250 | "cannot issue Data: x%x x%x\n", |
| 9251 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 9252 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9253 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 9254 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9255 | psli->sli_flag, MBX_NOWAIT); |
| 9256 | goto out_not_finished; |
| 9257 | } |
| 9258 | |
| 9259 | return rc; |
| 9260 | |
| 9261 | out_not_finished: |
| 9262 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 9263 | if (phba->sli.mbox_active) { |
| 9264 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 9265 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 9266 | /* Release the token */ |
| 9267 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 9268 | phba->sli.mbox_active = NULL; |
| 9269 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9270 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9271 | |
| 9272 | return MBX_NOT_FINISHED; |
| 9273 | } |
| 9274 | |
| 9275 | /** |
| 9276 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command |
| 9277 | * @phba: Pointer to HBA context object. |
| 9278 | * @pmbox: Pointer to mailbox object. |
| 9279 | * @flag: Flag indicating how the mailbox need to be processed. |
| 9280 | * |
| 9281 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from |
| 9282 | * the API jump table function pointer from the lpfc_hba struct. |
| 9283 | * |
| 9284 | * Return codes the caller owns the mailbox command after the return of the |
| 9285 | * function. |
| 9286 | **/ |
| 9287 | int |
| 9288 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| 9289 | { |
| 9290 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); |
| 9291 | } |
| 9292 | |
| 9293 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9294 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9295 | * @phba: The hba struct for which this call is being executed. |
| 9296 | * @dev_grp: The HBA PCI-Device group number. |
| 9297 | * |
| 9298 | * This routine sets up the mbox interface API function jump table in @phba |
| 9299 | * struct. |
| 9300 | * Returns: 0 - success, -ENODEV - failure. |
| 9301 | **/ |
| 9302 | int |
| 9303 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 9304 | { |
| 9305 | |
| 9306 | switch (dev_grp) { |
| 9307 | case LPFC_PCI_DEV_LP: |
| 9308 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; |
| 9309 | phba->lpfc_sli_handle_slow_ring_event = |
| 9310 | lpfc_sli_handle_slow_ring_event_s3; |
| 9311 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; |
| 9312 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; |
| 9313 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; |
| 9314 | break; |
| 9315 | case LPFC_PCI_DEV_OC: |
| 9316 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; |
| 9317 | phba->lpfc_sli_handle_slow_ring_event = |
| 9318 | lpfc_sli_handle_slow_ring_event_s4; |
| 9319 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; |
| 9320 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; |
| 9321 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; |
| 9322 | break; |
| 9323 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9324 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9325 | "1420 Invalid HBA PCI-device group: 0x%x\n", |
| 9326 | dev_grp); |
| 9327 | return -ENODEV; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9328 | } |
| 9329 | return 0; |
| 9330 | } |
| 9331 | |
| 9332 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9333 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9334 | * @phba: Pointer to HBA context object. |
| 9335 | * @pring: Pointer to driver SLI ring object. |
| 9336 | * @piocb: Pointer to address of newly added command iocb. |
| 9337 | * |
James Smart | 27f3efd | 2019-10-18 14:18:19 -0700 | [diff] [blame] | 9338 | * This function is called with hbalock held for SLI3 ports or |
| 9339 | * the ring lock held for SLI4 ports to add a command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9340 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 9341 | * to the ring. |
| 9342 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9343 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9344 | __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] | 9345 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9346 | { |
James Smart | 27f3efd | 2019-10-18 14:18:19 -0700 | [diff] [blame] | 9347 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 9348 | lockdep_assert_held(&pring->ring_lock); |
| 9349 | else |
| 9350 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9351 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 9352 | list_add_tail(&piocb->list, &pring->txq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9353 | } |
| 9354 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9355 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9356 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9357 | * @phba: Pointer to HBA context object. |
| 9358 | * @pring: Pointer to driver SLI ring object. |
| 9359 | * @piocb: Pointer to address of newly added command iocb. |
| 9360 | * |
| 9361 | * This function is called with hbalock held before a new |
| 9362 | * iocb is submitted to the firmware. This function checks |
| 9363 | * txq to flush the iocbs in txq to Firmware before |
| 9364 | * submitting new iocbs to the Firmware. |
| 9365 | * If there are iocbs in the txq which need to be submitted |
| 9366 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 9367 | * of the txq after dequeuing it from txq. |
| 9368 | * If there is no iocb in the txq then the function will return |
| 9369 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 9370 | * *piocb to find if there are more commands in the txq. |
| 9371 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9372 | static struct lpfc_iocbq * |
| 9373 | 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] | 9374 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9375 | { |
| 9376 | struct lpfc_iocbq * nextiocb; |
| 9377 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9378 | lockdep_assert_held(&phba->hbalock); |
| 9379 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9380 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 9381 | if (!nextiocb) { |
| 9382 | nextiocb = *piocb; |
| 9383 | *piocb = NULL; |
| 9384 | } |
| 9385 | |
| 9386 | return nextiocb; |
| 9387 | } |
| 9388 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9389 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9390 | * __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] | 9391 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9392 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9393 | * @piocb: Pointer to command iocb. |
| 9394 | * @flag: Flag indicating if this command can be put into txq. |
| 9395 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9396 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 9397 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 9398 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 9399 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 9400 | * this function allows only iocbs for posting buffers. This function finds |
| 9401 | * next available slot in the command ring and posts the command to the |
| 9402 | * available slot and writes the port attention register to request HBA start |
| 9403 | * processing new iocb. If there is no slot available in the ring and |
| 9404 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 9405 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9406 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9407 | * This function is called with hbalock held. The function will return success |
| 9408 | * after it successfully submit the iocb to firmware or after adding to the |
| 9409 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9410 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 9411 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9412 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9413 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9414 | { |
| 9415 | struct lpfc_iocbq *nextiocb; |
| 9416 | IOCB_t *iocb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9417 | struct lpfc_sli_ring *pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9418 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9419 | lockdep_assert_held(&phba->hbalock); |
| 9420 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9421 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 9422 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 9423 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9424 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9425 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9426 | piocb->iocb.ulpCommand); |
| 9427 | dump_stack(); |
| 9428 | return IOCB_ERROR; |
| 9429 | } |
| 9430 | |
| 9431 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9432 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 9433 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 9434 | return IOCB_ERROR; |
| 9435 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9436 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 9437 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 9438 | return IOCB_ERROR; |
| 9439 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9440 | /* |
| 9441 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 9442 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9443 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9444 | return IOCB_ERROR; |
| 9445 | |
| 9446 | /* |
| 9447 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 9448 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9449 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 9450 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9451 | goto iocb_busy; |
| 9452 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9453 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9454 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9455 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9456 | * can be issued if the link is not up. |
| 9457 | */ |
| 9458 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 9459 | case CMD_GEN_REQUEST64_CR: |
| 9460 | case CMD_GEN_REQUEST64_CX: |
| 9461 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 9462 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9463 | FC_RCTL_DD_UNSOL_CMD) || |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 9464 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 9465 | MENLO_TRANSPORT_TYPE)) |
| 9466 | |
| 9467 | goto iocb_busy; |
| 9468 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9469 | case CMD_QUE_RING_BUF_CN: |
| 9470 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9471 | /* |
| 9472 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 9473 | * completion, iocb_cmpl MUST be 0. |
| 9474 | */ |
| 9475 | if (piocb->iocb_cmpl) |
| 9476 | piocb->iocb_cmpl = NULL; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9477 | fallthrough; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9478 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9479 | case CMD_CLOSE_XRI_CN: |
| 9480 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9481 | break; |
| 9482 | default: |
| 9483 | goto iocb_busy; |
| 9484 | } |
| 9485 | |
| 9486 | /* |
| 9487 | * For FCP commands, we must be in a state where we can process link |
| 9488 | * attention events. |
| 9489 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9490 | } else if (unlikely(pring->ringno == LPFC_FCP_RING && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9491 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9492 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9493 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9494 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9495 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 9496 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 9497 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 9498 | |
| 9499 | if (iocb) |
| 9500 | lpfc_sli_update_ring(phba, pring); |
| 9501 | else |
| 9502 | lpfc_sli_update_full_ring(phba, pring); |
| 9503 | |
| 9504 | if (!piocb) |
| 9505 | return IOCB_SUCCESS; |
| 9506 | |
| 9507 | goto out_busy; |
| 9508 | |
| 9509 | iocb_busy: |
| 9510 | pring->stats.iocb_cmd_delay++; |
| 9511 | |
| 9512 | out_busy: |
| 9513 | |
| 9514 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9515 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9516 | return IOCB_SUCCESS; |
| 9517 | } |
| 9518 | |
| 9519 | return IOCB_BUSY; |
| 9520 | } |
| 9521 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9522 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9523 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
| 9524 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 9525 | * @piocbq: Pointer to command iocb. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9526 | * @sglq: Pointer to the scatter gather queue object. |
| 9527 | * |
| 9528 | * This routine converts the bpl or bde that is in the IOCB |
| 9529 | * to a sgl list for the sli4 hardware. The physical address |
| 9530 | * of the bpl/bde is converted back to a virtual address. |
| 9531 | * If the IOCB contains a BPL then the list of BDE's is |
| 9532 | * converted to sli4_sge's. If the IOCB contains a single |
| 9533 | * BDE then it is converted to a single sli_sge. |
| 9534 | * The IOCB is still in cpu endianess so the contents of |
| 9535 | * the bpl can be used without byte swapping. |
| 9536 | * |
| 9537 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 9538 | **/ |
| 9539 | static uint16_t |
| 9540 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
| 9541 | struct lpfc_sglq *sglq) |
| 9542 | { |
| 9543 | uint16_t xritag = NO_XRI; |
| 9544 | struct ulp_bde64 *bpl = NULL; |
| 9545 | struct ulp_bde64 bde; |
| 9546 | struct sli4_sge *sgl = NULL; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9547 | struct lpfc_dmabuf *dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9548 | IOCB_t *icmd; |
| 9549 | int numBdes = 0; |
| 9550 | int i = 0; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9551 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 9552 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9553 | |
| 9554 | if (!piocbq || !sglq) |
| 9555 | return xritag; |
| 9556 | |
| 9557 | sgl = (struct sli4_sge *)sglq->sgl; |
| 9558 | icmd = &piocbq->iocb; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9559 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
| 9560 | return sglq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9561 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
| 9562 | numBdes = icmd->un.genreq64.bdl.bdeSize / |
| 9563 | sizeof(struct ulp_bde64); |
| 9564 | /* The addrHigh and addrLow fields within the IOCB |
| 9565 | * have not been byteswapped yet so there is no |
| 9566 | * need to swap them back. |
| 9567 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9568 | if (piocbq->context3) |
| 9569 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; |
| 9570 | else |
| 9571 | return xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9572 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9573 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9574 | if (!bpl) |
| 9575 | return xritag; |
| 9576 | |
| 9577 | for (i = 0; i < numBdes; i++) { |
| 9578 | /* Should already be byte swapped. */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9579 | sgl->addr_hi = bpl->addrHigh; |
| 9580 | sgl->addr_lo = bpl->addrLow; |
| 9581 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9582 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9583 | if ((i+1) == numBdes) |
| 9584 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 9585 | else |
| 9586 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9587 | /* swap the size field back to the cpu so we |
| 9588 | * can assign it to the sgl. |
| 9589 | */ |
| 9590 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 9591 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9592 | /* The offsets in the sgl need to be accumulated |
| 9593 | * separately for the request and reply lists. |
| 9594 | * The request is always first, the reply follows. |
| 9595 | */ |
| 9596 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { |
| 9597 | /* add up the reply sg entries */ |
| 9598 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 9599 | inbound++; |
| 9600 | /* first inbound? reset the offset */ |
| 9601 | if (inbound == 1) |
| 9602 | offset = 0; |
| 9603 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 9604 | bf_set(lpfc_sli4_sge_type, sgl, |
| 9605 | LPFC_SGE_TYPE_DATA); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9606 | offset += bde.tus.f.bdeSize; |
| 9607 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9608 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9609 | bpl++; |
| 9610 | sgl++; |
| 9611 | } |
| 9612 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { |
| 9613 | /* The addrHigh and addrLow fields of the BDE have not |
| 9614 | * been byteswapped yet so they need to be swapped |
| 9615 | * before putting them in the sgl. |
| 9616 | */ |
| 9617 | sgl->addr_hi = |
| 9618 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); |
| 9619 | sgl->addr_lo = |
| 9620 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9621 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9622 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 9623 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9624 | sgl->sge_len = |
| 9625 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9626 | } |
| 9627 | return sglq->sli4_xritag; |
| 9628 | } |
| 9629 | |
| 9630 | /** |
Lee Jones | 8514e2f | 2021-03-03 14:46:18 +0000 | [diff] [blame] | 9631 | * lpfc_sli4_iocb2wqe - Convert the IOCB to a work queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9632 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 9633 | * @iocbq: Pointer to command iocb. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9634 | * @wqe: Pointer to the work queue entry. |
| 9635 | * |
| 9636 | * This routine converts the iocb command to its Work Queue Entry |
| 9637 | * equivalent. The wqe pointer should not have any fields set when |
| 9638 | * this routine is called because it will memcpy over them. |
| 9639 | * This routine does not set the CQ_ID or the WQEC bits in the |
| 9640 | * wqe. |
| 9641 | * |
| 9642 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
| 9643 | **/ |
| 9644 | static int |
| 9645 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9646 | union lpfc_wqe128 *wqe) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9647 | { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9648 | uint32_t xmit_len = 0, total_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9649 | uint8_t ct = 0; |
| 9650 | uint32_t fip; |
| 9651 | uint32_t abort_tag; |
| 9652 | uint8_t command_type = ELS_COMMAND_NON_FIP; |
| 9653 | uint8_t cmnd; |
| 9654 | uint16_t xritag; |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9655 | uint16_t abrt_iotag; |
| 9656 | struct lpfc_iocbq *abrtiocbq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9657 | struct ulp_bde64 *bpl = NULL; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9658 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9659 | int numBdes, i; |
| 9660 | struct ulp_bde64 bde; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 9661 | struct lpfc_nodelist *ndlp; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9662 | uint32_t *pcmd; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9663 | uint32_t if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9664 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9665 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9666 | /* The fcp commands will set command type */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 9667 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9668 | command_type = FCP_COMMAND; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9669 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 9670 | command_type = ELS_COMMAND_FIP; |
| 9671 | else |
| 9672 | command_type = ELS_COMMAND_NON_FIP; |
| 9673 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9674 | if (phba->fcp_embed_io) |
| 9675 | memset(wqe, 0, sizeof(union lpfc_wqe128)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9676 | /* Some of the fields are in the right position already */ |
| 9677 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 9678 | /* The ct field has moved so reset */ |
| 9679 | wqe->generic.wqe_com.word7 = 0; |
| 9680 | wqe->generic.wqe_com.word10 = 0; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9681 | |
| 9682 | abort_tag = (uint32_t) iocbq->iotag; |
| 9683 | xritag = iocbq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9684 | /* words0-2 bpl convert bde */ |
| 9685 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9686 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 9687 | sizeof(struct ulp_bde64); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9688 | bpl = (struct ulp_bde64 *) |
| 9689 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; |
| 9690 | if (!bpl) |
| 9691 | return IOCB_ERROR; |
| 9692 | |
| 9693 | /* Should already be byte swapped. */ |
| 9694 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); |
| 9695 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); |
| 9696 | /* swap the size field back to the cpu so we |
| 9697 | * can assign it to the sgl. |
| 9698 | */ |
| 9699 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9700 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
| 9701 | total_len = 0; |
| 9702 | for (i = 0; i < numBdes; i++) { |
| 9703 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 9704 | total_len += bde.tus.f.bdeSize; |
| 9705 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9706 | } else |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9707 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9708 | |
| 9709 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
| 9710 | cmnd = iocbq->iocb.ulpCommand; |
| 9711 | |
| 9712 | switch (iocbq->iocb.ulpCommand) { |
| 9713 | case CMD_ELS_REQUEST64_CR: |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 9714 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
| 9715 | ndlp = iocbq->context_un.ndlp; |
| 9716 | else |
| 9717 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9718 | if (!iocbq->iocb.ulpLe) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9719 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9720 | "2007 Only Limited Edition cmd Format" |
| 9721 | " supported 0x%x\n", |
| 9722 | iocbq->iocb.ulpCommand); |
| 9723 | return IOCB_ERROR; |
| 9724 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9725 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9726 | wqe->els_req.payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9727 | /* Els_reguest64 has a TMO */ |
| 9728 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, |
| 9729 | iocbq->iocb.ulpTimeout); |
| 9730 | /* Need a VF for word 4 set the vf bit*/ |
| 9731 | bf_set(els_req64_vf, &wqe->els_req, 0); |
| 9732 | /* And a VFID for word 12 */ |
| 9733 | bf_set(els_req64_vfid, &wqe->els_req, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9734 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9735 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 9736 | iocbq->iocb.ulpContext); |
| 9737 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); |
| 9738 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9739 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9740 | if (command_type == ELS_COMMAND_FIP) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9741 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
| 9742 | >> LPFC_FIP_ELS_ID_SHIFT); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9743 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 9744 | iocbq->context2)->virt); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9745 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 9746 | &phba->sli4_hba.sli_intf); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9747 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9748 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9749 | *pcmd == ELS_CMD_SCR || |
James Smart | df3fe76 | 2020-02-10 09:31:55 -0800 | [diff] [blame] | 9750 | *pcmd == ELS_CMD_RDF || |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 9751 | *pcmd == ELS_CMD_RSCN_XMT || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9752 | *pcmd == ELS_CMD_FDISC || |
James Smart | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 9753 | *pcmd == ELS_CMD_LOGO || |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9754 | *pcmd == ELS_CMD_PLOGI)) { |
| 9755 | bf_set(els_req64_sp, &wqe->els_req, 1); |
| 9756 | bf_set(els_req64_sid, &wqe->els_req, |
| 9757 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9758 | if ((*pcmd == ELS_CMD_FLOGI) && |
| 9759 | !(phba->fc_topology == |
| 9760 | LPFC_TOPOLOGY_LOOP)) |
| 9761 | bf_set(els_req64_sid, &wqe->els_req, 0); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9762 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
| 9763 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
James Smart | a7dd9c0 | 2012-05-09 21:16:50 -0400 | [diff] [blame] | 9764 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 9765 | } else if (pcmd && iocbq->context1) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9766 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
| 9767 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 9768 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
| 9769 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9770 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9771 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
| 9772 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9773 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
| 9774 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); |
| 9775 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); |
| 9776 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); |
| 9777 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 9778 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 9779 | wqe->els_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9780 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9781 | case CMD_XMIT_SEQUENCE64_CX: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9782 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
| 9783 | iocbq->iocb.un.ulpWord[3]); |
| 9784 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9785 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9786 | /* The entire sequence is transmitted for this IOCB */ |
| 9787 | xmit_len = total_len; |
| 9788 | cmnd = CMD_XMIT_SEQUENCE64_CR; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9789 | if (phba->link_flag & LS_LOOPBACK_MODE) |
| 9790 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9791 | fallthrough; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9792 | case CMD_XMIT_SEQUENCE64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9793 | /* word3 iocb=io_tag32 wqe=reserved */ |
| 9794 | wqe->xmit_sequence.rsvd3 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9795 | /* word4 relative_offset memcpy */ |
| 9796 | /* word5 r_ctl/df_ctl memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9797 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
| 9798 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); |
| 9799 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, |
| 9800 | LPFC_WQE_IOD_WRITE); |
| 9801 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, |
| 9802 | LPFC_WQE_LENLOC_WORD12); |
| 9803 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9804 | wqe->xmit_sequence.xmit_len = xmit_len; |
| 9805 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9806 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9807 | case CMD_XMIT_BCAST64_CN: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9808 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
| 9809 | wqe->xmit_bcast64.seq_payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9810 | /* word4 iocb=rsvd wqe=rsvd */ |
| 9811 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ |
| 9812 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9813 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9814 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9815 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
| 9816 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9817 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, |
| 9818 | LPFC_WQE_LENLOC_WORD3); |
| 9819 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9820 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9821 | case CMD_FCP_IWRITE64_CR: |
| 9822 | command_type = FCP_COMMAND_DATA_OUT; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9823 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9824 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9825 | bf_set(payload_offset_len, &wqe->fcp_iwrite, |
| 9826 | xmit_len + sizeof(struct fcp_rsp)); |
| 9827 | bf_set(cmd_buff_len, &wqe->fcp_iwrite, |
| 9828 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9829 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 9830 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 9831 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, |
| 9832 | iocbq->iocb.ulpFCP2Rcvy); |
| 9833 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); |
| 9834 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9835 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9836 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, |
| 9837 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9838 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 9839 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9840 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9841 | bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9842 | bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1); |
| 9843 | if (iocbq->priority) { |
| 9844 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 9845 | (iocbq->priority << 1)); |
| 9846 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9847 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 9848 | (phba->cfg_XLanePriority << 1)); |
| 9849 | } |
| 9850 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9851 | /* Note, word 10 is already initialized to 0 */ |
| 9852 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 9853 | /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */ |
| 9854 | if (phba->cfg_enable_pbde) |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 9855 | bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 1); |
| 9856 | else |
| 9857 | bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 0); |
| 9858 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9859 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 9860 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9861 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9862 | struct fcp_cmnd *fcp_cmnd; |
| 9863 | uint32_t *ptr; |
| 9864 | |
| 9865 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9866 | |
| 9867 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 9868 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9869 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9870 | |
| 9871 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9872 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9873 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9874 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9875 | wqe->generic.bde.addrHigh = 0; |
| 9876 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9877 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9878 | bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1); |
| 9879 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9880 | |
| 9881 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9882 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9883 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9884 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9885 | break; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9886 | case CMD_FCP_IREAD64_CR: |
| 9887 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9888 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9889 | bf_set(payload_offset_len, &wqe->fcp_iread, |
| 9890 | xmit_len + sizeof(struct fcp_rsp)); |
| 9891 | bf_set(cmd_buff_len, &wqe->fcp_iread, |
| 9892 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9893 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 9894 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 9895 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, |
| 9896 | iocbq->iocb.ulpFCP2Rcvy); |
| 9897 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9898 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9899 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
| 9900 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, |
| 9901 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9902 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 9903 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9904 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9905 | bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9906 | bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1); |
| 9907 | if (iocbq->priority) { |
| 9908 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 9909 | (iocbq->priority << 1)); |
| 9910 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9911 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 9912 | (phba->cfg_XLanePriority << 1)); |
| 9913 | } |
| 9914 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9915 | /* Note, word 10 is already initialized to 0 */ |
| 9916 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 9917 | /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */ |
| 9918 | if (phba->cfg_enable_pbde) |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 9919 | bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 1); |
| 9920 | else |
| 9921 | bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 0); |
| 9922 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9923 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 9924 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9925 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9926 | struct fcp_cmnd *fcp_cmnd; |
| 9927 | uint32_t *ptr; |
| 9928 | |
| 9929 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9930 | |
| 9931 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 9932 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9933 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9934 | |
| 9935 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9936 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9937 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9938 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9939 | wqe->generic.bde.addrHigh = 0; |
| 9940 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9941 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9942 | bf_set(wqe_wqes, &wqe->fcp_iread.wqe_com, 1); |
| 9943 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9944 | |
| 9945 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9946 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9947 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9948 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9949 | break; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9950 | case CMD_FCP_ICMND64_CR: |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9951 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9952 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 9953 | bf_set(payload_offset_len, &wqe->fcp_icmd, |
| 9954 | xmit_len + sizeof(struct fcp_rsp)); |
| 9955 | bf_set(cmd_buff_len, &wqe->fcp_icmd, |
| 9956 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9957 | /* word3 iocb=IO_TAG wqe=reserved */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9958 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9959 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9960 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
| 9961 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9962 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); |
| 9963 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, |
| 9964 | LPFC_WQE_LENLOC_NONE); |
James Smart | 2a94aea | 2012-09-29 11:30:31 -0400 | [diff] [blame] | 9965 | bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com, |
| 9966 | iocbq->iocb.ulpFCP2Rcvy); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9967 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9968 | bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9969 | bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1); |
| 9970 | if (iocbq->priority) { |
| 9971 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 9972 | (iocbq->priority << 1)); |
| 9973 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9974 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 9975 | (phba->cfg_XLanePriority << 1)); |
| 9976 | } |
| 9977 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9978 | /* Note, word 10 is already initialized to 0 */ |
| 9979 | |
| 9980 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 9981 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9982 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9983 | struct fcp_cmnd *fcp_cmnd; |
| 9984 | uint32_t *ptr; |
| 9985 | |
| 9986 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9987 | |
| 9988 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 9989 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9990 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9991 | |
| 9992 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9993 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9994 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9995 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9996 | wqe->generic.bde.addrHigh = 0; |
| 9997 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9998 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9999 | bf_set(wqe_wqes, &wqe->fcp_icmd.wqe_com, 1); |
| 10000 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10001 | |
| 10002 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 10003 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10004 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 10005 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10006 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10007 | case CMD_GEN_REQUEST64_CR: |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 10008 | /* For this command calculate the xmit length of the |
| 10009 | * request bde. |
| 10010 | */ |
| 10011 | xmit_len = 0; |
| 10012 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 10013 | sizeof(struct ulp_bde64); |
| 10014 | for (i = 0; i < numBdes; i++) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 10015 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 10016 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 10017 | break; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 10018 | xmit_len += bde.tus.f.bdeSize; |
| 10019 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10020 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
| 10021 | wqe->gen_req.request_payload_len = xmit_len; |
| 10022 | /* word4 iocb=parameter wqe=relative_offset memcpy */ |
| 10023 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10024 | /* word6 context tag copied in memcpy */ |
| 10025 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { |
| 10026 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10027 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10028 | "2015 Invalid CT %x command 0x%x\n", |
| 10029 | ct, iocbq->iocb.ulpCommand); |
| 10030 | return IOCB_ERROR; |
| 10031 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10032 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
| 10033 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); |
| 10034 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); |
| 10035 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); |
| 10036 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); |
| 10037 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); |
| 10038 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 10039 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 10040 | wqe->gen_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10041 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10042 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10043 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 10044 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10045 | /* words0-2 BDE memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10046 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
| 10047 | wqe->xmit_els_rsp.response_payload_len = xmit_len; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 10048 | /* word4 */ |
| 10049 | wqe->xmit_els_rsp.word4 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10050 | /* word5 iocb=rsvd wge=did */ |
| 10051 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 10052 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
| 10053 | |
| 10054 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 10055 | &phba->sli4_hba.sli_intf); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10056 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 10057 | if (iocbq->vport->fc_flag & FC_PT2PT) { |
| 10058 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 10059 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
| 10060 | iocbq->vport->fc_myDID); |
| 10061 | if (iocbq->vport->fc_myDID == Fabric_DID) { |
| 10062 | bf_set(wqe_els_did, |
| 10063 | &wqe->xmit_els_rsp.wqe_dest, 0); |
| 10064 | } |
| 10065 | } |
| 10066 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10067 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
| 10068 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 10069 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); |
| 10070 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10071 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10072 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10073 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 10074 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10075 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
| 10076 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); |
| 10077 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); |
| 10078 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, |
| 10079 | LPFC_WQE_LENLOC_WORD3); |
| 10080 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 10081 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
| 10082 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 10083 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 10084 | iocbq->context2)->virt); |
| 10085 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 10086 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 10087 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 10088 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 10089 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
| 10090 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 10091 | phba->vpi_ids[phba->pport->vpi]); |
| 10092 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10093 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10094 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10095 | case CMD_CLOSE_XRI_CN: |
| 10096 | case CMD_ABORT_XRI_CN: |
| 10097 | case CMD_ABORT_XRI_CX: |
| 10098 | /* words 0-2 memcpy should be 0 rserved */ |
| 10099 | /* port will send abts */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 10100 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
| 10101 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { |
| 10102 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; |
| 10103 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; |
| 10104 | } else |
| 10105 | fip = 0; |
| 10106 | |
| 10107 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10108 | /* |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 10109 | * The link is down, or the command was ELS_FIP |
| 10110 | * so the fw does not need to send abts |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10111 | * on the wire. |
| 10112 | */ |
| 10113 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); |
| 10114 | else |
| 10115 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); |
| 10116 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10117 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
| 10118 | wqe->abort_cmd.rsrvd5 = 0; |
| 10119 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10120 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 10121 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10122 | /* |
| 10123 | * The abort handler will send us CMD_ABORT_XRI_CN or |
| 10124 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX |
| 10125 | */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10126 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 10127 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); |
| 10128 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, |
| 10129 | LPFC_WQE_LENLOC_NONE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10130 | cmnd = CMD_ABORT_XRI_CX; |
| 10131 | command_type = OTHER_COMMAND; |
| 10132 | xritag = 0; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10133 | break; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10134 | case CMD_XMIT_BLS_RSP64_CX: |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10135 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 10136 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10137 | * we re-construct this WQE here based on information in |
| 10138 | * iocbq from scratch. |
| 10139 | */ |
James Smart | d9f492a | 2019-08-14 16:57:04 -0700 | [diff] [blame] | 10140 | memset(wqe, 0, sizeof(*wqe)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10141 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10142 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 10143 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
| 10144 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10145 | LPFC_ABTS_UNSOL_INT) { |
| 10146 | /* ABTS sent by initiator to CT exchange, the |
| 10147 | * RX_ID field will be filled with the newly |
| 10148 | * allocated responder XRI. |
| 10149 | */ |
| 10150 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
| 10151 | iocbq->sli4_xritag); |
| 10152 | } else { |
| 10153 | /* ABTS sent by responder to CT exchange, the |
| 10154 | * RX_ID field will be filled with the responder |
| 10155 | * RX_ID from ABTS. |
| 10156 | */ |
| 10157 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 10158 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10159 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10160 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
| 10161 | 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] | 10162 | |
| 10163 | /* Use CT=VPI */ |
| 10164 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, |
| 10165 | ndlp->nlp_DID); |
| 10166 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, |
| 10167 | iocbq->iocb.ulpContext); |
| 10168 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10169 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10170 | phba->vpi_ids[phba->pport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10171 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
| 10172 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, |
| 10173 | LPFC_WQE_LENLOC_NONE); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10174 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
| 10175 | command_type = OTHER_COMMAND; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 10176 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
| 10177 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, |
| 10178 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); |
| 10179 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, |
| 10180 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); |
| 10181 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, |
| 10182 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); |
| 10183 | } |
| 10184 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 10185 | break; |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 10186 | case CMD_SEND_FRAME: |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 10187 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, CMD_SEND_FRAME); |
| 10188 | bf_set(wqe_sof, &wqe->generic.wqe_com, 0x2E); /* SOF byte */ |
| 10189 | bf_set(wqe_eof, &wqe->generic.wqe_com, 0x41); /* EOF byte */ |
| 10190 | bf_set(wqe_lenloc, &wqe->generic.wqe_com, 1); |
| 10191 | bf_set(wqe_xbl, &wqe->generic.wqe_com, 1); |
| 10192 | bf_set(wqe_dbde, &wqe->generic.wqe_com, 1); |
| 10193 | bf_set(wqe_xc, &wqe->generic.wqe_com, 1); |
| 10194 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, 0xA); |
| 10195 | 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] | 10196 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 10197 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 10198 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10199 | case CMD_XRI_ABORTED_CX: |
| 10200 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10201 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
| 10202 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ |
| 10203 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ |
| 10204 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ |
| 10205 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10206 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10207 | "2014 Invalid command 0x%x\n", |
| 10208 | iocbq->iocb.ulpCommand); |
| 10209 | return IOCB_ERROR; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10210 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 10211 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 10212 | if (iocbq->iocb_flag & LPFC_IO_DIF_PASS) |
| 10213 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU); |
| 10214 | else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP) |
| 10215 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP); |
| 10216 | else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT) |
| 10217 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT); |
| 10218 | iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP | |
| 10219 | LPFC_IO_DIF_INSERT); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 10220 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 10221 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 10222 | wqe->generic.wqe_com.abort_tag = abort_tag; |
| 10223 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); |
| 10224 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); |
| 10225 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); |
| 10226 | 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] | 10227 | return 0; |
| 10228 | } |
| 10229 | |
| 10230 | /** |
James Smart | 47ff4c5 | 2020-11-15 11:26:41 -0800 | [diff] [blame] | 10231 | * __lpfc_sli_issue_fcp_io_s3 - SLI3 device for sending fcp io iocb |
| 10232 | * @phba: Pointer to HBA context object. |
| 10233 | * @ring_number: SLI ring number to issue wqe on. |
| 10234 | * @piocb: Pointer to command iocb. |
| 10235 | * @flag: Flag indicating if this command can be put into txq. |
| 10236 | * |
| 10237 | * __lpfc_sli_issue_fcp_io_s3 is wrapper function to invoke lockless func to |
| 10238 | * send an iocb command to an HBA with SLI-4 interface spec. |
| 10239 | * |
| 10240 | * This function takes the hbalock before invoking the lockless version. |
| 10241 | * The function will return success after it successfully submit the wqe to |
| 10242 | * firmware or after adding to the txq. |
| 10243 | **/ |
| 10244 | static int |
| 10245 | __lpfc_sli_issue_fcp_io_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| 10246 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 10247 | { |
| 10248 | unsigned long iflags; |
| 10249 | int rc; |
| 10250 | |
| 10251 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 10252 | rc = __lpfc_sli_issue_iocb_s3(phba, ring_number, piocb, flag); |
James Smart | 47ff4c5 | 2020-11-15 11:26:41 -0800 | [diff] [blame] | 10253 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10254 | |
| 10255 | return rc; |
| 10256 | } |
| 10257 | |
| 10258 | /** |
| 10259 | * __lpfc_sli_issue_fcp_io_s4 - SLI4 device for sending fcp io wqe |
| 10260 | * @phba: Pointer to HBA context object. |
| 10261 | * @ring_number: SLI ring number to issue wqe on. |
| 10262 | * @piocb: Pointer to command iocb. |
| 10263 | * @flag: Flag indicating if this command can be put into txq. |
| 10264 | * |
| 10265 | * __lpfc_sli_issue_fcp_io_s4 is used by other functions in the driver to issue |
| 10266 | * an wqe command to an HBA with SLI-4 interface spec. |
| 10267 | * |
| 10268 | * This function is a lockless version. The function will return success |
| 10269 | * after it successfully submit the wqe to firmware or after adding to the |
| 10270 | * txq. |
| 10271 | **/ |
| 10272 | static int |
| 10273 | __lpfc_sli_issue_fcp_io_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 10274 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 10275 | { |
James Smart | 47ff4c5 | 2020-11-15 11:26:41 -0800 | [diff] [blame] | 10276 | int rc; |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 10277 | struct lpfc_io_buf *lpfc_cmd = |
| 10278 | (struct lpfc_io_buf *)piocb->context1; |
| 10279 | union lpfc_wqe128 *wqe = &piocb->wqe; |
| 10280 | struct sli4_sge *sgl; |
James Smart | 47ff4c5 | 2020-11-15 11:26:41 -0800 | [diff] [blame] | 10281 | |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 10282 | /* 128 byte wqe support here */ |
| 10283 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | 47ff4c5 | 2020-11-15 11:26:41 -0800 | [diff] [blame] | 10284 | |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 10285 | if (phba->fcp_embed_io) { |
| 10286 | struct fcp_cmnd *fcp_cmnd; |
| 10287 | u32 *ptr; |
James Smart | 47ff4c5 | 2020-11-15 11:26:41 -0800 | [diff] [blame] | 10288 | |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 10289 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | 47ff4c5 | 2020-11-15 11:26:41 -0800 | [diff] [blame] | 10290 | |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 10291 | /* Word 0-2 - FCP_CMND */ |
| 10292 | wqe->generic.bde.tus.f.bdeFlags = |
| 10293 | BUFF_TYPE_BDE_IMMED; |
| 10294 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 10295 | wqe->generic.bde.addrHigh = 0; |
| 10296 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
| 10297 | |
| 10298 | bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1); |
| 10299 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0); |
| 10300 | |
| 10301 | /* Word 22-29 FCP CMND Payload */ |
| 10302 | ptr = &wqe->words[22]; |
| 10303 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 10304 | } else { |
| 10305 | /* Word 0-2 - Inline BDE */ |
| 10306 | wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 10307 | wqe->generic.bde.tus.f.bdeSize = sizeof(struct fcp_cmnd); |
| 10308 | wqe->generic.bde.addrHigh = sgl->addr_hi; |
| 10309 | wqe->generic.bde.addrLow = sgl->addr_lo; |
| 10310 | |
| 10311 | /* Word 10 */ |
| 10312 | bf_set(wqe_dbde, &wqe->generic.wqe_com, 1); |
| 10313 | bf_set(wqe_wqes, &wqe->generic.wqe_com, 0); |
| 10314 | } |
| 10315 | |
| 10316 | rc = lpfc_sli4_issue_wqe(phba, lpfc_cmd->hdwq, piocb); |
James Smart | 47ff4c5 | 2020-11-15 11:26:41 -0800 | [diff] [blame] | 10317 | return rc; |
| 10318 | } |
| 10319 | |
| 10320 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10321 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb |
| 10322 | * @phba: Pointer to HBA context object. |
| 10323 | * @ring_number: SLI ring number to issue iocb on. |
| 10324 | * @piocb: Pointer to command iocb. |
| 10325 | * @flag: Flag indicating if this command can be put into txq. |
| 10326 | * |
| 10327 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue |
| 10328 | * an iocb command to an HBA with SLI-4 interface spec. |
| 10329 | * |
James Smart | 27f3efd | 2019-10-18 14:18:19 -0700 | [diff] [blame] | 10330 | * This function is called with ringlock held. The function will return success |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10331 | * after it successfully submit the iocb to firmware or after adding to the |
| 10332 | * txq. |
| 10333 | **/ |
| 10334 | static int |
| 10335 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 10336 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 10337 | { |
| 10338 | struct lpfc_sglq *sglq; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 10339 | union lpfc_wqe128 wqe; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10340 | struct lpfc_queue *wq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10341 | struct lpfc_sli_ring *pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10342 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10343 | /* Get the WQ */ |
| 10344 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
| 10345 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10346 | wq = phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10347 | } else { |
| 10348 | wq = phba->sli4_hba.els_wq; |
| 10349 | } |
| 10350 | |
| 10351 | /* Get corresponding ring */ |
| 10352 | pring = wq->pring; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 10353 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10354 | /* |
| 10355 | * The WQE can be either 64 or 128 bytes, |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10356 | */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10357 | |
James Smart | cda7fa18 | 2019-03-04 15:15:43 -0800 | [diff] [blame] | 10358 | lockdep_assert_held(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10359 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10360 | if (piocb->sli4_xritag == NO_XRI) { |
| 10361 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10362 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10363 | sglq = NULL; |
| 10364 | else { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 10365 | if (!list_empty(&pring->txq)) { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10366 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 10367 | __lpfc_sli_ringtx_put(phba, |
| 10368 | pring, piocb); |
| 10369 | return IOCB_SUCCESS; |
| 10370 | } else { |
| 10371 | return IOCB_BUSY; |
| 10372 | } |
| 10373 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10374 | sglq = __lpfc_sli_get_els_sglq(phba, piocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10375 | if (!sglq) { |
| 10376 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 10377 | __lpfc_sli_ringtx_put(phba, |
| 10378 | pring, |
| 10379 | piocb); |
| 10380 | return IOCB_SUCCESS; |
| 10381 | } else |
| 10382 | return IOCB_BUSY; |
| 10383 | } |
| 10384 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10385 | } |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 10386 | } else if (piocb->iocb_flag & LPFC_IO_FCP) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 10387 | /* These IO's already have an XRI and a mapped sgl. */ |
| 10388 | sglq = NULL; |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 10389 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 10390 | else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 10391 | /* |
| 10392 | * This is a continuation of a commandi,(CX) so this |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10393 | * sglq is on the active list |
| 10394 | */ |
James Smart | edccdc1 | 2013-01-03 15:43:45 -0500 | [diff] [blame] | 10395 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10396 | if (!sglq) |
| 10397 | return IOCB_ERROR; |
| 10398 | } |
| 10399 | |
| 10400 | if (sglq) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 10401 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10402 | piocb->sli4_xritag = sglq->sli4_xritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10403 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10404 | return IOCB_ERROR; |
| 10405 | } |
| 10406 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 10407 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10408 | return IOCB_ERROR; |
| 10409 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 10410 | if (lpfc_sli4_wq_put(wq, &wqe)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10411 | return IOCB_ERROR; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10412 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); |
| 10413 | |
| 10414 | return 0; |
| 10415 | } |
| 10416 | |
Lee Jones | 8514e2f | 2021-03-03 14:46:18 +0000 | [diff] [blame] | 10417 | /* |
James Smart | 47ff4c5 | 2020-11-15 11:26:41 -0800 | [diff] [blame] | 10418 | * lpfc_sli_issue_fcp_io - Wrapper func for issuing fcp i/o |
| 10419 | * |
| 10420 | * This routine wraps the actual fcp i/o function for issusing WQE for sli-4 |
| 10421 | * or IOCB for sli-3 function. |
| 10422 | * pointer from the lpfc_hba struct. |
| 10423 | * |
| 10424 | * Return codes: |
| 10425 | * IOCB_ERROR - Error |
| 10426 | * IOCB_SUCCESS - Success |
| 10427 | * IOCB_BUSY - Busy |
| 10428 | **/ |
| 10429 | int |
| 10430 | lpfc_sli_issue_fcp_io(struct lpfc_hba *phba, uint32_t ring_number, |
| 10431 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 10432 | { |
| 10433 | return phba->__lpfc_sli_issue_fcp_io(phba, ring_number, piocb, flag); |
| 10434 | } |
| 10435 | |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 10436 | /* |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10437 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 10438 | * |
| 10439 | * This routine wraps the actual lockless version for issusing IOCB function |
| 10440 | * pointer from the lpfc_hba struct. |
| 10441 | * |
| 10442 | * Return codes: |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10443 | * IOCB_ERROR - Error |
| 10444 | * IOCB_SUCCESS - Success |
| 10445 | * IOCB_BUSY - Busy |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10446 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10447 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10448 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 10449 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 10450 | { |
| 10451 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 10452 | } |
| 10453 | |
| 10454 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10455 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10456 | * @phba: The hba struct for which this call is being executed. |
| 10457 | * @dev_grp: The HBA PCI-Device group number. |
| 10458 | * |
| 10459 | * This routine sets up the SLI interface API function jump table in @phba |
| 10460 | * struct. |
| 10461 | * Returns: 0 - success, -ENODEV - failure. |
| 10462 | **/ |
| 10463 | int |
| 10464 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 10465 | { |
| 10466 | |
| 10467 | switch (dev_grp) { |
| 10468 | case LPFC_PCI_DEV_LP: |
| 10469 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 10470 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
James Smart | 47ff4c5 | 2020-11-15 11:26:41 -0800 | [diff] [blame] | 10471 | phba->__lpfc_sli_issue_fcp_io = __lpfc_sli_issue_fcp_io_s3; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10472 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10473 | case LPFC_PCI_DEV_OC: |
| 10474 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; |
| 10475 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; |
James Smart | 47ff4c5 | 2020-11-15 11:26:41 -0800 | [diff] [blame] | 10476 | phba->__lpfc_sli_issue_fcp_io = __lpfc_sli_issue_fcp_io_s4; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10477 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10478 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10479 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10480 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 10481 | dev_grp); |
| 10482 | return -ENODEV; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10483 | } |
| 10484 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 10485 | return 0; |
| 10486 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10487 | |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10488 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10489 | * lpfc_sli4_calc_ring - Calculates which ring to use |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10490 | * @phba: Pointer to HBA context object. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10491 | * @piocb: Pointer to command iocb. |
| 10492 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10493 | * For SLI4 only, FCP IO can deferred to one fo many WQs, based on |
| 10494 | * hba_wqidx, thus we need to calculate the corresponding ring. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10495 | * 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] | 10496 | * aborting, we use command's hba_wqidx. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10497 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10498 | struct lpfc_sli_ring * |
| 10499 | lpfc_sli4_calc_ring(struct lpfc_hba *phba, struct lpfc_iocbq *piocb) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10500 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10501 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 10502 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10503 | if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10504 | if (unlikely(!phba->sli4_hba.hdwq)) |
James Smart | 7370d10 | 2019-01-28 11:14:20 -0800 | [diff] [blame] | 10505 | return NULL; |
| 10506 | /* |
| 10507 | * for abort iocb hba_wqidx should already |
| 10508 | * be setup based on what work queue we used. |
| 10509 | */ |
| 10510 | if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10511 | lpfc_cmd = (struct lpfc_io_buf *)piocb->context1; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 10512 | piocb->hba_wqidx = lpfc_cmd->hdwq_no; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10513 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10514 | return phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10515 | } else { |
| 10516 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 10517 | return NULL; |
| 10518 | piocb->hba_wqidx = 0; |
| 10519 | return phba->sli4_hba.els_wq->pring; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10520 | } |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10521 | } |
| 10522 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10523 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10524 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10525 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 10526 | * @ring_number: Ring number |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10527 | * @piocb: Pointer to command iocb. |
| 10528 | * @flag: Flag indicating if this command can be put into txq. |
| 10529 | * |
| 10530 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 10531 | * function. This function gets the hbalock and calls |
| 10532 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 10533 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 10534 | * functions which do not hold hbalock. |
| 10535 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10536 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10537 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10538 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 10539 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 10540 | struct lpfc_sli_ring *pring; |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 10541 | struct lpfc_queue *eq; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10542 | unsigned long iflags; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10543 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10544 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10545 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 10546 | eq = phba->sli4_hba.hdwq[piocb->hba_wqidx].hba_eq; |
| 10547 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10548 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 10549 | if (unlikely(pring == NULL)) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10550 | return IOCB_ERROR; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 10551 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10552 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 10553 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 10554 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 10555 | |
| 10556 | lpfc_sli4_poll_eq(eq, LPFC_POLL_FASTPATH); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10557 | } else { |
| 10558 | /* For now, SLI2/3 will still use hbalock */ |
| 10559 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10560 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 10561 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10562 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10563 | return rc; |
| 10564 | } |
| 10565 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10566 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10567 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10568 | * @phba: Pointer to HBA context object. |
| 10569 | * |
| 10570 | * This function is called while driver attaches with the |
| 10571 | * HBA to setup the extra ring. The extra ring is used |
| 10572 | * only when driver needs to support target mode functionality |
| 10573 | * or IP over FC functionalities. |
| 10574 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10575 | * This function is called with no lock held. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10576 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10577 | static int |
| 10578 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 10579 | { |
| 10580 | struct lpfc_sli *psli; |
| 10581 | struct lpfc_sli_ring *pring; |
| 10582 | |
| 10583 | psli = &phba->sli; |
| 10584 | |
| 10585 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10586 | |
| 10587 | /* Take some away from the FCP ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10588 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10589 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10590 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10591 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10592 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10593 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10594 | /* and give them to the extra ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10595 | pring = &psli->sli3_ring[LPFC_EXTRA_RING]; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10596 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10597 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10598 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10599 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10600 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10601 | |
| 10602 | /* Setup default profile for this ring */ |
| 10603 | pring->iotag_max = 4096; |
| 10604 | pring->num_mask = 1; |
| 10605 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10606 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 10607 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10608 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 10609 | return 0; |
| 10610 | } |
| 10611 | |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 10612 | static void |
| 10613 | lpfc_sli_post_recovery_event(struct lpfc_hba *phba, |
| 10614 | struct lpfc_nodelist *ndlp) |
| 10615 | { |
| 10616 | unsigned long iflags; |
| 10617 | struct lpfc_work_evt *evtp = &ndlp->recovery_evt; |
| 10618 | |
| 10619 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10620 | if (!list_empty(&evtp->evt_listp)) { |
| 10621 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10622 | return; |
| 10623 | } |
| 10624 | |
| 10625 | /* Incrementing the reference count until the queued work is done. */ |
| 10626 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
| 10627 | if (!evtp->evt_arg1) { |
| 10628 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10629 | return; |
| 10630 | } |
| 10631 | evtp->evt = LPFC_EVT_RECOVER_PORT; |
| 10632 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
| 10633 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10634 | |
| 10635 | lpfc_worker_wake_up(phba); |
| 10636 | } |
| 10637 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10638 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
| 10639 | * @phba: Pointer to HBA context object. |
| 10640 | * @iocbq: Pointer to iocb object. |
| 10641 | * |
| 10642 | * The async_event handler calls this routine when it receives |
| 10643 | * an ASYNC_STATUS_CN event from the port. The port generates |
| 10644 | * this event when an Abort Sequence request to an rport fails |
| 10645 | * twice in succession. The abort could be originated by the |
| 10646 | * driver or by the port. The ABTS could have been for an ELS |
| 10647 | * or FCP IO. The port only generates this event when an ABTS |
| 10648 | * fails to complete after one retry. |
| 10649 | */ |
| 10650 | static void |
| 10651 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, |
| 10652 | struct lpfc_iocbq *iocbq) |
| 10653 | { |
| 10654 | struct lpfc_nodelist *ndlp = NULL; |
| 10655 | uint16_t rpi = 0, vpi = 0; |
| 10656 | struct lpfc_vport *vport = NULL; |
| 10657 | |
| 10658 | /* The rpi in the ulpContext is vport-sensitive. */ |
| 10659 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; |
| 10660 | rpi = iocbq->iocb.ulpContext; |
| 10661 | |
| 10662 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 10663 | "3092 Port generated ABTS async event " |
| 10664 | "on vpi %d rpi %d status 0x%x\n", |
| 10665 | vpi, rpi, iocbq->iocb.ulpStatus); |
| 10666 | |
| 10667 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 10668 | if (!vport) |
| 10669 | goto err_exit; |
| 10670 | ndlp = lpfc_findnode_rpi(vport, rpi); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 10671 | if (!ndlp) |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10672 | goto err_exit; |
| 10673 | |
| 10674 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) |
| 10675 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 10676 | return; |
| 10677 | |
| 10678 | err_exit: |
| 10679 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10680 | "3095 Event Context not found, no " |
| 10681 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", |
| 10682 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, |
| 10683 | vpi, rpi); |
| 10684 | } |
| 10685 | |
| 10686 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. |
| 10687 | * @phba: pointer to HBA context object. |
| 10688 | * @ndlp: nodelist pointer for the impacted rport. |
| 10689 | * @axri: pointer to the wcqe containing the failed exchange. |
| 10690 | * |
| 10691 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the |
| 10692 | * port. The port generates this event when an abort exchange request to an |
| 10693 | * rport fails twice in succession with no reply. The abort could be originated |
| 10694 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. |
| 10695 | */ |
| 10696 | void |
| 10697 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, |
| 10698 | struct lpfc_nodelist *ndlp, |
| 10699 | struct sli4_wcqe_xri_aborted *axri) |
| 10700 | { |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10701 | uint32_t ext_status = 0; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10702 | |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 10703 | if (!ndlp) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10704 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10705 | "3115 Node Context not found, driver " |
| 10706 | "ignoring abts err event\n"); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10707 | return; |
| 10708 | } |
| 10709 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10710 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 10711 | "3116 Port generated FCP XRI ABORT event on " |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10712 | "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] | 10713 | ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi], |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10714 | bf_get(lpfc_wcqe_xa_xri, axri), |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10715 | bf_get(lpfc_wcqe_xa_status, axri), |
| 10716 | axri->parameter); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10717 | |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10718 | /* |
| 10719 | * Catch the ABTS protocol failure case. Older OCe FW releases returned |
| 10720 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and |
| 10721 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. |
| 10722 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 10723 | ext_status = axri->parameter & IOERR_PARAM_MASK; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10724 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
| 10725 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 10726 | lpfc_sli_post_recovery_event(phba, ndlp); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10727 | } |
| 10728 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10729 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10730 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10731 | * @phba: Pointer to HBA context object. |
| 10732 | * @pring: Pointer to driver SLI ring object. |
| 10733 | * @iocbq: Pointer to iocb object. |
| 10734 | * |
| 10735 | * This function is called by the slow ring event handler |
| 10736 | * function when there is an ASYNC event iocb in the ring. |
| 10737 | * This function is called with no lock held. |
| 10738 | * Currently this function handles only temperature related |
| 10739 | * ASYNC events. The function decodes the temperature sensor |
| 10740 | * event message and posts events for the management applications. |
| 10741 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10742 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10743 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 10744 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 10745 | { |
| 10746 | IOCB_t *icmd; |
| 10747 | uint16_t evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10748 | struct temp_event temp_event_data; |
| 10749 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10750 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10751 | |
| 10752 | icmd = &iocbq->iocb; |
| 10753 | evt_code = icmd->un.asyncstat.evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10754 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10755 | switch (evt_code) { |
| 10756 | case ASYNC_TEMP_WARN: |
| 10757 | case ASYNC_TEMP_SAFE: |
| 10758 | temp_event_data.data = (uint32_t) icmd->ulpContext; |
| 10759 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 10760 | if (evt_code == ASYNC_TEMP_WARN) { |
| 10761 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10762 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10763 | "0347 Adapter is very hot, please take " |
| 10764 | "corrective action. temperature : %d Celsius\n", |
| 10765 | (uint32_t) icmd->ulpContext); |
| 10766 | } else { |
| 10767 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10768 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10769 | "0340 Adapter temperature is OK now. " |
| 10770 | "temperature : %d Celsius\n", |
| 10771 | (uint32_t) icmd->ulpContext); |
| 10772 | } |
| 10773 | |
| 10774 | /* Send temperature change event to applications */ |
| 10775 | shost = lpfc_shost_from_vport(phba->pport); |
| 10776 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 10777 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 10778 | LPFC_NL_VENDOR_ID); |
| 10779 | break; |
| 10780 | case ASYNC_STATUS_CN: |
| 10781 | lpfc_sli_abts_err_handler(phba, iocbq); |
| 10782 | break; |
| 10783 | default: |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10784 | iocb_w = (uint32_t *) icmd; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10785 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10786 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 10787 | " evt_code 0x%x\n" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10788 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 10789 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 10790 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 10791 | "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] | 10792 | pring->ringno, icmd->un.asyncstat.evt_code, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10793 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 10794 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 10795 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 10796 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 10797 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10798 | break; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10799 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10800 | } |
| 10801 | |
| 10802 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10803 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10804 | * lpfc_sli4_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10805 | * @phba: Pointer to HBA context object. |
| 10806 | * |
| 10807 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 10808 | * number of iocbs per ring and iotags. This function is |
| 10809 | * called while driver attach to the HBA and before the |
| 10810 | * interrupts are enabled. So there is no need for locking. |
| 10811 | * |
| 10812 | * This function always returns 0. |
| 10813 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10814 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10815 | lpfc_sli4_setup(struct lpfc_hba *phba) |
| 10816 | { |
| 10817 | struct lpfc_sli_ring *pring; |
| 10818 | |
| 10819 | pring = phba->sli4_hba.els_wq->pring; |
| 10820 | pring->num_mask = LPFC_MAX_RING_MASK; |
| 10821 | pring->prt[0].profile = 0; /* Mask 0 */ |
| 10822 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 10823 | pring->prt[0].type = FC_TYPE_ELS; |
| 10824 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
| 10825 | lpfc_els_unsol_event; |
| 10826 | pring->prt[1].profile = 0; /* Mask 1 */ |
| 10827 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 10828 | pring->prt[1].type = FC_TYPE_ELS; |
| 10829 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
| 10830 | lpfc_els_unsol_event; |
| 10831 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 10832 | /* NameServer Inquiry */ |
| 10833 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| 10834 | /* NameServer */ |
| 10835 | pring->prt[2].type = FC_TYPE_CT; |
| 10836 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
| 10837 | lpfc_ct_unsol_event; |
| 10838 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 10839 | /* NameServer response */ |
| 10840 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| 10841 | /* NameServer */ |
| 10842 | pring->prt[3].type = FC_TYPE_CT; |
| 10843 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
| 10844 | lpfc_ct_unsol_event; |
| 10845 | return 0; |
| 10846 | } |
| 10847 | |
| 10848 | /** |
| 10849 | * lpfc_sli_setup - SLI ring setup function |
| 10850 | * @phba: Pointer to HBA context object. |
| 10851 | * |
| 10852 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 10853 | * number of iocbs per ring and iotags. This function is |
| 10854 | * called while driver attach to the HBA and before the |
| 10855 | * interrupts are enabled. So there is no need for locking. |
| 10856 | * |
| 10857 | * This function always returns 0. SLI3 only. |
| 10858 | **/ |
| 10859 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10860 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 10861 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10862 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10863 | struct lpfc_sli *psli = &phba->sli; |
| 10864 | struct lpfc_sli_ring *pring; |
| 10865 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 10866 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10867 | psli->sli_flag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10868 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10869 | psli->iocbq_lookup = NULL; |
| 10870 | psli->iocbq_lookup_len = 0; |
| 10871 | psli->last_iotag = 0; |
| 10872 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10873 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10874 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10875 | switch (i) { |
| 10876 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 10877 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10878 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 10879 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 10880 | pring->sli.sli3.numCiocb += |
| 10881 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10882 | pring->sli.sli3.numRiocb += |
| 10883 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10884 | pring->sli.sli3.numCiocb += |
| 10885 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10886 | pring->sli.sli3.numRiocb += |
| 10887 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 10888 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10889 | SLI3_IOCB_CMD_SIZE : |
| 10890 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10891 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10892 | SLI3_IOCB_RSP_SIZE : |
| 10893 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10894 | pring->iotag_ctr = 0; |
| 10895 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10896 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10897 | pring->fast_iotag = pring->iotag_max; |
| 10898 | pring->num_mask = 0; |
| 10899 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10900 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10901 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10902 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 10903 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
| 10904 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10905 | SLI3_IOCB_CMD_SIZE : |
| 10906 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10907 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10908 | SLI3_IOCB_RSP_SIZE : |
| 10909 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10910 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10911 | pring->num_mask = 0; |
| 10912 | break; |
| 10913 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 10914 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10915 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 10916 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
| 10917 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10918 | SLI3_IOCB_CMD_SIZE : |
| 10919 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10920 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10921 | SLI3_IOCB_RSP_SIZE : |
| 10922 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10923 | pring->fast_iotag = 0; |
| 10924 | pring->iotag_ctr = 0; |
| 10925 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10926 | pring->lpfc_sli_rcv_async_status = |
| 10927 | lpfc_sli_async_event_handler; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10928 | pring->num_mask = LPFC_MAX_RING_MASK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10929 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10930 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 10931 | pring->prt[0].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10932 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10933 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10934 | pring->prt[1].profile = 0; /* Mask 1 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10935 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 10936 | pring->prt[1].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10937 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10938 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10939 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 10940 | /* NameServer Inquiry */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10941 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10942 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10943 | pring->prt[2].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10944 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10945 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10946 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 10947 | /* NameServer response */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10948 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10949 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10950 | pring->prt[3].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10951 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10952 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10953 | break; |
| 10954 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10955 | totiocbsize += (pring->sli.sli3.numCiocb * |
| 10956 | pring->sli.sli3.sizeCiocb) + |
| 10957 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10958 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10959 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10960 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10961 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 10962 | "SLI2 SLIM Data: x%x x%lx\n", |
| 10963 | phba->brd_no, totiocbsize, |
| 10964 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10965 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10966 | if (phba->cfg_multi_ring_support == 2) |
| 10967 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10968 | |
| 10969 | return 0; |
| 10970 | } |
| 10971 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10972 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10973 | * lpfc_sli4_queue_init - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10974 | * @phba: Pointer to HBA context object. |
| 10975 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10976 | * 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] | 10977 | * ring. This function also initializes ring indices of each ring. |
| 10978 | * This function is called during the initialization of the SLI |
| 10979 | * interface of an HBA. |
| 10980 | * This function is called with no lock held and always returns |
| 10981 | * 1. |
| 10982 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10983 | void |
| 10984 | lpfc_sli4_queue_init(struct lpfc_hba *phba) |
| 10985 | { |
| 10986 | struct lpfc_sli *psli; |
| 10987 | struct lpfc_sli_ring *pring; |
| 10988 | int i; |
| 10989 | |
| 10990 | psli = &phba->sli; |
| 10991 | spin_lock_irq(&phba->hbalock); |
| 10992 | INIT_LIST_HEAD(&psli->mboxq); |
| 10993 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| 10994 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10995 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10996 | pring = phba->sli4_hba.hdwq[i].io_wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10997 | pring->flag = 0; |
| 10998 | pring->ringno = LPFC_FCP_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10999 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11000 | INIT_LIST_HEAD(&pring->txq); |
| 11001 | INIT_LIST_HEAD(&pring->txcmplq); |
| 11002 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 11003 | spin_lock_init(&pring->ring_lock); |
| 11004 | } |
| 11005 | pring = phba->sli4_hba.els_wq->pring; |
| 11006 | pring->flag = 0; |
| 11007 | pring->ringno = LPFC_ELS_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11008 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11009 | INIT_LIST_HEAD(&pring->txq); |
| 11010 | INIT_LIST_HEAD(&pring->txcmplq); |
| 11011 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 11012 | spin_lock_init(&pring->ring_lock); |
| 11013 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11014 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11015 | pring = phba->sli4_hba.nvmels_wq->pring; |
| 11016 | pring->flag = 0; |
| 11017 | pring->ringno = LPFC_ELS_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11018 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11019 | INIT_LIST_HEAD(&pring->txq); |
| 11020 | INIT_LIST_HEAD(&pring->txcmplq); |
| 11021 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 11022 | spin_lock_init(&pring->ring_lock); |
| 11023 | } |
| 11024 | |
| 11025 | spin_unlock_irq(&phba->hbalock); |
| 11026 | } |
| 11027 | |
| 11028 | /** |
| 11029 | * lpfc_sli_queue_init - Queue initialization function |
| 11030 | * @phba: Pointer to HBA context object. |
| 11031 | * |
| 11032 | * lpfc_sli_queue_init sets up mailbox queues and iocb queues for each |
| 11033 | * ring. This function also initializes ring indices of each ring. |
| 11034 | * This function is called during the initialization of the SLI |
| 11035 | * interface of an HBA. |
| 11036 | * This function is called with no lock held and always returns |
| 11037 | * 1. |
| 11038 | **/ |
| 11039 | void |
| 11040 | lpfc_sli_queue_init(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11041 | { |
| 11042 | struct lpfc_sli *psli; |
| 11043 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11044 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11045 | |
| 11046 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11047 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11048 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11049 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11050 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 11051 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11052 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11053 | pring->ringno = i; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11054 | pring->sli.sli3.next_cmdidx = 0; |
| 11055 | pring->sli.sli3.local_getidx = 0; |
| 11056 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11057 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 11058 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11059 | INIT_LIST_HEAD(&pring->postbufq); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11060 | pring->flag = 0; |
| 11061 | INIT_LIST_HEAD(&pring->txq); |
| 11062 | INIT_LIST_HEAD(&pring->txcmplq); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11063 | spin_lock_init(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11064 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11065 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11066 | } |
| 11067 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11068 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11069 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system |
| 11070 | * @phba: Pointer to HBA context object. |
| 11071 | * |
| 11072 | * This routine flushes the mailbox command subsystem. It will unconditionally |
| 11073 | * flush all the mailbox commands in the three possible stages in the mailbox |
| 11074 | * command sub-system: pending mailbox command queue; the outstanding mailbox |
| 11075 | * command; and completed mailbox command queue. It is caller's responsibility |
| 11076 | * to make sure that the driver is in the proper state to flush the mailbox |
| 11077 | * command sub-system. Namely, the posting of mailbox commands into the |
| 11078 | * pending mailbox command queue from the various clients must be stopped; |
| 11079 | * either the HBA is in a state that it will never works on the outstanding |
| 11080 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding |
| 11081 | * mailbox command has been completed. |
| 11082 | **/ |
| 11083 | static void |
| 11084 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) |
| 11085 | { |
| 11086 | LIST_HEAD(completions); |
| 11087 | struct lpfc_sli *psli = &phba->sli; |
| 11088 | LPFC_MBOXQ_t *pmb; |
| 11089 | unsigned long iflag; |
| 11090 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 11091 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 11092 | local_bh_disable(); |
| 11093 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11094 | /* Flush all the mailbox commands in the mbox system */ |
| 11095 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 11096 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11097 | /* The pending mailbox command queue */ |
| 11098 | list_splice_init(&phba->sli.mboxq, &completions); |
| 11099 | /* The outstanding active mailbox command */ |
| 11100 | if (psli->mbox_active) { |
| 11101 | list_add_tail(&psli->mbox_active->list, &completions); |
| 11102 | psli->mbox_active = NULL; |
| 11103 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 11104 | } |
| 11105 | /* The completed mailbox command queue */ |
| 11106 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
| 11107 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 11108 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 11109 | /* Enable softirqs again, done with phba->hbalock */ |
| 11110 | local_bh_enable(); |
| 11111 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11112 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ |
| 11113 | while (!list_empty(&completions)) { |
| 11114 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| 11115 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 11116 | if (pmb->mbox_cmpl) |
| 11117 | pmb->mbox_cmpl(phba, pmb); |
| 11118 | } |
| 11119 | } |
| 11120 | |
| 11121 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11122 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11123 | * @vport: Pointer to virtual port object. |
| 11124 | * |
| 11125 | * lpfc_sli_host_down is called to clean up the resources |
| 11126 | * associated with a vport before destroying virtual |
| 11127 | * port data structures. |
| 11128 | * This function does following operations: |
| 11129 | * - Free discovery resources associated with this virtual |
| 11130 | * port. |
| 11131 | * - Free iocbs associated with this virtual port in |
| 11132 | * the txq. |
| 11133 | * - Send abort for all iocb commands associated with this |
| 11134 | * vport in txcmplq. |
| 11135 | * |
| 11136 | * This function is called with no lock held and always returns 1. |
| 11137 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11138 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11139 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 11140 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11141 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11142 | struct lpfc_hba *phba = vport->phba; |
| 11143 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11144 | struct lpfc_queue *qp = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11145 | struct lpfc_sli_ring *pring; |
| 11146 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11147 | int i; |
| 11148 | unsigned long flags = 0; |
| 11149 | uint16_t prev_pring_flag; |
| 11150 | |
| 11151 | lpfc_cleanup_discovery_resources(vport); |
| 11152 | |
| 11153 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11154 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11155 | /* |
| 11156 | * Error everything on the txq since these iocbs |
| 11157 | * have not been given to the FW yet. |
| 11158 | * Also issue ABTS for everything on the txcmplq |
| 11159 | */ |
| 11160 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 11161 | for (i = 0; i < psli->num_rings; i++) { |
| 11162 | pring = &psli->sli3_ring[i]; |
| 11163 | prev_pring_flag = pring->flag; |
| 11164 | /* Only slow rings */ |
| 11165 | if (pring->ringno == LPFC_ELS_RING) { |
| 11166 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 11167 | /* Set the lpfc data pending flag */ |
| 11168 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 11169 | } |
| 11170 | list_for_each_entry_safe(iocb, next_iocb, |
| 11171 | &pring->txq, list) { |
| 11172 | if (iocb->vport != vport) |
| 11173 | continue; |
| 11174 | list_move_tail(&iocb->list, &completions); |
| 11175 | } |
| 11176 | list_for_each_entry_safe(iocb, next_iocb, |
| 11177 | &pring->txcmplq, list) { |
| 11178 | if (iocb->vport != vport) |
| 11179 | continue; |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 11180 | lpfc_sli_issue_abort_iotag(phba, pring, iocb, |
| 11181 | NULL); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11182 | } |
| 11183 | pring->flag = prev_pring_flag; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11184 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11185 | } else { |
| 11186 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 11187 | pring = qp->pring; |
| 11188 | if (!pring) |
| 11189 | continue; |
| 11190 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 11191 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 11192 | /* Set the lpfc data pending flag */ |
| 11193 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 11194 | } |
| 11195 | prev_pring_flag = pring->flag; |
James Smart | 65a3df6 | 2019-09-21 20:58:48 -0700 | [diff] [blame] | 11196 | spin_lock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11197 | list_for_each_entry_safe(iocb, next_iocb, |
| 11198 | &pring->txq, list) { |
| 11199 | if (iocb->vport != vport) |
| 11200 | continue; |
| 11201 | list_move_tail(&iocb->list, &completions); |
| 11202 | } |
James Smart | 65a3df6 | 2019-09-21 20:58:48 -0700 | [diff] [blame] | 11203 | spin_unlock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11204 | list_for_each_entry_safe(iocb, next_iocb, |
| 11205 | &pring->txcmplq, list) { |
| 11206 | if (iocb->vport != vport) |
| 11207 | continue; |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 11208 | lpfc_sli_issue_abort_iotag(phba, pring, iocb, |
| 11209 | NULL); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11210 | } |
| 11211 | pring->flag = prev_pring_flag; |
| 11212 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11213 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11214 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 11215 | |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 11216 | /* Make sure HBA is alive */ |
| 11217 | lpfc_issue_hb_tmo(phba); |
| 11218 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11219 | /* Cancel all the IOCBs from the completions list */ |
| 11220 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 11221 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11222 | return 1; |
| 11223 | } |
| 11224 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11225 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11226 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11227 | * @phba: Pointer to HBA context object. |
| 11228 | * |
| 11229 | * This function cleans up all iocb, buffers, mailbox commands |
| 11230 | * while shutting down the HBA. This function is called with no |
| 11231 | * lock held and always returns 1. |
| 11232 | * This function does the following to cleanup driver resources: |
| 11233 | * - Free discovery resources for each virtual port |
| 11234 | * - Cleanup any pending fabric iocbs |
| 11235 | * - Iterate through the iocb txq and free each entry |
| 11236 | * in the list. |
| 11237 | * - Free up any buffer posted to the HBA |
| 11238 | * - Free mailbox commands in the mailbox queue. |
| 11239 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11240 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11241 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11242 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 11243 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11244 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11245 | struct lpfc_queue *qp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11246 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 11247 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11248 | unsigned long flags = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11249 | int i; |
| 11250 | |
| 11251 | /* Shutdown the mailbox command sub-system */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 11252 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11253 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11254 | lpfc_hba_down_prep(phba); |
| 11255 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 11256 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 11257 | local_bh_disable(); |
| 11258 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11259 | lpfc_fabric_abort_hba(phba); |
| 11260 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11261 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11262 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11263 | /* |
| 11264 | * Error everything on the txq since these iocbs |
| 11265 | * have not been given to the FW yet. |
| 11266 | */ |
| 11267 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 11268 | for (i = 0; i < psli->num_rings; i++) { |
| 11269 | pring = &psli->sli3_ring[i]; |
| 11270 | /* Only slow rings */ |
| 11271 | if (pring->ringno == LPFC_ELS_RING) { |
| 11272 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 11273 | /* Set the lpfc data pending flag */ |
| 11274 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 11275 | } |
| 11276 | list_splice_init(&pring->txq, &completions); |
| 11277 | } |
| 11278 | } else { |
| 11279 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 11280 | pring = qp->pring; |
| 11281 | if (!pring) |
| 11282 | continue; |
James Smart | 4b0a42b | 2019-08-14 16:56:42 -0700 | [diff] [blame] | 11283 | spin_lock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11284 | list_splice_init(&pring->txq, &completions); |
James Smart | 4b0a42b | 2019-08-14 16:56:42 -0700 | [diff] [blame] | 11285 | spin_unlock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11286 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 11287 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 11288 | /* Set the lpfc data pending flag */ |
| 11289 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 11290 | } |
| 11291 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11292 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11293 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11294 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11295 | /* Cancel all the IOCBs from the completions list */ |
| 11296 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 11297 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 11298 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 11299 | spin_lock_irqsave(&phba->hbalock, flags); |
| 11300 | list_splice_init(&phba->elsbuf, &completions); |
| 11301 | phba->elsbuf_cnt = 0; |
| 11302 | phba->elsbuf_prev_cnt = 0; |
| 11303 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 11304 | |
| 11305 | while (!list_empty(&completions)) { |
| 11306 | list_remove_head(&completions, buf_ptr, |
| 11307 | struct lpfc_dmabuf, list); |
| 11308 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 11309 | kfree(buf_ptr); |
| 11310 | } |
| 11311 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 11312 | /* Enable softirqs again, done with phba->hbalock */ |
| 11313 | local_bh_enable(); |
| 11314 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11315 | /* Return any active mbox cmds */ |
| 11316 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11317 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11318 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11319 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11320 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11321 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11322 | return 1; |
| 11323 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11324 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11325 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11326 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11327 | * @srcp: Source memory pointer. |
| 11328 | * @destp: Destination memory pointer. |
| 11329 | * @cnt: Number of words required to be copied. |
| 11330 | * |
| 11331 | * This function is used for copying data between driver memory |
| 11332 | * and the SLI memory. This function also changes the endianness |
| 11333 | * of each word if native endianness is different from SLI |
| 11334 | * endianness. This function can be called with or without |
| 11335 | * lock. |
| 11336 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11337 | void |
| 11338 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 11339 | { |
| 11340 | uint32_t *src = srcp; |
| 11341 | uint32_t *dest = destp; |
| 11342 | uint32_t ldata; |
| 11343 | int i; |
| 11344 | |
| 11345 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 11346 | ldata = *src; |
| 11347 | ldata = le32_to_cpu(ldata); |
| 11348 | *dest = ldata; |
| 11349 | src++; |
| 11350 | dest++; |
| 11351 | } |
| 11352 | } |
| 11353 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11354 | |
| 11355 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 11356 | * lpfc_sli_bemem_bcopy - SLI memory copy function |
| 11357 | * @srcp: Source memory pointer. |
| 11358 | * @destp: Destination memory pointer. |
| 11359 | * @cnt: Number of words required to be copied. |
| 11360 | * |
| 11361 | * This function is used for copying data between a data structure |
| 11362 | * with big endian representation to local endianness. |
| 11363 | * This function can be called with or without lock. |
| 11364 | **/ |
| 11365 | void |
| 11366 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 11367 | { |
| 11368 | uint32_t *src = srcp; |
| 11369 | uint32_t *dest = destp; |
| 11370 | uint32_t ldata; |
| 11371 | int i; |
| 11372 | |
| 11373 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { |
| 11374 | ldata = *src; |
| 11375 | ldata = be32_to_cpu(ldata); |
| 11376 | *dest = ldata; |
| 11377 | src++; |
| 11378 | dest++; |
| 11379 | } |
| 11380 | } |
| 11381 | |
| 11382 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11383 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11384 | * @phba: Pointer to HBA context object. |
| 11385 | * @pring: Pointer to driver SLI ring object. |
| 11386 | * @mp: Pointer to driver buffer object. |
| 11387 | * |
| 11388 | * This function is called with no lock held. |
| 11389 | * It always return zero after adding the buffer to the postbufq |
| 11390 | * buffer list. |
| 11391 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11392 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11393 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 11394 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11395 | { |
| 11396 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 11397 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11398 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11399 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11400 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11401 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11402 | return 0; |
| 11403 | } |
| 11404 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11405 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11406 | * 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] | 11407 | * @phba: Pointer to HBA context object. |
| 11408 | * |
| 11409 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 11410 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 11411 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 11412 | * does not conflict with tags of buffer posted for unsolicited events. |
| 11413 | * The function returns the allocated tag. The function is called with |
| 11414 | * no locks held. |
| 11415 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 11416 | uint32_t |
| 11417 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 11418 | { |
| 11419 | spin_lock_irq(&phba->hbalock); |
| 11420 | phba->buffer_tag_count++; |
| 11421 | /* |
| 11422 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 11423 | * a tag assigned by HBQ. |
| 11424 | */ |
| 11425 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 11426 | spin_unlock_irq(&phba->hbalock); |
| 11427 | return phba->buffer_tag_count; |
| 11428 | } |
| 11429 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11430 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11431 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11432 | * @phba: Pointer to HBA context object. |
| 11433 | * @pring: Pointer to driver SLI ring object. |
| 11434 | * @tag: Buffer tag. |
| 11435 | * |
| 11436 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 11437 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 11438 | * iocb is posted to the response ring with the tag of the buffer. |
| 11439 | * This function searches the pring->postbufq list using the tag |
| 11440 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 11441 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 11442 | * buffer is returned to the caller else NULL is returned. |
| 11443 | * This function is called with no lock held. |
| 11444 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 11445 | struct lpfc_dmabuf * |
| 11446 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 11447 | uint32_t tag) |
| 11448 | { |
| 11449 | struct lpfc_dmabuf *mp, *next_mp; |
| 11450 | struct list_head *slp = &pring->postbufq; |
| 11451 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11452 | /* Search postbufq, from the beginning, looking for a match on tag */ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 11453 | spin_lock_irq(&phba->hbalock); |
| 11454 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 11455 | if (mp->buffer_tag == tag) { |
| 11456 | list_del_init(&mp->list); |
| 11457 | pring->postbufq_cnt--; |
| 11458 | spin_unlock_irq(&phba->hbalock); |
| 11459 | return mp; |
| 11460 | } |
| 11461 | } |
| 11462 | |
| 11463 | spin_unlock_irq(&phba->hbalock); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11464 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11465 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 11466 | "ring %d Data x%lx x%px x%px x%x\n", |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 11467 | pring->ringno, (unsigned long) tag, |
| 11468 | slp->next, slp->prev, pring->postbufq_cnt); |
| 11469 | |
| 11470 | return NULL; |
| 11471 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11472 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11473 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11474 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11475 | * @phba: Pointer to HBA context object. |
| 11476 | * @pring: Pointer to driver SLI ring object. |
| 11477 | * @phys: DMA address of the buffer. |
| 11478 | * |
| 11479 | * This function searches the buffer list using the dma_address |
| 11480 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 11481 | * corresponding to the dma_address. The function returns the |
| 11482 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 11483 | * This function is called by the ct and els unsolicited event |
| 11484 | * handlers to get the buffer associated with the unsolicited |
| 11485 | * event. |
| 11486 | * |
| 11487 | * This function is called with no lock held. |
| 11488 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11489 | struct lpfc_dmabuf * |
| 11490 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 11491 | dma_addr_t phys) |
| 11492 | { |
| 11493 | struct lpfc_dmabuf *mp, *next_mp; |
| 11494 | struct list_head *slp = &pring->postbufq; |
| 11495 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11496 | /* Search postbufq, from the beginning, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11497 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11498 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 11499 | if (mp->phys == phys) { |
| 11500 | list_del_init(&mp->list); |
| 11501 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11502 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11503 | return mp; |
| 11504 | } |
| 11505 | } |
| 11506 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11507 | spin_unlock_irq(&phba->hbalock); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11508 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11509 | "0410 Cannot find virtual addr for mapped buf on " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 11510 | "ring %d Data x%llx x%px x%px x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11511 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11512 | slp->next, slp->prev, pring->postbufq_cnt); |
| 11513 | return NULL; |
| 11514 | } |
| 11515 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11516 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11517 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11518 | * @phba: Pointer to HBA context object. |
| 11519 | * @cmdiocb: Pointer to driver command iocb object. |
| 11520 | * @rspiocb: Pointer to driver response iocb object. |
| 11521 | * |
| 11522 | * This function is the completion handler for the abort iocbs for |
| 11523 | * ELS commands. This function is called from the ELS ring event |
| 11524 | * handler with no lock held. This function frees memory resources |
| 11525 | * associated with the abort iocb. |
| 11526 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11527 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11528 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11529 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11530 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11531 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11532 | uint16_t abort_iotag, abort_context; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11533 | struct lpfc_iocbq *abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11534 | |
| 11535 | if (irsp->ulpStatus) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11536 | |
| 11537 | /* |
| 11538 | * Assume that the port already completed and returned, or |
| 11539 | * will return the iocb. Just Log the message. |
| 11540 | */ |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11541 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 11542 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 11543 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11544 | spin_lock_irq(&phba->hbalock); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11545 | if (phba->sli_rev < LPFC_SLI_REV4) { |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11546 | if (irsp->ulpCommand == CMD_ABORT_XRI_CX && |
| 11547 | irsp->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 11548 | irsp->un.ulpWord[4] == IOERR_ABORT_REQUESTED) { |
| 11549 | spin_unlock_irq(&phba->hbalock); |
| 11550 | goto release_iocb; |
| 11551 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11552 | if (abort_iotag != 0 && |
| 11553 | abort_iotag <= phba->sli.last_iotag) |
| 11554 | abort_iocb = |
| 11555 | phba->sli.iocbq_lookup[abort_iotag]; |
| 11556 | } else |
| 11557 | /* For sli4 the abort_tag is the XRI, |
| 11558 | * so the abort routine puts the iotag of the iocb |
| 11559 | * being aborted in the context field of the abort |
| 11560 | * IOCB. |
| 11561 | */ |
| 11562 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11563 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11564 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 11565 | "0327 Cannot abort els iocb x%px " |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11566 | "with tag %x context %x, abort status %x, " |
| 11567 | "abort code %x\n", |
| 11568 | abort_iocb, abort_iotag, abort_context, |
| 11569 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11570 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11571 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11572 | } |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11573 | release_iocb: |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11574 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11575 | return; |
| 11576 | } |
| 11577 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11578 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11579 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11580 | * @phba: Pointer to HBA context object. |
| 11581 | * @cmdiocb: Pointer to driver command iocb object. |
| 11582 | * @rspiocb: Pointer to driver response iocb object. |
| 11583 | * |
| 11584 | * The function is called from SLI ring event handler with no |
| 11585 | * lock held. This function is the completion handler for ELS commands |
| 11586 | * which are aborted. The function frees memory resources used for |
| 11587 | * the aborted ELS commands. |
| 11588 | **/ |
James Smart | 9dd83f7 | 2021-03-01 09:18:11 -0800 | [diff] [blame] | 11589 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11590 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11591 | struct lpfc_iocbq *rspiocb) |
| 11592 | { |
| 11593 | IOCB_t *irsp = &rspiocb->iocb; |
| 11594 | |
| 11595 | /* ELS cmd tag <ulpIoTag> completes */ |
| 11596 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11597 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11598 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11599 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11600 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 11601 | lpfc_nlp_put((struct lpfc_nodelist *)cmdiocb->context1); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11602 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 11603 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 11604 | else |
| 11605 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11606 | } |
| 11607 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11608 | /** |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 11609 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11610 | * @phba: Pointer to HBA context object. |
| 11611 | * @pring: Pointer to driver SLI ring object. |
| 11612 | * @cmdiocb: Pointer to driver command iocb object. |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 11613 | * @cmpl: completion function. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11614 | * |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 11615 | * This function issues an abort iocb for the provided command iocb. In case |
| 11616 | * of unloading, the abort iocb will not be issued to commands on the ELS |
| 11617 | * ring. Instead, the callback function shall be changed to those commands |
| 11618 | * so that nothing happens when them finishes. This function is called with |
| 11619 | * hbalock held andno ring_lock held (SLI4). The function returns IOCB_SUCCESS |
| 11620 | * when the command iocb is an abort request. |
| 11621 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11622 | **/ |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 11623 | int |
| 11624 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 11625 | struct lpfc_iocbq *cmdiocb, void *cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11626 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11627 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11628 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11629 | IOCB_t *icmd = NULL; |
| 11630 | IOCB_t *iabt = NULL; |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 11631 | int retval = IOCB_ERROR; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11632 | unsigned long iflags; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11633 | struct lpfc_nodelist *ndlp; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11634 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11635 | /* |
| 11636 | * There are certain command types we don't want to abort. And we |
| 11637 | * don't want to abort commands that are already in the process of |
| 11638 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11639 | */ |
| 11640 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11641 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11642 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
James Smart | 078c68b | 2021-04-11 18:31:12 -0700 | [diff] [blame] | 11643 | cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 11644 | return IOCB_ABORTING; |
| 11645 | |
| 11646 | if (!pring) { |
| 11647 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 11648 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11649 | else |
| 11650 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11651 | return retval; |
| 11652 | } |
| 11653 | |
| 11654 | /* |
| 11655 | * If we're unloading, don't abort iocb on the ELS ring, but change |
| 11656 | * the callback so that nothing happens when it finishes. |
| 11657 | */ |
| 11658 | if ((vport->load_flag & FC_UNLOADING) && |
| 11659 | pring->ringno == LPFC_ELS_RING) { |
| 11660 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 11661 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11662 | else |
| 11663 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11664 | return retval; |
| 11665 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11666 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11667 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11668 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11669 | if (abtsiocbp == NULL) |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 11670 | return IOCB_NORESOURCE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11671 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11672 | /* This signals the response to set the correct status |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11673 | * before calling the completion handler |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11674 | */ |
| 11675 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11676 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11677 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11678 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11679 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11680 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11681 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 11682 | if (pring->ringno == LPFC_ELS_RING) |
| 11683 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11684 | } else { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11685 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11686 | if (pring->ringno == LPFC_ELS_RING) { |
| 11687 | ndlp = (struct lpfc_nodelist *)(cmdiocb->context1); |
| 11688 | iabt->un.acxri.abortContextTag = ndlp->nlp_rpi; |
| 11689 | } |
| 11690 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11691 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11692 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11693 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11694 | /* 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] | 11695 | abtsiocbp->hba_wqidx = cmdiocb->hba_wqidx; |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 11696 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) { |
| 11697 | abtsiocbp->iocb_flag |= LPFC_IO_FCP; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11698 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 11699 | } |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11700 | if (cmdiocb->iocb_flag & LPFC_IO_FOF) |
| 11701 | abtsiocbp->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11702 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11703 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11704 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 11705 | else |
| 11706 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 11707 | |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 11708 | if (cmpl) |
| 11709 | abtsiocbp->iocb_cmpl = cmpl; |
| 11710 | else |
| 11711 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | e6c6acc | 2016-12-19 15:07:23 -0800 | [diff] [blame] | 11712 | abtsiocbp->vport = vport; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 11713 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11714 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11715 | pring = lpfc_sli4_calc_ring(phba, abtsiocbp); |
| 11716 | if (unlikely(pring == NULL)) |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 11717 | goto abort_iotag_exit; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11718 | /* Note: both hbalock and ring_lock need to be set here */ |
| 11719 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 11720 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11721 | abtsiocbp, 0); |
| 11722 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 11723 | } else { |
| 11724 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11725 | abtsiocbp, 0); |
| 11726 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11727 | |
| 11728 | abort_iotag_exit: |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 11729 | |
| 11730 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 11731 | "0339 Abort xri x%x, original iotag x%x, " |
| 11732 | "abort cmd iotag x%x retval x%x\n", |
| 11733 | iabt->un.acxri.abortIoTag, |
| 11734 | iabt->un.acxri.abortContextTag, |
| 11735 | abtsiocbp->iotag, retval); |
| 11736 | |
| 11737 | if (retval) { |
| 11738 | cmdiocb->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 11739 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
| 11740 | } |
| 11741 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11742 | /* |
| 11743 | * Caller to this routine should check for IOCB_ERROR |
| 11744 | * and handle it properly. This routine no longer removes |
| 11745 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11746 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11747 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11748 | } |
| 11749 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11750 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11751 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. |
| 11752 | * @phba: pointer to lpfc HBA data structure. |
| 11753 | * |
| 11754 | * This routine will abort all pending and outstanding iocbs to an HBA. |
| 11755 | **/ |
| 11756 | void |
| 11757 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) |
| 11758 | { |
| 11759 | struct lpfc_sli *psli = &phba->sli; |
| 11760 | struct lpfc_sli_ring *pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11761 | struct lpfc_queue *qp = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11762 | int i; |
| 11763 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11764 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 11765 | for (i = 0; i < psli->num_rings; i++) { |
| 11766 | pring = &psli->sli3_ring[i]; |
| 11767 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 11768 | } |
| 11769 | return; |
| 11770 | } |
| 11771 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 11772 | pring = qp->pring; |
| 11773 | if (!pring) |
| 11774 | continue; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 11775 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11776 | } |
| 11777 | } |
| 11778 | |
| 11779 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11780 | * 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] | 11781 | * @iocbq: Pointer to driver iocb object. |
| 11782 | * @vport: Pointer to driver virtual port object. |
| 11783 | * @tgt_id: SCSI ID of the target. |
| 11784 | * @lun_id: LUN ID of the scsi device. |
| 11785 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 11786 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11787 | * 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] | 11788 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 11789 | * 0 if the filtering criteria is met for the given iocb and will return |
| 11790 | * 1 if the filtering criteria is not met. |
| 11791 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 11792 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 11793 | * lun_id parameter. |
| 11794 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 11795 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 11796 | * parameters. |
| 11797 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 11798 | * given iocb is for the SCSI host associated with the given vport. |
| 11799 | * This function is called with no locks held. |
| 11800 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11801 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11802 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 11803 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11804 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11805 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11806 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | e136471 | 2021-04-21 16:44:33 -0700 | [diff] [blame] | 11807 | IOCB_t *icmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11808 | int rc = 1; |
| 11809 | |
James Smart | 9ec58ec | 2021-01-04 10:02:35 -0800 | [diff] [blame] | 11810 | if (!iocbq || iocbq->vport != vport) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11811 | return rc; |
| 11812 | |
James Smart | e136471 | 2021-04-21 16:44:33 -0700 | [diff] [blame] | 11813 | if (!(iocbq->iocb_flag & LPFC_IO_FCP) || |
| 11814 | !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ) || |
| 11815 | iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 11816 | return rc; |
| 11817 | |
| 11818 | icmd = &iocbq->iocb; |
| 11819 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
| 11820 | icmd->ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11821 | return rc; |
| 11822 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11823 | 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] | 11824 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11825 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11826 | return rc; |
| 11827 | |
| 11828 | switch (ctx_cmd) { |
| 11829 | case LPFC_CTX_LUN: |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11830 | if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) && |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11831 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 11832 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11833 | rc = 0; |
| 11834 | break; |
| 11835 | case LPFC_CTX_TGT: |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11836 | if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) && |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11837 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11838 | rc = 0; |
| 11839 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11840 | case LPFC_CTX_HOST: |
| 11841 | rc = 0; |
| 11842 | break; |
| 11843 | default: |
| 11844 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 11845 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11846 | break; |
| 11847 | } |
| 11848 | |
| 11849 | return rc; |
| 11850 | } |
| 11851 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11852 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11853 | * 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] | 11854 | * @vport: Pointer to virtual port. |
| 11855 | * @tgt_id: SCSI ID of the target. |
| 11856 | * @lun_id: LUN ID of the scsi device. |
| 11857 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11858 | * |
| 11859 | * This function returns number of FCP commands pending for the vport. |
| 11860 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 11861 | * commands pending on the vport associated with SCSI device specified |
| 11862 | * by tgt_id and lun_id parameters. |
| 11863 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 11864 | * commands pending on the vport associated with SCSI target specified |
| 11865 | * by tgt_id parameter. |
| 11866 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 11867 | * commands pending on the vport. |
| 11868 | * This function returns the number of iocbs which satisfy the filter. |
| 11869 | * This function is called without any lock held. |
| 11870 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11871 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11872 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 11873 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11874 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11875 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11876 | struct lpfc_iocbq *iocbq; |
| 11877 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11878 | |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 11879 | spin_lock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11880 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 11881 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11882 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11883 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 11884 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11885 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11886 | } |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 11887 | spin_unlock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11888 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11889 | return sum; |
| 11890 | } |
| 11891 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11892 | /** |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 11893 | * lpfc_sli4_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
| 11894 | * @phba: Pointer to HBA context object |
| 11895 | * @cmdiocb: Pointer to command iocb object. |
| 11896 | * @wcqe: pointer to the complete wcqe |
| 11897 | * |
| 11898 | * This function is called when an aborted FCP iocb completes. This |
| 11899 | * function is called by the ring event handler with no lock held. |
| 11900 | * This function frees the iocb. It is called for sli-4 adapters. |
| 11901 | **/ |
| 11902 | void |
| 11903 | lpfc_sli4_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11904 | struct lpfc_wcqe_complete *wcqe) |
| 11905 | { |
| 11906 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 11907 | "3017 ABORT_XRI_CN completing on rpi x%x " |
| 11908 | "original iotag x%x, abort cmd iotag x%x " |
| 11909 | "status 0x%x, reason 0x%x\n", |
| 11910 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 11911 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 11912 | cmdiocb->iotag, |
| 11913 | (bf_get(lpfc_wcqe_c_status, wcqe) |
| 11914 | & LPFC_IOCB_STATUS_MASK), |
| 11915 | wcqe->parameter); |
| 11916 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| 11917 | } |
| 11918 | |
| 11919 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11920 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11921 | * @phba: Pointer to HBA context object |
| 11922 | * @cmdiocb: Pointer to command iocb object. |
| 11923 | * @rspiocb: Pointer to response iocb object. |
| 11924 | * |
| 11925 | * This function is called when an aborted FCP iocb completes. This |
| 11926 | * function is called by the ring event handler with no lock held. |
| 11927 | * This function frees the iocb. |
| 11928 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11929 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11930 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11931 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11932 | { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11933 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 8e668af | 2013-05-31 17:04:28 -0400 | [diff] [blame] | 11934 | "3096 ABORT_XRI_CN completing on rpi x%x " |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11935 | "original iotag x%x, abort cmd iotag x%x " |
| 11936 | "status 0x%x, reason 0x%x\n", |
| 11937 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 11938 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 11939 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, |
| 11940 | rspiocb->iocb.un.ulpWord[4]); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11941 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11942 | return; |
| 11943 | } |
| 11944 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11945 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11946 | * 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] | 11947 | * @vport: Pointer to virtual port. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11948 | * @tgt_id: SCSI ID of the target. |
| 11949 | * @lun_id: LUN ID of the scsi device. |
| 11950 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11951 | * |
| 11952 | * This function sends an abort command for every SCSI command |
| 11953 | * associated with the given virtual port pending on the ring |
| 11954 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 11955 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 11956 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 11957 | * parameters |
| 11958 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 11959 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 11960 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 11961 | * FCP iocbs associated with virtual port. |
James Smart | 078c68b | 2021-04-11 18:31:12 -0700 | [diff] [blame] | 11962 | * The pring used for SLI3 is sli3_ring[LPFC_FCP_RING], for SLI4 |
| 11963 | * lpfc_sli4_calc_ring is used. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11964 | * This function returns number of iocbs it failed to abort. |
| 11965 | * This function is called with no locks held. |
| 11966 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11967 | int |
James Smart | 078c68b | 2021-04-11 18:31:12 -0700 | [diff] [blame] | 11968 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, u16 tgt_id, u64 lun_id, |
| 11969 | lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11970 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11971 | struct lpfc_hba *phba = vport->phba; |
James Smart | 078c68b | 2021-04-11 18:31:12 -0700 | [diff] [blame] | 11972 | struct lpfc_sli_ring *pring = NULL; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11973 | struct lpfc_iocbq *iocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11974 | int errcnt = 0, ret_val = 0; |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 11975 | unsigned long iflags; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11976 | int i; |
James Smart | 078c68b | 2021-04-11 18:31:12 -0700 | [diff] [blame] | 11977 | void *fcp_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11978 | |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11979 | /* all I/Os are in process of being flushed */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11980 | if (phba->hba_flag & HBA_IOQ_FLUSH) |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11981 | return errcnt; |
| 11982 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11983 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 11984 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11985 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11986 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11987 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11988 | continue; |
| 11989 | |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 11990 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 078c68b | 2021-04-11 18:31:12 -0700 | [diff] [blame] | 11991 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 11992 | pring = &phba->sli.sli3_ring[LPFC_FCP_RING]; |
| 11993 | fcp_cmpl = lpfc_sli_abort_fcp_cmpl; |
| 11994 | } else if (phba->sli_rev == LPFC_SLI_REV4) { |
| 11995 | pring = lpfc_sli4_calc_ring(phba, iocbq); |
| 11996 | fcp_cmpl = lpfc_sli4_abort_fcp_cmpl; |
| 11997 | } |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 11998 | ret_val = lpfc_sli_issue_abort_iotag(phba, pring, iocbq, |
James Smart | 078c68b | 2021-04-11 18:31:12 -0700 | [diff] [blame] | 11999 | fcp_cmpl); |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 12000 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12001 | if (ret_val != IOCB_SUCCESS) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12002 | errcnt++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12003 | } |
| 12004 | |
| 12005 | return errcnt; |
| 12006 | } |
| 12007 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12008 | /** |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12009 | * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN |
| 12010 | * @vport: Pointer to virtual port. |
| 12011 | * @pring: Pointer to driver SLI ring object. |
| 12012 | * @tgt_id: SCSI ID of the target. |
| 12013 | * @lun_id: LUN ID of the scsi device. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 12014 | * @cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12015 | * |
| 12016 | * This function sends an abort command for every SCSI command |
| 12017 | * associated with the given virtual port pending on the ring |
| 12018 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 12019 | * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 12020 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 12021 | * parameters |
| 12022 | * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 12023 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 12024 | * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 12025 | * FCP iocbs associated with virtual port. |
| 12026 | * This function returns number of iocbs it aborted . |
| 12027 | * This function is called with no locks held right after a taskmgmt |
| 12028 | * command is sent. |
| 12029 | **/ |
| 12030 | int |
| 12031 | lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 12032 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd) |
| 12033 | { |
| 12034 | struct lpfc_hba *phba = vport->phba; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 12035 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12036 | struct lpfc_iocbq *abtsiocbq; |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 12037 | struct lpfc_nodelist *ndlp; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12038 | struct lpfc_iocbq *iocbq; |
| 12039 | IOCB_t *icmd; |
| 12040 | int sum, i, ret_val; |
| 12041 | unsigned long iflags; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 12042 | struct lpfc_sli_ring *pring_s4 = NULL; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12043 | |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 12044 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12045 | |
| 12046 | /* all I/Os are in process of being flushed */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 12047 | if (phba->hba_flag & HBA_IOQ_FLUSH) { |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 12048 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12049 | return 0; |
| 12050 | } |
| 12051 | sum = 0; |
| 12052 | |
| 12053 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 12054 | iocbq = phba->sli.iocbq_lookup[i]; |
| 12055 | |
| 12056 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
| 12057 | cmd) != 0) |
| 12058 | continue; |
| 12059 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 12060 | /* Guard against IO completion being called at same time */ |
| 12061 | lpfc_cmd = container_of(iocbq, struct lpfc_io_buf, cur_iocbq); |
| 12062 | spin_lock(&lpfc_cmd->buf_lock); |
| 12063 | |
| 12064 | if (!lpfc_cmd->pCmd) { |
| 12065 | spin_unlock(&lpfc_cmd->buf_lock); |
| 12066 | continue; |
| 12067 | } |
| 12068 | |
| 12069 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 12070 | pring_s4 = |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 12071 | phba->sli4_hba.hdwq[iocbq->hba_wqidx].io_wq->pring; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 12072 | if (!pring_s4) { |
| 12073 | spin_unlock(&lpfc_cmd->buf_lock); |
| 12074 | continue; |
| 12075 | } |
| 12076 | /* Note: both hbalock and ring_lock must be set here */ |
| 12077 | spin_lock(&pring_s4->ring_lock); |
| 12078 | } |
| 12079 | |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12080 | /* |
| 12081 | * If the iocbq is already being aborted, don't take a second |
| 12082 | * action, but do count it. |
| 12083 | */ |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 12084 | if ((iocbq->iocb_flag & LPFC_DRIVER_ABORTED) || |
| 12085 | !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ)) { |
| 12086 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 12087 | spin_unlock(&pring_s4->ring_lock); |
| 12088 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12089 | continue; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 12090 | } |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12091 | |
| 12092 | /* issue ABTS for this IOCB based on iotag */ |
| 12093 | abtsiocbq = __lpfc_sli_get_iocbq(phba); |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 12094 | if (!abtsiocbq) { |
| 12095 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 12096 | spin_unlock(&pring_s4->ring_lock); |
| 12097 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12098 | continue; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 12099 | } |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12100 | |
| 12101 | icmd = &iocbq->iocb; |
| 12102 | abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 12103 | abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext; |
| 12104 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 12105 | abtsiocbq->iocb.un.acxri.abortIoTag = |
| 12106 | iocbq->sli4_xritag; |
| 12107 | else |
| 12108 | abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag; |
| 12109 | abtsiocbq->iocb.ulpLe = 1; |
| 12110 | abtsiocbq->iocb.ulpClass = icmd->ulpClass; |
| 12111 | abtsiocbq->vport = vport; |
| 12112 | |
| 12113 | /* 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] | 12114 | abtsiocbq->hba_wqidx = iocbq->hba_wqidx; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12115 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 12116 | abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 12117 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 12118 | abtsiocbq->iocb_flag |= LPFC_IO_FOF; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12119 | |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 12120 | ndlp = lpfc_cmd->rdata->pnode; |
| 12121 | |
| 12122 | if (lpfc_is_link_up(phba) && |
| 12123 | (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12124 | abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 12125 | else |
| 12126 | abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 12127 | |
| 12128 | /* Setup callback routine and issue the command. */ |
| 12129 | abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
| 12130 | |
| 12131 | /* |
| 12132 | * Indicate the IO is being aborted by the driver and set |
| 12133 | * the caller's flag into the aborted IO. |
| 12134 | */ |
| 12135 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 12136 | |
| 12137 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12138 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 12139 | abtsiocbq, 0); |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 12140 | spin_unlock(&pring_s4->ring_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12141 | } else { |
| 12142 | ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 12143 | abtsiocbq, 0); |
| 12144 | } |
| 12145 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 12146 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12147 | |
| 12148 | if (ret_val == IOCB_ERROR) |
| 12149 | __lpfc_sli_release_iocbq(phba, abtsiocbq); |
| 12150 | else |
| 12151 | sum++; |
| 12152 | } |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 12153 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 12154 | return sum; |
| 12155 | } |
| 12156 | |
| 12157 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12158 | * 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] | 12159 | * @phba: Pointer to HBA context object. |
| 12160 | * @cmdiocbq: Pointer to command iocb. |
| 12161 | * @rspiocbq: Pointer to response iocb. |
| 12162 | * |
| 12163 | * This function is the completion handler for iocbs issued using |
| 12164 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 12165 | * ring event handler function without any lock held. This function |
| 12166 | * can be called from both worker thread context and interrupt |
| 12167 | * context. This function also can be called from other thread which |
| 12168 | * cleans up the SLI layer objects. |
| 12169 | * This function copy the contents of the response iocb to the |
| 12170 | * response iocb memory object provided by the caller of |
| 12171 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 12172 | * sleeps for the iocb completion. |
| 12173 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12174 | static void |
| 12175 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 12176 | struct lpfc_iocbq *cmdiocbq, |
| 12177 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12178 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12179 | wait_queue_head_t *pdone_q; |
| 12180 | unsigned long iflags; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 12181 | struct lpfc_io_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12182 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12183 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 12184 | if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) { |
| 12185 | |
| 12186 | /* |
| 12187 | * A time out has occurred for the iocb. If a time out |
| 12188 | * completion handler has been supplied, call it. Otherwise, |
| 12189 | * just free the iocbq. |
| 12190 | */ |
| 12191 | |
| 12192 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12193 | cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl; |
| 12194 | cmdiocbq->wait_iocb_cmpl = NULL; |
| 12195 | if (cmdiocbq->iocb_cmpl) |
| 12196 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL); |
| 12197 | else |
| 12198 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
| 12199 | return; |
| 12200 | } |
| 12201 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12202 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 12203 | if (cmdiocbq->context2 && rspiocbq) |
| 12204 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 12205 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 12206 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 12207 | /* Set the exchange busy flag for task management commands */ |
| 12208 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 12209 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 12210 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_io_buf, |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 12211 | cur_iocbq); |
James Smart | 324e1c4 | 2019-10-18 14:18:21 -0700 | [diff] [blame] | 12212 | if (rspiocbq && (rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY)) |
| 12213 | lpfc_cmd->flags |= LPFC_SBUF_XBUSY; |
| 12214 | else |
| 12215 | lpfc_cmd->flags &= ~LPFC_SBUF_XBUSY; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 12216 | } |
| 12217 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12218 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12219 | if (pdone_q) |
| 12220 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12221 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12222 | return; |
| 12223 | } |
| 12224 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12225 | /** |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 12226 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. |
| 12227 | * @phba: Pointer to HBA context object.. |
| 12228 | * @piocbq: Pointer to command iocb. |
| 12229 | * @flag: Flag to test. |
| 12230 | * |
| 12231 | * This routine grabs the hbalock and then test the iocb_flag to |
| 12232 | * see if the passed in flag is set. |
| 12233 | * Returns: |
| 12234 | * 1 if flag is set. |
| 12235 | * 0 if flag is not set. |
| 12236 | **/ |
| 12237 | static int |
| 12238 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, |
| 12239 | struct lpfc_iocbq *piocbq, uint32_t flag) |
| 12240 | { |
| 12241 | unsigned long iflags; |
| 12242 | int ret; |
| 12243 | |
| 12244 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12245 | ret = piocbq->iocb_flag & flag; |
| 12246 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12247 | return ret; |
| 12248 | |
| 12249 | } |
| 12250 | |
| 12251 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12252 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12253 | * @phba: Pointer to HBA context object.. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 12254 | * @ring_number: Ring number |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12255 | * @piocb: Pointer to command iocb. |
| 12256 | * @prspiocbq: Pointer to response iocb. |
| 12257 | * @timeout: Timeout in number of seconds. |
| 12258 | * |
| 12259 | * This function issues the iocb to firmware and waits for the |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 12260 | * iocb to complete. The iocb_cmpl field of the shall be used |
| 12261 | * to handle iocbs which time out. If the field is NULL, the |
| 12262 | * function shall free the iocbq structure. If more clean up is |
| 12263 | * needed, the caller is expected to provide a completion function |
| 12264 | * that will provide the needed clean up. If the iocb command is |
| 12265 | * not completed within timeout seconds, the function will either |
| 12266 | * free the iocbq structure (if iocb_cmpl == NULL) or execute the |
| 12267 | * completion function set in the iocb_cmpl field and then return |
| 12268 | * a status of IOCB_TIMEDOUT. The caller should not free the iocb |
| 12269 | * resources if this function returns IOCB_TIMEDOUT. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12270 | * The function waits for the iocb completion using an |
| 12271 | * non-interruptible wait. |
| 12272 | * This function will sleep while waiting for iocb completion. |
| 12273 | * So, this function should not be called from any context which |
| 12274 | * does not allow sleeping. Due to the same reason, this function |
| 12275 | * cannot be called with interrupt disabled. |
| 12276 | * This function assumes that the iocb completions occur while |
| 12277 | * this function sleep. So, this function cannot be called from |
| 12278 | * the thread which process iocb completion for this ring. |
| 12279 | * This function clears the iocb_flag of the iocb object before |
| 12280 | * issuing the iocb and the iocb completion handler sets this |
| 12281 | * flag and wakes this thread when the iocb completes. |
| 12282 | * The contents of the response iocb will be copied to prspiocbq |
| 12283 | * by the completion handler when the command completes. |
| 12284 | * This function returns IOCB_SUCCESS when success. |
| 12285 | * This function is called with no lock held. |
| 12286 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12287 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12288 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12289 | uint32_t ring_number, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12290 | struct lpfc_iocbq *piocb, |
| 12291 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12292 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12293 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 12294 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12295 | long timeleft, timeout_req = 0; |
| 12296 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 12297 | uint32_t creg_val; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 12298 | struct lpfc_iocbq *iocb; |
| 12299 | int txq_cnt = 0; |
| 12300 | int txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12301 | struct lpfc_sli_ring *pring; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 12302 | unsigned long iflags; |
| 12303 | bool iocb_completed = true; |
| 12304 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12305 | if (phba->sli_rev >= LPFC_SLI_REV4) |
| 12306 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 12307 | else |
| 12308 | pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12309 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12310 | * If the caller has provided a response iocbq buffer, then context2 |
| 12311 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12312 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12313 | if (prspiocbq) { |
| 12314 | if (piocb->context2) |
| 12315 | return IOCB_ERROR; |
| 12316 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12317 | } |
| 12318 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 12319 | piocb->wait_iocb_cmpl = piocb->iocb_cmpl; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12320 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 12321 | piocb->context_un.wait_queue = &done_q; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 12322 | piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12323 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 12324 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12325 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 12326 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 12327 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 12328 | writel(creg_val, phba->HCregaddr); |
| 12329 | readl(phba->HCregaddr); /* flush */ |
| 12330 | } |
| 12331 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 12332 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 12333 | SLI_IOCB_RET_IOCB); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12334 | if (retval == IOCB_SUCCESS) { |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 12335 | timeout_req = msecs_to_jiffies(timeout * 1000); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12336 | timeleft = wait_event_timeout(done_q, |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 12337 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12338 | timeout_req); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 12339 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12340 | if (!(piocb->iocb_flag & LPFC_IO_WAKE)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12341 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 12342 | /* |
| 12343 | * IOCB timed out. Inform the wake iocb wait |
| 12344 | * completion function and set local status |
| 12345 | */ |
| 12346 | |
| 12347 | iocb_completed = false; |
| 12348 | piocb->iocb_flag |= LPFC_IO_WAKE_TMO; |
| 12349 | } |
| 12350 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12351 | if (iocb_completed) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12352 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12353 | "0331 IOCB wake signaled\n"); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 12354 | /* Note: we are not indicating if the IOCB has a success |
| 12355 | * status or not - that's for the caller to check. |
| 12356 | * IOCB_SUCCESS means just that the command was sent and |
| 12357 | * completed. Not that it completed successfully. |
| 12358 | * */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12359 | } else if (timeleft == 0) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12360 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12361 | "0338 IOCB wait timeout error - no " |
| 12362 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12363 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12364 | } else { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12365 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12366 | "0330 IOCB wake NOT set, " |
| 12367 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12368 | timeout, (timeleft / jiffies)); |
| 12369 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12370 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 12371 | } else if (retval == IOCB_BUSY) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 12372 | if (phba->cfg_log_verbose & LOG_SLI) { |
| 12373 | list_for_each_entry(iocb, &pring->txq, list) { |
| 12374 | txq_cnt++; |
| 12375 | } |
| 12376 | list_for_each_entry(iocb, &pring->txcmplq, list) { |
| 12377 | txcmplq_cnt++; |
| 12378 | } |
| 12379 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 12380 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", |
| 12381 | phba->iocb_cnt, txq_cnt, txcmplq_cnt); |
| 12382 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 12383 | return retval; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12384 | } else { |
| 12385 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 12386 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12387 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12388 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12389 | } |
| 12390 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 12391 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12392 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 12393 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 12394 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 12395 | writel(creg_val, phba->HCregaddr); |
| 12396 | readl(phba->HCregaddr); /* flush */ |
| 12397 | } |
| 12398 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12399 | if (prspiocbq) |
| 12400 | piocb->context2 = NULL; |
| 12401 | |
| 12402 | piocb->context_un.wait_queue = NULL; |
| 12403 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12404 | return retval; |
| 12405 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12406 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12407 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12408 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12409 | * @phba: Pointer to HBA context object. |
| 12410 | * @pmboxq: Pointer to driver mailbox object. |
| 12411 | * @timeout: Timeout in number of seconds. |
| 12412 | * |
| 12413 | * This function issues the mailbox to firmware and waits for the |
| 12414 | * mailbox command to complete. If the mailbox command is not |
| 12415 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 12416 | * The function waits for the mailbox completion using an |
| 12417 | * interruptible wait. If the thread is woken up due to a |
| 12418 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 12419 | * should not free the mailbox resources, if this function returns |
| 12420 | * MBX_TIMEOUT. |
| 12421 | * This function will sleep while waiting for mailbox completion. |
| 12422 | * So, this function should not be called from any context which |
| 12423 | * does not allow sleeping. Due to the same reason, this function |
| 12424 | * cannot be called with interrupt disabled. |
| 12425 | * This function assumes that the mailbox completion occurs while |
| 12426 | * this function sleep. So, this function cannot be called from |
| 12427 | * the worker thread which processes mailbox completion. |
| 12428 | * This function is called in the context of HBA management |
| 12429 | * applications. |
| 12430 | * This function returns MBX_SUCCESS when successful. |
| 12431 | * This function is called with no lock held. |
| 12432 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12433 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12434 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12435 | uint32_t timeout) |
| 12436 | { |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12437 | struct completion mbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12438 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12439 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12440 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 12441 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12442 | /* setup wake call as IOCB callback */ |
| 12443 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12444 | |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12445 | /* setup context3 field to pass wait_queue pointer to wake function */ |
| 12446 | init_completion(&mbox_done); |
| 12447 | pmboxq->context3 = &mbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12448 | /* now issue the command */ |
| 12449 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12450 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12451 | wait_for_completion_timeout(&mbox_done, |
| 12452 | msecs_to_jiffies(timeout * 1000)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12453 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12454 | spin_lock_irqsave(&phba->hbalock, flag); |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12455 | pmboxq->context3 = NULL; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12456 | /* |
| 12457 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 12458 | * else do not free the resources. |
| 12459 | */ |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 12460 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12461 | retval = MBX_SUCCESS; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 12462 | } else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12463 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12464 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12465 | } |
| 12466 | spin_unlock_irqrestore(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12467 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12468 | return retval; |
| 12469 | } |
| 12470 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12471 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12472 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12473 | * @phba: Pointer to HBA context. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 12474 | * @mbx_action: Mailbox shutdown options. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12475 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12476 | * This function is called to shutdown the driver's mailbox sub-system. |
| 12477 | * It first marks the mailbox sub-system is in a block state to prevent |
| 12478 | * the asynchronous mailbox command from issued off the pending mailbox |
| 12479 | * command queue. If the mailbox command sub-system shutdown is due to |
| 12480 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 12481 | * the mailbox sub-system flush routine to forcefully bring down the |
| 12482 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 12483 | * as with offline or HBA function reset), this routine will wait for the |
| 12484 | * outstanding mailbox command to complete before invoking the mailbox |
| 12485 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12486 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12487 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12488 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12489 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12490 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12491 | unsigned long timeout; |
| 12492 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12493 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
| 12494 | /* delay 100ms for port state */ |
| 12495 | msleep(100); |
| 12496 | lpfc_sli_mbox_sys_flush(phba); |
| 12497 | return; |
| 12498 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 12499 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 12500 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12501 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 12502 | local_bh_disable(); |
| 12503 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12504 | spin_lock_irq(&phba->hbalock); |
| 12505 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12506 | |
| 12507 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12508 | /* Determine how long we might wait for the active mailbox |
| 12509 | * command to be gracefully completed by firmware. |
| 12510 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 12511 | if (phba->sli.mbox_active) |
| 12512 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 12513 | phba->sli.mbox_active) * |
| 12514 | 1000) + jiffies; |
| 12515 | spin_unlock_irq(&phba->hbalock); |
| 12516 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12517 | /* Enable softirqs again, done with phba->hbalock */ |
| 12518 | local_bh_enable(); |
| 12519 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12520 | while (phba->sli.mbox_active) { |
| 12521 | /* Check active mailbox complete status every 2ms */ |
| 12522 | msleep(2); |
| 12523 | if (time_after(jiffies, timeout)) |
| 12524 | /* Timeout, let the mailbox flush routine to |
| 12525 | * forcefully release active mailbox command |
| 12526 | */ |
| 12527 | break; |
| 12528 | } |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12529 | } else { |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 12530 | spin_unlock_irq(&phba->hbalock); |
| 12531 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12532 | /* Enable softirqs again, done with phba->hbalock */ |
| 12533 | local_bh_enable(); |
| 12534 | } |
| 12535 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12536 | lpfc_sli_mbox_sys_flush(phba); |
| 12537 | } |
| 12538 | |
| 12539 | /** |
| 12540 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 12541 | * @phba: Pointer to HBA context. |
| 12542 | * |
| 12543 | * This function is called to read the SLI3 device error attention registers |
| 12544 | * for possible error attention events. The caller must hold the hostlock |
| 12545 | * with spin_lock_irq(). |
| 12546 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12547 | * 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] | 12548 | * Register and returns 0 otherwise. |
| 12549 | **/ |
| 12550 | static int |
| 12551 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 12552 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 12553 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12554 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12555 | /* Read chip Host Attention (HA) register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12556 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12557 | goto unplug_err; |
| 12558 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12559 | if (ha_copy & HA_ERATT) { |
| 12560 | /* Read host status register to retrieve error event */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12561 | if (lpfc_sli_read_hs(phba)) |
| 12562 | goto unplug_err; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12563 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12564 | /* Check if there is a deferred error condition is active */ |
| 12565 | if ((HS_FFER1 & phba->work_hs) && |
| 12566 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 12567 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12568 | phba->hba_flag |= DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12569 | /* Clear all interrupt enable conditions */ |
| 12570 | writel(0, phba->HCregaddr); |
| 12571 | readl(phba->HCregaddr); |
| 12572 | } |
| 12573 | |
| 12574 | /* Set the driver HA work bitmap */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12575 | phba->work_ha |= HA_ERATT; |
| 12576 | /* Indicate polling handles this ERATT */ |
| 12577 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12578 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12579 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12580 | return 0; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12581 | |
| 12582 | unplug_err: |
| 12583 | /* Set the driver HS work bitmap */ |
| 12584 | phba->work_hs |= UNPLUG_ERR; |
| 12585 | /* Set the driver HA work bitmap */ |
| 12586 | phba->work_ha |= HA_ERATT; |
| 12587 | /* Indicate polling handles this ERATT */ |
| 12588 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12589 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12590 | } |
| 12591 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12592 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12593 | * lpfc_sli4_eratt_read - read sli-4 error attention events |
| 12594 | * @phba: Pointer to HBA context. |
| 12595 | * |
| 12596 | * This function is called to read the SLI4 device error attention registers |
| 12597 | * for possible error attention events. The caller must hold the hostlock |
| 12598 | * with spin_lock_irq(). |
| 12599 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12600 | * 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] | 12601 | * Register and returns 0 otherwise. |
| 12602 | **/ |
| 12603 | static int |
| 12604 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) |
| 12605 | { |
| 12606 | uint32_t uerr_sta_hi, uerr_sta_lo; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12607 | uint32_t if_type, portsmphr; |
| 12608 | struct lpfc_register portstat_reg; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12609 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12610 | /* |
| 12611 | * For now, use the SLI4 device internal unrecoverable error |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12612 | * registers for error attention. This can be changed later. |
| 12613 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12614 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 12615 | switch (if_type) { |
| 12616 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12617 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 12618 | &uerr_sta_lo) || |
| 12619 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, |
| 12620 | &uerr_sta_hi)) { |
| 12621 | phba->work_hs |= UNPLUG_ERR; |
| 12622 | phba->work_ha |= HA_ERATT; |
| 12623 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12624 | return 1; |
| 12625 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12626 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
| 12627 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12628 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12629 | "1423 HBA Unrecoverable error: " |
| 12630 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " |
| 12631 | "ue_mask_lo_reg=0x%x, " |
| 12632 | "ue_mask_hi_reg=0x%x\n", |
| 12633 | uerr_sta_lo, uerr_sta_hi, |
| 12634 | phba->sli4_hba.ue_mask_lo, |
| 12635 | phba->sli4_hba.ue_mask_hi); |
| 12636 | phba->work_status[0] = uerr_sta_lo; |
| 12637 | phba->work_status[1] = uerr_sta_hi; |
| 12638 | phba->work_ha |= HA_ERATT; |
| 12639 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12640 | return 1; |
| 12641 | } |
| 12642 | break; |
| 12643 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 12644 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12645 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 12646 | &portstat_reg.word0) || |
| 12647 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 12648 | &portsmphr)){ |
| 12649 | phba->work_hs |= UNPLUG_ERR; |
| 12650 | phba->work_ha |= HA_ERATT; |
| 12651 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12652 | return 1; |
| 12653 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12654 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
| 12655 | phba->work_status[0] = |
| 12656 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 12657 | phba->work_status[1] = |
| 12658 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12659 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12660 | "2885 Port Status Event: " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12661 | "port status reg 0x%x, " |
| 12662 | "port smphr reg 0x%x, " |
| 12663 | "error 1=0x%x, error 2=0x%x\n", |
| 12664 | portstat_reg.word0, |
| 12665 | portsmphr, |
| 12666 | phba->work_status[0], |
| 12667 | phba->work_status[1]); |
| 12668 | phba->work_ha |= HA_ERATT; |
| 12669 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12670 | return 1; |
| 12671 | } |
| 12672 | break; |
| 12673 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 12674 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12675 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12676 | "2886 HBA Error Attention on unsupported " |
| 12677 | "if type %d.", if_type); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12678 | return 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12679 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12680 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12681 | return 0; |
| 12682 | } |
| 12683 | |
| 12684 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12685 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12686 | * @phba: Pointer to HBA context. |
| 12687 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12688 | * 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] | 12689 | * error attention register bit for error attention events. |
| 12690 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12691 | * 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] | 12692 | * Register and returns 0 otherwise. |
| 12693 | **/ |
| 12694 | int |
| 12695 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 12696 | { |
| 12697 | uint32_t ha_copy; |
| 12698 | |
| 12699 | /* If somebody is waiting to handle an eratt, don't process it |
| 12700 | * here. The brdkill function will do this. |
| 12701 | */ |
| 12702 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 12703 | return 0; |
| 12704 | |
| 12705 | /* Check if interrupt handler handles this ERATT */ |
| 12706 | spin_lock_irq(&phba->hbalock); |
| 12707 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 12708 | /* Interrupt handler has handled ERATT */ |
| 12709 | spin_unlock_irq(&phba->hbalock); |
| 12710 | return 0; |
| 12711 | } |
| 12712 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12713 | /* |
| 12714 | * If there is deferred error attention, do not check for error |
| 12715 | * attention |
| 12716 | */ |
| 12717 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 12718 | spin_unlock_irq(&phba->hbalock); |
| 12719 | return 0; |
| 12720 | } |
| 12721 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12722 | /* If PCI channel is offline, don't process it */ |
| 12723 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12724 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12725 | return 0; |
| 12726 | } |
| 12727 | |
| 12728 | switch (phba->sli_rev) { |
| 12729 | case LPFC_SLI_REV2: |
| 12730 | case LPFC_SLI_REV3: |
| 12731 | /* Read chip Host Attention (HA) register */ |
| 12732 | ha_copy = lpfc_sli_eratt_read(phba); |
| 12733 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12734 | case LPFC_SLI_REV4: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12735 | /* Read device Uncoverable Error (UERR) registers */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12736 | ha_copy = lpfc_sli4_eratt_read(phba); |
| 12737 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12738 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12739 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12740 | "0299 Invalid SLI revision (%d)\n", |
| 12741 | phba->sli_rev); |
| 12742 | ha_copy = 0; |
| 12743 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12744 | } |
| 12745 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12746 | |
| 12747 | return ha_copy; |
| 12748 | } |
| 12749 | |
| 12750 | /** |
| 12751 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 12752 | * @phba: Pointer to HBA context. |
| 12753 | * |
| 12754 | * This inline routine checks whether a device or its PCI slot is in a state |
| 12755 | * that the interrupt should be handled. |
| 12756 | * |
| 12757 | * This function returns 0 if the device or the PCI slot is in a state that |
| 12758 | * interrupt should be handled, otherwise -EIO. |
| 12759 | */ |
| 12760 | static inline int |
| 12761 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 12762 | { |
| 12763 | /* If the pci channel is offline, ignore all the interrupts */ |
| 12764 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 12765 | return -EIO; |
| 12766 | |
| 12767 | /* Update device level interrupt statistics */ |
| 12768 | phba->sli.slistat.sli_intr++; |
| 12769 | |
| 12770 | /* Ignore all interrupts during initialization. */ |
| 12771 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 12772 | return -EIO; |
| 12773 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12774 | return 0; |
| 12775 | } |
| 12776 | |
| 12777 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12778 | * 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] | 12779 | * @irq: Interrupt number. |
| 12780 | * @dev_id: The device context pointer. |
| 12781 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12782 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12783 | * service routine when device with SLI-3 interface spec is enabled with |
| 12784 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 12785 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 12786 | * interrupt mode, this function is called as part of the device-level |
| 12787 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 12788 | * is undergoing initialization, the interrupt handler will not process |
| 12789 | * the interrupt. The link attention and ELS ring attention events are |
| 12790 | * handled by the worker thread. The interrupt handler signals the worker |
| 12791 | * thread and returns for these events. This function is called without |
| 12792 | * 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] | 12793 | * structures. |
| 12794 | * |
| 12795 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12796 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12797 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12798 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12799 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12800 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12801 | struct lpfc_hba *phba; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12802 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12803 | uint32_t work_ha_copy; |
| 12804 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12805 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12806 | uint32_t control; |
| 12807 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12808 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12809 | struct lpfc_vport *vport; |
| 12810 | struct lpfc_nodelist *ndlp; |
| 12811 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12812 | LPFC_MBOXQ_t *pmb; |
| 12813 | int rc; |
| 12814 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12815 | /* |
| 12816 | * Get the driver's phba structure from the dev_id and |
| 12817 | * assume the HBA is not interrupting. |
| 12818 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12819 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12820 | |
| 12821 | if (unlikely(!phba)) |
| 12822 | return IRQ_NONE; |
| 12823 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12824 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12825 | * Stuff needs to be attented to when this function is invoked as an |
| 12826 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12827 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12828 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12829 | /* Check device state for handling interrupt */ |
| 12830 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12831 | return IRQ_NONE; |
| 12832 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12833 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12834 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12835 | goto unplug_error; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12836 | /* If somebody is waiting to handle an eratt don't process it |
| 12837 | * here. The brdkill function will do this. |
| 12838 | */ |
| 12839 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 12840 | ha_copy &= ~HA_ERATT; |
| 12841 | /* Check the need for handling ERATT in interrupt handler */ |
| 12842 | if (ha_copy & HA_ERATT) { |
| 12843 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 12844 | /* ERATT polling has handled ERATT */ |
| 12845 | ha_copy &= ~HA_ERATT; |
| 12846 | else |
| 12847 | /* Indicate interrupt handler handles ERATT */ |
| 12848 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12849 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12850 | |
| 12851 | /* |
| 12852 | * If there is deferred error attention, do not check for any |
| 12853 | * interrupt. |
| 12854 | */ |
| 12855 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12856 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12857 | return IRQ_NONE; |
| 12858 | } |
| 12859 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12860 | /* Clear up only attention source related to slow-path */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12861 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 12862 | goto unplug_error; |
| 12863 | |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12864 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
| 12865 | HC_LAINT_ENA | HC_ERINT_ENA), |
| 12866 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12867 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 12868 | phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12869 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12870 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12871 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12872 | } else |
| 12873 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12874 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12875 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 12876 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12877 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12878 | if (work_ha_copy & HA_LATT) { |
| 12879 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 12880 | /* |
| 12881 | * Turn off Link Attention interrupts |
| 12882 | * until CLEAR_LA done |
| 12883 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12884 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12885 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12886 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 12887 | goto unplug_error; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12888 | control &= ~HC_LAINT_ENA; |
| 12889 | writel(control, phba->HCregaddr); |
| 12890 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12891 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12892 | } |
| 12893 | else |
| 12894 | work_ha_copy &= ~HA_LATT; |
| 12895 | } |
| 12896 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12897 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12898 | /* |
| 12899 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 12900 | * the only slow ring. |
| 12901 | */ |
| 12902 | status = (work_ha_copy & |
| 12903 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 12904 | status >>= (4*LPFC_ELS_RING); |
| 12905 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12906 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12907 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 12908 | goto unplug_error; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12909 | |
| 12910 | lpfc_debugfs_slow_ring_trc(phba, |
| 12911 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 12912 | control, status, |
| 12913 | (uint32_t)phba->sli.slistat.sli_intr); |
| 12914 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12915 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12916 | lpfc_debugfs_slow_ring_trc(phba, |
| 12917 | "ISR Disable ring:" |
| 12918 | "pwork:x%x hawork:x%x wait:x%x", |
| 12919 | phba->work_ha, work_ha_copy, |
| 12920 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12921 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12922 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12923 | control &= |
| 12924 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12925 | writel(control, phba->HCregaddr); |
| 12926 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12927 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12928 | else { |
| 12929 | lpfc_debugfs_slow_ring_trc(phba, |
| 12930 | "ISR slow ring: pwork:" |
| 12931 | "x%x hawork:x%x wait:x%x", |
| 12932 | phba->work_ha, work_ha_copy, |
| 12933 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12934 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12935 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12936 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12937 | } |
| 12938 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12939 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12940 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12941 | if (lpfc_sli_read_hs(phba)) |
| 12942 | goto unplug_error; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12943 | /* |
| 12944 | * Check if there is a deferred error condition |
| 12945 | * is active |
| 12946 | */ |
| 12947 | if ((HS_FFER1 & phba->work_hs) && |
| 12948 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 12949 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
| 12950 | phba->work_hs)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12951 | phba->hba_flag |= DEFER_ERATT; |
| 12952 | /* Clear all interrupt enable conditions */ |
| 12953 | writel(0, phba->HCregaddr); |
| 12954 | readl(phba->HCregaddr); |
| 12955 | } |
| 12956 | } |
| 12957 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12958 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12959 | pmb = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12960 | pmbox = &pmb->u.mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 12961 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12962 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12963 | |
| 12964 | /* First check out the status word */ |
| 12965 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 12966 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12967 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12968 | /* |
| 12969 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 12970 | * mbxStatus <status> |
| 12971 | */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12972 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12973 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12974 | "Interrupt mbxCommand x%x " |
| 12975 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12976 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12977 | pmbox->mbxCommand, |
| 12978 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12979 | /* clear mailbox attention bit */ |
| 12980 | work_ha_copy &= ~HA_MBATT; |
| 12981 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 12982 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12983 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12984 | phba->last_completion_time = jiffies; |
| 12985 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12986 | if (pmb->mbox_cmpl) { |
| 12987 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 12988 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12989 | if (pmb->out_ext_byte_len && |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12990 | pmb->ctx_buf) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12991 | lpfc_sli_pcimem_bcopy( |
| 12992 | phba->mbox_ext, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12993 | pmb->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12994 | pmb->out_ext_byte_len); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12995 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12996 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 12997 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 12998 | |
| 12999 | lpfc_debugfs_disc_trc(vport, |
| 13000 | LPFC_DISC_TRC_MBOX_VPORT, |
| 13001 | "MBOX dflt rpi: : " |
| 13002 | "status:x%x rpi:x%x", |
| 13003 | (uint32_t)pmbox->mbxStatus, |
| 13004 | pmbox->un.varWords[0], 0); |
| 13005 | |
| 13006 | if (!pmbox->mbxStatus) { |
| 13007 | mp = (struct lpfc_dmabuf *) |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13008 | (pmb->ctx_buf); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 13009 | ndlp = (struct lpfc_nodelist *) |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13010 | pmb->ctx_ndlp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 13011 | |
| 13012 | /* Reg_LOGIN of dflt RPI was |
| 13013 | * successful. new lets get |
| 13014 | * rid of the RPI using the |
| 13015 | * same mbox buffer. |
| 13016 | */ |
| 13017 | lpfc_unreg_login(phba, |
| 13018 | vport->vpi, |
| 13019 | pmbox->un.varWords[0], |
| 13020 | pmb); |
| 13021 | pmb->mbox_cmpl = |
| 13022 | lpfc_mbx_cmpl_dflt_rpi; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13023 | pmb->ctx_buf = mp; |
| 13024 | pmb->ctx_ndlp = ndlp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 13025 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 13026 | rc = lpfc_sli_issue_mbox(phba, |
| 13027 | pmb, |
| 13028 | MBX_NOWAIT); |
| 13029 | if (rc != MBX_BUSY) |
| 13030 | lpfc_printf_log(phba, |
| 13031 | KERN_ERR, |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13032 | LOG_TRACE_EVENT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 13033 | "0350 rc should have" |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 13034 | "been MBX_BUSY\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13035 | if (rc != MBX_NOT_FINISHED) |
| 13036 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 13037 | } |
| 13038 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13039 | spin_lock_irqsave( |
| 13040 | &phba->pport->work_port_lock, |
| 13041 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 13042 | phba->pport->work_port_events &= |
| 13043 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13044 | spin_unlock_irqrestore( |
| 13045 | &phba->pport->work_port_lock, |
| 13046 | iflag); |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 13047 | |
| 13048 | /* Do NOT queue MBX_HEARTBEAT to the worker |
| 13049 | * thread for processing. |
| 13050 | */ |
| 13051 | if (pmbox->mbxCommand == MBX_HEARTBEAT) { |
| 13052 | /* Process mbox now */ |
| 13053 | phba->sli.mbox_active = NULL; |
| 13054 | phba->sli.sli_flag &= |
| 13055 | ~LPFC_SLI_MBOX_ACTIVE; |
| 13056 | if (pmb->mbox_cmpl) |
| 13057 | pmb->mbox_cmpl(phba, pmb); |
| 13058 | } else { |
| 13059 | /* Queue to worker thread to process */ |
| 13060 | lpfc_mbox_cmpl_put(phba, pmb); |
| 13061 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 13062 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 13063 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13064 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13065 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 13066 | if ((work_ha_copy & HA_MBATT) && |
| 13067 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 13068 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 13069 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 13070 | do { |
| 13071 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 13072 | MBX_NOWAIT); |
| 13073 | } while (rc == MBX_NOT_FINISHED); |
| 13074 | if (rc != MBX_SUCCESS) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13075 | lpfc_printf_log(phba, KERN_ERR, |
| 13076 | LOG_TRACE_EVENT, |
| 13077 | "0349 rc should be " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 13078 | "MBX_SUCCESS\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 13079 | } |
| 13080 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13081 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13082 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13083 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 13084 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13085 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13086 | return IRQ_HANDLED; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 13087 | unplug_error: |
| 13088 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 13089 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13090 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13091 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13092 | |
| 13093 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13094 | * 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] | 13095 | * @irq: Interrupt number. |
| 13096 | * @dev_id: The device context pointer. |
| 13097 | * |
| 13098 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13099 | * service routine when device with SLI-3 interface spec is enabled with |
| 13100 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 13101 | * ring event in the HBA. However, when the device is enabled with either |
| 13102 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 13103 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 13104 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 13105 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 13106 | * the intrrupt context. This function is called without any lock held. |
| 13107 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13108 | * |
| 13109 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 13110 | * returns IRQ_NONE. |
| 13111 | **/ |
| 13112 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13113 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13114 | { |
| 13115 | struct lpfc_hba *phba; |
| 13116 | uint32_t ha_copy; |
| 13117 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13118 | unsigned long iflag; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13119 | struct lpfc_sli_ring *pring; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13120 | |
| 13121 | /* Get the driver's phba structure from the dev_id and |
| 13122 | * assume the HBA is not interrupting. |
| 13123 | */ |
| 13124 | phba = (struct lpfc_hba *) dev_id; |
| 13125 | |
| 13126 | if (unlikely(!phba)) |
| 13127 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13128 | |
| 13129 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13130 | * Stuff needs to be attented to when this function is invoked as an |
| 13131 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13132 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13133 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13134 | /* Check device state for handling interrupt */ |
| 13135 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13136 | return IRQ_NONE; |
| 13137 | /* Need to read HA REG for FCP ring and other ring events */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 13138 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 13139 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13140 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13141 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 13142 | /* |
| 13143 | * If there is deferred error attention, do not check for |
| 13144 | * any interrupt. |
| 13145 | */ |
| 13146 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13147 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 13148 | return IRQ_NONE; |
| 13149 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13150 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 13151 | phba->HAregaddr); |
| 13152 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13153 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13154 | } else |
| 13155 | ha_copy = phba->ha_copy; |
| 13156 | |
| 13157 | /* |
| 13158 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 13159 | */ |
| 13160 | ha_copy &= ~(phba->work_ha_mask); |
| 13161 | |
| 13162 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13163 | status >>= (4*LPFC_FCP_RING); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13164 | pring = &phba->sli.sli3_ring[LPFC_FCP_RING]; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 13165 | if (status & HA_RXMASK) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13166 | lpfc_sli_handle_fast_ring_event(phba, pring, status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 13167 | |
| 13168 | if (phba->cfg_multi_ring_support == 2) { |
| 13169 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13170 | * Process all events on extra ring. Take the optimized path |
| 13171 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 13172 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13173 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 13174 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 13175 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 13176 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13177 | &phba->sli.sli3_ring[LPFC_EXTRA_RING], |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 13178 | status); |
| 13179 | } |
| 13180 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13181 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13182 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13183 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13184 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13185 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13186 | * @irq: Interrupt number. |
| 13187 | * @dev_id: The device context pointer. |
| 13188 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13189 | * This function is the HBA device-level interrupt handler to device with |
| 13190 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 13191 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 13192 | * requires driver attention. This function invokes the slow-path interrupt |
| 13193 | * attention handling function and fast-path interrupt attention handling |
| 13194 | * function in turn to process the relevant HBA attention events. This |
| 13195 | * function is called without any lock held. It gets the hbalock to access |
| 13196 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13197 | * |
| 13198 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 13199 | * returns IRQ_NONE. |
| 13200 | **/ |
| 13201 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13202 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13203 | { |
| 13204 | struct lpfc_hba *phba; |
| 13205 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 13206 | unsigned long status1, status2; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 13207 | uint32_t hc_copy; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13208 | |
| 13209 | /* |
| 13210 | * Get the driver's phba structure from the dev_id and |
| 13211 | * assume the HBA is not interrupting. |
| 13212 | */ |
| 13213 | phba = (struct lpfc_hba *) dev_id; |
| 13214 | |
| 13215 | if (unlikely(!phba)) |
| 13216 | return IRQ_NONE; |
| 13217 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13218 | /* Check device state for handling interrupt */ |
| 13219 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13220 | return IRQ_NONE; |
| 13221 | |
| 13222 | spin_lock(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 13223 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
| 13224 | spin_unlock(&phba->hbalock); |
| 13225 | return IRQ_HANDLED; |
| 13226 | } |
| 13227 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13228 | if (unlikely(!phba->ha_copy)) { |
| 13229 | spin_unlock(&phba->hbalock); |
| 13230 | return IRQ_NONE; |
| 13231 | } else if (phba->ha_copy & HA_ERATT) { |
| 13232 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 13233 | /* ERATT polling has handled ERATT */ |
| 13234 | phba->ha_copy &= ~HA_ERATT; |
| 13235 | else |
| 13236 | /* Indicate interrupt handler handles ERATT */ |
| 13237 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 13238 | } |
| 13239 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 13240 | /* |
| 13241 | * If there is deferred error attention, do not check for any interrupt. |
| 13242 | */ |
| 13243 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 13244 | spin_unlock(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 13245 | return IRQ_NONE; |
| 13246 | } |
| 13247 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13248 | /* Clear attention sources except link and error attentions */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 13249 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
| 13250 | spin_unlock(&phba->hbalock); |
| 13251 | return IRQ_HANDLED; |
| 13252 | } |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 13253 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
| 13254 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), |
| 13255 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13256 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 13257 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13258 | readl(phba->HAregaddr); /* flush */ |
| 13259 | spin_unlock(&phba->hbalock); |
| 13260 | |
| 13261 | /* |
| 13262 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 13263 | */ |
| 13264 | |
| 13265 | /* status of events with mailbox and link attention */ |
| 13266 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 13267 | |
| 13268 | /* status of events with ELS ring */ |
| 13269 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 13270 | status2 >>= (4*LPFC_ELS_RING); |
| 13271 | |
| 13272 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13273 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13274 | else |
| 13275 | sp_irq_rc = IRQ_NONE; |
| 13276 | |
| 13277 | /* |
| 13278 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 13279 | */ |
| 13280 | |
| 13281 | /* status of events with FCP ring */ |
| 13282 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 13283 | status1 >>= (4*LPFC_FCP_RING); |
| 13284 | |
| 13285 | /* status of events with extra ring */ |
| 13286 | if (phba->cfg_multi_ring_support == 2) { |
| 13287 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 13288 | status2 >>= (4*LPFC_EXTRA_RING); |
| 13289 | } else |
| 13290 | status2 = 0; |
| 13291 | |
| 13292 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13293 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 13294 | else |
| 13295 | fp_irq_rc = IRQ_NONE; |
| 13296 | |
| 13297 | /* Return device-level interrupt handling status */ |
| 13298 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13299 | } /* lpfc_sli_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13300 | |
| 13301 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13302 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event |
| 13303 | * @phba: pointer to lpfc hba data structure. |
| 13304 | * |
| 13305 | * This routine is invoked by the worker thread to process all the pending |
| 13306 | * SLI4 els abort xri events. |
| 13307 | **/ |
| 13308 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) |
| 13309 | { |
| 13310 | struct lpfc_cq_event *cq_event; |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 13311 | unsigned long iflags; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13312 | |
| 13313 | /* First, declare the els xri abort event has been handled */ |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 13314 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13315 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 13316 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13317 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13318 | /* Now, handle all the els xri abort events */ |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 13319 | spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13320 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { |
| 13321 | /* Get the first event from the head of the event queue */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13322 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 13323 | cq_event, struct lpfc_cq_event, list); |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 13324 | spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock, |
| 13325 | iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13326 | /* Notify aborted XRI for ELS work queue */ |
| 13327 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 13328 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13329 | /* Free the event processed back to the free pool */ |
| 13330 | lpfc_sli4_cq_event_release(phba, cq_event); |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 13331 | spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock, |
| 13332 | iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13333 | } |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 13334 | spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13335 | } |
| 13336 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13337 | /** |
| 13338 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn |
| 13339 | * @phba: pointer to lpfc hba data structure |
| 13340 | * @pIocbIn: pointer to the rspiocbq |
| 13341 | * @pIocbOut: pointer to the cmdiocbq |
| 13342 | * @wcqe: pointer to the complete wcqe |
| 13343 | * |
| 13344 | * This routine transfers the fields of a command iocbq to a response iocbq |
| 13345 | * by copying all the IOCB fields from command iocbq and transferring the |
| 13346 | * completion status information from the complete wcqe. |
| 13347 | **/ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13348 | static void |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13349 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
| 13350 | struct lpfc_iocbq *pIocbIn, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13351 | struct lpfc_iocbq *pIocbOut, |
| 13352 | struct lpfc_wcqe_complete *wcqe) |
| 13353 | { |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 13354 | int numBdes, i; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13355 | unsigned long iflags; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 13356 | uint32_t status, max_response; |
| 13357 | struct lpfc_dmabuf *dmabuf; |
| 13358 | struct ulp_bde64 *bpl, bde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13359 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
| 13360 | |
| 13361 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, |
| 13362 | sizeof(struct lpfc_iocbq) - offset); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13363 | /* Map WCQE parameters into irspiocb parameters */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 13364 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 13365 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13366 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
| 13367 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 13368 | pIocbIn->iocb.un.fcpi.fcpi_parm = |
| 13369 | pIocbOut->iocb.un.fcpi.fcpi_parm - |
| 13370 | wcqe->total_data_placed; |
| 13371 | else |
| 13372 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 13373 | else { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13374 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 13375 | switch (pIocbOut->iocb.ulpCommand) { |
| 13376 | case CMD_ELS_REQUEST64_CR: |
| 13377 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 13378 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 13379 | bde.tus.w = le32_to_cpu(bpl[1].tus.w); |
| 13380 | max_response = bde.tus.f.bdeSize; |
| 13381 | break; |
| 13382 | case CMD_GEN_REQUEST64_CR: |
| 13383 | max_response = 0; |
| 13384 | if (!pIocbOut->context3) |
| 13385 | break; |
| 13386 | numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/ |
| 13387 | sizeof(struct ulp_bde64); |
| 13388 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 13389 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 13390 | for (i = 0; i < numBdes; i++) { |
| 13391 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 13392 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 13393 | max_response += bde.tus.f.bdeSize; |
| 13394 | } |
| 13395 | break; |
| 13396 | default: |
| 13397 | max_response = wcqe->total_data_placed; |
| 13398 | break; |
| 13399 | } |
| 13400 | if (max_response < wcqe->total_data_placed) |
| 13401 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response; |
| 13402 | else |
| 13403 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = |
| 13404 | wcqe->total_data_placed; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 13405 | } |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13406 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 13407 | /* Convert BG errors for completion status */ |
| 13408 | if (status == CQE_STATUS_DI_ERROR) { |
| 13409 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 13410 | |
| 13411 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) |
| 13412 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; |
| 13413 | else |
| 13414 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; |
| 13415 | |
| 13416 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; |
| 13417 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ |
| 13418 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13419 | BGS_GUARD_ERR_MASK; |
| 13420 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ |
| 13421 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13422 | BGS_APPTAG_ERR_MASK; |
| 13423 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ |
| 13424 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13425 | BGS_REFTAG_ERR_MASK; |
| 13426 | |
| 13427 | /* Check to see if there was any good data before the error */ |
| 13428 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { |
| 13429 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13430 | BGS_HI_WATER_MARK_PRESENT_MASK; |
| 13431 | pIocbIn->iocb.unsli3.sli3_bg.bghm = |
| 13432 | wcqe->total_data_placed; |
| 13433 | } |
| 13434 | |
| 13435 | /* |
| 13436 | * Set ALL the error bits to indicate we don't know what |
| 13437 | * type of error it is. |
| 13438 | */ |
| 13439 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) |
| 13440 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13441 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | |
| 13442 | BGS_GUARD_ERR_MASK); |
| 13443 | } |
| 13444 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13445 | /* Pick up HBA exchange busy condition */ |
| 13446 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
| 13447 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13448 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; |
| 13449 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13450 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13451 | } |
| 13452 | |
| 13453 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13454 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe |
| 13455 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 13456 | * @irspiocbq: Pointer to work-queue completion queue entry. |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13457 | * |
| 13458 | * This routine handles an ELS work-queue completion event and construct |
| 13459 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common |
| 13460 | * discovery engine to handle. |
| 13461 | * |
| 13462 | * Return: Pointer to the receive IOCBQ, NULL otherwise. |
| 13463 | **/ |
| 13464 | static struct lpfc_iocbq * |
| 13465 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, |
| 13466 | struct lpfc_iocbq *irspiocbq) |
| 13467 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13468 | struct lpfc_sli_ring *pring; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13469 | struct lpfc_iocbq *cmdiocbq; |
| 13470 | struct lpfc_wcqe_complete *wcqe; |
| 13471 | unsigned long iflags; |
| 13472 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13473 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 13474 | if (unlikely(!pring)) |
| 13475 | return NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13476 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13477 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13478 | pring->stats.iocb_event++; |
| 13479 | /* Look up the ELS command IOCB and create pseudo response IOCB */ |
| 13480 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 13481 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13482 | if (unlikely(!cmdiocbq)) { |
| 13483 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13484 | "0386 ELS complete with no corresponding " |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 13485 | "cmdiocb: 0x%x 0x%x 0x%x 0x%x\n", |
| 13486 | wcqe->word0, wcqe->total_data_placed, |
| 13487 | wcqe->parameter, wcqe->word3); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13488 | lpfc_sli_release_iocbq(phba, irspiocbq); |
| 13489 | return NULL; |
| 13490 | } |
| 13491 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 13492 | spin_lock_irqsave(&pring->ring_lock, iflags); |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 13493 | /* Put the iocb back on the txcmplq */ |
| 13494 | lpfc_sli_ringtxcmpl_put(phba, pring, cmdiocbq); |
| 13495 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 13496 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13497 | /* Fake the irspiocbq and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13498 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13499 | |
| 13500 | return irspiocbq; |
| 13501 | } |
| 13502 | |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13503 | inline struct lpfc_cq_event * |
| 13504 | lpfc_cq_event_setup(struct lpfc_hba *phba, void *entry, int size) |
| 13505 | { |
| 13506 | struct lpfc_cq_event *cq_event; |
| 13507 | |
| 13508 | /* Allocate a new internal CQ_EVENT entry */ |
| 13509 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 13510 | if (!cq_event) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13511 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13512 | "0602 Failed to alloc CQ_EVENT entry\n"); |
| 13513 | return NULL; |
| 13514 | } |
| 13515 | |
| 13516 | /* Move the CQE into the event */ |
| 13517 | memcpy(&cq_event->cqe, entry, size); |
| 13518 | return cq_event; |
| 13519 | } |
| 13520 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13521 | /** |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 13522 | * lpfc_sli4_sp_handle_async_event - Handle an asynchronous event |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13523 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 13524 | * @mcqe: Pointer to mailbox completion queue entry. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13525 | * |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 13526 | * This routine process a mailbox completion queue entry with asynchronous |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13527 | * event. |
| 13528 | * |
| 13529 | * Return: true if work posted to worker thread, otherwise false. |
| 13530 | **/ |
| 13531 | static bool |
| 13532 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 13533 | { |
| 13534 | struct lpfc_cq_event *cq_event; |
| 13535 | unsigned long iflags; |
| 13536 | |
| 13537 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13538 | "0392 Async Event: word0:x%x, word1:x%x, " |
| 13539 | "word2:x%x, word3:x%x\n", mcqe->word0, |
| 13540 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); |
| 13541 | |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13542 | cq_event = lpfc_cq_event_setup(phba, mcqe, sizeof(struct lpfc_mcqe)); |
| 13543 | if (!cq_event) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13544 | return false; |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 13545 | |
| 13546 | spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13547 | 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] | 13548 | spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags); |
| 13549 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13550 | /* Set the async event flag */ |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 13551 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13552 | phba->hba_flag |= ASYNC_EVENT; |
| 13553 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13554 | |
| 13555 | return true; |
| 13556 | } |
| 13557 | |
| 13558 | /** |
| 13559 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event |
| 13560 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 13561 | * @mcqe: Pointer to mailbox completion queue entry. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13562 | * |
| 13563 | * This routine process a mailbox completion queue entry with mailbox |
| 13564 | * completion event. |
| 13565 | * |
| 13566 | * Return: true if work posted to worker thread, otherwise false. |
| 13567 | **/ |
| 13568 | static bool |
| 13569 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 13570 | { |
| 13571 | uint32_t mcqe_status; |
| 13572 | MAILBOX_t *mbox, *pmbox; |
| 13573 | struct lpfc_mqe *mqe; |
| 13574 | struct lpfc_vport *vport; |
| 13575 | struct lpfc_nodelist *ndlp; |
| 13576 | struct lpfc_dmabuf *mp; |
| 13577 | unsigned long iflags; |
| 13578 | LPFC_MBOXQ_t *pmb; |
| 13579 | bool workposted = false; |
| 13580 | int rc; |
| 13581 | |
| 13582 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ |
| 13583 | if (!bf_get(lpfc_trailer_completed, mcqe)) |
| 13584 | goto out_no_mqe_complete; |
| 13585 | |
| 13586 | /* Get the reference to the active mbox command */ |
| 13587 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13588 | pmb = phba->sli.mbox_active; |
| 13589 | if (unlikely(!pmb)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13590 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13591 | "1832 No pending MBOX command to handle\n"); |
| 13592 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13593 | goto out_no_mqe_complete; |
| 13594 | } |
| 13595 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13596 | mqe = &pmb->u.mqe; |
| 13597 | pmbox = (MAILBOX_t *)&pmb->u.mqe; |
| 13598 | mbox = phba->mbox; |
| 13599 | vport = pmb->vport; |
| 13600 | |
| 13601 | /* Reset heartbeat timer */ |
| 13602 | phba->last_completion_time = jiffies; |
| 13603 | del_timer(&phba->sli.mbox_tmo); |
| 13604 | |
| 13605 | /* Move mbox data to caller's mailbox region, do endian swapping */ |
| 13606 | if (pmb->mbox_cmpl && mbox) |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13607 | lpfc_sli4_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13608 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 13609 | /* |
| 13610 | * For mcqe errors, conditionally move a modified error code to |
| 13611 | * the mbox so that the error will not be missed. |
| 13612 | */ |
| 13613 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); |
| 13614 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
| 13615 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) |
| 13616 | bf_set(lpfc_mqe_status, mqe, |
| 13617 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
| 13618 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13619 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 13620 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 13621 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, |
| 13622 | "MBOX dflt rpi: status:x%x rpi:x%x", |
| 13623 | mcqe_status, |
| 13624 | pmbox->un.varWords[0], 0); |
| 13625 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13626 | mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 13627 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | 01131e7 | 2021-05-14 12:55:49 -0700 | [diff] [blame^] | 13628 | |
| 13629 | /* Reg_LOGIN of dflt RPI was successful. Mark the |
| 13630 | * node as having an UNREG_LOGIN in progress to stop |
| 13631 | * an unsolicited PLOGI from the same NPortId from |
| 13632 | * starting another mailbox transaction. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13633 | */ |
James Smart | 01131e7 | 2021-05-14 12:55:49 -0700 | [diff] [blame^] | 13634 | spin_lock_irqsave(&ndlp->lock, iflags); |
| 13635 | ndlp->nlp_flag |= NLP_UNREG_INP; |
| 13636 | spin_unlock_irqrestore(&ndlp->lock, iflags); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13637 | lpfc_unreg_login(phba, vport->vpi, |
| 13638 | pmbox->un.varWords[0], pmb); |
| 13639 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13640 | pmb->ctx_buf = mp; |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 13641 | |
| 13642 | /* No reference taken here. This is a default |
| 13643 | * RPI reg/immediate unreg cycle. The reference was |
| 13644 | * taken in the reg rpi path and is released when |
| 13645 | * this mailbox completes. |
| 13646 | */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13647 | pmb->ctx_ndlp = ndlp; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13648 | pmb->vport = vport; |
| 13649 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 13650 | if (rc != MBX_BUSY) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13651 | lpfc_printf_log(phba, KERN_ERR, |
| 13652 | LOG_TRACE_EVENT, |
| 13653 | "0385 rc should " |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13654 | "have been MBX_BUSY\n"); |
| 13655 | if (rc != MBX_NOT_FINISHED) |
| 13656 | goto send_current_mbox; |
| 13657 | } |
| 13658 | } |
| 13659 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 13660 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 13661 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 13662 | |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 13663 | /* Do NOT queue MBX_HEARTBEAT to the worker thread for processing. */ |
| 13664 | if (pmbox->mbxCommand == MBX_HEARTBEAT) { |
| 13665 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13666 | /* Release the mailbox command posting token */ |
| 13667 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 13668 | phba->sli.mbox_active = NULL; |
| 13669 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 13670 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
| 13671 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13672 | |
| 13673 | /* Post the next mbox command, if there is one */ |
| 13674 | lpfc_sli4_post_async_mbox(phba); |
| 13675 | |
| 13676 | /* Process cmpl now */ |
| 13677 | if (pmb->mbox_cmpl) |
| 13678 | pmb->mbox_cmpl(phba, pmb); |
| 13679 | return false; |
| 13680 | } |
| 13681 | |
| 13682 | /* There is mailbox completion work to queue to the worker thread */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13683 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13684 | __lpfc_mbox_cmpl_put(phba, pmb); |
| 13685 | phba->work_ha |= HA_MBATT; |
| 13686 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13687 | workposted = true; |
| 13688 | |
| 13689 | send_current_mbox: |
| 13690 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13691 | /* Release the mailbox command posting token */ |
| 13692 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 13693 | /* Setting active mailbox pointer need to be in sync to flag clear */ |
| 13694 | phba->sli.mbox_active = NULL; |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame] | 13695 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 13696 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13697 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13698 | /* Wake up worker thread to post the next pending mailbox command */ |
| 13699 | lpfc_worker_wake_up(phba); |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame] | 13700 | return workposted; |
| 13701 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13702 | out_no_mqe_complete: |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame] | 13703 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13704 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 13705 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame] | 13706 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13707 | return false; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13708 | } |
| 13709 | |
| 13710 | /** |
| 13711 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry |
| 13712 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 13713 | * @cq: Pointer to associated CQ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13714 | * @cqe: Pointer to mailbox completion queue entry. |
| 13715 | * |
| 13716 | * This routine process a mailbox completion queue entry, it invokes the |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 13717 | * proper mailbox complete handling or asynchronous event handling routine |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13718 | * according to the MCQE's async bit. |
| 13719 | * |
| 13720 | * Return: true if work posted to worker thread, otherwise false. |
| 13721 | **/ |
| 13722 | static bool |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13723 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13724 | struct lpfc_cqe *cqe) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13725 | { |
| 13726 | struct lpfc_mcqe mcqe; |
| 13727 | bool workposted; |
| 13728 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13729 | cq->CQ_mbox++; |
| 13730 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13731 | /* Copy the mailbox MCQE and convert endian order as needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13732 | lpfc_sli4_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13733 | |
| 13734 | /* Invoke the proper event handling routine */ |
| 13735 | if (!bf_get(lpfc_trailer_async, &mcqe)) |
| 13736 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); |
| 13737 | else |
| 13738 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); |
| 13739 | return workposted; |
| 13740 | } |
| 13741 | |
| 13742 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13743 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event |
| 13744 | * @phba: Pointer to HBA context object. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13745 | * @cq: Pointer to associated CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13746 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13747 | * |
| 13748 | * This routine handles an ELS work-queue completion event. |
| 13749 | * |
| 13750 | * Return: true if work posted to worker thread, otherwise false. |
| 13751 | **/ |
| 13752 | static bool |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13753 | 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] | 13754 | struct lpfc_wcqe_complete *wcqe) |
| 13755 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13756 | struct lpfc_iocbq *irspiocbq; |
| 13757 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13758 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13759 | int txq_cnt = 0; |
| 13760 | int txcmplq_cnt = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13761 | |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 13762 | /* Check for response status */ |
| 13763 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 13764 | /* Log the error status */ |
| 13765 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13766 | "0357 ELS CQE error: status=x%x: " |
| 13767 | "CQE: %08x %08x %08x %08x\n", |
| 13768 | bf_get(lpfc_wcqe_c_status, wcqe), |
| 13769 | wcqe->word0, wcqe->total_data_placed, |
| 13770 | wcqe->parameter, wcqe->word3); |
| 13771 | } |
| 13772 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13773 | /* Get an irspiocbq for later ELS response processing use */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13774 | irspiocbq = lpfc_sli_get_iocbq(phba); |
| 13775 | if (!irspiocbq) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13776 | if (!list_empty(&pring->txq)) |
| 13777 | txq_cnt++; |
| 13778 | if (!list_empty(&pring->txcmplq)) |
| 13779 | txcmplq_cnt++; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13780 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 13781 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
James Smart | ff349bc | 2019-09-21 20:59:05 -0700 | [diff] [blame] | 13782 | "els_txcmplq_cnt=%d\n", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13783 | txq_cnt, phba->iocb_cnt, |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13784 | txcmplq_cnt); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13785 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13786 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13787 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13788 | /* Save off the slow-path queue event for work thread to process */ |
| 13789 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13790 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13791 | list_add_tail(&irspiocbq->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13792 | &phba->sli4_hba.sp_queue_event); |
| 13793 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13794 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13795 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13796 | return true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13797 | } |
| 13798 | |
| 13799 | /** |
| 13800 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event |
| 13801 | * @phba: Pointer to HBA context object. |
| 13802 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13803 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 13804 | * This routine handles slow-path WQ entry consumed event by invoking the |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13805 | * proper WQ release routine to the slow-path WQ. |
| 13806 | **/ |
| 13807 | static void |
| 13808 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, |
| 13809 | struct lpfc_wcqe_release *wcqe) |
| 13810 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13811 | /* sanity check on queue memory */ |
| 13812 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 13813 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13814 | /* Check for the slow-path ELS work queue */ |
| 13815 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) |
| 13816 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, |
| 13817 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 13818 | else |
| 13819 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13820 | "2579 Slow-path wqe consume event carries " |
| 13821 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", |
| 13822 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), |
| 13823 | phba->sli4_hba.els_wq->queue_id); |
| 13824 | } |
| 13825 | |
| 13826 | /** |
| 13827 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event |
| 13828 | * @phba: Pointer to HBA context object. |
| 13829 | * @cq: Pointer to a WQ completion queue. |
| 13830 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13831 | * |
| 13832 | * This routine handles an XRI abort event. |
| 13833 | * |
| 13834 | * Return: true if work posted to worker thread, otherwise false. |
| 13835 | **/ |
| 13836 | static bool |
| 13837 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, |
| 13838 | struct lpfc_queue *cq, |
| 13839 | struct sli4_wcqe_xri_aborted *wcqe) |
| 13840 | { |
| 13841 | bool workposted = false; |
| 13842 | struct lpfc_cq_event *cq_event; |
| 13843 | unsigned long iflags; |
| 13844 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13845 | switch (cq->subtype) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 13846 | case LPFC_IO: |
| 13847 | lpfc_sli4_io_xri_aborted(phba, wcqe, cq->hdwq); |
| 13848 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 13849 | /* Notify aborted XRI for NVME work queue */ |
| 13850 | if (phba->nvmet_support) |
| 13851 | lpfc_sli4_nvmet_xri_aborted(phba, wcqe); |
| 13852 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13853 | workposted = false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13854 | break; |
James Smart | 422c4cb | 2017-11-20 16:00:32 -0800 | [diff] [blame] | 13855 | case LPFC_NVME_LS: /* NVME LS uses ELS resources */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13856 | case LPFC_ELS: |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 13857 | cq_event = lpfc_cq_event_setup(phba, wcqe, sizeof(*wcqe)); |
| 13858 | if (!cq_event) { |
| 13859 | workposted = false; |
| 13860 | break; |
| 13861 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13862 | cq_event->hdwq = cq->hdwq; |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 13863 | spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock, |
| 13864 | iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13865 | list_add_tail(&cq_event->list, |
| 13866 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 13867 | /* Set the els xri abort event flag */ |
| 13868 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 13869 | spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock, |
| 13870 | iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13871 | workposted = true; |
| 13872 | break; |
| 13873 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13874 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 13875 | "0603 Invalid CQ subtype %d: " |
| 13876 | "%08x %08x %08x %08x\n", |
| 13877 | cq->subtype, wcqe->word0, wcqe->parameter, |
| 13878 | wcqe->word2, wcqe->word3); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13879 | workposted = false; |
| 13880 | break; |
| 13881 | } |
| 13882 | return workposted; |
| 13883 | } |
| 13884 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13885 | #define FC_RCTL_MDS_DIAGS 0xF4 |
| 13886 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13887 | /** |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13888 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13889 | * @phba: Pointer to HBA context object. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13890 | * @rcqe: Pointer to receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13891 | * |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13892 | * This routine process a receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13893 | * |
| 13894 | * Return: true if work posted to worker thread, otherwise false. |
| 13895 | **/ |
| 13896 | static bool |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13897 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
| 13898 | { |
| 13899 | bool workposted = false; |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13900 | struct fc_frame_header *fc_hdr; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13901 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; |
| 13902 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13903 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13904 | struct hbq_dmabuf *dma_buf; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13905 | uint32_t status, rq_id; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13906 | unsigned long iflags; |
| 13907 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13908 | /* sanity check on queue memory */ |
| 13909 | if (unlikely(!hrq) || unlikely(!drq)) |
| 13910 | return workposted; |
| 13911 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13912 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 13913 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 13914 | else |
| 13915 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 13916 | if (rq_id != hrq->queue_id) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13917 | goto out; |
| 13918 | |
| 13919 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 13920 | switch (status) { |
| 13921 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13922 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13923 | "2537 Receive Frame Truncated!!\n"); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 13924 | fallthrough; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13925 | case FC_STATUS_RQ_SUCCESS: |
| 13926 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 13927 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13928 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); |
| 13929 | if (!dma_buf) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13930 | hrq->RQ_no_buf_found++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13931 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13932 | goto out; |
| 13933 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13934 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13935 | hrq->RQ_buf_posted--; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13936 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13937 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13938 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 13939 | |
| 13940 | if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS || |
| 13941 | fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) { |
| 13942 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13943 | /* Handle MDS Loopback frames */ |
Dick Kennedy | 24411fc | 2020-08-03 14:02:25 -0700 | [diff] [blame] | 13944 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 13945 | lpfc_sli4_handle_mds_loopback(phba->pport, |
| 13946 | dma_buf); |
| 13947 | else |
| 13948 | lpfc_in_buf_free(phba, &dma_buf->dbuf); |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13949 | break; |
| 13950 | } |
| 13951 | |
| 13952 | /* save off the frame for the work thread to process */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13953 | list_add_tail(&dma_buf->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13954 | &phba->sli4_hba.sp_queue_event); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13955 | /* Frame received */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13956 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13957 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13958 | workposted = true; |
| 13959 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13960 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13961 | if (phba->nvmet_support) { |
| 13962 | tgtp = phba->targetport->private; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13963 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13964 | "6402 RQE Error x%x, posted %d err_cnt " |
| 13965 | "%d: %x %x %x\n", |
| 13966 | status, hrq->RQ_buf_posted, |
| 13967 | hrq->RQ_no_posted_buf, |
| 13968 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 13969 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 13970 | atomic_read(&tgtp->xmt_fcp_release)); |
| 13971 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 13972 | fallthrough; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13973 | |
| 13974 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13975 | hrq->RQ_no_posted_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13976 | /* Post more buffers if possible */ |
| 13977 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13978 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; |
| 13979 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13980 | workposted = true; |
| 13981 | break; |
| 13982 | } |
| 13983 | out: |
| 13984 | return workposted; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13985 | } |
| 13986 | |
| 13987 | /** |
| 13988 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry |
| 13989 | * @phba: Pointer to HBA context object. |
| 13990 | * @cq: Pointer to the completion queue. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13991 | * @cqe: Pointer to a completion queue entry. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13992 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 13993 | * 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] | 13994 | * entry. |
| 13995 | * |
| 13996 | * Return: true if work posted to worker thread, otherwise false. |
| 13997 | **/ |
| 13998 | static bool |
| 13999 | 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] | 14000 | struct lpfc_cqe *cqe) |
| 14001 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14002 | struct lpfc_cqe cqevt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14003 | bool workposted = false; |
| 14004 | |
| 14005 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 14006 | lpfc_sli4_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14007 | |
| 14008 | /* Check and process for different type of WCQE and dispatch */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14009 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14010 | case CQE_CODE_COMPL_WQE: |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14011 | /* Process the WQ/RQ complete event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 14012 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 14013 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14014 | (struct lpfc_wcqe_complete *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14015 | break; |
| 14016 | case CQE_CODE_RELEASE_WQE: |
| 14017 | /* Process the WQ release event */ |
| 14018 | lpfc_sli4_sp_handle_rel_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14019 | (struct lpfc_wcqe_release *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14020 | break; |
| 14021 | case CQE_CODE_XRI_ABORTED: |
| 14022 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 14023 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14024 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14025 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14026 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14027 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14028 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14029 | /* Process the RQ event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 14030 | phba->last_completion_time = jiffies; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14031 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14032 | (struct lpfc_rcqe *)&cqevt); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14033 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14034 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14035 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14036 | "0388 Not a valid WCQE code: x%x\n", |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14037 | bf_get(lpfc_cqe_code, &cqevt)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14038 | break; |
| 14039 | } |
| 14040 | return workposted; |
| 14041 | } |
| 14042 | |
| 14043 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14044 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry |
| 14045 | * @phba: Pointer to HBA context object. |
| 14046 | * @eqe: Pointer to fast-path event queue entry. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 14047 | * @speq: Pointer to slow-path event queue. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14048 | * |
| 14049 | * This routine process a event queue entry from the slow-path event queue. |
| 14050 | * It will check the MajorCode and MinorCode to determine this is for a |
| 14051 | * completion event on a completion queue, if not, an error shall be logged |
| 14052 | * and just return. Otherwise, it will get to the corresponding completion |
| 14053 | * queue and process all the entries on that completion queue, rearm the |
| 14054 | * completion queue, and then return. |
| 14055 | * |
| 14056 | **/ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14057 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14058 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 14059 | struct lpfc_queue *speq) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14060 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14061 | struct lpfc_queue *cq = NULL, *childq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14062 | uint16_t cqid; |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 14063 | int ret = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14064 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14065 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14066 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14067 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14068 | list_for_each_entry(childq, &speq->child_list, list) { |
| 14069 | if (childq->queue_id == cqid) { |
| 14070 | cq = childq; |
| 14071 | break; |
| 14072 | } |
| 14073 | } |
| 14074 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 14075 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14076 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 14077 | "0365 Slow-path CQ identifier " |
| 14078 | "(%d) does not exist\n", cqid); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14079 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14080 | } |
| 14081 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14082 | /* Save EQ associated with this CQ */ |
| 14083 | cq->assoc_qp = speq; |
| 14084 | |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 14085 | if (is_kdump_kernel()) |
| 14086 | ret = queue_work(phba->wq, &cq->spwork); |
| 14087 | else |
| 14088 | ret = queue_work_on(cq->chann, phba->wq, &cq->spwork); |
| 14089 | |
| 14090 | if (!ret) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14091 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 14092 | "0390 Cannot schedule queue work " |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14093 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
Bart Van Assche | d6d189c | 2019-03-28 11:06:22 -0700 | [diff] [blame] | 14094 | cqid, cq->queue_id, raw_smp_processor_id()); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14095 | } |
| 14096 | |
| 14097 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14098 | * __lpfc_sli4_process_cq - Process elements of a CQ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14099 | * @phba: Pointer to HBA context object. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14100 | * @cq: Pointer to CQ to be processed |
| 14101 | * @handler: Routine to process each cqe |
| 14102 | * @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] | 14103 | * @poll_mode: Polling mode we were called from |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14104 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14105 | * This routine processes completion queue entries in a CQ. While a valid |
| 14106 | * queue element is found, the handler is called. During processing checks |
| 14107 | * are made for periodic doorbell writes to let the hardware know of |
| 14108 | * element consumption. |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14109 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14110 | * If the max limit on cqes to process is hit, or there are no more valid |
| 14111 | * entries, the loop stops. If we processed a sufficient number of elements, |
| 14112 | * meaning there is sufficient load, rather than rearming and generating |
| 14113 | * another interrupt, a cq rescheduling delay will be set. A delay of 0 |
| 14114 | * indicates no rescheduling. |
| 14115 | * |
| 14116 | * Returns True if work scheduled, False otherwise. |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14117 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14118 | static bool |
| 14119 | __lpfc_sli4_process_cq(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 14120 | bool (*handler)(struct lpfc_hba *, struct lpfc_queue *, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 14121 | struct lpfc_cqe *), unsigned long *delay, |
| 14122 | enum lpfc_poll_mode poll_mode) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14123 | { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14124 | struct lpfc_cqe *cqe; |
| 14125 | bool workposted = false; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14126 | int count = 0, consumed = 0; |
| 14127 | bool arm = true; |
| 14128 | |
| 14129 | /* default - no reschedule */ |
| 14130 | *delay = 0; |
| 14131 | |
| 14132 | if (cmpxchg(&cq->queue_claimed, 0, 1) != 0) |
| 14133 | goto rearm_and_exit; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14134 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14135 | /* Process all the entries to the CQ */ |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 14136 | cq->q_flag = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14137 | cqe = lpfc_sli4_cq_get(cq); |
| 14138 | while (cqe) { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14139 | workposted |= handler(phba, cq, cqe); |
| 14140 | __lpfc_sli4_consume_cqe(phba, cq, cqe); |
| 14141 | |
| 14142 | consumed++; |
| 14143 | if (!(++count % cq->max_proc_limit)) |
| 14144 | break; |
| 14145 | |
| 14146 | if (!(count % cq->notify_interval)) { |
| 14147 | phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed, |
| 14148 | LPFC_QUEUE_NOARM); |
| 14149 | consumed = 0; |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 14150 | cq->assoc_qp->q_flag |= HBA_EQ_DELAY_CHK; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14151 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14152 | |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 14153 | if (count == LPFC_NVMET_CQ_NOTIFY) |
| 14154 | cq->q_flag |= HBA_NVMET_CQ_NOTIFY; |
| 14155 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14156 | cqe = lpfc_sli4_cq_get(cq); |
| 14157 | } |
| 14158 | if (count >= phba->cfg_cq_poll_threshold) { |
| 14159 | *delay = 1; |
| 14160 | arm = false; |
| 14161 | } |
| 14162 | |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 14163 | /* Note: complete the irq_poll softirq before rearming CQ */ |
| 14164 | if (poll_mode == LPFC_IRQ_POLL) |
| 14165 | irq_poll_complete(&cq->iop); |
| 14166 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14167 | /* Track the max number of CQEs processed in 1 EQ */ |
| 14168 | if (count > cq->CQ_max_cqe) |
| 14169 | cq->CQ_max_cqe = count; |
| 14170 | |
| 14171 | cq->assoc_qp->EQ_cqe_cnt += count; |
| 14172 | |
| 14173 | /* Catch the no cq entry condition */ |
| 14174 | if (unlikely(count == 0)) |
| 14175 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 14176 | "0369 No entry from completion queue " |
| 14177 | "qid=%d\n", cq->queue_id); |
| 14178 | |
Dick Kennedy | 164ba8d | 2020-05-01 14:43:03 -0700 | [diff] [blame] | 14179 | xchg(&cq->queue_claimed, 0); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14180 | |
| 14181 | rearm_and_exit: |
| 14182 | phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed, |
| 14183 | arm ? LPFC_QUEUE_REARM : LPFC_QUEUE_NOARM); |
| 14184 | |
| 14185 | return workposted; |
| 14186 | } |
| 14187 | |
| 14188 | /** |
Lee Jones | 8514e2f | 2021-03-03 14:46:18 +0000 | [diff] [blame] | 14189 | * __lpfc_sli4_sp_process_cq - Process a slow-path event queue entry |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14190 | * @cq: pointer to CQ to process |
| 14191 | * |
| 14192 | * This routine calls the cq processing routine with a handler specific |
| 14193 | * to the type of queue bound to it. |
| 14194 | * |
| 14195 | * The CQ routine returns two values: the first is the calling status, |
| 14196 | * which indicates whether work was queued to the background discovery |
| 14197 | * thread. If true, the routine should wakeup the discovery thread; |
| 14198 | * the second is the delay parameter. If non-zero, rather than rearming |
| 14199 | * the CQ and yet another interrupt, the CQ handler should be queued so |
| 14200 | * that it is processed in a subsequent polling action. The value of |
| 14201 | * the delay indicates when to reschedule it. |
| 14202 | **/ |
| 14203 | static void |
| 14204 | __lpfc_sli4_sp_process_cq(struct lpfc_queue *cq) |
| 14205 | { |
| 14206 | struct lpfc_hba *phba = cq->phba; |
| 14207 | unsigned long delay; |
| 14208 | bool workposted = false; |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 14209 | int ret = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14210 | |
| 14211 | /* Process and rearm the CQ */ |
| 14212 | switch (cq->type) { |
| 14213 | case LPFC_MCQ: |
| 14214 | workposted |= __lpfc_sli4_process_cq(phba, cq, |
| 14215 | lpfc_sli4_sp_handle_mcqe, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 14216 | &delay, LPFC_QUEUE_WORK); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14217 | break; |
| 14218 | case LPFC_WCQ: |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 14219 | if (cq->subtype == LPFC_IO) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14220 | workposted |= __lpfc_sli4_process_cq(phba, cq, |
| 14221 | lpfc_sli4_fp_handle_cqe, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 14222 | &delay, LPFC_QUEUE_WORK); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14223 | else |
| 14224 | workposted |= __lpfc_sli4_process_cq(phba, cq, |
| 14225 | lpfc_sli4_sp_handle_cqe, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 14226 | &delay, LPFC_QUEUE_WORK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14227 | break; |
| 14228 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14229 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14230 | "0370 Invalid completion queue type (%d)\n", |
| 14231 | cq->type); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14232 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14233 | } |
| 14234 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14235 | if (delay) { |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 14236 | if (is_kdump_kernel()) |
| 14237 | ret = queue_delayed_work(phba->wq, &cq->sched_spwork, |
| 14238 | delay); |
| 14239 | else |
| 14240 | ret = queue_delayed_work_on(cq->chann, phba->wq, |
| 14241 | &cq->sched_spwork, delay); |
| 14242 | if (!ret) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14243 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 14244 | "0394 Cannot schedule queue work " |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14245 | "for cqid=%d on CPU %d\n", |
| 14246 | cq->queue_id, cq->chann); |
| 14247 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14248 | |
| 14249 | /* wake up worker thread if there are works to be done */ |
| 14250 | if (workposted) |
| 14251 | lpfc_worker_wake_up(phba); |
| 14252 | } |
| 14253 | |
| 14254 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14255 | * lpfc_sli4_sp_process_cq - slow-path work handler when started by |
| 14256 | * interrupt |
| 14257 | * @work: pointer to work element |
| 14258 | * |
| 14259 | * translates from the work handler and calls the slow-path handler. |
| 14260 | **/ |
| 14261 | static void |
| 14262 | lpfc_sli4_sp_process_cq(struct work_struct *work) |
| 14263 | { |
| 14264 | struct lpfc_queue *cq = container_of(work, struct lpfc_queue, spwork); |
| 14265 | |
| 14266 | __lpfc_sli4_sp_process_cq(cq); |
| 14267 | } |
| 14268 | |
| 14269 | /** |
| 14270 | * lpfc_sli4_dly_sp_process_cq - slow-path work handler when started by timer |
| 14271 | * @work: pointer to work element |
| 14272 | * |
| 14273 | * translates from the work handler and calls the slow-path handler. |
| 14274 | **/ |
| 14275 | static void |
| 14276 | lpfc_sli4_dly_sp_process_cq(struct work_struct *work) |
| 14277 | { |
| 14278 | struct lpfc_queue *cq = container_of(to_delayed_work(work), |
| 14279 | struct lpfc_queue, sched_spwork); |
| 14280 | |
| 14281 | __lpfc_sli4_sp_process_cq(cq); |
| 14282 | } |
| 14283 | |
| 14284 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14285 | * 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] | 14286 | * @phba: Pointer to HBA context object. |
| 14287 | * @cq: Pointer to associated CQ |
| 14288 | * @wcqe: Pointer to work-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14289 | * |
| 14290 | * This routine process a fast-path work queue completion entry from fast-path |
| 14291 | * event queue for FCP command response completion. |
| 14292 | **/ |
| 14293 | static void |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 14294 | 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] | 14295 | struct lpfc_wcqe_complete *wcqe) |
| 14296 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 14297 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14298 | struct lpfc_iocbq *cmdiocbq; |
| 14299 | struct lpfc_iocbq irspiocbq; |
| 14300 | unsigned long iflags; |
| 14301 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14302 | /* Check for response status */ |
| 14303 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 14304 | /* If resource errors reported from HBA, reduce queue |
| 14305 | * depth of the SCSI device. |
| 14306 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 14307 | if (((bf_get(lpfc_wcqe_c_status, wcqe) == |
| 14308 | IOSTAT_LOCAL_REJECT)) && |
| 14309 | ((wcqe->parameter & IOERR_PARAM_MASK) == |
| 14310 | IOERR_NO_RESOURCES)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14311 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 14312 | |
Dick Kennedy | 28ed737 | 2020-06-30 14:49:56 -0700 | [diff] [blame] | 14313 | /* Log the cmpl status */ |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 14314 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
Dick Kennedy | 28ed737 | 2020-06-30 14:49:56 -0700 | [diff] [blame] | 14315 | "0373 FCP CQE cmpl: status=x%x: " |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 14316 | "CQE: %08x %08x %08x %08x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14317 | bf_get(lpfc_wcqe_c_status, wcqe), |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 14318 | wcqe->word0, wcqe->total_data_placed, |
| 14319 | wcqe->parameter, wcqe->word3); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14320 | } |
| 14321 | |
| 14322 | /* Look up the FCP command IOCB and create pseudo response IOCB */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 14323 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 14324 | pring->stats.iocb_event++; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 14325 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14326 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 14327 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14328 | if (unlikely(!cmdiocbq)) { |
| 14329 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 14330 | "0374 FCP complete with no corresponding " |
| 14331 | "cmdiocb: iotag (%d)\n", |
| 14332 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 14333 | return; |
| 14334 | } |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 14335 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 14336 | cmdiocbq->isr_timestamp = cq->isr_timestamp; |
| 14337 | #endif |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14338 | if (cmdiocbq->iocb_cmpl == NULL) { |
| 14339 | if (cmdiocbq->wqe_cmpl) { |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 14340 | /* For FCP the flag is cleared in wqe_cmpl */ |
| 14341 | if (!(cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 14342 | cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14343 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 14344 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 14345 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 14346 | } |
| 14347 | |
| 14348 | /* Pass the cmd_iocb and the wcqe to the upper layer */ |
| 14349 | (cmdiocbq->wqe_cmpl)(phba, cmdiocbq, wcqe); |
| 14350 | return; |
| 14351 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14352 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 14353 | "0375 FCP cmdiocb not callback function " |
| 14354 | "iotag: (%d)\n", |
| 14355 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 14356 | return; |
| 14357 | } |
| 14358 | |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 14359 | /* Only SLI4 non-IO commands stil use IOCB */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14360 | /* Fake the irspiocb and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 14361 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14362 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 14363 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 14364 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 14365 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 14366 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 14367 | } |
| 14368 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14369 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
| 14370 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); |
| 14371 | } |
| 14372 | |
| 14373 | /** |
| 14374 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event |
| 14375 | * @phba: Pointer to HBA context object. |
| 14376 | * @cq: Pointer to completion queue. |
| 14377 | * @wcqe: Pointer to work-queue completion queue entry. |
| 14378 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 14379 | * 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] | 14380 | * proper WQ release routine to the slow-path WQ. |
| 14381 | **/ |
| 14382 | static void |
| 14383 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 14384 | struct lpfc_wcqe_release *wcqe) |
| 14385 | { |
| 14386 | struct lpfc_queue *childwq; |
| 14387 | bool wqid_matched = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14388 | uint16_t hba_wqid; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14389 | |
| 14390 | /* Check for fast-path FCP work queue release */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14391 | hba_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14392 | list_for_each_entry(childwq, &cq->child_list, list) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14393 | if (childwq->queue_id == hba_wqid) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14394 | lpfc_sli4_wq_release(childwq, |
| 14395 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
James Smart | 6e8e1c1 | 2018-01-30 15:58:49 -0800 | [diff] [blame] | 14396 | if (childwq->q_flag & HBA_NVMET_WQFULL) |
| 14397 | lpfc_nvmet_wqfull_process(phba, childwq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14398 | wqid_matched = true; |
| 14399 | break; |
| 14400 | } |
| 14401 | } |
| 14402 | /* Report warning log message if no match found */ |
| 14403 | if (wqid_matched != true) |
| 14404 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 14405 | "2580 Fast-path wqe consume event carries " |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14406 | "miss-matched qid: wcqe-qid=x%x\n", hba_wqid); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14407 | } |
| 14408 | |
| 14409 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14410 | * lpfc_sli4_nvmet_handle_rcqe - Process a receive-queue completion queue entry |
| 14411 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 14412 | * @cq: Pointer to completion queue. |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14413 | * @rcqe: Pointer to receive-queue completion queue entry. |
| 14414 | * |
| 14415 | * This routine process a receive-queue completion queue entry. |
| 14416 | * |
| 14417 | * Return: true if work posted to worker thread, otherwise false. |
| 14418 | **/ |
| 14419 | static bool |
| 14420 | lpfc_sli4_nvmet_handle_rcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 14421 | struct lpfc_rcqe *rcqe) |
| 14422 | { |
| 14423 | bool workposted = false; |
| 14424 | struct lpfc_queue *hrq; |
| 14425 | struct lpfc_queue *drq; |
| 14426 | struct rqb_dmabuf *dma_buf; |
| 14427 | struct fc_frame_header *fc_hdr; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 14428 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14429 | uint32_t status, rq_id; |
| 14430 | unsigned long iflags; |
| 14431 | uint32_t fctl, idx; |
| 14432 | |
| 14433 | if ((phba->nvmet_support == 0) || |
| 14434 | (phba->sli4_hba.nvmet_cqset == NULL)) |
| 14435 | return workposted; |
| 14436 | |
| 14437 | idx = cq->queue_id - phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 14438 | hrq = phba->sli4_hba.nvmet_mrq_hdr[idx]; |
| 14439 | drq = phba->sli4_hba.nvmet_mrq_data[idx]; |
| 14440 | |
| 14441 | /* sanity check on queue memory */ |
| 14442 | if (unlikely(!hrq) || unlikely(!drq)) |
| 14443 | return workposted; |
| 14444 | |
| 14445 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 14446 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 14447 | else |
| 14448 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 14449 | |
| 14450 | if ((phba->nvmet_support == 0) || |
| 14451 | (rq_id != hrq->queue_id)) |
| 14452 | return workposted; |
| 14453 | |
| 14454 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 14455 | switch (status) { |
| 14456 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14457 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14458 | "6126 Receive Frame Truncated!!\n"); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 14459 | fallthrough; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14460 | case FC_STATUS_RQ_SUCCESS: |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14461 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 14462 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14463 | dma_buf = lpfc_sli_rqbuf_get(phba, hrq); |
| 14464 | if (!dma_buf) { |
| 14465 | hrq->RQ_no_buf_found++; |
| 14466 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 14467 | goto out; |
| 14468 | } |
| 14469 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 14470 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 14471 | hrq->RQ_buf_posted--; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14472 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 14473 | |
| 14474 | /* Just some basic sanity checks on FCP Command frame */ |
| 14475 | fctl = (fc_hdr->fh_f_ctl[0] << 16 | |
James Smart | 3a8070c | 2020-03-31 09:50:05 -0700 | [diff] [blame] | 14476 | fc_hdr->fh_f_ctl[1] << 8 | |
| 14477 | fc_hdr->fh_f_ctl[2]); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14478 | if (((fctl & |
| 14479 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) != |
| 14480 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) || |
| 14481 | (fc_hdr->fh_seq_cnt != 0)) /* 0 byte swapped is still 0 */ |
| 14482 | goto drop; |
| 14483 | |
| 14484 | if (fc_hdr->fh_type == FC_TYPE_FCP) { |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 14485 | dma_buf->bytes_recv = bf_get(lpfc_rcqe_length, rcqe); |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 14486 | lpfc_nvmet_unsol_fcp_event( |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 14487 | phba, idx, dma_buf, cq->isr_timestamp, |
| 14488 | cq->q_flag & HBA_NVMET_CQ_NOTIFY); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14489 | return false; |
| 14490 | } |
| 14491 | drop: |
James Smart | 22b738a | 2019-03-12 16:30:11 -0700 | [diff] [blame] | 14492 | lpfc_rq_buf_free(phba, &dma_buf->hbuf); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14493 | break; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14494 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 14495 | if (phba->nvmet_support) { |
| 14496 | tgtp = phba->targetport->private; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14497 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 14498 | "6401 RQE Error x%x, posted %d err_cnt " |
| 14499 | "%d: %x %x %x\n", |
| 14500 | status, hrq->RQ_buf_posted, |
| 14501 | hrq->RQ_no_posted_buf, |
| 14502 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 14503 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 14504 | atomic_read(&tgtp->xmt_fcp_release)); |
| 14505 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 14506 | fallthrough; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 14507 | |
| 14508 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14509 | hrq->RQ_no_posted_buf++; |
| 14510 | /* Post more buffers if possible */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14511 | break; |
| 14512 | } |
| 14513 | out: |
| 14514 | return workposted; |
| 14515 | } |
| 14516 | |
| 14517 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14518 | * lpfc_sli4_fp_handle_cqe - Process fast-path work queue completion entry |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14519 | * @phba: adapter with cq |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14520 | * @cq: Pointer to the completion queue. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 14521 | * @cqe: Pointer to fast-path completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14522 | * |
| 14523 | * This routine process a fast-path work queue completion entry from fast-path |
| 14524 | * event queue for FCP command response completion. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14525 | * |
| 14526 | * Return: true if work posted to worker thread, otherwise false. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14527 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14528 | static bool |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14529 | 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] | 14530 | struct lpfc_cqe *cqe) |
| 14531 | { |
| 14532 | struct lpfc_wcqe_release wcqe; |
| 14533 | bool workposted = false; |
| 14534 | |
| 14535 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 14536 | lpfc_sli4_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14537 | |
| 14538 | /* Check and process for different type of WCQE and dispatch */ |
| 14539 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { |
| 14540 | case CQE_CODE_COMPL_WQE: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14541 | case CQE_CODE_NVME_ERSP: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14542 | cq->CQ_wq++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14543 | /* Process the WQ complete event */ |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 14544 | phba->last_completion_time = jiffies; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 14545 | if (cq->subtype == LPFC_IO || cq->subtype == LPFC_NVME_LS) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14546 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14547 | (struct lpfc_wcqe_complete *)&wcqe); |
| 14548 | break; |
| 14549 | case CQE_CODE_RELEASE_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14550 | cq->CQ_release_wqe++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14551 | /* Process the WQ release event */ |
| 14552 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, |
| 14553 | (struct lpfc_wcqe_release *)&wcqe); |
| 14554 | break; |
| 14555 | case CQE_CODE_XRI_ABORTED: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14556 | cq->CQ_xri_aborted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14557 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 14558 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14559 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
| 14560 | (struct sli4_wcqe_xri_aborted *)&wcqe); |
| 14561 | break; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14562 | case CQE_CODE_RECEIVE_V1: |
| 14563 | case CQE_CODE_RECEIVE: |
| 14564 | phba->last_completion_time = jiffies; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14565 | if (cq->subtype == LPFC_NVMET) { |
| 14566 | workposted = lpfc_sli4_nvmet_handle_rcqe( |
| 14567 | phba, cq, (struct lpfc_rcqe *)&wcqe); |
| 14568 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14569 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14570 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14571 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14572 | "0144 Not a valid CQE code: x%x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14573 | bf_get(lpfc_wcqe_c_code, &wcqe)); |
| 14574 | break; |
| 14575 | } |
| 14576 | return workposted; |
| 14577 | } |
| 14578 | |
| 14579 | /** |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 14580 | * lpfc_sli4_sched_cq_work - Schedules cq work |
| 14581 | * @phba: Pointer to HBA context object. |
| 14582 | * @cq: Pointer to CQ |
| 14583 | * @cqid: CQ ID |
| 14584 | * |
| 14585 | * This routine checks the poll mode of the CQ corresponding to |
| 14586 | * cq->chann, then either schedules a softirq or queue_work to complete |
| 14587 | * cq work. |
| 14588 | * |
| 14589 | * queue_work path is taken if in NVMET mode, or if poll_mode is in |
| 14590 | * LPFC_QUEUE_WORK mode. Otherwise, softirq path is taken. |
| 14591 | * |
| 14592 | **/ |
| 14593 | static void lpfc_sli4_sched_cq_work(struct lpfc_hba *phba, |
| 14594 | struct lpfc_queue *cq, uint16_t cqid) |
| 14595 | { |
| 14596 | int ret = 0; |
| 14597 | |
| 14598 | switch (cq->poll_mode) { |
| 14599 | case LPFC_IRQ_POLL: |
| 14600 | irq_poll_sched(&cq->iop); |
| 14601 | break; |
| 14602 | case LPFC_QUEUE_WORK: |
| 14603 | default: |
| 14604 | if (is_kdump_kernel()) |
| 14605 | ret = queue_work(phba->wq, &cq->irqwork); |
| 14606 | else |
| 14607 | ret = queue_work_on(cq->chann, phba->wq, &cq->irqwork); |
| 14608 | if (!ret) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14609 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 14610 | "0383 Cannot schedule queue work " |
| 14611 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
| 14612 | cqid, cq->queue_id, |
| 14613 | raw_smp_processor_id()); |
| 14614 | } |
| 14615 | } |
| 14616 | |
| 14617 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14618 | * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14619 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 14620 | * @eq: Pointer to the queue structure. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14621 | * @eqe: Pointer to fast-path event queue entry. |
| 14622 | * |
| 14623 | * This routine process a event queue entry from the fast-path event queue. |
| 14624 | * It will check the MajorCode and MinorCode to determine this is for a |
| 14625 | * completion event on a completion queue, if not, an error shall be logged |
| 14626 | * and just return. Otherwise, it will get to the corresponding completion |
| 14627 | * queue and process all the entries on the completion queue, rearm the |
| 14628 | * completion queue, and then return. |
| 14629 | **/ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14630 | static void |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14631 | lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_queue *eq, |
| 14632 | struct lpfc_eqe *eqe) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14633 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14634 | struct lpfc_queue *cq = NULL; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14635 | uint32_t qidx = eq->hdwq; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14636 | uint16_t cqid, id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14637 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14638 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14639 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14640 | "0366 Not a valid completion " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14641 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14642 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 14643 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14644 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14645 | } |
| 14646 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14647 | /* Get the reference to the corresponding CQ */ |
| 14648 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 14649 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14650 | /* Use the fast lookup method first */ |
| 14651 | if (cqid <= phba->sli4_hba.cq_max) { |
| 14652 | cq = phba->sli4_hba.cq_lookup[cqid]; |
| 14653 | if (cq) |
| 14654 | goto work_cq; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14655 | } |
| 14656 | |
| 14657 | /* Next check for NVMET completion */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14658 | if (phba->cfg_nvmet_mrq && phba->sli4_hba.nvmet_cqset) { |
| 14659 | id = phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 14660 | if ((cqid >= id) && (cqid < (id + phba->cfg_nvmet_mrq))) { |
| 14661 | /* Process NVMET unsol rcv */ |
| 14662 | cq = phba->sli4_hba.nvmet_cqset[cqid - id]; |
| 14663 | goto process_cq; |
| 14664 | } |
| 14665 | } |
| 14666 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14667 | if (phba->sli4_hba.nvmels_cq && |
| 14668 | (cqid == phba->sli4_hba.nvmels_cq->queue_id)) { |
| 14669 | /* Process NVME unsol rcv */ |
| 14670 | cq = phba->sli4_hba.nvmels_cq; |
| 14671 | } |
| 14672 | |
| 14673 | /* Otherwise this is a Slow path event */ |
| 14674 | if (cq == NULL) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14675 | lpfc_sli4_sp_handle_eqe(phba, eqe, |
| 14676 | phba->sli4_hba.hdwq[qidx].hba_eq); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14677 | return; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14678 | } |
| 14679 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14680 | process_cq: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14681 | if (unlikely(cqid != cq->queue_id)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14682 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14683 | "0368 Miss-matched fast-path completion " |
| 14684 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", |
| 14685 | cqid, cq->queue_id); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14686 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14687 | } |
| 14688 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14689 | work_cq: |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 14690 | #if defined(CONFIG_SCSI_LPFC_DEBUG_FS) |
| 14691 | if (phba->ktime_on) |
| 14692 | cq->isr_timestamp = ktime_get_ns(); |
| 14693 | else |
| 14694 | cq->isr_timestamp = 0; |
| 14695 | #endif |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 14696 | lpfc_sli4_sched_cq_work(phba, cq, cqid); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14697 | } |
| 14698 | |
| 14699 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14700 | * __lpfc_sli4_hba_process_cq - Process a fast-path event queue entry |
| 14701 | * @cq: Pointer to CQ to be processed |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 14702 | * @poll_mode: Enum lpfc_poll_state to determine poll mode |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14703 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14704 | * This routine calls the cq processing routine with the handler for |
| 14705 | * fast path CQEs. |
| 14706 | * |
| 14707 | * The CQ routine returns two values: the first is the calling status, |
| 14708 | * which indicates whether work was queued to the background discovery |
| 14709 | * thread. If true, the routine should wakeup the discovery thread; |
| 14710 | * the second is the delay parameter. If non-zero, rather than rearming |
| 14711 | * the CQ and yet another interrupt, the CQ handler should be queued so |
| 14712 | * that it is processed in a subsequent polling action. The value of |
| 14713 | * the delay indicates when to reschedule it. |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14714 | **/ |
| 14715 | static void |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 14716 | __lpfc_sli4_hba_process_cq(struct lpfc_queue *cq, |
| 14717 | enum lpfc_poll_mode poll_mode) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14718 | { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14719 | struct lpfc_hba *phba = cq->phba; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14720 | unsigned long delay; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14721 | bool workposted = false; |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 14722 | int ret = 0; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14723 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14724 | /* process and rearm the CQ */ |
| 14725 | workposted |= __lpfc_sli4_process_cq(phba, cq, lpfc_sli4_fp_handle_cqe, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 14726 | &delay, poll_mode); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14727 | |
| 14728 | if (delay) { |
Dick Kennedy | 86ee57a | 2020-06-30 14:49:55 -0700 | [diff] [blame] | 14729 | if (is_kdump_kernel()) |
| 14730 | ret = queue_delayed_work(phba->wq, &cq->sched_irqwork, |
| 14731 | delay); |
| 14732 | else |
| 14733 | ret = queue_delayed_work_on(cq->chann, phba->wq, |
| 14734 | &cq->sched_irqwork, delay); |
| 14735 | if (!ret) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14736 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 14737 | "0367 Cannot schedule queue work " |
| 14738 | "for cqid=%d on CPU %d\n", |
| 14739 | cq->queue_id, cq->chann); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14740 | } |
| 14741 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14742 | /* wake up worker thread if there are works to be done */ |
| 14743 | if (workposted) |
| 14744 | lpfc_worker_wake_up(phba); |
| 14745 | } |
| 14746 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14747 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14748 | * lpfc_sli4_hba_process_cq - fast-path work handler when started by |
| 14749 | * interrupt |
| 14750 | * @work: pointer to work element |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14751 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14752 | * translates from the work handler and calls the fast-path handler. |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14753 | **/ |
| 14754 | static void |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14755 | lpfc_sli4_hba_process_cq(struct work_struct *work) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14756 | { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14757 | struct lpfc_queue *cq = container_of(work, struct lpfc_queue, irqwork); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14758 | |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 14759 | __lpfc_sli4_hba_process_cq(cq, LPFC_QUEUE_WORK); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14760 | } |
| 14761 | |
| 14762 | /** |
Lee Jones | 8514e2f | 2021-03-03 14:46:18 +0000 | [diff] [blame] | 14763 | * 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] | 14764 | * @work: pointer to work element |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14765 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14766 | * translates from the work handler and calls the fast-path handler. |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14767 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14768 | static void |
| 14769 | lpfc_sli4_dly_hba_process_cq(struct work_struct *work) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14770 | { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14771 | struct lpfc_queue *cq = container_of(to_delayed_work(work), |
| 14772 | struct lpfc_queue, sched_irqwork); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14773 | |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 14774 | __lpfc_sli4_hba_process_cq(cq, LPFC_QUEUE_WORK); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14775 | } |
| 14776 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14777 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14778 | * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14779 | * @irq: Interrupt number. |
| 14780 | * @dev_id: The device context pointer. |
| 14781 | * |
| 14782 | * This function is directly called from the PCI layer as an interrupt |
| 14783 | * service routine when device with SLI-4 interface spec is enabled with |
| 14784 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 14785 | * ring event in the HBA. However, when the device is enabled with either |
| 14786 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 14787 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 14788 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 14789 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 14790 | * the intrrupt context. This function is called without any lock held. |
| 14791 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 14792 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is |
| 14793 | * equal to that of FCP CQ index. |
| 14794 | * |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14795 | * The link attention and ELS ring attention events are handled |
| 14796 | * by the worker thread. The interrupt handler signals the worker thread |
| 14797 | * and returns for these events. This function is called without any lock |
| 14798 | * held. It gets the hbalock to access and update SLI data structures. |
| 14799 | * |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14800 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 14801 | * returns IRQ_NONE. |
| 14802 | **/ |
| 14803 | irqreturn_t |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14804 | lpfc_sli4_hba_intr_handler(int irq, void *dev_id) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14805 | { |
| 14806 | struct lpfc_hba *phba; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14807 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14808 | struct lpfc_queue *fpeq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14809 | unsigned long iflag; |
| 14810 | int ecount = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14811 | int hba_eqidx; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14812 | struct lpfc_eq_intr_info *eqi; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14813 | |
| 14814 | /* Get the driver's phba structure from the dev_id */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14815 | hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id; |
| 14816 | phba = hba_eq_hdl->phba; |
| 14817 | hba_eqidx = hba_eq_hdl->idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14818 | |
| 14819 | if (unlikely(!phba)) |
| 14820 | return IRQ_NONE; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14821 | if (unlikely(!phba->sli4_hba.hdwq)) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 14822 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14823 | |
| 14824 | /* Get to the EQ struct associated with this vector */ |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 14825 | fpeq = phba->sli4_hba.hba_eq_hdl[hba_eqidx].eq; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14826 | if (unlikely(!fpeq)) |
| 14827 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14828 | |
| 14829 | /* Check device state for handling interrupt */ |
| 14830 | if (unlikely(lpfc_intr_state_check(phba))) { |
| 14831 | /* Check again for link_state with lock held */ |
| 14832 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 14833 | if (phba->link_state < LPFC_LINK_DOWN) |
| 14834 | /* Flush, clear interrupt, and rearm the EQ */ |
James Smart | 24c7c0a | 2019-09-21 20:58:58 -0700 | [diff] [blame] | 14835 | lpfc_sli4_eqcq_flush(phba, fpeq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14836 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 14837 | return IRQ_NONE; |
| 14838 | } |
| 14839 | |
Dick Kennedy | a7fc071 | 2020-05-01 14:43:08 -0700 | [diff] [blame] | 14840 | eqi = this_cpu_ptr(phba->sli4_hba.eq_info); |
| 14841 | eqi->icnt++; |
| 14842 | |
Bart Van Assche | d6d189c | 2019-03-28 11:06:22 -0700 | [diff] [blame] | 14843 | fpeq->last_cpu = raw_smp_processor_id(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14844 | |
Dick Kennedy | a7fc071 | 2020-05-01 14:43:08 -0700 | [diff] [blame] | 14845 | if (eqi->icnt > LPFC_EQD_ISR_TRIGGER && |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 14846 | fpeq->q_flag & HBA_EQ_DELAY_CHK && |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14847 | phba->cfg_auto_imax && |
| 14848 | fpeq->q_mode != LPFC_MAX_AUTO_EQ_DELAY && |
| 14849 | phba->sli.sli_flag & LPFC_SLI_USE_EQDR) |
| 14850 | 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] | 14851 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14852 | /* process and rearm the EQ */ |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14853 | ecount = lpfc_sli4_process_eq(phba, fpeq, LPFC_QUEUE_REARM); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14854 | |
| 14855 | if (unlikely(ecount == 0)) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14856 | fpeq->EQ_no_entry++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14857 | if (phba->intr_type == MSIX) |
| 14858 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 14859 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 14860 | "0358 MSI-X interrupt with no EQE\n"); |
| 14861 | else |
| 14862 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 14863 | return IRQ_NONE; |
| 14864 | } |
| 14865 | |
| 14866 | return IRQ_HANDLED; |
James Smart | 3bfab8a | 2021-04-11 18:31:23 -0700 | [diff] [blame] | 14867 | } /* lpfc_sli4_hba_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14868 | |
| 14869 | /** |
| 14870 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device |
| 14871 | * @irq: Interrupt number. |
| 14872 | * @dev_id: The device context pointer. |
| 14873 | * |
| 14874 | * This function is the device-level interrupt handler to device with SLI-4 |
| 14875 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ |
| 14876 | * interrupt mode is enabled and there is an event in the HBA which requires |
| 14877 | * driver attention. This function invokes the slow-path interrupt attention |
| 14878 | * handling function and fast-path interrupt attention handling function in |
| 14879 | * turn to process the relevant HBA attention events. This function is called |
| 14880 | * without any lock held. It gets the hbalock to access and update SLI data |
| 14881 | * structures. |
| 14882 | * |
| 14883 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 14884 | * returns IRQ_NONE. |
| 14885 | **/ |
| 14886 | irqreturn_t |
| 14887 | lpfc_sli4_intr_handler(int irq, void *dev_id) |
| 14888 | { |
| 14889 | struct lpfc_hba *phba; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14890 | irqreturn_t hba_irq_rc; |
| 14891 | bool hba_handled = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14892 | int qidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14893 | |
| 14894 | /* Get the driver's phba structure from the dev_id */ |
| 14895 | phba = (struct lpfc_hba *)dev_id; |
| 14896 | |
| 14897 | if (unlikely(!phba)) |
| 14898 | return IRQ_NONE; |
| 14899 | |
| 14900 | /* |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14901 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 14902 | */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14903 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14904 | hba_irq_rc = lpfc_sli4_hba_intr_handler(irq, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14905 | &phba->sli4_hba.hba_eq_hdl[qidx]); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14906 | if (hba_irq_rc == IRQ_HANDLED) |
| 14907 | hba_handled |= true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14908 | } |
| 14909 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14910 | return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14911 | } /* lpfc_sli4_intr_handler */ |
| 14912 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14913 | void lpfc_sli4_poll_hbtimer(struct timer_list *t) |
| 14914 | { |
| 14915 | struct lpfc_hba *phba = from_timer(phba, t, cpuhp_poll_timer); |
| 14916 | struct lpfc_queue *eq; |
| 14917 | int i = 0; |
| 14918 | |
| 14919 | rcu_read_lock(); |
| 14920 | |
| 14921 | list_for_each_entry_rcu(eq, &phba->poll_list, _poll_list) |
| 14922 | i += lpfc_sli4_poll_eq(eq, LPFC_POLL_SLOWPATH); |
| 14923 | if (!list_empty(&phba->poll_list)) |
| 14924 | mod_timer(&phba->cpuhp_poll_timer, |
| 14925 | jiffies + msecs_to_jiffies(LPFC_POLL_HB)); |
| 14926 | |
| 14927 | rcu_read_unlock(); |
| 14928 | } |
| 14929 | |
| 14930 | inline int lpfc_sli4_poll_eq(struct lpfc_queue *eq, uint8_t path) |
| 14931 | { |
| 14932 | struct lpfc_hba *phba = eq->phba; |
| 14933 | int i = 0; |
| 14934 | |
| 14935 | /* |
| 14936 | * Unlocking an irq is one of the entry point to check |
| 14937 | * for re-schedule, but we are good for io submission |
| 14938 | * path as midlayer does a get_cpu to glue us in. Flush |
| 14939 | * out the invalidate queue so we can see the updated |
| 14940 | * value for flag. |
| 14941 | */ |
| 14942 | smp_rmb(); |
| 14943 | |
| 14944 | if (READ_ONCE(eq->mode) == LPFC_EQ_POLL) |
| 14945 | /* We will not likely get the completion for the caller |
| 14946 | * during this iteration but i guess that's fine. |
| 14947 | * Future io's coming on this eq should be able to |
| 14948 | * pick it up. As for the case of single io's, they |
| 14949 | * will be handled through a sched from polling timer |
| 14950 | * function which is currently triggered every 1msec. |
| 14951 | */ |
| 14952 | i = lpfc_sli4_process_eq(phba, eq, LPFC_QUEUE_NOARM); |
| 14953 | |
| 14954 | return i; |
| 14955 | } |
| 14956 | |
| 14957 | static inline void lpfc_sli4_add_to_poll_list(struct lpfc_queue *eq) |
| 14958 | { |
| 14959 | struct lpfc_hba *phba = eq->phba; |
| 14960 | |
James Smart | f861f59 | 2020-03-22 11:12:54 -0700 | [diff] [blame] | 14961 | /* kickstart slowpath processing if needed */ |
| 14962 | if (list_empty(&phba->poll_list)) |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14963 | mod_timer(&phba->cpuhp_poll_timer, |
| 14964 | jiffies + msecs_to_jiffies(LPFC_POLL_HB)); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14965 | |
| 14966 | list_add_rcu(&eq->_poll_list, &phba->poll_list); |
| 14967 | synchronize_rcu(); |
| 14968 | } |
| 14969 | |
| 14970 | static inline void lpfc_sli4_remove_from_poll_list(struct lpfc_queue *eq) |
| 14971 | { |
| 14972 | struct lpfc_hba *phba = eq->phba; |
| 14973 | |
| 14974 | /* Disable slowpath processing for this eq. Kick start the eq |
| 14975 | * by RE-ARMING the eq's ASAP |
| 14976 | */ |
| 14977 | list_del_rcu(&eq->_poll_list); |
| 14978 | synchronize_rcu(); |
| 14979 | |
| 14980 | if (list_empty(&phba->poll_list)) |
| 14981 | del_timer_sync(&phba->cpuhp_poll_timer); |
| 14982 | } |
| 14983 | |
James Smart | d480e57 | 2019-11-11 15:03:58 -0800 | [diff] [blame] | 14984 | void lpfc_sli4_cleanup_poll_list(struct lpfc_hba *phba) |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14985 | { |
| 14986 | struct lpfc_queue *eq, *next; |
| 14987 | |
| 14988 | list_for_each_entry_safe(eq, next, &phba->poll_list, _poll_list) |
| 14989 | list_del(&eq->_poll_list); |
| 14990 | |
| 14991 | INIT_LIST_HEAD(&phba->poll_list); |
| 14992 | synchronize_rcu(); |
| 14993 | } |
| 14994 | |
| 14995 | static inline void |
| 14996 | __lpfc_sli4_switch_eqmode(struct lpfc_queue *eq, uint8_t mode) |
| 14997 | { |
| 14998 | if (mode == eq->mode) |
| 14999 | return; |
| 15000 | /* |
| 15001 | * currently this function is only called during a hotplug |
| 15002 | * event and the cpu on which this function is executing |
| 15003 | * is going offline. By now the hotplug has instructed |
| 15004 | * the scheduler to remove this cpu from cpu active mask. |
| 15005 | * So we don't need to work about being put aside by the |
| 15006 | * scheduler for a high priority process. Yes, the inte- |
| 15007 | * rrupts could come but they are known to retire ASAP. |
| 15008 | */ |
| 15009 | |
| 15010 | /* Disable polling in the fastpath */ |
| 15011 | WRITE_ONCE(eq->mode, mode); |
| 15012 | /* flush out the store buffer */ |
| 15013 | smp_wmb(); |
| 15014 | |
| 15015 | /* |
| 15016 | * Add this eq to the polling list and start polling. For |
| 15017 | * a grace period both interrupt handler and poller will |
| 15018 | * try to process the eq _but_ that's fine. We have a |
| 15019 | * synchronization mechanism in place (queue_claimed) to |
| 15020 | * deal with it. This is just a draining phase for int- |
| 15021 | * errupt handler (not eq's) as we have guranteed through |
| 15022 | * barrier that all the CPUs have seen the new CQ_POLLED |
| 15023 | * state. which will effectively disable the REARMING of |
| 15024 | * the EQ. The whole idea is eq's die off eventually as |
| 15025 | * we are not rearming EQ's anymore. |
| 15026 | */ |
| 15027 | mode ? lpfc_sli4_add_to_poll_list(eq) : |
| 15028 | lpfc_sli4_remove_from_poll_list(eq); |
| 15029 | } |
| 15030 | |
| 15031 | void lpfc_sli4_start_polling(struct lpfc_queue *eq) |
| 15032 | { |
| 15033 | __lpfc_sli4_switch_eqmode(eq, LPFC_EQ_POLL); |
| 15034 | } |
| 15035 | |
| 15036 | void lpfc_sli4_stop_polling(struct lpfc_queue *eq) |
| 15037 | { |
| 15038 | struct lpfc_hba *phba = eq->phba; |
| 15039 | |
| 15040 | __lpfc_sli4_switch_eqmode(eq, LPFC_EQ_INTERRUPT); |
| 15041 | |
| 15042 | /* Kick start for the pending io's in h/w. |
| 15043 | * Once we switch back to interrupt processing on a eq |
| 15044 | * the io path completion will only arm eq's when it |
| 15045 | * receives a completion. But since eq's are in disa- |
| 15046 | * rmed state it doesn't receive a completion. This |
| 15047 | * creates a deadlock scenaro. |
| 15048 | */ |
| 15049 | phba->sli4_hba.sli4_write_eq_db(phba, eq, 0, LPFC_QUEUE_REARM); |
| 15050 | } |
| 15051 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15052 | /** |
| 15053 | * lpfc_sli4_queue_free - free a queue structure and associated memory |
| 15054 | * @queue: The queue structure to free. |
| 15055 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 15056 | * This function frees a queue structure and the DMAable memory used for |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15057 | * the host resident queue. This function must be called after destroying the |
| 15058 | * queue on the HBA. |
| 15059 | **/ |
| 15060 | void |
| 15061 | lpfc_sli4_queue_free(struct lpfc_queue *queue) |
| 15062 | { |
| 15063 | struct lpfc_dmabuf *dmabuf; |
| 15064 | |
| 15065 | if (!queue) |
| 15066 | return; |
| 15067 | |
James Smart | 4645f7b | 2019-03-12 16:30:14 -0700 | [diff] [blame] | 15068 | if (!list_empty(&queue->wq_list)) |
| 15069 | list_del(&queue->wq_list); |
| 15070 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15071 | while (!list_empty(&queue->page_list)) { |
| 15072 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, |
| 15073 | list); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15074 | dma_free_coherent(&queue->phba->pcidev->dev, queue->page_size, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15075 | dmabuf->virt, dmabuf->phys); |
| 15076 | kfree(dmabuf); |
| 15077 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15078 | if (queue->rqbp) { |
| 15079 | lpfc_free_rq_buffer(queue->phba, queue); |
| 15080 | kfree(queue->rqbp); |
| 15081 | } |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 15082 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15083 | if (!list_empty(&queue->cpu_list)) |
| 15084 | list_del(&queue->cpu_list); |
| 15085 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15086 | kfree(queue); |
| 15087 | return; |
| 15088 | } |
| 15089 | |
| 15090 | /** |
| 15091 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure |
| 15092 | * @phba: The HBA that this queue is being created on. |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15093 | * @page_size: The size of a queue page |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15094 | * @entry_size: The size of each queue entry for this queue. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 15095 | * @entry_count: The number of entries that this queue will handle. |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 15096 | * @cpu: The cpu that will primarily utilize this queue. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15097 | * |
| 15098 | * This function allocates a queue structure and the DMAable memory used for |
| 15099 | * the host resident queue. This function must be called before creating the |
| 15100 | * queue on the HBA. |
| 15101 | **/ |
| 15102 | struct lpfc_queue * |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15103 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t page_size, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 15104 | uint32_t entry_size, uint32_t entry_count, int cpu) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15105 | { |
| 15106 | struct lpfc_queue *queue; |
| 15107 | struct lpfc_dmabuf *dmabuf; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 15108 | 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] | 15109 | uint16_t x, pgcnt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15110 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 15111 | if (!phba->sli4_hba.pc_sli4_params.supported) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15112 | hw_page_size = page_size; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 15113 | |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 15114 | pgcnt = ALIGN(entry_size * entry_count, hw_page_size) / hw_page_size; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15115 | |
| 15116 | /* If needed, Adjust page count to match the max the adapter supports */ |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 15117 | if (pgcnt > phba->sli4_hba.pc_sli4_params.wqpcnt) |
| 15118 | pgcnt = phba->sli4_hba.pc_sli4_params.wqpcnt; |
| 15119 | |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 15120 | queue = kzalloc_node(sizeof(*queue) + (sizeof(void *) * pgcnt), |
| 15121 | GFP_KERNEL, cpu_to_node(cpu)); |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 15122 | if (!queue) |
| 15123 | return NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15124 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15125 | INIT_LIST_HEAD(&queue->list); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 15126 | INIT_LIST_HEAD(&queue->_poll_list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15127 | INIT_LIST_HEAD(&queue->wq_list); |
James Smart | 6e8e1c1 | 2018-01-30 15:58:49 -0800 | [diff] [blame] | 15128 | INIT_LIST_HEAD(&queue->wqfull_list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15129 | INIT_LIST_HEAD(&queue->page_list); |
| 15130 | INIT_LIST_HEAD(&queue->child_list); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15131 | INIT_LIST_HEAD(&queue->cpu_list); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15132 | |
| 15133 | /* Set queue parameters now. If the system cannot provide memory |
| 15134 | * resources, the free routine needs to know what was allocated. |
| 15135 | */ |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 15136 | queue->page_count = pgcnt; |
| 15137 | queue->q_pgs = (void **)&queue[1]; |
| 15138 | queue->entry_cnt_per_pg = hw_page_size / entry_size; |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15139 | queue->entry_size = entry_size; |
| 15140 | queue->entry_count = entry_count; |
| 15141 | queue->page_size = hw_page_size; |
| 15142 | queue->phba = phba; |
| 15143 | |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 15144 | for (x = 0; x < queue->page_count; x++) { |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 15145 | dmabuf = kzalloc_node(sizeof(*dmabuf), GFP_KERNEL, |
| 15146 | dev_to_node(&phba->pcidev->dev)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15147 | if (!dmabuf) |
| 15148 | goto out_fail; |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 15149 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 15150 | hw_page_size, &dmabuf->phys, |
| 15151 | GFP_KERNEL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15152 | if (!dmabuf->virt) { |
| 15153 | kfree(dmabuf); |
| 15154 | goto out_fail; |
| 15155 | } |
| 15156 | dmabuf->buffer_tag = x; |
| 15157 | list_add_tail(&dmabuf->list, &queue->page_list); |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 15158 | /* use lpfc_sli4_qe to index a paritcular entry in this page */ |
| 15159 | queue->q_pgs[x] = dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15160 | } |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 15161 | INIT_WORK(&queue->irqwork, lpfc_sli4_hba_process_cq); |
| 15162 | INIT_WORK(&queue->spwork, lpfc_sli4_sp_process_cq); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15163 | INIT_DELAYED_WORK(&queue->sched_irqwork, lpfc_sli4_dly_hba_process_cq); |
| 15164 | INIT_DELAYED_WORK(&queue->sched_spwork, lpfc_sli4_dly_sp_process_cq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15165 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15166 | /* notify_interval will be set during q creation */ |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 15167 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15168 | return queue; |
| 15169 | out_fail: |
| 15170 | lpfc_sli4_queue_free(queue); |
| 15171 | return NULL; |
| 15172 | } |
| 15173 | |
| 15174 | /** |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15175 | * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory |
| 15176 | * @phba: HBA structure that indicates port to create a queue on. |
| 15177 | * @pci_barset: PCI BAR set flag. |
| 15178 | * |
| 15179 | * This function shall perform iomap of the specified PCI BAR address to host |
| 15180 | * memory address if not already done so and return it. The returned host |
| 15181 | * memory address can be NULL. |
| 15182 | */ |
| 15183 | static void __iomem * |
| 15184 | lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset) |
| 15185 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15186 | if (!phba->pcidev) |
| 15187 | return NULL; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15188 | |
| 15189 | switch (pci_barset) { |
| 15190 | case WQ_PCI_BAR_0_AND_1: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15191 | return phba->pci_bar0_memmap_p; |
| 15192 | case WQ_PCI_BAR_2_AND_3: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15193 | return phba->pci_bar2_memmap_p; |
| 15194 | case WQ_PCI_BAR_4_AND_5: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15195 | return phba->pci_bar4_memmap_p; |
| 15196 | default: |
| 15197 | break; |
| 15198 | } |
| 15199 | return NULL; |
| 15200 | } |
| 15201 | |
| 15202 | /** |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15203 | * lpfc_modify_hba_eq_delay - Modify Delay Multiplier on EQs |
| 15204 | * @phba: HBA structure that EQs are on. |
| 15205 | * @startq: The starting EQ index to modify |
| 15206 | * @numq: The number of EQs (consecutive indexes) to modify |
| 15207 | * @usdelay: amount of delay |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15208 | * |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15209 | * This function revises the EQ delay on 1 or more EQs. The EQ delay |
| 15210 | * is set either by writing to a register (if supported by the SLI Port) |
| 15211 | * or by mailbox command. The mailbox command allows several EQs to be |
| 15212 | * updated at once. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15213 | * |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15214 | * The @phba struct is used to send a mailbox command to HBA. The @startq |
| 15215 | * is used to get the starting EQ index to change. The @numq value is |
| 15216 | * used to specify how many consecutive EQ indexes, starting at EQ index, |
| 15217 | * are to be changed. This function is asynchronous and will wait for any |
| 15218 | * mailbox commands to finish before returning. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15219 | * |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15220 | * On success this function will return a zero. If unable to allocate |
| 15221 | * enough memory this function will return -ENOMEM. If a mailbox command |
| 15222 | * fails this function will return -ENXIO. Note: on ENXIO, some EQs may |
| 15223 | * have had their delay multipler changed. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15224 | **/ |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15225 | void |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 15226 | lpfc_modify_hba_eq_delay(struct lpfc_hba *phba, uint32_t startq, |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15227 | uint32_t numq, uint32_t usdelay) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15228 | { |
| 15229 | struct lpfc_mbx_modify_eq_delay *eq_delay; |
| 15230 | LPFC_MBOXQ_t *mbox; |
| 15231 | struct lpfc_queue *eq; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15232 | int cnt = 0, rc, length; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15233 | uint32_t shdr_status, shdr_add_status; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15234 | uint32_t dmult; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15235 | int qidx; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15236 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15237 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15238 | if (startq >= phba->cfg_irq_chann) |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15239 | return; |
| 15240 | |
| 15241 | if (usdelay > 0xFFFF) { |
| 15242 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP | LOG_NVME, |
| 15243 | "6429 usdelay %d too large. Scaled down to " |
| 15244 | "0xFFFF.\n", usdelay); |
| 15245 | usdelay = 0xFFFF; |
| 15246 | } |
| 15247 | |
| 15248 | /* set values by EQ_DELAY register if supported */ |
| 15249 | if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) { |
| 15250 | for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 15251 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15252 | if (!eq) |
| 15253 | continue; |
| 15254 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15255 | lpfc_sli4_mod_hba_eq_delay(phba, eq, usdelay); |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15256 | |
| 15257 | if (++cnt >= numq) |
| 15258 | break; |
| 15259 | } |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15260 | return; |
| 15261 | } |
| 15262 | |
| 15263 | /* Otherwise, set values by mailbox cmd */ |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15264 | |
| 15265 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15266 | if (!mbox) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15267 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15268 | "6428 Failed allocating mailbox cmd buffer." |
| 15269 | " EQ delay was not set.\n"); |
| 15270 | return; |
| 15271 | } |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15272 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - |
| 15273 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15274 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15275 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, |
| 15276 | length, LPFC_SLI4_MBX_EMBED); |
| 15277 | eq_delay = &mbox->u.mqe.un.eq_delay; |
| 15278 | |
| 15279 | /* Calculate delay multiper from maximum interrupt per second */ |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15280 | dmult = (usdelay * LPFC_DMULT_CONST) / LPFC_SEC_TO_USEC; |
| 15281 | if (dmult) |
| 15282 | dmult--; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 15283 | if (dmult > LPFC_DMULT_MAX) |
| 15284 | dmult = LPFC_DMULT_MAX; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15285 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15286 | for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 15287 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15288 | if (!eq) |
| 15289 | continue; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15290 | eq->q_mode = usdelay; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15291 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; |
| 15292 | eq_delay->u.request.eq[cnt].phase = 0; |
| 15293 | eq_delay->u.request.eq[cnt].delay_multi = dmult; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 15294 | |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15295 | if (++cnt >= numq) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15296 | break; |
| 15297 | } |
| 15298 | eq_delay->u.request.num_eq = cnt; |
| 15299 | |
| 15300 | mbox->vport = phba->pport; |
| 15301 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 15302 | mbox->ctx_buf = NULL; |
| 15303 | mbox->ctx_ndlp = NULL; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15304 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15305 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; |
| 15306 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15307 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15308 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15309 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15310 | "2512 MODIFY_EQ_DELAY mailbox failed with " |
| 15311 | "status x%x add_status x%x, mbx status x%x\n", |
| 15312 | shdr_status, shdr_add_status, rc); |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15313 | } |
| 15314 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 15315 | return; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 15316 | } |
| 15317 | |
| 15318 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15319 | * lpfc_eq_create - Create an Event Queue on the HBA |
| 15320 | * @phba: HBA structure that indicates port to create a queue on. |
| 15321 | * @eq: The queue structure to use to create the event queue. |
| 15322 | * @imax: The maximum interrupt per second limit. |
| 15323 | * |
| 15324 | * This function creates an event queue, as detailed in @eq, on a port, |
| 15325 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. |
| 15326 | * |
| 15327 | * The @phba struct is used to send mailbox command to HBA. The @eq struct |
| 15328 | * is used to get the entry count and entry size that are necessary to |
| 15329 | * determine the number of pages to allocate and use for this queue. This |
| 15330 | * function will send the EQ_CREATE mailbox command to the HBA to setup the |
| 15331 | * event queue. This function is asynchronous and will wait for the mailbox |
| 15332 | * command to finish before continuing. |
| 15333 | * |
| 15334 | * 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] | 15335 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15336 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15337 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15338 | int |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 15339 | 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] | 15340 | { |
| 15341 | struct lpfc_mbx_eq_create *eq_create; |
| 15342 | LPFC_MBOXQ_t *mbox; |
| 15343 | int rc, length, status = 0; |
| 15344 | struct lpfc_dmabuf *dmabuf; |
| 15345 | uint32_t shdr_status, shdr_add_status; |
| 15346 | union lpfc_sli4_cfg_shdr *shdr; |
| 15347 | uint16_t dmult; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15348 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 15349 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15350 | /* sanity check on queue memory */ |
| 15351 | if (!eq) |
| 15352 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15353 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15354 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15355 | |
| 15356 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15357 | if (!mbox) |
| 15358 | return -ENOMEM; |
| 15359 | length = (sizeof(struct lpfc_mbx_eq_create) - |
| 15360 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15361 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15362 | LPFC_MBOX_OPCODE_EQ_CREATE, |
| 15363 | length, LPFC_SLI4_MBX_EMBED); |
| 15364 | eq_create = &mbox->u.mqe.un.eq_create; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 15365 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15366 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, |
| 15367 | eq->page_count); |
| 15368 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, |
| 15369 | LPFC_EQE_SIZE); |
| 15370 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 15371 | |
| 15372 | /* Use version 2 of CREATE_EQ if eqav is set */ |
| 15373 | if (phba->sli4_hba.pc_sli4_params.eqav) { |
| 15374 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15375 | LPFC_Q_CREATE_VERSION_2); |
| 15376 | bf_set(lpfc_eq_context_autovalid, &eq_create->u.request.context, |
| 15377 | phba->sli4_hba.pc_sli4_params.eqav); |
| 15378 | } |
| 15379 | |
James Smart | 2c9c5a0 | 2015-04-07 15:07:15 -0400 | [diff] [blame] | 15380 | /* don't setup delay multiplier using EQ_CREATE */ |
| 15381 | dmult = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15382 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
| 15383 | dmult); |
| 15384 | switch (eq->entry_count) { |
| 15385 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15386 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15387 | "0360 Unsupported EQ count. (%d)\n", |
| 15388 | eq->entry_count); |
James Smart | 04d210c | 2019-05-21 17:49:03 -0700 | [diff] [blame] | 15389 | if (eq->entry_count < 256) { |
| 15390 | status = -EINVAL; |
| 15391 | goto out; |
| 15392 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 15393 | fallthrough; /* otherwise default to smallest count */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15394 | case 256: |
| 15395 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 15396 | LPFC_EQ_CNT_256); |
| 15397 | break; |
| 15398 | case 512: |
| 15399 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 15400 | LPFC_EQ_CNT_512); |
| 15401 | break; |
| 15402 | case 1024: |
| 15403 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 15404 | LPFC_EQ_CNT_1024); |
| 15405 | break; |
| 15406 | case 2048: |
| 15407 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 15408 | LPFC_EQ_CNT_2048); |
| 15409 | break; |
| 15410 | case 4096: |
| 15411 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 15412 | LPFC_EQ_CNT_4096); |
| 15413 | break; |
| 15414 | } |
| 15415 | list_for_each_entry(dmabuf, &eq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15416 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15417 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15418 | putPaddrLow(dmabuf->phys); |
| 15419 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 15420 | putPaddrHigh(dmabuf->phys); |
| 15421 | } |
| 15422 | mbox->vport = phba->pport; |
| 15423 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 15424 | mbox->ctx_buf = NULL; |
| 15425 | mbox->ctx_ndlp = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15426 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15427 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15428 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15429 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15430 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15431 | "2500 EQ_CREATE mailbox failed with " |
| 15432 | "status x%x add_status x%x, mbx status x%x\n", |
| 15433 | shdr_status, shdr_add_status, rc); |
| 15434 | status = -ENXIO; |
| 15435 | } |
| 15436 | eq->type = LPFC_EQ; |
| 15437 | eq->subtype = LPFC_NONE; |
| 15438 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); |
| 15439 | if (eq->queue_id == 0xFFFF) |
| 15440 | status = -ENXIO; |
| 15441 | eq->host_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15442 | eq->notify_interval = LPFC_EQ_NOTIFY_INTRVL; |
| 15443 | eq->max_proc_limit = LPFC_EQ_MAX_PROC_LIMIT; |
James Smart | 04d210c | 2019-05-21 17:49:03 -0700 | [diff] [blame] | 15444 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15445 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15446 | return status; |
| 15447 | } |
| 15448 | |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 15449 | static int lpfc_cq_poll_hdler(struct irq_poll *iop, int budget) |
| 15450 | { |
| 15451 | struct lpfc_queue *cq = container_of(iop, struct lpfc_queue, iop); |
| 15452 | |
Colin Ian King | 26e0b9a | 2020-07-07 16:00:18 +0100 | [diff] [blame] | 15453 | __lpfc_sli4_hba_process_cq(cq, LPFC_IRQ_POLL); |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 15454 | |
| 15455 | return 1; |
| 15456 | } |
| 15457 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15458 | /** |
| 15459 | * lpfc_cq_create - Create a Completion Queue on the HBA |
| 15460 | * @phba: HBA structure that indicates port to create a queue on. |
| 15461 | * @cq: The queue structure to use to create the completion queue. |
| 15462 | * @eq: The event queue to bind this completion queue to. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 15463 | * @type: Type of queue (EQ, GCQ, MCQ, WCQ, etc). |
| 15464 | * @subtype: Functional purpose of the queue (MBOX, IO, ELS, NVMET, etc). |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15465 | * |
| 15466 | * This function creates a completion queue, as detailed in @wq, on a port, |
| 15467 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. |
| 15468 | * |
| 15469 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 15470 | * is used to get the entry count and entry size that are necessary to |
| 15471 | * determine the number of pages to allocate and use for this queue. The @eq |
| 15472 | * is used to indicate which event queue to bind this completion queue to. This |
| 15473 | * function will send the CQ_CREATE mailbox command to the HBA to setup the |
| 15474 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 15475 | * command to finish before continuing. |
| 15476 | * |
| 15477 | * 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] | 15478 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15479 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15480 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15481 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15482 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 15483 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) |
| 15484 | { |
| 15485 | struct lpfc_mbx_cq_create *cq_create; |
| 15486 | struct lpfc_dmabuf *dmabuf; |
| 15487 | LPFC_MBOXQ_t *mbox; |
| 15488 | int rc, length, status = 0; |
| 15489 | uint32_t shdr_status, shdr_add_status; |
| 15490 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15491 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15492 | /* sanity check on queue memory */ |
| 15493 | if (!cq || !eq) |
| 15494 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15495 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15496 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15497 | if (!mbox) |
| 15498 | return -ENOMEM; |
| 15499 | length = (sizeof(struct lpfc_mbx_cq_create) - |
| 15500 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15501 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15502 | LPFC_MBOX_OPCODE_CQ_CREATE, |
| 15503 | length, LPFC_SLI4_MBX_EMBED); |
| 15504 | cq_create = &mbox->u.mqe.un.cq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15505 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15506 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
| 15507 | cq->page_count); |
| 15508 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); |
| 15509 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15510 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15511 | phba->sli4_hba.pc_sli4_params.cqv); |
| 15512 | 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] | 15513 | bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, |
| 15514 | (cq->page_size / SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15515 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
| 15516 | eq->queue_id); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 15517 | bf_set(lpfc_cq_context_autovalid, &cq_create->u.request.context, |
| 15518 | phba->sli4_hba.pc_sli4_params.cqav); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15519 | } else { |
| 15520 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, |
| 15521 | eq->queue_id); |
| 15522 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15523 | switch (cq->entry_count) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15524 | case 2048: |
| 15525 | case 4096: |
| 15526 | if (phba->sli4_hba.pc_sli4_params.cqv == |
| 15527 | LPFC_Q_CREATE_VERSION_2) { |
| 15528 | cq_create->u.request.context.lpfc_cq_context_count = |
| 15529 | cq->entry_count; |
| 15530 | bf_set(lpfc_cq_context_count, |
| 15531 | &cq_create->u.request.context, |
| 15532 | LPFC_CQ_CNT_WORD7); |
| 15533 | break; |
| 15534 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 15535 | fallthrough; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15536 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15537 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 15538 | "0361 Unsupported CQ count: " |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 15539 | "entry cnt %d sz %d pg cnt %d\n", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 15540 | cq->entry_count, cq->entry_size, |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 15541 | cq->page_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15542 | if (cq->entry_count < 256) { |
| 15543 | status = -EINVAL; |
| 15544 | goto out; |
| 15545 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 15546 | fallthrough; /* otherwise default to smallest count */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15547 | case 256: |
| 15548 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 15549 | LPFC_CQ_CNT_256); |
| 15550 | break; |
| 15551 | case 512: |
| 15552 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 15553 | LPFC_CQ_CNT_512); |
| 15554 | break; |
| 15555 | case 1024: |
| 15556 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 15557 | LPFC_CQ_CNT_1024); |
| 15558 | break; |
| 15559 | } |
| 15560 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15561 | memset(dmabuf->virt, 0, cq->page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15562 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15563 | putPaddrLow(dmabuf->phys); |
| 15564 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 15565 | putPaddrHigh(dmabuf->phys); |
| 15566 | } |
| 15567 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15568 | |
| 15569 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15570 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15571 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15572 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15573 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15574 | "2501 CQ_CREATE mailbox failed with " |
| 15575 | "status x%x add_status x%x, mbx status x%x\n", |
| 15576 | shdr_status, shdr_add_status, rc); |
| 15577 | status = -ENXIO; |
| 15578 | goto out; |
| 15579 | } |
| 15580 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
| 15581 | if (cq->queue_id == 0xFFFF) { |
| 15582 | status = -ENXIO; |
| 15583 | goto out; |
| 15584 | } |
| 15585 | /* link the cq onto the parent eq child list */ |
| 15586 | list_add_tail(&cq->list, &eq->child_list); |
| 15587 | /* Set up completion queue's type and subtype */ |
| 15588 | cq->type = type; |
| 15589 | cq->subtype = subtype; |
| 15590 | 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] | 15591 | cq->assoc_qid = eq->queue_id; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15592 | cq->assoc_qp = eq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15593 | cq->host_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15594 | cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL; |
| 15595 | 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] | 15596 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15597 | if (cq->queue_id > phba->sli4_hba.cq_max) |
| 15598 | phba->sli4_hba.cq_max = cq->queue_id; |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 15599 | |
| 15600 | 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] | 15601 | out: |
| 15602 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15603 | return status; |
| 15604 | } |
| 15605 | |
| 15606 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15607 | * lpfc_cq_create_set - Create a set of Completion Queues on the HBA for MRQ |
| 15608 | * @phba: HBA structure that indicates port to create a queue on. |
| 15609 | * @cqp: The queue structure array to use to create the completion queues. |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 15610 | * @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] | 15611 | * @type: Type of queue (EQ, GCQ, MCQ, WCQ, etc). |
| 15612 | * @subtype: Functional purpose of the queue (MBOX, IO, ELS, NVMET, etc). |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15613 | * |
| 15614 | * This function creates a set of completion queue, s to support MRQ |
| 15615 | * as detailed in @cqp, on a port, |
| 15616 | * described by @phba by sending a CREATE_CQ_SET mailbox command to the HBA. |
| 15617 | * |
| 15618 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 15619 | * is used to get the entry count and entry size that are necessary to |
| 15620 | * determine the number of pages to allocate and use for this queue. The @eq |
| 15621 | * is used to indicate which event queue to bind this completion queue to. This |
| 15622 | * function will send the CREATE_CQ_SET mailbox command to the HBA to setup the |
| 15623 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 15624 | * command to finish before continuing. |
| 15625 | * |
| 15626 | * On success this function will return a zero. If unable to allocate enough |
| 15627 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15628 | * fails this function will return -ENXIO. |
| 15629 | **/ |
| 15630 | int |
| 15631 | lpfc_cq_create_set(struct lpfc_hba *phba, struct lpfc_queue **cqp, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 15632 | struct lpfc_sli4_hdw_queue *hdwq, uint32_t type, |
| 15633 | uint32_t subtype) |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15634 | { |
| 15635 | struct lpfc_queue *cq; |
| 15636 | struct lpfc_queue *eq; |
| 15637 | struct lpfc_mbx_cq_create_set *cq_set; |
| 15638 | struct lpfc_dmabuf *dmabuf; |
| 15639 | LPFC_MBOXQ_t *mbox; |
| 15640 | int rc, length, alloclen, status = 0; |
| 15641 | int cnt, idx, numcq, page_idx = 0; |
| 15642 | uint32_t shdr_status, shdr_add_status; |
| 15643 | union lpfc_sli4_cfg_shdr *shdr; |
| 15644 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 15645 | |
| 15646 | /* sanity check on queue memory */ |
| 15647 | numcq = phba->cfg_nvmet_mrq; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 15648 | if (!cqp || !hdwq || !numcq) |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15649 | return -ENODEV; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15650 | |
| 15651 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15652 | if (!mbox) |
| 15653 | return -ENOMEM; |
| 15654 | |
| 15655 | length = sizeof(struct lpfc_mbx_cq_create_set); |
| 15656 | length += ((numcq * cqp[0]->page_count) * |
| 15657 | sizeof(struct dma_address)); |
| 15658 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15659 | LPFC_MBOX_OPCODE_FCOE_CQ_CREATE_SET, length, |
| 15660 | LPFC_SLI4_MBX_NEMBED); |
| 15661 | if (alloclen < length) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15662 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15663 | "3098 Allocated DMA memory size (%d) is " |
| 15664 | "less than the requested DMA memory size " |
| 15665 | "(%d)\n", alloclen, length); |
| 15666 | status = -ENOMEM; |
| 15667 | goto out; |
| 15668 | } |
| 15669 | cq_set = mbox->sge_array->addr[0]; |
| 15670 | shdr = (union lpfc_sli4_cfg_shdr *)&cq_set->cfg_shdr; |
| 15671 | bf_set(lpfc_mbox_hdr_version, &shdr->request, 0); |
| 15672 | |
| 15673 | for (idx = 0; idx < numcq; idx++) { |
| 15674 | cq = cqp[idx]; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 15675 | eq = hdwq[idx].hba_eq; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15676 | if (!cq || !eq) { |
| 15677 | status = -ENOMEM; |
| 15678 | goto out; |
| 15679 | } |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15680 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15681 | hw_page_size = cq->page_size; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15682 | |
| 15683 | switch (idx) { |
| 15684 | case 0: |
| 15685 | bf_set(lpfc_mbx_cq_create_set_page_size, |
| 15686 | &cq_set->u.request, |
| 15687 | (hw_page_size / SLI4_PAGE_SIZE)); |
| 15688 | bf_set(lpfc_mbx_cq_create_set_num_pages, |
| 15689 | &cq_set->u.request, cq->page_count); |
| 15690 | bf_set(lpfc_mbx_cq_create_set_evt, |
| 15691 | &cq_set->u.request, 1); |
| 15692 | bf_set(lpfc_mbx_cq_create_set_valid, |
| 15693 | &cq_set->u.request, 1); |
| 15694 | bf_set(lpfc_mbx_cq_create_set_cqe_size, |
| 15695 | &cq_set->u.request, 0); |
| 15696 | bf_set(lpfc_mbx_cq_create_set_num_cq, |
| 15697 | &cq_set->u.request, numcq); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 15698 | bf_set(lpfc_mbx_cq_create_set_autovalid, |
| 15699 | &cq_set->u.request, |
| 15700 | phba->sli4_hba.pc_sli4_params.cqav); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15701 | switch (cq->entry_count) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15702 | case 2048: |
| 15703 | case 4096: |
| 15704 | if (phba->sli4_hba.pc_sli4_params.cqv == |
| 15705 | LPFC_Q_CREATE_VERSION_2) { |
| 15706 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15707 | &cq_set->u.request, |
| 15708 | cq->entry_count); |
| 15709 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15710 | &cq_set->u.request, |
| 15711 | LPFC_CQ_CNT_WORD7); |
| 15712 | break; |
| 15713 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 15714 | fallthrough; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15715 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15716 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15717 | "3118 Bad CQ count. (%d)\n", |
| 15718 | cq->entry_count); |
| 15719 | if (cq->entry_count < 256) { |
| 15720 | status = -EINVAL; |
| 15721 | goto out; |
| 15722 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 15723 | fallthrough; /* otherwise default to smallest */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15724 | case 256: |
| 15725 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15726 | &cq_set->u.request, LPFC_CQ_CNT_256); |
| 15727 | break; |
| 15728 | case 512: |
| 15729 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15730 | &cq_set->u.request, LPFC_CQ_CNT_512); |
| 15731 | break; |
| 15732 | case 1024: |
| 15733 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15734 | &cq_set->u.request, LPFC_CQ_CNT_1024); |
| 15735 | break; |
| 15736 | } |
| 15737 | bf_set(lpfc_mbx_cq_create_set_eq_id0, |
| 15738 | &cq_set->u.request, eq->queue_id); |
| 15739 | break; |
| 15740 | case 1: |
| 15741 | bf_set(lpfc_mbx_cq_create_set_eq_id1, |
| 15742 | &cq_set->u.request, eq->queue_id); |
| 15743 | break; |
| 15744 | case 2: |
| 15745 | bf_set(lpfc_mbx_cq_create_set_eq_id2, |
| 15746 | &cq_set->u.request, eq->queue_id); |
| 15747 | break; |
| 15748 | case 3: |
| 15749 | bf_set(lpfc_mbx_cq_create_set_eq_id3, |
| 15750 | &cq_set->u.request, eq->queue_id); |
| 15751 | break; |
| 15752 | case 4: |
| 15753 | bf_set(lpfc_mbx_cq_create_set_eq_id4, |
| 15754 | &cq_set->u.request, eq->queue_id); |
| 15755 | break; |
| 15756 | case 5: |
| 15757 | bf_set(lpfc_mbx_cq_create_set_eq_id5, |
| 15758 | &cq_set->u.request, eq->queue_id); |
| 15759 | break; |
| 15760 | case 6: |
| 15761 | bf_set(lpfc_mbx_cq_create_set_eq_id6, |
| 15762 | &cq_set->u.request, eq->queue_id); |
| 15763 | break; |
| 15764 | case 7: |
| 15765 | bf_set(lpfc_mbx_cq_create_set_eq_id7, |
| 15766 | &cq_set->u.request, eq->queue_id); |
| 15767 | break; |
| 15768 | case 8: |
| 15769 | bf_set(lpfc_mbx_cq_create_set_eq_id8, |
| 15770 | &cq_set->u.request, eq->queue_id); |
| 15771 | break; |
| 15772 | case 9: |
| 15773 | bf_set(lpfc_mbx_cq_create_set_eq_id9, |
| 15774 | &cq_set->u.request, eq->queue_id); |
| 15775 | break; |
| 15776 | case 10: |
| 15777 | bf_set(lpfc_mbx_cq_create_set_eq_id10, |
| 15778 | &cq_set->u.request, eq->queue_id); |
| 15779 | break; |
| 15780 | case 11: |
| 15781 | bf_set(lpfc_mbx_cq_create_set_eq_id11, |
| 15782 | &cq_set->u.request, eq->queue_id); |
| 15783 | break; |
| 15784 | case 12: |
| 15785 | bf_set(lpfc_mbx_cq_create_set_eq_id12, |
| 15786 | &cq_set->u.request, eq->queue_id); |
| 15787 | break; |
| 15788 | case 13: |
| 15789 | bf_set(lpfc_mbx_cq_create_set_eq_id13, |
| 15790 | &cq_set->u.request, eq->queue_id); |
| 15791 | break; |
| 15792 | case 14: |
| 15793 | bf_set(lpfc_mbx_cq_create_set_eq_id14, |
| 15794 | &cq_set->u.request, eq->queue_id); |
| 15795 | break; |
| 15796 | case 15: |
| 15797 | bf_set(lpfc_mbx_cq_create_set_eq_id15, |
| 15798 | &cq_set->u.request, eq->queue_id); |
| 15799 | break; |
| 15800 | } |
| 15801 | |
| 15802 | /* link the cq onto the parent eq child list */ |
| 15803 | list_add_tail(&cq->list, &eq->child_list); |
| 15804 | /* Set up completion queue's type and subtype */ |
| 15805 | cq->type = type; |
| 15806 | cq->subtype = subtype; |
| 15807 | cq->assoc_qid = eq->queue_id; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15808 | cq->assoc_qp = eq; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15809 | cq->host_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15810 | cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL; |
| 15811 | cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit, |
| 15812 | cq->entry_count); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15813 | cq->chann = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15814 | |
| 15815 | rc = 0; |
| 15816 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
| 15817 | memset(dmabuf->virt, 0, hw_page_size); |
| 15818 | cnt = page_idx + dmabuf->buffer_tag; |
| 15819 | cq_set->u.request.page[cnt].addr_lo = |
| 15820 | putPaddrLow(dmabuf->phys); |
| 15821 | cq_set->u.request.page[cnt].addr_hi = |
| 15822 | putPaddrHigh(dmabuf->phys); |
| 15823 | rc++; |
| 15824 | } |
| 15825 | page_idx += rc; |
| 15826 | } |
| 15827 | |
| 15828 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15829 | |
| 15830 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15831 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15832 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15833 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15834 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15835 | "3119 CQ_CREATE_SET mailbox failed with " |
| 15836 | "status x%x add_status x%x, mbx status x%x\n", |
| 15837 | shdr_status, shdr_add_status, rc); |
| 15838 | status = -ENXIO; |
| 15839 | goto out; |
| 15840 | } |
| 15841 | rc = bf_get(lpfc_mbx_cq_create_set_base_id, &cq_set->u.response); |
| 15842 | if (rc == 0xFFFF) { |
| 15843 | status = -ENXIO; |
| 15844 | goto out; |
| 15845 | } |
| 15846 | |
| 15847 | for (idx = 0; idx < numcq; idx++) { |
| 15848 | cq = cqp[idx]; |
| 15849 | cq->queue_id = rc + idx; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15850 | if (cq->queue_id > phba->sli4_hba.cq_max) |
| 15851 | phba->sli4_hba.cq_max = cq->queue_id; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15852 | } |
| 15853 | |
| 15854 | out: |
| 15855 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 15856 | return status; |
| 15857 | } |
| 15858 | |
| 15859 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15860 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15861 | * @phba: HBA structure that indicates port to create a queue on. |
| 15862 | * @mq: The queue structure to use to create the mailbox queue. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15863 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
| 15864 | * @cq: The completion queue to associate with this cq. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15865 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15866 | * This function provides failback (fb) functionality when the |
| 15867 | * mq_create_ext fails on older FW generations. It's purpose is identical |
| 15868 | * to mq_create_ext otherwise. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15869 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15870 | * This routine cannot fail as all attributes were previously accessed and |
| 15871 | * initialized in mq_create_ext. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15872 | **/ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15873 | static void |
| 15874 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 15875 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15876 | { |
| 15877 | struct lpfc_mbx_mq_create *mq_create; |
| 15878 | struct lpfc_dmabuf *dmabuf; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15879 | int length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15880 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15881 | length = (sizeof(struct lpfc_mbx_mq_create) - |
| 15882 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15883 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15884 | LPFC_MBOX_OPCODE_MQ_CREATE, |
| 15885 | length, LPFC_SLI4_MBX_EMBED); |
| 15886 | mq_create = &mbox->u.mqe.un.mq_create; |
| 15887 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15888 | mq->page_count); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15889 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15890 | cq->queue_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15891 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); |
| 15892 | switch (mq->entry_count) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15893 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15894 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15895 | LPFC_MQ_RING_SIZE_16); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15896 | break; |
| 15897 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15898 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15899 | LPFC_MQ_RING_SIZE_32); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15900 | break; |
| 15901 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15902 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15903 | LPFC_MQ_RING_SIZE_64); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15904 | break; |
| 15905 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15906 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15907 | LPFC_MQ_RING_SIZE_128); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15908 | break; |
| 15909 | } |
| 15910 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
| 15911 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15912 | putPaddrLow(dmabuf->phys); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15913 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15914 | putPaddrHigh(dmabuf->phys); |
| 15915 | } |
| 15916 | } |
| 15917 | |
| 15918 | /** |
| 15919 | * lpfc_mq_create - Create a mailbox Queue on the HBA |
| 15920 | * @phba: HBA structure that indicates port to create a queue on. |
| 15921 | * @mq: The queue structure to use to create the mailbox queue. |
| 15922 | * @cq: The completion queue to associate with this cq. |
| 15923 | * @subtype: The queue's subtype. |
| 15924 | * |
| 15925 | * This function creates a mailbox queue, as detailed in @mq, on a port, |
| 15926 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. |
| 15927 | * |
| 15928 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 15929 | * is used to get the entry count and entry size that are necessary to |
| 15930 | * determine the number of pages to allocate and use for this queue. This |
| 15931 | * function will send the MQ_CREATE mailbox command to the HBA to setup the |
| 15932 | * mailbox queue. This function is asynchronous and will wait for the mailbox |
| 15933 | * command to finish before continuing. |
| 15934 | * |
| 15935 | * 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] | 15936 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15937 | * fails this function will return -ENXIO. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15938 | **/ |
| 15939 | int32_t |
| 15940 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 15941 | struct lpfc_queue *cq, uint32_t subtype) |
| 15942 | { |
| 15943 | struct lpfc_mbx_mq_create *mq_create; |
| 15944 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
| 15945 | struct lpfc_dmabuf *dmabuf; |
| 15946 | LPFC_MBOXQ_t *mbox; |
| 15947 | int rc, length, status = 0; |
| 15948 | uint32_t shdr_status, shdr_add_status; |
| 15949 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15950 | 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] | 15951 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15952 | /* sanity check on queue memory */ |
| 15953 | if (!mq || !cq) |
| 15954 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15955 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15956 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15957 | |
| 15958 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15959 | if (!mbox) |
| 15960 | return -ENOMEM; |
| 15961 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
| 15962 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15963 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15964 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
| 15965 | length, LPFC_SLI4_MBX_EMBED); |
| 15966 | |
| 15967 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15968 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 15969 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
| 15970 | &mq_create_ext->u.request, mq->page_count); |
| 15971 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, |
| 15972 | &mq_create_ext->u.request, 1); |
| 15973 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15974 | &mq_create_ext->u.request, 1); |
| 15975 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, |
| 15976 | &mq_create_ext->u.request, 1); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 15977 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
| 15978 | &mq_create_ext->u.request, 1); |
| 15979 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, |
| 15980 | &mq_create_ext->u.request, 1); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15981 | 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] | 15982 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15983 | phba->sli4_hba.pc_sli4_params.mqv); |
| 15984 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) |
| 15985 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, |
| 15986 | cq->queue_id); |
| 15987 | else |
| 15988 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, |
| 15989 | cq->queue_id); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15990 | switch (mq->entry_count) { |
| 15991 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15992 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15993 | "0362 Unsupported MQ count. (%d)\n", |
| 15994 | mq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15995 | if (mq->entry_count < 16) { |
| 15996 | status = -EINVAL; |
| 15997 | goto out; |
| 15998 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 15999 | fallthrough; /* otherwise default to smallest count */ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16000 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16001 | bf_set(lpfc_mq_context_ring_size, |
| 16002 | &mq_create_ext->u.request.context, |
| 16003 | LPFC_MQ_RING_SIZE_16); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16004 | break; |
| 16005 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16006 | bf_set(lpfc_mq_context_ring_size, |
| 16007 | &mq_create_ext->u.request.context, |
| 16008 | LPFC_MQ_RING_SIZE_32); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16009 | break; |
| 16010 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16011 | bf_set(lpfc_mq_context_ring_size, |
| 16012 | &mq_create_ext->u.request.context, |
| 16013 | LPFC_MQ_RING_SIZE_64); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16014 | break; |
| 16015 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16016 | bf_set(lpfc_mq_context_ring_size, |
| 16017 | &mq_create_ext->u.request.context, |
| 16018 | LPFC_MQ_RING_SIZE_128); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16019 | break; |
| 16020 | } |
| 16021 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16022 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16023 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 16024 | putPaddrLow(dmabuf->phys); |
| 16025 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16026 | putPaddrHigh(dmabuf->phys); |
| 16027 | } |
| 16028 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 16029 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 16030 | &mq_create_ext->u.response); |
| 16031 | if (rc != MBX_SUCCESS) { |
| 16032 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 16033 | "2795 MQ_CREATE_EXT failed with " |
| 16034 | "status x%x. Failback to MQ_CREATE.\n", |
| 16035 | rc); |
| 16036 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); |
| 16037 | mq_create = &mbox->u.mqe.un.mq_create; |
| 16038 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16039 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; |
| 16040 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 16041 | &mq_create->u.response); |
| 16042 | } |
| 16043 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16044 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16045 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16046 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16047 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16048 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16049 | "2502 MQ_CREATE mailbox failed with " |
| 16050 | "status x%x add_status x%x, mbx status x%x\n", |
| 16051 | shdr_status, shdr_add_status, rc); |
| 16052 | status = -ENXIO; |
| 16053 | goto out; |
| 16054 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16055 | if (mq->queue_id == 0xFFFF) { |
| 16056 | status = -ENXIO; |
| 16057 | goto out; |
| 16058 | } |
| 16059 | mq->type = LPFC_MQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 16060 | mq->assoc_qid = cq->queue_id; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16061 | mq->subtype = subtype; |
| 16062 | mq->host_index = 0; |
| 16063 | mq->hba_index = 0; |
| 16064 | |
| 16065 | /* link the mq onto the parent cq child list */ |
| 16066 | list_add_tail(&mq->list, &cq->child_list); |
| 16067 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16068 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16069 | return status; |
| 16070 | } |
| 16071 | |
| 16072 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16073 | * lpfc_wq_create - Create a Work Queue on the HBA |
| 16074 | * @phba: HBA structure that indicates port to create a queue on. |
| 16075 | * @wq: The queue structure to use to create the work queue. |
| 16076 | * @cq: The completion queue to bind this work queue to. |
| 16077 | * @subtype: The subtype of the work queue indicating its functionality. |
| 16078 | * |
| 16079 | * This function creates a work queue, as detailed in @wq, on a port, described |
| 16080 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. |
| 16081 | * |
| 16082 | * The @phba struct is used to send mailbox command to HBA. The @wq struct |
| 16083 | * is used to get the entry count and entry size that are necessary to |
| 16084 | * determine the number of pages to allocate and use for this queue. The @cq |
| 16085 | * is used to indicate which completion queue to bind this work queue to. This |
| 16086 | * function will send the WQ_CREATE mailbox command to the HBA to setup the |
| 16087 | * work queue. This function is asynchronous and will wait for the mailbox |
| 16088 | * command to finish before continuing. |
| 16089 | * |
| 16090 | * 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] | 16091 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 16092 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16093 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16094 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16095 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
| 16096 | struct lpfc_queue *cq, uint32_t subtype) |
| 16097 | { |
| 16098 | struct lpfc_mbx_wq_create *wq_create; |
| 16099 | struct lpfc_dmabuf *dmabuf; |
| 16100 | LPFC_MBOXQ_t *mbox; |
| 16101 | int rc, length, status = 0; |
| 16102 | uint32_t shdr_status, shdr_add_status; |
| 16103 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16104 | 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] | 16105 | struct dma_address *page; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16106 | void __iomem *bar_memmap_p; |
| 16107 | uint32_t db_offset; |
| 16108 | uint16_t pci_barset; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16109 | uint8_t dpp_barset; |
| 16110 | uint32_t dpp_offset; |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 16111 | uint8_t wq_create_version; |
Lee Jones | 11d8e56 | 2020-07-21 17:41:44 +0100 | [diff] [blame] | 16112 | #ifdef CONFIG_X86 |
| 16113 | unsigned long pg_addr; |
| 16114 | #endif |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16115 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16116 | /* sanity check on queue memory */ |
| 16117 | if (!wq || !cq) |
| 16118 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16119 | if (!phba->sli4_hba.pc_sli4_params.supported) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 16120 | hw_page_size = wq->page_size; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16121 | |
| 16122 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16123 | if (!mbox) |
| 16124 | return -ENOMEM; |
| 16125 | length = (sizeof(struct lpfc_mbx_wq_create) - |
| 16126 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16127 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16128 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, |
| 16129 | length, LPFC_SLI4_MBX_EMBED); |
| 16130 | wq_create = &mbox->u.mqe.un.wq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16131 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16132 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
| 16133 | wq->page_count); |
| 16134 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, |
| 16135 | cq->queue_id); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 16136 | |
| 16137 | /* wqv is the earliest version supported, NOT the latest */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16138 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 16139 | phba->sli4_hba.pc_sli4_params.wqv); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16140 | |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 16141 | if ((phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) || |
| 16142 | (wq->page_size > SLI4_PAGE_SIZE)) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 16143 | wq_create_version = LPFC_Q_CREATE_VERSION_1; |
| 16144 | else |
| 16145 | wq_create_version = LPFC_Q_CREATE_VERSION_0; |
| 16146 | |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16147 | switch (wq_create_version) { |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 16148 | case LPFC_Q_CREATE_VERSION_1: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16149 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
| 16150 | wq->entry_count); |
James Smart | 3f247de | 2017-04-21 16:04:56 -0700 | [diff] [blame] | 16151 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 16152 | LPFC_Q_CREATE_VERSION_1); |
| 16153 | |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16154 | switch (wq->entry_size) { |
| 16155 | default: |
| 16156 | case 64: |
| 16157 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 16158 | &wq_create->u.request_1, |
| 16159 | LPFC_WQ_WQE_SIZE_64); |
| 16160 | break; |
| 16161 | case 128: |
| 16162 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 16163 | &wq_create->u.request_1, |
| 16164 | LPFC_WQ_WQE_SIZE_128); |
| 16165 | break; |
| 16166 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16167 | /* Request DPP by default */ |
| 16168 | 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] | 16169 | bf_set(lpfc_mbx_wq_create_page_size, |
| 16170 | &wq_create->u.request_1, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 16171 | (wq->page_size / SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16172 | page = wq_create->u.request_1.page; |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 16173 | break; |
| 16174 | default: |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16175 | page = wq_create->u.request.page; |
| 16176 | break; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16177 | } |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 16178 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16179 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16180 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16181 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
| 16182 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16183 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16184 | |
| 16185 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 16186 | bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1); |
| 16187 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16188 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16189 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16190 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16191 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16192 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16193 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16194 | "2503 WQ_CREATE mailbox failed with " |
| 16195 | "status x%x add_status x%x, mbx status x%x\n", |
| 16196 | shdr_status, shdr_add_status, rc); |
| 16197 | status = -ENXIO; |
| 16198 | goto out; |
| 16199 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16200 | |
| 16201 | if (wq_create_version == LPFC_Q_CREATE_VERSION_0) |
| 16202 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, |
| 16203 | &wq_create->u.response); |
| 16204 | else |
| 16205 | wq->queue_id = bf_get(lpfc_mbx_wq_create_v1_q_id, |
| 16206 | &wq_create->u.response_1); |
| 16207 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16208 | if (wq->queue_id == 0xFFFF) { |
| 16209 | status = -ENXIO; |
| 16210 | goto out; |
| 16211 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16212 | |
| 16213 | wq->db_format = LPFC_DB_LIST_FORMAT; |
| 16214 | if (wq_create_version == LPFC_Q_CREATE_VERSION_0) { |
| 16215 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 16216 | wq->db_format = bf_get(lpfc_mbx_wq_create_db_format, |
| 16217 | &wq_create->u.response); |
| 16218 | if ((wq->db_format != LPFC_DB_LIST_FORMAT) && |
| 16219 | (wq->db_format != LPFC_DB_RING_FORMAT)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16220 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16221 | "3265 WQ[%d] doorbell format " |
| 16222 | "not supported: x%x\n", |
| 16223 | wq->queue_id, wq->db_format); |
| 16224 | status = -EINVAL; |
| 16225 | goto out; |
| 16226 | } |
| 16227 | pci_barset = bf_get(lpfc_mbx_wq_create_bar_set, |
| 16228 | &wq_create->u.response); |
| 16229 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 16230 | pci_barset); |
| 16231 | if (!bar_memmap_p) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16232 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16233 | "3263 WQ[%d] failed to memmap " |
| 16234 | "pci barset:x%x\n", |
| 16235 | wq->queue_id, pci_barset); |
| 16236 | status = -ENOMEM; |
| 16237 | goto out; |
| 16238 | } |
| 16239 | db_offset = wq_create->u.response.doorbell_offset; |
| 16240 | if ((db_offset != LPFC_ULP0_WQ_DOORBELL) && |
| 16241 | (db_offset != LPFC_ULP1_WQ_DOORBELL)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16242 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16243 | "3252 WQ[%d] doorbell offset " |
| 16244 | "not supported: x%x\n", |
| 16245 | wq->queue_id, db_offset); |
| 16246 | status = -EINVAL; |
| 16247 | goto out; |
| 16248 | } |
| 16249 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 16250 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 16251 | "3264 WQ[%d]: barset:x%x, offset:x%x, " |
| 16252 | "format:x%x\n", wq->queue_id, |
| 16253 | pci_barset, db_offset, wq->db_format); |
| 16254 | } else |
| 16255 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16256 | } else { |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16257 | /* Check if DPP was honored by the firmware */ |
| 16258 | wq->dpp_enable = bf_get(lpfc_mbx_wq_create_dpp_rsp, |
| 16259 | &wq_create->u.response_1); |
| 16260 | if (wq->dpp_enable) { |
| 16261 | pci_barset = bf_get(lpfc_mbx_wq_create_v1_bar_set, |
| 16262 | &wq_create->u.response_1); |
| 16263 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 16264 | pci_barset); |
| 16265 | if (!bar_memmap_p) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16266 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16267 | "3267 WQ[%d] failed to memmap " |
| 16268 | "pci barset:x%x\n", |
| 16269 | wq->queue_id, pci_barset); |
| 16270 | status = -ENOMEM; |
| 16271 | goto out; |
| 16272 | } |
| 16273 | db_offset = wq_create->u.response_1.doorbell_offset; |
| 16274 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 16275 | wq->dpp_id = bf_get(lpfc_mbx_wq_create_dpp_id, |
| 16276 | &wq_create->u.response_1); |
| 16277 | dpp_barset = bf_get(lpfc_mbx_wq_create_dpp_bar, |
| 16278 | &wq_create->u.response_1); |
| 16279 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 16280 | dpp_barset); |
| 16281 | if (!bar_memmap_p) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16282 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16283 | "3268 WQ[%d] failed to memmap " |
| 16284 | "pci barset:x%x\n", |
| 16285 | wq->queue_id, dpp_barset); |
| 16286 | status = -ENOMEM; |
| 16287 | goto out; |
| 16288 | } |
| 16289 | dpp_offset = wq_create->u.response_1.dpp_offset; |
| 16290 | wq->dpp_regaddr = bar_memmap_p + dpp_offset; |
| 16291 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 16292 | "3271 WQ[%d]: barset:x%x, offset:x%x, " |
| 16293 | "dpp_id:x%x dpp_barset:x%x " |
| 16294 | "dpp_offset:x%x\n", |
| 16295 | wq->queue_id, pci_barset, db_offset, |
| 16296 | wq->dpp_id, dpp_barset, dpp_offset); |
| 16297 | |
Lee Jones | 3c1311a | 2020-07-21 17:41:28 +0100 | [diff] [blame] | 16298 | #ifdef CONFIG_X86 |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16299 | /* Enable combined writes for DPP aperture */ |
| 16300 | pg_addr = (unsigned long)(wq->dpp_regaddr) & PAGE_MASK; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 16301 | rc = set_memory_wc(pg_addr, 1); |
| 16302 | if (rc) { |
| 16303 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16304 | "3272 Cannot setup Combined " |
| 16305 | "Write on WQ[%d] - disable DPP\n", |
| 16306 | wq->queue_id); |
| 16307 | phba->cfg_enable_dpp = 0; |
| 16308 | } |
| 16309 | #else |
| 16310 | phba->cfg_enable_dpp = 0; |
| 16311 | #endif |
| 16312 | } else |
| 16313 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16314 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16315 | wq->pring = kzalloc(sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 16316 | if (wq->pring == NULL) { |
| 16317 | status = -ENOMEM; |
| 16318 | goto out; |
| 16319 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16320 | wq->type = LPFC_WQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 16321 | wq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16322 | wq->subtype = subtype; |
| 16323 | wq->host_index = 0; |
| 16324 | wq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16325 | wq->notify_interval = LPFC_WQ_NOTIFY_INTRVL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16326 | |
| 16327 | /* link the wq onto the parent cq child list */ |
| 16328 | list_add_tail(&wq->list, &cq->child_list); |
| 16329 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16330 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16331 | return status; |
| 16332 | } |
| 16333 | |
| 16334 | /** |
| 16335 | * lpfc_rq_create - Create a Receive Queue on the HBA |
| 16336 | * @phba: HBA structure that indicates port to create a queue on. |
| 16337 | * @hrq: The queue structure to use to create the header receive queue. |
| 16338 | * @drq: The queue structure to use to create the data receive queue. |
| 16339 | * @cq: The completion queue to bind this work queue to. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 16340 | * @subtype: The subtype of the work queue indicating its functionality. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16341 | * |
| 16342 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 16343 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 16344 | * to the HBA. |
| 16345 | * |
| 16346 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 16347 | * struct is used to get the entry count that is necessary to determine the |
| 16348 | * number of pages to use for this queue. The @cq is used to indicate which |
| 16349 | * completion queue to bind received buffers that are posted to these queues to. |
| 16350 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 16351 | * receive queue pair. This function is asynchronous and will wait for the |
| 16352 | * mailbox command to finish before continuing. |
| 16353 | * |
| 16354 | * 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] | 16355 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 16356 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16357 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16358 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16359 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 16360 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) |
| 16361 | { |
| 16362 | struct lpfc_mbx_rq_create *rq_create; |
| 16363 | struct lpfc_dmabuf *dmabuf; |
| 16364 | LPFC_MBOXQ_t *mbox; |
| 16365 | int rc, length, status = 0; |
| 16366 | uint32_t shdr_status, shdr_add_status; |
| 16367 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16368 | 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] | 16369 | void __iomem *bar_memmap_p; |
| 16370 | uint32_t db_offset; |
| 16371 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16372 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16373 | /* sanity check on queue memory */ |
| 16374 | if (!hrq || !drq || !cq) |
| 16375 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16376 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 16377 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16378 | |
| 16379 | if (hrq->entry_count != drq->entry_count) |
| 16380 | return -EINVAL; |
| 16381 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16382 | if (!mbox) |
| 16383 | return -ENOMEM; |
| 16384 | length = (sizeof(struct lpfc_mbx_rq_create) - |
| 16385 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16386 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16387 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 16388 | length, LPFC_SLI4_MBX_EMBED); |
| 16389 | rq_create = &mbox->u.mqe.un.rq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16390 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 16391 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 16392 | phba->sli4_hba.pc_sli4_params.rqv); |
| 16393 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 16394 | bf_set(lpfc_rq_context_rqe_count_1, |
| 16395 | &rq_create->u.request.context, |
| 16396 | hrq->entry_count); |
| 16397 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 16398 | bf_set(lpfc_rq_context_rqe_size, |
| 16399 | &rq_create->u.request.context, |
| 16400 | LPFC_RQE_SIZE_8); |
| 16401 | bf_set(lpfc_rq_context_page_size, |
| 16402 | &rq_create->u.request.context, |
James Smart | 8ea73db | 2017-02-12 13:52:25 -0800 | [diff] [blame] | 16403 | LPFC_RQ_PAGE_SIZE_4096); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16404 | } else { |
| 16405 | switch (hrq->entry_count) { |
| 16406 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16407 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16408 | "2535 Unsupported RQ count. (%d)\n", |
| 16409 | hrq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 16410 | if (hrq->entry_count < 512) { |
| 16411 | status = -EINVAL; |
| 16412 | goto out; |
| 16413 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 16414 | fallthrough; /* otherwise default to smallest count */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16415 | case 512: |
| 16416 | bf_set(lpfc_rq_context_rqe_count, |
| 16417 | &rq_create->u.request.context, |
| 16418 | LPFC_RQ_RING_SIZE_512); |
| 16419 | break; |
| 16420 | case 1024: |
| 16421 | bf_set(lpfc_rq_context_rqe_count, |
| 16422 | &rq_create->u.request.context, |
| 16423 | LPFC_RQ_RING_SIZE_1024); |
| 16424 | break; |
| 16425 | case 2048: |
| 16426 | bf_set(lpfc_rq_context_rqe_count, |
| 16427 | &rq_create->u.request.context, |
| 16428 | LPFC_RQ_RING_SIZE_2048); |
| 16429 | break; |
| 16430 | case 4096: |
| 16431 | bf_set(lpfc_rq_context_rqe_count, |
| 16432 | &rq_create->u.request.context, |
| 16433 | LPFC_RQ_RING_SIZE_4096); |
| 16434 | break; |
| 16435 | } |
| 16436 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 16437 | LPFC_HDR_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16438 | } |
| 16439 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 16440 | cq->queue_id); |
| 16441 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 16442 | hrq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16443 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16444 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16445 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 16446 | putPaddrLow(dmabuf->phys); |
| 16447 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 16448 | putPaddrHigh(dmabuf->phys); |
| 16449 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16450 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 16451 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
| 16452 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16453 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16454 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16455 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16456 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16457 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16458 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16459 | "2504 RQ_CREATE mailbox failed with " |
| 16460 | "status x%x add_status x%x, mbx status x%x\n", |
| 16461 | shdr_status, shdr_add_status, rc); |
| 16462 | status = -ENXIO; |
| 16463 | goto out; |
| 16464 | } |
| 16465 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 16466 | if (hrq->queue_id == 0xFFFF) { |
| 16467 | status = -ENXIO; |
| 16468 | goto out; |
| 16469 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16470 | |
| 16471 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 16472 | hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format, |
| 16473 | &rq_create->u.response); |
| 16474 | if ((hrq->db_format != LPFC_DB_LIST_FORMAT) && |
| 16475 | (hrq->db_format != LPFC_DB_RING_FORMAT)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16476 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16477 | "3262 RQ [%d] doorbell format not " |
| 16478 | "supported: x%x\n", hrq->queue_id, |
| 16479 | hrq->db_format); |
| 16480 | status = -EINVAL; |
| 16481 | goto out; |
| 16482 | } |
| 16483 | |
| 16484 | pci_barset = bf_get(lpfc_mbx_rq_create_bar_set, |
| 16485 | &rq_create->u.response); |
| 16486 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 16487 | if (!bar_memmap_p) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16488 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16489 | "3269 RQ[%d] failed to memmap pci " |
| 16490 | "barset:x%x\n", hrq->queue_id, |
| 16491 | pci_barset); |
| 16492 | status = -ENOMEM; |
| 16493 | goto out; |
| 16494 | } |
| 16495 | |
| 16496 | db_offset = rq_create->u.response.doorbell_offset; |
| 16497 | if ((db_offset != LPFC_ULP0_RQ_DOORBELL) && |
| 16498 | (db_offset != LPFC_ULP1_RQ_DOORBELL)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16499 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16500 | "3270 RQ[%d] doorbell offset not " |
| 16501 | "supported: x%x\n", hrq->queue_id, |
| 16502 | db_offset); |
| 16503 | status = -EINVAL; |
| 16504 | goto out; |
| 16505 | } |
| 16506 | hrq->db_regaddr = bar_memmap_p + db_offset; |
| 16507 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 16508 | "3266 RQ[qid:%d]: barset:x%x, offset:x%x, " |
| 16509 | "format:x%x\n", hrq->queue_id, pci_barset, |
| 16510 | db_offset, hrq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16511 | } else { |
| 16512 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 16513 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 16514 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16515 | hrq->type = LPFC_HRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 16516 | hrq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16517 | hrq->subtype = subtype; |
| 16518 | hrq->host_index = 0; |
| 16519 | hrq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16520 | hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16521 | |
| 16522 | /* now create the data queue */ |
| 16523 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16524 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 16525 | length, LPFC_SLI4_MBX_EMBED); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16526 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 16527 | phba->sli4_hba.pc_sli4_params.rqv); |
| 16528 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 16529 | bf_set(lpfc_rq_context_rqe_count_1, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 16530 | &rq_create->u.request.context, hrq->entry_count); |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 16531 | if (subtype == LPFC_NVMET) |
| 16532 | rq_create->u.request.context.buffer_size = |
| 16533 | LPFC_NVMET_DATA_BUF_SIZE; |
| 16534 | else |
| 16535 | rq_create->u.request.context.buffer_size = |
| 16536 | LPFC_DATA_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 16537 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
| 16538 | LPFC_RQE_SIZE_8); |
| 16539 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, |
| 16540 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16541 | } else { |
| 16542 | switch (drq->entry_count) { |
| 16543 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16544 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16545 | "2536 Unsupported RQ count. (%d)\n", |
| 16546 | drq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 16547 | if (drq->entry_count < 512) { |
| 16548 | status = -EINVAL; |
| 16549 | goto out; |
| 16550 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 16551 | fallthrough; /* otherwise default to smallest count */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16552 | case 512: |
| 16553 | bf_set(lpfc_rq_context_rqe_count, |
| 16554 | &rq_create->u.request.context, |
| 16555 | LPFC_RQ_RING_SIZE_512); |
| 16556 | break; |
| 16557 | case 1024: |
| 16558 | bf_set(lpfc_rq_context_rqe_count, |
| 16559 | &rq_create->u.request.context, |
| 16560 | LPFC_RQ_RING_SIZE_1024); |
| 16561 | break; |
| 16562 | case 2048: |
| 16563 | bf_set(lpfc_rq_context_rqe_count, |
| 16564 | &rq_create->u.request.context, |
| 16565 | LPFC_RQ_RING_SIZE_2048); |
| 16566 | break; |
| 16567 | case 4096: |
| 16568 | bf_set(lpfc_rq_context_rqe_count, |
| 16569 | &rq_create->u.request.context, |
| 16570 | LPFC_RQ_RING_SIZE_4096); |
| 16571 | break; |
| 16572 | } |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 16573 | if (subtype == LPFC_NVMET) |
| 16574 | bf_set(lpfc_rq_context_buf_size, |
| 16575 | &rq_create->u.request.context, |
| 16576 | LPFC_NVMET_DATA_BUF_SIZE); |
| 16577 | else |
| 16578 | bf_set(lpfc_rq_context_buf_size, |
| 16579 | &rq_create->u.request.context, |
| 16580 | LPFC_DATA_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16581 | } |
| 16582 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 16583 | cq->queue_id); |
| 16584 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 16585 | drq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16586 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 16587 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 16588 | putPaddrLow(dmabuf->phys); |
| 16589 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 16590 | putPaddrHigh(dmabuf->phys); |
| 16591 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16592 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 16593 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16594 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16595 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16596 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 16597 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16598 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16599 | if (shdr_status || shdr_add_status || rc) { |
| 16600 | status = -ENXIO; |
| 16601 | goto out; |
| 16602 | } |
| 16603 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 16604 | if (drq->queue_id == 0xFFFF) { |
| 16605 | status = -ENXIO; |
| 16606 | goto out; |
| 16607 | } |
| 16608 | drq->type = LPFC_DRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 16609 | drq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16610 | drq->subtype = subtype; |
| 16611 | drq->host_index = 0; |
| 16612 | drq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16613 | drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16614 | |
| 16615 | /* link the header and data RQs onto the parent cq child list */ |
| 16616 | list_add_tail(&hrq->list, &cq->child_list); |
| 16617 | list_add_tail(&drq->list, &cq->child_list); |
| 16618 | |
| 16619 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16620 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16621 | return status; |
| 16622 | } |
| 16623 | |
| 16624 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16625 | * lpfc_mrq_create - Create MRQ Receive Queues on the HBA |
| 16626 | * @phba: HBA structure that indicates port to create a queue on. |
| 16627 | * @hrqp: The queue structure array to use to create the header receive queues. |
| 16628 | * @drqp: The queue structure array to use to create the data receive queues. |
| 16629 | * @cqp: The completion queue array to bind these receive queues to. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 16630 | * @subtype: Functional purpose of the queue (MBOX, IO, ELS, NVMET, etc). |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16631 | * |
| 16632 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 16633 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 16634 | * to the HBA. |
| 16635 | * |
| 16636 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 16637 | * struct is used to get the entry count that is necessary to determine the |
| 16638 | * number of pages to use for this queue. The @cq is used to indicate which |
| 16639 | * completion queue to bind received buffers that are posted to these queues to. |
| 16640 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 16641 | * receive queue pair. This function is asynchronous and will wait for the |
| 16642 | * mailbox command to finish before continuing. |
| 16643 | * |
| 16644 | * On success this function will return a zero. If unable to allocate enough |
| 16645 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 16646 | * fails this function will return -ENXIO. |
| 16647 | **/ |
| 16648 | int |
| 16649 | lpfc_mrq_create(struct lpfc_hba *phba, struct lpfc_queue **hrqp, |
| 16650 | struct lpfc_queue **drqp, struct lpfc_queue **cqp, |
| 16651 | uint32_t subtype) |
| 16652 | { |
| 16653 | struct lpfc_queue *hrq, *drq, *cq; |
| 16654 | struct lpfc_mbx_rq_create_v2 *rq_create; |
| 16655 | struct lpfc_dmabuf *dmabuf; |
| 16656 | LPFC_MBOXQ_t *mbox; |
| 16657 | int rc, length, alloclen, status = 0; |
| 16658 | int cnt, idx, numrq, page_idx = 0; |
| 16659 | uint32_t shdr_status, shdr_add_status; |
| 16660 | union lpfc_sli4_cfg_shdr *shdr; |
| 16661 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 16662 | |
| 16663 | numrq = phba->cfg_nvmet_mrq; |
| 16664 | /* sanity check on array memory */ |
| 16665 | if (!hrqp || !drqp || !cqp || !numrq) |
| 16666 | return -ENODEV; |
| 16667 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 16668 | hw_page_size = SLI4_PAGE_SIZE; |
| 16669 | |
| 16670 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16671 | if (!mbox) |
| 16672 | return -ENOMEM; |
| 16673 | |
| 16674 | length = sizeof(struct lpfc_mbx_rq_create_v2); |
| 16675 | length += ((2 * numrq * hrqp[0]->page_count) * |
| 16676 | sizeof(struct dma_address)); |
| 16677 | |
| 16678 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16679 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, length, |
| 16680 | LPFC_SLI4_MBX_NEMBED); |
| 16681 | if (alloclen < length) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16682 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16683 | "3099 Allocated DMA memory size (%d) is " |
| 16684 | "less than the requested DMA memory size " |
| 16685 | "(%d)\n", alloclen, length); |
| 16686 | status = -ENOMEM; |
| 16687 | goto out; |
| 16688 | } |
| 16689 | |
| 16690 | |
| 16691 | |
| 16692 | rq_create = mbox->sge_array->addr[0]; |
| 16693 | shdr = (union lpfc_sli4_cfg_shdr *)&rq_create->cfg_shdr; |
| 16694 | |
| 16695 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_Q_CREATE_VERSION_2); |
| 16696 | cnt = 0; |
| 16697 | |
| 16698 | for (idx = 0; idx < numrq; idx++) { |
| 16699 | hrq = hrqp[idx]; |
| 16700 | drq = drqp[idx]; |
| 16701 | cq = cqp[idx]; |
| 16702 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16703 | /* sanity check on queue memory */ |
| 16704 | if (!hrq || !drq || !cq) { |
| 16705 | status = -ENODEV; |
| 16706 | goto out; |
| 16707 | } |
| 16708 | |
James Smart | 7aabe84 | 2017-03-04 09:30:22 -0800 | [diff] [blame] | 16709 | if (hrq->entry_count != drq->entry_count) { |
| 16710 | status = -EINVAL; |
| 16711 | goto out; |
| 16712 | } |
| 16713 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16714 | if (idx == 0) { |
| 16715 | bf_set(lpfc_mbx_rq_create_num_pages, |
| 16716 | &rq_create->u.request, |
| 16717 | hrq->page_count); |
| 16718 | bf_set(lpfc_mbx_rq_create_rq_cnt, |
| 16719 | &rq_create->u.request, (numrq * 2)); |
| 16720 | bf_set(lpfc_mbx_rq_create_dnb, &rq_create->u.request, |
| 16721 | 1); |
| 16722 | bf_set(lpfc_rq_context_base_cq, |
| 16723 | &rq_create->u.request.context, |
| 16724 | cq->queue_id); |
| 16725 | bf_set(lpfc_rq_context_data_size, |
| 16726 | &rq_create->u.request.context, |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 16727 | LPFC_NVMET_DATA_BUF_SIZE); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16728 | bf_set(lpfc_rq_context_hdr_size, |
| 16729 | &rq_create->u.request.context, |
| 16730 | LPFC_HDR_BUF_SIZE); |
| 16731 | bf_set(lpfc_rq_context_rqe_count_1, |
| 16732 | &rq_create->u.request.context, |
| 16733 | hrq->entry_count); |
| 16734 | bf_set(lpfc_rq_context_rqe_size, |
| 16735 | &rq_create->u.request.context, |
| 16736 | LPFC_RQE_SIZE_8); |
| 16737 | bf_set(lpfc_rq_context_page_size, |
| 16738 | &rq_create->u.request.context, |
| 16739 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 16740 | } |
| 16741 | rc = 0; |
| 16742 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
| 16743 | memset(dmabuf->virt, 0, hw_page_size); |
| 16744 | cnt = page_idx + dmabuf->buffer_tag; |
| 16745 | rq_create->u.request.page[cnt].addr_lo = |
| 16746 | putPaddrLow(dmabuf->phys); |
| 16747 | rq_create->u.request.page[cnt].addr_hi = |
| 16748 | putPaddrHigh(dmabuf->phys); |
| 16749 | rc++; |
| 16750 | } |
| 16751 | page_idx += rc; |
| 16752 | |
| 16753 | rc = 0; |
| 16754 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 16755 | memset(dmabuf->virt, 0, hw_page_size); |
| 16756 | cnt = page_idx + dmabuf->buffer_tag; |
| 16757 | rq_create->u.request.page[cnt].addr_lo = |
| 16758 | putPaddrLow(dmabuf->phys); |
| 16759 | rq_create->u.request.page[cnt].addr_hi = |
| 16760 | putPaddrHigh(dmabuf->phys); |
| 16761 | rc++; |
| 16762 | } |
| 16763 | page_idx += rc; |
| 16764 | |
| 16765 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 16766 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 16767 | hrq->type = LPFC_HRQ; |
| 16768 | hrq->assoc_qid = cq->queue_id; |
| 16769 | hrq->subtype = subtype; |
| 16770 | hrq->host_index = 0; |
| 16771 | hrq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16772 | hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16773 | |
| 16774 | drq->db_format = LPFC_DB_RING_FORMAT; |
| 16775 | drq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 16776 | drq->type = LPFC_DRQ; |
| 16777 | drq->assoc_qid = cq->queue_id; |
| 16778 | drq->subtype = subtype; |
| 16779 | drq->host_index = 0; |
| 16780 | drq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16781 | drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16782 | |
| 16783 | list_add_tail(&hrq->list, &cq->child_list); |
| 16784 | list_add_tail(&drq->list, &cq->child_list); |
| 16785 | } |
| 16786 | |
| 16787 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16788 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16789 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16790 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16791 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16792 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16793 | "3120 RQ_CREATE mailbox failed with " |
| 16794 | "status x%x add_status x%x, mbx status x%x\n", |
| 16795 | shdr_status, shdr_add_status, rc); |
| 16796 | status = -ENXIO; |
| 16797 | goto out; |
| 16798 | } |
| 16799 | rc = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 16800 | if (rc == 0xFFFF) { |
| 16801 | status = -ENXIO; |
| 16802 | goto out; |
| 16803 | } |
| 16804 | |
| 16805 | /* Initialize all RQs with associated queue id */ |
| 16806 | for (idx = 0; idx < numrq; idx++) { |
| 16807 | hrq = hrqp[idx]; |
| 16808 | hrq->queue_id = rc + (2 * idx); |
| 16809 | drq = drqp[idx]; |
| 16810 | drq->queue_id = rc + (2 * idx) + 1; |
| 16811 | } |
| 16812 | |
| 16813 | out: |
| 16814 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16815 | return status; |
| 16816 | } |
| 16817 | |
| 16818 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16819 | * lpfc_eq_destroy - Destroy an event Queue on the HBA |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 16820 | * @phba: HBA structure that indicates port to destroy a queue on. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16821 | * @eq: The queue structure associated with the queue to destroy. |
| 16822 | * |
| 16823 | * This function destroys a queue, as detailed in @eq by sending an mailbox |
| 16824 | * command, specific to the type of queue, to the HBA. |
| 16825 | * |
| 16826 | * The @eq struct is used to get the queue ID of the queue to destroy. |
| 16827 | * |
| 16828 | * 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] | 16829 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16830 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16831 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16832 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 16833 | { |
| 16834 | LPFC_MBOXQ_t *mbox; |
| 16835 | int rc, length, status = 0; |
| 16836 | uint32_t shdr_status, shdr_add_status; |
| 16837 | union lpfc_sli4_cfg_shdr *shdr; |
| 16838 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16839 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16840 | if (!eq) |
| 16841 | return -ENODEV; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16842 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16843 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16844 | if (!mbox) |
| 16845 | return -ENOMEM; |
| 16846 | length = (sizeof(struct lpfc_mbx_eq_destroy) - |
| 16847 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16848 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16849 | LPFC_MBOX_OPCODE_EQ_DESTROY, |
| 16850 | length, LPFC_SLI4_MBX_EMBED); |
| 16851 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, |
| 16852 | eq->queue_id); |
| 16853 | mbox->vport = eq->phba->pport; |
| 16854 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16855 | |
| 16856 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); |
| 16857 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16858 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16859 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; |
| 16860 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16861 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16862 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16863 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16864 | "2505 EQ_DESTROY mailbox failed with " |
| 16865 | "status x%x add_status x%x, mbx status x%x\n", |
| 16866 | shdr_status, shdr_add_status, rc); |
| 16867 | status = -ENXIO; |
| 16868 | } |
| 16869 | |
| 16870 | /* Remove eq from any list */ |
| 16871 | list_del_init(&eq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16872 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16873 | return status; |
| 16874 | } |
| 16875 | |
| 16876 | /** |
| 16877 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 16878 | * @phba: HBA structure that indicates port to destroy a queue on. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16879 | * @cq: The queue structure associated with the queue to destroy. |
| 16880 | * |
| 16881 | * This function destroys a queue, as detailed in @cq by sending an mailbox |
| 16882 | * command, specific to the type of queue, to the HBA. |
| 16883 | * |
| 16884 | * The @cq struct is used to get the queue ID of the queue to destroy. |
| 16885 | * |
| 16886 | * 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] | 16887 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16888 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16889 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16890 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
| 16891 | { |
| 16892 | LPFC_MBOXQ_t *mbox; |
| 16893 | int rc, length, status = 0; |
| 16894 | uint32_t shdr_status, shdr_add_status; |
| 16895 | union lpfc_sli4_cfg_shdr *shdr; |
| 16896 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16897 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16898 | if (!cq) |
| 16899 | return -ENODEV; |
| 16900 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16901 | if (!mbox) |
| 16902 | return -ENOMEM; |
| 16903 | length = (sizeof(struct lpfc_mbx_cq_destroy) - |
| 16904 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16905 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16906 | LPFC_MBOX_OPCODE_CQ_DESTROY, |
| 16907 | length, LPFC_SLI4_MBX_EMBED); |
| 16908 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, |
| 16909 | cq->queue_id); |
| 16910 | mbox->vport = cq->phba->pport; |
| 16911 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16912 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); |
| 16913 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16914 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16915 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; |
| 16916 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16917 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16918 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16919 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16920 | "2506 CQ_DESTROY mailbox failed with " |
| 16921 | "status x%x add_status x%x, mbx status x%x\n", |
| 16922 | shdr_status, shdr_add_status, rc); |
| 16923 | status = -ENXIO; |
| 16924 | } |
| 16925 | /* Remove cq from any list */ |
| 16926 | list_del_init(&cq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16927 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16928 | return status; |
| 16929 | } |
| 16930 | |
| 16931 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16932 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 16933 | * @phba: HBA structure that indicates port to destroy a queue on. |
| 16934 | * @mq: The queue structure associated with the queue to destroy. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16935 | * |
| 16936 | * This function destroys a queue, as detailed in @mq by sending an mailbox |
| 16937 | * command, specific to the type of queue, to the HBA. |
| 16938 | * |
| 16939 | * The @mq struct is used to get the queue ID of the queue to destroy. |
| 16940 | * |
| 16941 | * 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] | 16942 | * command fails this function will return -ENXIO. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16943 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16944 | int |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16945 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
| 16946 | { |
| 16947 | LPFC_MBOXQ_t *mbox; |
| 16948 | int rc, length, status = 0; |
| 16949 | uint32_t shdr_status, shdr_add_status; |
| 16950 | union lpfc_sli4_cfg_shdr *shdr; |
| 16951 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16952 | /* sanity check on queue memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16953 | if (!mq) |
| 16954 | return -ENODEV; |
| 16955 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16956 | if (!mbox) |
| 16957 | return -ENOMEM; |
| 16958 | length = (sizeof(struct lpfc_mbx_mq_destroy) - |
| 16959 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16960 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16961 | LPFC_MBOX_OPCODE_MQ_DESTROY, |
| 16962 | length, LPFC_SLI4_MBX_EMBED); |
| 16963 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, |
| 16964 | mq->queue_id); |
| 16965 | mbox->vport = mq->phba->pport; |
| 16966 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16967 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); |
| 16968 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16969 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16970 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; |
| 16971 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16972 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16973 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 16974 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16975 | "2507 MQ_DESTROY mailbox failed with " |
| 16976 | "status x%x add_status x%x, mbx status x%x\n", |
| 16977 | shdr_status, shdr_add_status, rc); |
| 16978 | status = -ENXIO; |
| 16979 | } |
| 16980 | /* Remove mq from any list */ |
| 16981 | list_del_init(&mq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16982 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16983 | return status; |
| 16984 | } |
| 16985 | |
| 16986 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16987 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 16988 | * @phba: HBA structure that indicates port to destroy a queue on. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16989 | * @wq: The queue structure associated with the queue to destroy. |
| 16990 | * |
| 16991 | * This function destroys a queue, as detailed in @wq by sending an mailbox |
| 16992 | * command, specific to the type of queue, to the HBA. |
| 16993 | * |
| 16994 | * The @wq struct is used to get the queue ID of the queue to destroy. |
| 16995 | * |
| 16996 | * 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] | 16997 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16998 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16999 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17000 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
| 17001 | { |
| 17002 | LPFC_MBOXQ_t *mbox; |
| 17003 | int rc, length, status = 0; |
| 17004 | uint32_t shdr_status, shdr_add_status; |
| 17005 | union lpfc_sli4_cfg_shdr *shdr; |
| 17006 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 17007 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17008 | if (!wq) |
| 17009 | return -ENODEV; |
| 17010 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); |
| 17011 | if (!mbox) |
| 17012 | return -ENOMEM; |
| 17013 | length = (sizeof(struct lpfc_mbx_wq_destroy) - |
| 17014 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 17015 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 17016 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, |
| 17017 | length, LPFC_SLI4_MBX_EMBED); |
| 17018 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, |
| 17019 | wq->queue_id); |
| 17020 | mbox->vport = wq->phba->pport; |
| 17021 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 17022 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); |
| 17023 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 17024 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; |
| 17025 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17026 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 17027 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17028 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17029 | "2508 WQ_DESTROY mailbox failed with " |
| 17030 | "status x%x add_status x%x, mbx status x%x\n", |
| 17031 | shdr_status, shdr_add_status, rc); |
| 17032 | status = -ENXIO; |
| 17033 | } |
| 17034 | /* Remove wq from any list */ |
| 17035 | list_del_init(&wq->list); |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 17036 | kfree(wq->pring); |
| 17037 | wq->pring = NULL; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 17038 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17039 | return status; |
| 17040 | } |
| 17041 | |
| 17042 | /** |
| 17043 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 17044 | * @phba: HBA structure that indicates port to destroy a queue on. |
| 17045 | * @hrq: The queue structure associated with the queue to destroy. |
| 17046 | * @drq: The queue structure associated with the queue to destroy. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17047 | * |
| 17048 | * This function destroys a queue, as detailed in @rq by sending an mailbox |
| 17049 | * command, specific to the type of queue, to the HBA. |
| 17050 | * |
| 17051 | * The @rq struct is used to get the queue ID of the queue to destroy. |
| 17052 | * |
| 17053 | * 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] | 17054 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17055 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 17056 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17057 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 17058 | struct lpfc_queue *drq) |
| 17059 | { |
| 17060 | LPFC_MBOXQ_t *mbox; |
| 17061 | int rc, length, status = 0; |
| 17062 | uint32_t shdr_status, shdr_add_status; |
| 17063 | union lpfc_sli4_cfg_shdr *shdr; |
| 17064 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 17065 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17066 | if (!hrq || !drq) |
| 17067 | return -ENODEV; |
| 17068 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); |
| 17069 | if (!mbox) |
| 17070 | return -ENOMEM; |
| 17071 | length = (sizeof(struct lpfc_mbx_rq_destroy) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 17072 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17073 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 17074 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, |
| 17075 | length, LPFC_SLI4_MBX_EMBED); |
| 17076 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 17077 | hrq->queue_id); |
| 17078 | mbox->vport = hrq->phba->pport; |
| 17079 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 17080 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); |
| 17081 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 17082 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 17083 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 17084 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17085 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 17086 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17087 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17088 | "2509 RQ_DESTROY mailbox failed with " |
| 17089 | "status x%x add_status x%x, mbx status x%x\n", |
| 17090 | shdr_status, shdr_add_status, rc); |
James Smart | 304ee43 | 2021-04-11 18:31:17 -0700 | [diff] [blame] | 17091 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17092 | return -ENXIO; |
| 17093 | } |
| 17094 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 17095 | drq->queue_id); |
| 17096 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); |
| 17097 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 17098 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 17099 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17100 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 17101 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17102 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17103 | "2510 RQ_DESTROY mailbox failed with " |
| 17104 | "status x%x add_status x%x, mbx status x%x\n", |
| 17105 | shdr_status, shdr_add_status, rc); |
| 17106 | status = -ENXIO; |
| 17107 | } |
| 17108 | list_del_init(&hrq->list); |
| 17109 | list_del_init(&drq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 17110 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17111 | return status; |
| 17112 | } |
| 17113 | |
| 17114 | /** |
| 17115 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA |
| 17116 | * @phba: The virtual port for which this call being executed. |
| 17117 | * @pdma_phys_addr0: Physical address of the 1st SGL page. |
| 17118 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. |
| 17119 | * @xritag: the xritag that ties this io to the SGL pages. |
| 17120 | * |
| 17121 | * This routine will post the sgl pages for the IO that has the xritag |
| 17122 | * that is in the iocbq structure. The xritag is assigned during iocbq |
| 17123 | * creation and persists for as long as the driver is loaded. |
| 17124 | * if the caller has fewer than 256 scatter gather segments to map then |
| 17125 | * pdma_phys_addr1 should be 0. |
| 17126 | * If the caller needs to map more than 256 scatter gather segment then |
| 17127 | * pdma_phys_addr1 should be a valid physical address. |
| 17128 | * physical address for SGLs must be 64 byte aligned. |
| 17129 | * If you are going to map 2 SGL's then the first one must have 256 entries |
| 17130 | * the second sgl can have between 1 and 256 entries. |
| 17131 | * |
| 17132 | * Return codes: |
| 17133 | * 0 - Success |
| 17134 | * -ENXIO, -ENOMEM - Failure |
| 17135 | **/ |
| 17136 | int |
| 17137 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, |
| 17138 | dma_addr_t pdma_phys_addr0, |
| 17139 | dma_addr_t pdma_phys_addr1, |
| 17140 | uint16_t xritag) |
| 17141 | { |
| 17142 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; |
| 17143 | LPFC_MBOXQ_t *mbox; |
| 17144 | int rc; |
| 17145 | uint32_t shdr_status, shdr_add_status; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17146 | uint32_t mbox_tmo; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17147 | union lpfc_sli4_cfg_shdr *shdr; |
| 17148 | |
| 17149 | if (xritag == NO_XRI) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17150 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17151 | "0364 Invalid param:\n"); |
| 17152 | return -EINVAL; |
| 17153 | } |
| 17154 | |
| 17155 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17156 | if (!mbox) |
| 17157 | return -ENOMEM; |
| 17158 | |
| 17159 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 17160 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 17161 | sizeof(struct lpfc_mbx_post_sgl_pages) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 17162 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17163 | |
| 17164 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) |
| 17165 | &mbox->u.mqe.un.post_sgl_pages; |
| 17166 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); |
| 17167 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); |
| 17168 | |
| 17169 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = |
| 17170 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); |
| 17171 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = |
| 17172 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); |
| 17173 | |
| 17174 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = |
| 17175 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); |
| 17176 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = |
| 17177 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); |
| 17178 | if (!phba->sli4_hba.intr_enable) |
| 17179 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17180 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 17181 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17182 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 17183 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17184 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 17185 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; |
| 17186 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17187 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 304ee43 | 2021-04-11 18:31:17 -0700 | [diff] [blame] | 17188 | if (!phba->sli4_hba.intr_enable) |
| 17189 | mempool_free(mbox, phba->mbox_mem_pool); |
| 17190 | else if (rc != MBX_TIMEOUT) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17191 | mempool_free(mbox, phba->mbox_mem_pool); |
| 17192 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17193 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17194 | "2511 POST_SGL mailbox failed with " |
| 17195 | "status x%x add_status x%x, mbx status x%x\n", |
| 17196 | shdr_status, shdr_add_status, rc); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17197 | } |
| 17198 | return 0; |
| 17199 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17200 | |
| 17201 | /** |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 17202 | * 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] | 17203 | * @phba: pointer to lpfc hba data structure. |
| 17204 | * |
| 17205 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 17206 | * HBA consistent with the SLI-4 interface spec. This routine |
| 17207 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 17208 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17209 | * |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 17210 | * Returns |
| 17211 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
| 17212 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 17213 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17214 | static uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17215 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
| 17216 | { |
| 17217 | unsigned long xri; |
| 17218 | |
| 17219 | /* |
| 17220 | * Fetch the next logical xri. Because this index is logical, |
| 17221 | * the driver starts at 0 each time. |
| 17222 | */ |
| 17223 | spin_lock_irq(&phba->hbalock); |
| 17224 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, |
| 17225 | phba->sli4_hba.max_cfg_param.max_xri, 0); |
| 17226 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { |
| 17227 | spin_unlock_irq(&phba->hbalock); |
| 17228 | return NO_XRI; |
| 17229 | } else { |
| 17230 | set_bit(xri, phba->sli4_hba.xri_bmask); |
| 17231 | phba->sli4_hba.max_cfg_param.xri_used++; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17232 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17233 | spin_unlock_irq(&phba->hbalock); |
| 17234 | return xri; |
| 17235 | } |
| 17236 | |
| 17237 | /** |
Lee Jones | 8514e2f | 2021-03-03 14:46:18 +0000 | [diff] [blame] | 17238 | * __lpfc_sli4_free_xri - Release an xri for reuse. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17239 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 17240 | * @xri: xri to release. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17241 | * |
| 17242 | * This routine is invoked to release an xri to the pool of |
| 17243 | * available rpis maintained by the driver. |
| 17244 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17245 | static void |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17246 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 17247 | { |
| 17248 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17249 | phba->sli4_hba.max_cfg_param.xri_used--; |
| 17250 | } |
| 17251 | } |
| 17252 | |
| 17253 | /** |
| 17254 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 17255 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 17256 | * @xri: xri to release. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17257 | * |
| 17258 | * This routine is invoked to release an xri to the pool of |
| 17259 | * available rpis maintained by the driver. |
| 17260 | **/ |
| 17261 | void |
| 17262 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 17263 | { |
| 17264 | spin_lock_irq(&phba->hbalock); |
| 17265 | __lpfc_sli4_free_xri(phba, xri); |
| 17266 | spin_unlock_irq(&phba->hbalock); |
| 17267 | } |
| 17268 | |
| 17269 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17270 | * lpfc_sli4_next_xritag - Get an xritag for the io |
| 17271 | * @phba: Pointer to HBA context object. |
| 17272 | * |
| 17273 | * This function gets an xritag for the iocb. If there is no unused xritag |
| 17274 | * it will return 0xffff. |
| 17275 | * The function returns the allocated xritag if successful, else returns zero. |
| 17276 | * Zero is not a valid xritag. |
| 17277 | * The caller is not required to hold any lock. |
| 17278 | **/ |
| 17279 | uint16_t |
| 17280 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) |
| 17281 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17282 | uint16_t xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17283 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17284 | xri_index = lpfc_sli4_alloc_xri(phba); |
James Smart | 8137805 | 2012-05-09 21:17:37 -0400 | [diff] [blame] | 17285 | if (xri_index == NO_XRI) |
| 17286 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 17287 | "2004 Failed to allocate XRI.last XRITAG is %d" |
| 17288 | " Max XRI is %d, Used XRI is %d\n", |
| 17289 | xri_index, |
| 17290 | phba->sli4_hba.max_cfg_param.max_xri, |
| 17291 | phba->sli4_hba.max_cfg_param.xri_used); |
| 17292 | return xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17293 | } |
| 17294 | |
| 17295 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17296 | * 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] | 17297 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 17298 | * @post_sgl_list: pointer to els sgl entry list. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 17299 | * @post_cnt: number of els sgl entries on the list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17300 | * |
| 17301 | * This routine is invoked to post a block of driver's sgl pages to the |
| 17302 | * HBA using non-embedded mailbox command. No Lock is held. This routine |
| 17303 | * is only called when the driver is loading and after all IO has been |
| 17304 | * stopped. |
| 17305 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 17306 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17307 | lpfc_sli4_post_sgl_list(struct lpfc_hba *phba, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 17308 | struct list_head *post_sgl_list, |
| 17309 | int post_cnt) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17310 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 17311 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17312 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 17313 | struct sgl_page_pairs *sgl_pg_pairs; |
| 17314 | void *viraddr; |
| 17315 | LPFC_MBOXQ_t *mbox; |
| 17316 | uint32_t reqlen, alloclen, pg_pairs; |
| 17317 | uint32_t mbox_tmo; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 17318 | uint16_t xritag_start = 0; |
| 17319 | int rc = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17320 | uint32_t shdr_status, shdr_add_status; |
| 17321 | union lpfc_sli4_cfg_shdr *shdr; |
| 17322 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17323 | reqlen = post_cnt * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17324 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 17325 | if (reqlen > SLI4_PAGE_SIZE) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17326 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17327 | "2559 Block sgl registration required DMA " |
| 17328 | "size (%d) great than a page\n", reqlen); |
| 17329 | return -ENOMEM; |
| 17330 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17331 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17332 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17333 | if (!mbox) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17334 | return -ENOMEM; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17335 | |
| 17336 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 17337 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 17338 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 17339 | LPFC_SLI4_MBX_NEMBED); |
| 17340 | |
| 17341 | if (alloclen < reqlen) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17342 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17343 | "0285 Allocated DMA memory size (%d) is " |
| 17344 | "less than the requested DMA memory " |
| 17345 | "size (%d)\n", alloclen, reqlen); |
| 17346 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 17347 | return -ENOMEM; |
| 17348 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17349 | /* Set up the SGL pages in the non-embedded DMA pages */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17350 | viraddr = mbox->sge_array->addr[0]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17351 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 17352 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 17353 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 17354 | pg_pairs = 0; |
| 17355 | 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] | 17356 | /* Set up the sge entry */ |
| 17357 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 17358 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); |
| 17359 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 17360 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); |
| 17361 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 17362 | cpu_to_le32(putPaddrLow(0)); |
| 17363 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 17364 | cpu_to_le32(putPaddrHigh(0)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17365 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17366 | /* Keep the first xritag on the list */ |
| 17367 | if (pg_pairs == 0) |
| 17368 | xritag_start = sglq_entry->sli4_xritag; |
| 17369 | sgl_pg_pairs++; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 17370 | pg_pairs++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17371 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17372 | |
| 17373 | /* Complete initialization and perform endian conversion. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17374 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17375 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, post_cnt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17376 | sgl->word0 = cpu_to_le32(sgl->word0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17377 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17378 | if (!phba->sli4_hba.intr_enable) |
| 17379 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 17380 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 17381 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17382 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 17383 | } |
| 17384 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 17385 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17386 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 304ee43 | 2021-04-11 18:31:17 -0700 | [diff] [blame] | 17387 | if (!phba->sli4_hba.intr_enable) |
| 17388 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 17389 | else if (rc != MBX_TIMEOUT) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17390 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 17391 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17392 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17393 | "2513 POST_SGL_BLOCK mailbox command failed " |
| 17394 | "status x%x add_status x%x mbx status x%x\n", |
| 17395 | shdr_status, shdr_add_status, rc); |
| 17396 | rc = -ENXIO; |
| 17397 | } |
| 17398 | return rc; |
| 17399 | } |
| 17400 | |
| 17401 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 17402 | * 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] | 17403 | * @phba: pointer to lpfc hba data structure. |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17404 | * @nblist: pointer to nvme buffer list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17405 | * @count: number of scsi buffers on the list. |
| 17406 | * |
| 17407 | * 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] | 17408 | * SCSI buffer list @nblist to the HBA using non-embedded mailbox command. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17409 | * No Lock is held. |
| 17410 | * |
| 17411 | **/ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17412 | static int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 17413 | lpfc_sli4_post_io_sgl_block(struct lpfc_hba *phba, struct list_head *nblist, |
| 17414 | int count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17415 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 17416 | struct lpfc_io_buf *lpfc_ncmd; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17417 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 17418 | struct sgl_page_pairs *sgl_pg_pairs; |
| 17419 | void *viraddr; |
| 17420 | LPFC_MBOXQ_t *mbox; |
| 17421 | uint32_t reqlen, alloclen, pg_pairs; |
| 17422 | uint32_t mbox_tmo; |
| 17423 | uint16_t xritag_start = 0; |
| 17424 | int rc = 0; |
| 17425 | uint32_t shdr_status, shdr_add_status; |
| 17426 | dma_addr_t pdma_phys_bpl1; |
| 17427 | union lpfc_sli4_cfg_shdr *shdr; |
| 17428 | |
| 17429 | /* Calculate the requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 17430 | reqlen = count * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17431 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 17432 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17433 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17434 | "6118 Block sgl registration required DMA " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17435 | "size (%d) great than a page\n", reqlen); |
| 17436 | return -ENOMEM; |
| 17437 | } |
| 17438 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17439 | if (!mbox) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17440 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17441 | "6119 Failed to allocate mbox cmd memory\n"); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17442 | return -ENOMEM; |
| 17443 | } |
| 17444 | |
| 17445 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 17446 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17447 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 17448 | reqlen, LPFC_SLI4_MBX_NEMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17449 | |
| 17450 | if (alloclen < reqlen) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17451 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17452 | "6120 Allocated DMA memory size (%d) is " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17453 | "less than the requested DMA memory " |
| 17454 | "size (%d)\n", alloclen, reqlen); |
| 17455 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 17456 | return -ENOMEM; |
| 17457 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17458 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17459 | /* Get the first SGE entry from the non-embedded DMA memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17460 | viraddr = mbox->sge_array->addr[0]; |
| 17461 | |
| 17462 | /* Set up the SGL pages in the non-embedded DMA pages */ |
| 17463 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 17464 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 17465 | |
| 17466 | pg_pairs = 0; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17467 | list_for_each_entry(lpfc_ncmd, nblist, list) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17468 | /* Set up the sge entry */ |
| 17469 | sgl_pg_pairs->sgl_pg0_addr_lo = |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17470 | cpu_to_le32(putPaddrLow(lpfc_ncmd->dma_phys_sgl)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17471 | sgl_pg_pairs->sgl_pg0_addr_hi = |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17472 | cpu_to_le32(putPaddrHigh(lpfc_ncmd->dma_phys_sgl)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17473 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17474 | pdma_phys_bpl1 = lpfc_ncmd->dma_phys_sgl + |
| 17475 | SGL_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17476 | else |
| 17477 | pdma_phys_bpl1 = 0; |
| 17478 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 17479 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); |
| 17480 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 17481 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); |
| 17482 | /* Keep the first xritag on the list */ |
| 17483 | if (pg_pairs == 0) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17484 | xritag_start = lpfc_ncmd->cur_iocbq.sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17485 | sgl_pg_pairs++; |
| 17486 | pg_pairs++; |
| 17487 | } |
| 17488 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
| 17489 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); |
| 17490 | /* Perform endian conversion if necessary */ |
| 17491 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 17492 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17493 | if (!phba->sli4_hba.intr_enable) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17494 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17495 | } else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 17496 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17497 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 17498 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17499 | shdr = (union lpfc_sli4_cfg_shdr *)&sgl->cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17500 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17501 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 304ee43 | 2021-04-11 18:31:17 -0700 | [diff] [blame] | 17502 | if (!phba->sli4_hba.intr_enable) |
| 17503 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 17504 | else if (rc != MBX_TIMEOUT) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17505 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 17506 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 17507 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17508 | "6125 POST_SGL_BLOCK mailbox command failed " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17509 | "status x%x add_status x%x mbx status x%x\n", |
| 17510 | shdr_status, shdr_add_status, rc); |
| 17511 | rc = -ENXIO; |
| 17512 | } |
| 17513 | return rc; |
| 17514 | } |
| 17515 | |
| 17516 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 17517 | * 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] | 17518 | * @phba: pointer to lpfc hba data structure. |
| 17519 | * @post_nblist: pointer to the nvme buffer list. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 17520 | * @sb_count: number of nvme buffers. |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17521 | * |
| 17522 | * This routine walks a list of nvme buffers that was passed in. It attempts |
| 17523 | * to construct blocks of nvme buffer sgls which contains contiguous xris and |
| 17524 | * uses the non-embedded SGL block post mailbox commands to post to the port. |
| 17525 | * For single NVME buffer sgl with non-contiguous xri, if any, it shall use |
| 17526 | * embedded SGL post mailbox command for posting. The @post_nblist passed in |
| 17527 | * must be local list, thus no lock is needed when manipulate the list. |
| 17528 | * |
| 17529 | * Returns: 0 = failure, non-zero number of successfully posted buffers. |
| 17530 | **/ |
| 17531 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 17532 | lpfc_sli4_post_io_sgl_list(struct lpfc_hba *phba, |
| 17533 | struct list_head *post_nblist, int sb_count) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17534 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 17535 | struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17536 | int status, sgl_size; |
| 17537 | int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0; |
| 17538 | dma_addr_t pdma_phys_sgl1; |
| 17539 | int last_xritag = NO_XRI; |
| 17540 | int cur_xritag; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17541 | LIST_HEAD(prep_nblist); |
| 17542 | LIST_HEAD(blck_nblist); |
| 17543 | LIST_HEAD(nvme_nblist); |
| 17544 | |
| 17545 | /* sanity check */ |
| 17546 | if (sb_count <= 0) |
| 17547 | return -EINVAL; |
| 17548 | |
| 17549 | sgl_size = phba->cfg_sg_dma_buf_size; |
| 17550 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, post_nblist, list) { |
| 17551 | list_del_init(&lpfc_ncmd->list); |
| 17552 | block_cnt++; |
| 17553 | if ((last_xritag != NO_XRI) && |
| 17554 | (lpfc_ncmd->cur_iocbq.sli4_xritag != last_xritag + 1)) { |
| 17555 | /* a hole in xri block, form a sgl posting block */ |
| 17556 | list_splice_init(&prep_nblist, &blck_nblist); |
| 17557 | post_cnt = block_cnt - 1; |
| 17558 | /* prepare list for next posting block */ |
| 17559 | list_add_tail(&lpfc_ncmd->list, &prep_nblist); |
| 17560 | block_cnt = 1; |
| 17561 | } else { |
| 17562 | /* prepare list for next posting block */ |
| 17563 | list_add_tail(&lpfc_ncmd->list, &prep_nblist); |
| 17564 | /* enough sgls for non-embed sgl mbox command */ |
| 17565 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 17566 | list_splice_init(&prep_nblist, &blck_nblist); |
| 17567 | post_cnt = block_cnt; |
| 17568 | block_cnt = 0; |
| 17569 | } |
| 17570 | } |
| 17571 | num_posting++; |
| 17572 | last_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag; |
| 17573 | |
| 17574 | /* end of repost sgl list condition for NVME buffers */ |
| 17575 | if (num_posting == sb_count) { |
| 17576 | if (post_cnt == 0) { |
| 17577 | /* last sgl posting block */ |
| 17578 | list_splice_init(&prep_nblist, &blck_nblist); |
| 17579 | post_cnt = block_cnt; |
| 17580 | } else if (block_cnt == 1) { |
| 17581 | /* last single sgl with non-contiguous xri */ |
| 17582 | if (sgl_size > SGL_PAGE_SIZE) |
| 17583 | pdma_phys_sgl1 = |
| 17584 | lpfc_ncmd->dma_phys_sgl + |
| 17585 | SGL_PAGE_SIZE; |
| 17586 | else |
| 17587 | pdma_phys_sgl1 = 0; |
| 17588 | cur_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag; |
| 17589 | status = lpfc_sli4_post_sgl( |
| 17590 | phba, lpfc_ncmd->dma_phys_sgl, |
| 17591 | pdma_phys_sgl1, cur_xritag); |
| 17592 | if (status) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 17593 | /* Post error. Buffer unavailable. */ |
| 17594 | lpfc_ncmd->flags |= |
| 17595 | LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17596 | } else { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 17597 | /* Post success. Bffer available. */ |
| 17598 | lpfc_ncmd->flags &= |
| 17599 | ~LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17600 | lpfc_ncmd->status = IOSTAT_SUCCESS; |
| 17601 | num_posted++; |
| 17602 | } |
| 17603 | /* success, put on NVME buffer sgl list */ |
| 17604 | list_add_tail(&lpfc_ncmd->list, &nvme_nblist); |
| 17605 | } |
| 17606 | } |
| 17607 | |
| 17608 | /* continue until a nembed page worth of sgls */ |
| 17609 | if (post_cnt == 0) |
| 17610 | continue; |
| 17611 | |
| 17612 | /* post block of NVME buffer list sgls */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 17613 | status = lpfc_sli4_post_io_sgl_block(phba, &blck_nblist, |
| 17614 | post_cnt); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17615 | |
| 17616 | /* don't reset xirtag due to hole in xri block */ |
| 17617 | if (block_cnt == 0) |
| 17618 | last_xritag = NO_XRI; |
| 17619 | |
| 17620 | /* reset NVME buffer post count for next round of posting */ |
| 17621 | post_cnt = 0; |
| 17622 | |
| 17623 | /* put posted NVME buffer-sgl posted on NVME buffer sgl list */ |
| 17624 | while (!list_empty(&blck_nblist)) { |
| 17625 | list_remove_head(&blck_nblist, lpfc_ncmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 17626 | struct lpfc_io_buf, list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17627 | if (status) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 17628 | /* Post error. Mark buffer unavailable. */ |
| 17629 | lpfc_ncmd->flags |= LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17630 | } else { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 17631 | /* Post success, Mark buffer available. */ |
| 17632 | lpfc_ncmd->flags &= ~LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17633 | lpfc_ncmd->status = IOSTAT_SUCCESS; |
| 17634 | num_posted++; |
| 17635 | } |
| 17636 | list_add_tail(&lpfc_ncmd->list, &nvme_nblist); |
| 17637 | } |
| 17638 | } |
| 17639 | /* Push NVME buffers with sgl posted to the available list */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 17640 | lpfc_io_buf_replenish(phba, &nvme_nblist); |
| 17641 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17642 | return num_posted; |
| 17643 | } |
| 17644 | |
| 17645 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17646 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle |
| 17647 | * @phba: pointer to lpfc_hba struct that the frame was received on |
| 17648 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 17649 | * |
| 17650 | * This function checks the fields in the @fc_hdr to see if the FC frame is a |
| 17651 | * valid type of frame that the LPFC driver will handle. This function will |
| 17652 | * return a zero if the frame is a valid frame or a non zero value when the |
| 17653 | * frame does not pass the check. |
| 17654 | **/ |
| 17655 | static int |
| 17656 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) |
| 17657 | { |
Tomas Henzl | 474ffb7 | 2010-12-22 16:52:40 +0100 | [diff] [blame] | 17658 | /* make rctl_names static to save stack space */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17659 | struct fc_vft_header *fc_vft_hdr; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17660 | uint32_t *header = (uint32_t *) fc_hdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17661 | |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 17662 | #define FC_RCTL_MDS_DIAGS 0xF4 |
| 17663 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17664 | switch (fc_hdr->fh_r_ctl) { |
| 17665 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ |
| 17666 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ |
| 17667 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ |
| 17668 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ |
| 17669 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ |
| 17670 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ |
| 17671 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ |
| 17672 | case FC_RCTL_DD_CMD_STATUS: /* command status */ |
| 17673 | case FC_RCTL_ELS_REQ: /* extended link services request */ |
| 17674 | case FC_RCTL_ELS_REP: /* extended link services reply */ |
| 17675 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ |
| 17676 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ |
| 17677 | case FC_RCTL_BA_NOP: /* basic link service NOP */ |
| 17678 | case FC_RCTL_BA_ABTS: /* basic link service abort */ |
| 17679 | case FC_RCTL_BA_RMC: /* remove connection */ |
| 17680 | case FC_RCTL_BA_ACC: /* basic accept */ |
| 17681 | case FC_RCTL_BA_RJT: /* basic reject */ |
| 17682 | case FC_RCTL_BA_PRMT: |
| 17683 | case FC_RCTL_ACK_1: /* acknowledge_1 */ |
| 17684 | case FC_RCTL_ACK_0: /* acknowledge_0 */ |
| 17685 | case FC_RCTL_P_RJT: /* port reject */ |
| 17686 | case FC_RCTL_F_RJT: /* fabric reject */ |
| 17687 | case FC_RCTL_P_BSY: /* port busy */ |
| 17688 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ |
| 17689 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ |
| 17690 | case FC_RCTL_LCR: /* link credit reset */ |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17691 | case FC_RCTL_MDS_DIAGS: /* MDS Diagnostics */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17692 | case FC_RCTL_END: /* end */ |
| 17693 | break; |
| 17694 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ |
| 17695 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 17696 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; |
| 17697 | return lpfc_fc_frame_check(phba, fc_hdr); |
| 17698 | default: |
| 17699 | goto drop; |
| 17700 | } |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17701 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17702 | switch (fc_hdr->fh_type) { |
| 17703 | case FC_TYPE_BLS: |
| 17704 | case FC_TYPE_ELS: |
| 17705 | case FC_TYPE_FCP: |
| 17706 | case FC_TYPE_CT: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17707 | case FC_TYPE_NVME: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17708 | break; |
| 17709 | case FC_TYPE_IP: |
| 17710 | case FC_TYPE_ILS: |
| 17711 | default: |
| 17712 | goto drop; |
| 17713 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17714 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17715 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 17716 | "2538 Received frame rctl:x%x, type:x%x, " |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 17717 | "frame Data:%08x %08x %08x %08x %08x %08x %08x\n", |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 17718 | fc_hdr->fh_r_ctl, fc_hdr->fh_type, |
| 17719 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
| 17720 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), |
| 17721 | be32_to_cpu(header[4]), be32_to_cpu(header[5]), |
| 17722 | be32_to_cpu(header[6])); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17723 | return 0; |
| 17724 | drop: |
| 17725 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 17726 | "2539 Dropped frame rctl:x%x type:x%x\n", |
| 17727 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17728 | return 1; |
| 17729 | } |
| 17730 | |
| 17731 | /** |
| 17732 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame |
| 17733 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 17734 | * |
| 17735 | * This function processes the FC header to retrieve the VFI from the VF |
| 17736 | * header, if one exists. This function will return the VFI if one exists |
| 17737 | * or 0 if no VSAN Header exists. |
| 17738 | **/ |
| 17739 | static uint32_t |
| 17740 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) |
| 17741 | { |
| 17742 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 17743 | |
| 17744 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) |
| 17745 | return 0; |
| 17746 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); |
| 17747 | } |
| 17748 | |
| 17749 | /** |
| 17750 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to |
| 17751 | * @phba: Pointer to the HBA structure to search for the vport on |
| 17752 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 17753 | * @fcfi: The FC Fabric ID that the frame came from |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 17754 | * @did: Destination ID to match against |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17755 | * |
| 17756 | * This function searches the @phba for a vport that matches the content of the |
| 17757 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the |
| 17758 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function |
| 17759 | * returns the matching vport pointer or NULL if unable to match frame to a |
| 17760 | * vport. |
| 17761 | **/ |
| 17762 | static struct lpfc_vport * |
| 17763 | 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] | 17764 | uint16_t fcfi, uint32_t did) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17765 | { |
| 17766 | struct lpfc_vport **vports; |
| 17767 | struct lpfc_vport *vport = NULL; |
| 17768 | int i; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17769 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 17770 | if (did == Fabric_DID) |
| 17771 | return phba->pport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17772 | if ((phba->pport->fc_flag & FC_PT2PT) && |
| 17773 | !(phba->link_state == LPFC_HBA_READY)) |
| 17774 | return phba->pport; |
| 17775 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17776 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17777 | if (vports != NULL) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17778 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 17779 | if (phba->fcf.fcfi == fcfi && |
| 17780 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && |
| 17781 | vports[i]->fc_myDID == did) { |
| 17782 | vport = vports[i]; |
| 17783 | break; |
| 17784 | } |
| 17785 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17786 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17787 | lpfc_destroy_vport_work_array(phba, vports); |
| 17788 | return vport; |
| 17789 | } |
| 17790 | |
| 17791 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17792 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp |
| 17793 | * @vport: The vport to work on. |
| 17794 | * |
| 17795 | * This function updates the receive sequence time stamp for this vport. The |
| 17796 | * receive sequence time stamp indicates the time that the last frame of the |
| 17797 | * the sequence that has been idle for the longest amount of time was received. |
| 17798 | * the driver uses this time stamp to indicate if any received sequences have |
| 17799 | * timed out. |
| 17800 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17801 | static void |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17802 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
| 17803 | { |
| 17804 | struct lpfc_dmabuf *h_buf; |
| 17805 | struct hbq_dmabuf *dmabuf = NULL; |
| 17806 | |
| 17807 | /* get the oldest sequence on the rcv list */ |
| 17808 | h_buf = list_get_first(&vport->rcv_buffer_list, |
| 17809 | struct lpfc_dmabuf, list); |
| 17810 | if (!h_buf) |
| 17811 | return; |
| 17812 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17813 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; |
| 17814 | } |
| 17815 | |
| 17816 | /** |
| 17817 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. |
| 17818 | * @vport: The vport that the received sequences were sent to. |
| 17819 | * |
| 17820 | * This function cleans up all outstanding received sequences. This is called |
| 17821 | * by the driver when a link event or user action invalidates all the received |
| 17822 | * sequences. |
| 17823 | **/ |
| 17824 | void |
| 17825 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) |
| 17826 | { |
| 17827 | struct lpfc_dmabuf *h_buf, *hnext; |
| 17828 | struct lpfc_dmabuf *d_buf, *dnext; |
| 17829 | struct hbq_dmabuf *dmabuf = NULL; |
| 17830 | |
| 17831 | /* start with the oldest sequence on the rcv list */ |
| 17832 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 17833 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17834 | list_del_init(&dmabuf->hbuf.list); |
| 17835 | list_for_each_entry_safe(d_buf, dnext, |
| 17836 | &dmabuf->dbuf.list, list) { |
| 17837 | list_del_init(&d_buf->list); |
| 17838 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17839 | } |
| 17840 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 17841 | } |
| 17842 | } |
| 17843 | |
| 17844 | /** |
| 17845 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. |
| 17846 | * @vport: The vport that the received sequences were sent to. |
| 17847 | * |
| 17848 | * This function determines whether any received sequences have timed out by |
| 17849 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp |
| 17850 | * indicates that there is at least one timed out sequence this routine will |
| 17851 | * go through the received sequences one at a time from most inactive to most |
| 17852 | * active to determine which ones need to be cleaned up. Once it has determined |
| 17853 | * that a sequence needs to be cleaned up it will simply free up the resources |
| 17854 | * without sending an abort. |
| 17855 | **/ |
| 17856 | void |
| 17857 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) |
| 17858 | { |
| 17859 | struct lpfc_dmabuf *h_buf, *hnext; |
| 17860 | struct lpfc_dmabuf *d_buf, *dnext; |
| 17861 | struct hbq_dmabuf *dmabuf = NULL; |
| 17862 | unsigned long timeout; |
| 17863 | int abort_count = 0; |
| 17864 | |
| 17865 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 17866 | vport->rcv_buffer_time_stamp); |
| 17867 | if (list_empty(&vport->rcv_buffer_list) || |
| 17868 | time_before(jiffies, timeout)) |
| 17869 | return; |
| 17870 | /* start with the oldest sequence on the rcv list */ |
| 17871 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 17872 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17873 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 17874 | dmabuf->time_stamp); |
| 17875 | if (time_before(jiffies, timeout)) |
| 17876 | break; |
| 17877 | abort_count++; |
| 17878 | list_del_init(&dmabuf->hbuf.list); |
| 17879 | list_for_each_entry_safe(d_buf, dnext, |
| 17880 | &dmabuf->dbuf.list, list) { |
| 17881 | list_del_init(&d_buf->list); |
| 17882 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17883 | } |
| 17884 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 17885 | } |
| 17886 | if (abort_count) |
| 17887 | lpfc_update_rcv_time_stamp(vport); |
| 17888 | } |
| 17889 | |
| 17890 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17891 | * 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] | 17892 | * @vport: pointer to a vitural port |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17893 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame |
| 17894 | * |
| 17895 | * This function searches through the existing incomplete sequences that have |
| 17896 | * been sent to this @vport. If the frame matches one of the incomplete |
| 17897 | * sequences then the dbuf in the @dmabuf is added to the list of frames that |
| 17898 | * make up that sequence. If no sequence is found that matches this frame then |
| 17899 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list |
| 17900 | * This function returns a pointer to the first dmabuf in the sequence list that |
| 17901 | * the frame was linked to. |
| 17902 | **/ |
| 17903 | static struct hbq_dmabuf * |
| 17904 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 17905 | { |
| 17906 | struct fc_frame_header *new_hdr; |
| 17907 | struct fc_frame_header *temp_hdr; |
| 17908 | struct lpfc_dmabuf *d_buf; |
| 17909 | struct lpfc_dmabuf *h_buf; |
| 17910 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 17911 | struct hbq_dmabuf *temp_dmabuf = NULL; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17912 | uint8_t found = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17913 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17914 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17915 | dmabuf->time_stamp = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17916 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17917 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17918 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
| 17919 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 17920 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 17921 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 17922 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 17923 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 17924 | continue; |
| 17925 | /* found a pending sequence that matches this frame */ |
| 17926 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17927 | break; |
| 17928 | } |
| 17929 | if (!seq_dmabuf) { |
| 17930 | /* |
| 17931 | * This indicates first frame received for this sequence. |
| 17932 | * Queue the buffer on the vport's rcv_buffer_list. |
| 17933 | */ |
| 17934 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17935 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17936 | return dmabuf; |
| 17937 | } |
| 17938 | temp_hdr = seq_dmabuf->hbuf.virt; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17939 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
| 17940 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17941 | list_del_init(&seq_dmabuf->hbuf.list); |
| 17942 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 17943 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17944 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17945 | return dmabuf; |
| 17946 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17947 | /* move this sequence to the tail to indicate a young sequence */ |
| 17948 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 17949 | seq_dmabuf->time_stamp = jiffies; |
| 17950 | lpfc_update_rcv_time_stamp(vport); |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17951 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17952 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
| 17953 | return seq_dmabuf; |
| 17954 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17955 | /* find the correct place in the sequence to insert this frame */ |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17956 | d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list); |
| 17957 | while (!found) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17958 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17959 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; |
| 17960 | /* |
| 17961 | * If the frame's sequence count is greater than the frame on |
| 17962 | * the list then insert the frame right after this frame |
| 17963 | */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17964 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
| 17965 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17966 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17967 | found = 1; |
| 17968 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17969 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17970 | |
| 17971 | if (&d_buf->list == &seq_dmabuf->dbuf.list) |
| 17972 | break; |
| 17973 | d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17974 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17975 | |
| 17976 | if (found) |
| 17977 | return seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17978 | return NULL; |
| 17979 | } |
| 17980 | |
| 17981 | /** |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17982 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence |
| 17983 | * @vport: pointer to a vitural port |
| 17984 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17985 | * |
| 17986 | * This function tries to abort from the partially assembed sequence, described |
| 17987 | * by the information from basic abbort @dmabuf. It checks to see whether such |
| 17988 | * partially assembled sequence held by the driver. If so, it shall free up all |
| 17989 | * the frames from the partially assembled sequence. |
| 17990 | * |
| 17991 | * Return |
| 17992 | * true -- if there is matching partially assembled sequence present and all |
| 17993 | * the frames freed with the sequence; |
| 17994 | * false -- if there is no matching partially assembled sequence present so |
| 17995 | * nothing got aborted in the lower layer driver |
| 17996 | **/ |
| 17997 | static bool |
| 17998 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, |
| 17999 | struct hbq_dmabuf *dmabuf) |
| 18000 | { |
| 18001 | struct fc_frame_header *new_hdr; |
| 18002 | struct fc_frame_header *temp_hdr; |
| 18003 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; |
| 18004 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 18005 | |
| 18006 | /* Use the hdr_buf to find the sequence that matches this frame */ |
| 18007 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
| 18008 | INIT_LIST_HEAD(&dmabuf->hbuf.list); |
| 18009 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 18010 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 18011 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 18012 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 18013 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 18014 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 18015 | continue; |
| 18016 | /* found a pending sequence that matches this frame */ |
| 18017 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 18018 | break; |
| 18019 | } |
| 18020 | |
| 18021 | /* Free up all the frames from the partially assembled sequence */ |
| 18022 | if (seq_dmabuf) { |
| 18023 | list_for_each_entry_safe(d_buf, n_buf, |
| 18024 | &seq_dmabuf->dbuf.list, list) { |
| 18025 | list_del_init(&d_buf->list); |
| 18026 | lpfc_in_buf_free(vport->phba, d_buf); |
| 18027 | } |
| 18028 | return true; |
| 18029 | } |
| 18030 | return false; |
| 18031 | } |
| 18032 | |
| 18033 | /** |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18034 | * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp |
| 18035 | * @vport: pointer to a vitural port |
| 18036 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 18037 | * |
| 18038 | * This function tries to abort from the assembed sequence from upper level |
| 18039 | * protocol, described by the information from basic abbort @dmabuf. It |
| 18040 | * checks to see whether such pending context exists at upper level protocol. |
| 18041 | * If so, it shall clean up the pending context. |
| 18042 | * |
| 18043 | * Return |
| 18044 | * true -- if there is matching pending context of the sequence cleaned |
| 18045 | * at ulp; |
| 18046 | * false -- if there is no matching pending context of the sequence present |
| 18047 | * at ulp. |
| 18048 | **/ |
| 18049 | static bool |
| 18050 | lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 18051 | { |
| 18052 | struct lpfc_hba *phba = vport->phba; |
| 18053 | int handled; |
| 18054 | |
| 18055 | /* Accepting abort at ulp with SLI4 only */ |
| 18056 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 18057 | return false; |
| 18058 | |
| 18059 | /* Register all caring upper level protocols to attend abort */ |
| 18060 | handled = lpfc_ct_handle_unsol_abort(phba, dmabuf); |
| 18061 | if (handled) |
| 18062 | return true; |
| 18063 | |
| 18064 | return false; |
| 18065 | } |
| 18066 | |
| 18067 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18068 | * 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] | 18069 | * @phba: Pointer to HBA context object. |
| 18070 | * @cmd_iocbq: pointer to the command iocbq structure. |
| 18071 | * @rsp_iocbq: pointer to the response iocbq structure. |
| 18072 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18073 | * This function handles the sequence abort response iocb command complete |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18074 | * event. It properly releases the memory allocated to the sequence abort |
| 18075 | * accept iocb. |
| 18076 | **/ |
| 18077 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18078 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18079 | struct lpfc_iocbq *cmd_iocbq, |
| 18080 | struct lpfc_iocbq *rsp_iocbq) |
| 18081 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18082 | struct lpfc_nodelist *ndlp; |
| 18083 | |
| 18084 | if (cmd_iocbq) { |
| 18085 | ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1; |
| 18086 | lpfc_nlp_put(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18087 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18088 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18089 | |
| 18090 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ |
| 18091 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 18092 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18093 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", |
| 18094 | rsp_iocbq->iocb.ulpStatus, |
| 18095 | rsp_iocbq->iocb.un.ulpWord[4]); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18096 | } |
| 18097 | |
| 18098 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18099 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. |
| 18100 | * @phba: Pointer to HBA context object. |
| 18101 | * @xri: xri id in transaction. |
| 18102 | * |
| 18103 | * This function validates the xri maps to the known range of XRIs allocated an |
| 18104 | * used by the driver. |
| 18105 | **/ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18106 | uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18107 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
| 18108 | uint16_t xri) |
| 18109 | { |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 18110 | uint16_t i; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18111 | |
| 18112 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { |
| 18113 | if (xri == phba->sli4_hba.xri_ids[i]) |
| 18114 | return i; |
| 18115 | } |
| 18116 | return NO_XRI; |
| 18117 | } |
| 18118 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18119 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18120 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
James Smart | 3bfab8a | 2021-04-11 18:31:23 -0700 | [diff] [blame] | 18121 | * @vport: pointer to a virtual port. |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18122 | * @fc_hdr: pointer to a FC frame header. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 18123 | * @aborted: was the partially assembled receive sequence successfully aborted |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18124 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18125 | * This function sends a basic response to a previous unsol sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18126 | * event after aborting the sequence handling. |
| 18127 | **/ |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 18128 | void |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18129 | lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport, |
| 18130 | struct fc_frame_header *fc_hdr, bool aborted) |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18131 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18132 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18133 | struct lpfc_iocbq *ctiocb = NULL; |
| 18134 | struct lpfc_nodelist *ndlp; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 18135 | uint16_t oxid, rxid, xri, lxri; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 18136 | uint32_t sid, fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18137 | IOCB_t *icmd; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18138 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18139 | |
| 18140 | if (!lpfc_is_link_up(phba)) |
| 18141 | return; |
| 18142 | |
| 18143 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 18144 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 18145 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18146 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18147 | ndlp = lpfc_findnode_did(vport, sid); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18148 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 18149 | ndlp = lpfc_nlp_init(vport, sid); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18150 | if (!ndlp) { |
| 18151 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 18152 | "1268 Failed to allocate ndlp for " |
| 18153 | "oxid:x%x SID:x%x\n", oxid, sid); |
| 18154 | return; |
| 18155 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18156 | /* Put ndlp onto pport node list */ |
| 18157 | lpfc_enqueue_node(vport, ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18158 | } |
| 18159 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18160 | /* Allocate buffer for rsp iocb */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18161 | ctiocb = lpfc_sli_get_iocbq(phba); |
| 18162 | if (!ctiocb) |
| 18163 | return; |
| 18164 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 18165 | /* Extract the F_CTL field from FC_HDR */ |
| 18166 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); |
| 18167 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18168 | icmd = &ctiocb->iocb; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18169 | icmd->un.xseq64.bdl.bdeSize = 0; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 18170 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18171 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 18172 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; |
| 18173 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; |
| 18174 | |
| 18175 | /* Fill in the rest of iocb fields */ |
| 18176 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; |
| 18177 | icmd->ulpBdeCount = 0; |
| 18178 | icmd->ulpLe = 1; |
| 18179 | icmd->ulpClass = CLASS3; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18180 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18181 | ctiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 4430f7f | 2020-11-15 11:26:31 -0800 | [diff] [blame] | 18182 | if (!ctiocb->context1) { |
| 18183 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 18184 | return; |
| 18185 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18186 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18187 | ctiocb->vport = phba->pport; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18188 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18189 | ctiocb->sli4_lxritag = NO_XRI; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18190 | ctiocb->sli4_xritag = NO_XRI; |
| 18191 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 18192 | if (fctl & FC_FC_EX_CTX) |
| 18193 | /* Exchange responder sent the abort so we |
| 18194 | * own the oxid. |
| 18195 | */ |
| 18196 | xri = oxid; |
| 18197 | else |
| 18198 | xri = rxid; |
| 18199 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 18200 | if (lxri != NO_XRI) |
| 18201 | lpfc_set_rrq_active(phba, ndlp, lxri, |
| 18202 | (xri == oxid) ? rxid : oxid, 0); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18203 | /* For BA_ABTS from exchange responder, if the logical xri with |
| 18204 | * the oxid maps to the FCP XRI range, the port no longer has |
| 18205 | * that exchange context, send a BLS_RJT. Override the IOCB for |
| 18206 | * a BA_RJT. |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18207 | */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18208 | if ((fctl & FC_FC_EX_CTX) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18209 | (lxri > lpfc_sli4_get_iocb_cnt(phba))) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18210 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 18211 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 18212 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 18213 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 18214 | } |
| 18215 | |
| 18216 | /* If BA_ABTS failed to abort a partially assembled receive sequence, |
| 18217 | * the driver no longer has that exchange, send a BLS_RJT. Override |
| 18218 | * the IOCB for a BA_RJT. |
| 18219 | */ |
| 18220 | if (aborted == false) { |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18221 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 18222 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 18223 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 18224 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 18225 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18226 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 18227 | if (fctl & FC_FC_EX_CTX) { |
| 18228 | /* ABTS sent by responder to CT exchange, construction |
| 18229 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG |
| 18230 | * field and RX_ID from ABTS for RX_ID field. |
| 18231 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18232 | 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] | 18233 | } else { |
| 18234 | /* ABTS sent by initiator to CT exchange, construction |
| 18235 | * 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] | 18236 | * XRI_TAG field. |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 18237 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18238 | 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] | 18239 | } |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 18240 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18241 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 18242 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18243 | /* Xmit CT abts response on exchange <xid> */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18244 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 18245 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
| 18246 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18247 | |
| 18248 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
| 18249 | if (rc == IOCB_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 18250 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18251 | "2925 Failed to issue CT ABTS RSP x%x on " |
| 18252 | "xri x%x, Data x%x\n", |
| 18253 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, |
| 18254 | phba->link_state); |
| 18255 | lpfc_nlp_put(ndlp); |
| 18256 | ctiocb->context1 = NULL; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 18257 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 18258 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18259 | } |
| 18260 | |
| 18261 | /** |
| 18262 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event |
| 18263 | * @vport: Pointer to the vport on which this sequence was received |
| 18264 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 18265 | * |
| 18266 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited |
| 18267 | * receive sequence is only partially assembed by the driver, it shall abort |
| 18268 | * the partially assembled frames for the sequence. Otherwise, if the |
| 18269 | * unsolicited receive sequence has been completely assembled and passed to |
Ferruh Yigit | 02e3e58 | 2020-07-28 15:56:06 +0100 | [diff] [blame] | 18270 | * 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] | 18271 | * unsolicited sequence has been aborted. After that, it will issue a basic |
| 18272 | * accept to accept the abort. |
| 18273 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18274 | static void |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18275 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
| 18276 | struct hbq_dmabuf *dmabuf) |
| 18277 | { |
| 18278 | struct lpfc_hba *phba = vport->phba; |
| 18279 | struct fc_frame_header fc_hdr; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 18280 | uint32_t fctl; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18281 | bool aborted; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18282 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18283 | /* Make a copy of fc_hdr before the dmabuf being released */ |
| 18284 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 18285 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18286 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 18287 | if (fctl & FC_FC_EX_CTX) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18288 | /* ABTS by responder to exchange, no cleanup needed */ |
| 18289 | aborted = true; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 18290 | } else { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18291 | /* ABTS by initiator to exchange, need to do cleanup */ |
| 18292 | aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf); |
| 18293 | if (aborted == false) |
| 18294 | aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 18295 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18296 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18297 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 18298 | if (phba->nvmet_support) { |
| 18299 | lpfc_nvmet_rcv_unsol_abort(vport, &fc_hdr); |
| 18300 | return; |
| 18301 | } |
| 18302 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 18303 | /* Respond with BA_ACC or BA_RJT accordingly */ |
| 18304 | lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18305 | } |
| 18306 | |
| 18307 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18308 | * lpfc_seq_complete - Indicates if a sequence is complete |
| 18309 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 18310 | * |
| 18311 | * This function checks the sequence, starting with the frame described by |
| 18312 | * @dmabuf, to see if all the frames associated with this sequence are present. |
| 18313 | * the frames associated with this sequence are linked to the @dmabuf using the |
| 18314 | * dbuf list. This function looks for two major things. 1) That the first frame |
| 18315 | * has a sequence count of zero. 2) There is a frame with last frame of sequence |
| 18316 | * set. 3) That there are no holes in the sequence count. The function will |
| 18317 | * return 1 when the sequence is complete, otherwise it will return 0. |
| 18318 | **/ |
| 18319 | static int |
| 18320 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) |
| 18321 | { |
| 18322 | struct fc_frame_header *hdr; |
| 18323 | struct lpfc_dmabuf *d_buf; |
| 18324 | struct hbq_dmabuf *seq_dmabuf; |
| 18325 | uint32_t fctl; |
| 18326 | int seq_count = 0; |
| 18327 | |
| 18328 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 18329 | /* make sure first fame of sequence has a sequence count of zero */ |
| 18330 | if (hdr->fh_seq_cnt != seq_count) |
| 18331 | return 0; |
| 18332 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 18333 | hdr->fh_f_ctl[1] << 8 | |
| 18334 | hdr->fh_f_ctl[2]); |
| 18335 | /* If last frame of sequence we can return success. */ |
| 18336 | if (fctl & FC_FC_END_SEQ) |
| 18337 | return 1; |
| 18338 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { |
| 18339 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 18340 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 18341 | /* If there is a hole in the sequence count then fail. */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 18342 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18343 | return 0; |
| 18344 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 18345 | hdr->fh_f_ctl[1] << 8 | |
| 18346 | hdr->fh_f_ctl[2]); |
| 18347 | /* If last frame of sequence we can return success. */ |
| 18348 | if (fctl & FC_FC_END_SEQ) |
| 18349 | return 1; |
| 18350 | } |
| 18351 | return 0; |
| 18352 | } |
| 18353 | |
| 18354 | /** |
| 18355 | * lpfc_prep_seq - Prep sequence for ULP processing |
| 18356 | * @vport: Pointer to the vport on which this sequence was received |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 18357 | * @seq_dmabuf: pointer to a dmabuf that describes the FC sequence |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18358 | * |
| 18359 | * This function takes a sequence, described by a list of frames, and creates |
| 18360 | * a list of iocbq structures to describe the sequence. This iocbq list will be |
| 18361 | * used to issue to the generic unsolicited sequence handler. This routine |
| 18362 | * returns a pointer to the first iocbq in the list. If the function is unable |
| 18363 | * to allocate an iocbq then it throw out the received frames that were not |
| 18364 | * able to be described and return a pointer to the first iocbq. If unable to |
| 18365 | * allocate any iocbqs (including the first) this function will return NULL. |
| 18366 | **/ |
| 18367 | static struct lpfc_iocbq * |
| 18368 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) |
| 18369 | { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18370 | struct hbq_dmabuf *hbq_buf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18371 | struct lpfc_dmabuf *d_buf, *n_buf; |
| 18372 | struct lpfc_iocbq *first_iocbq, *iocbq; |
| 18373 | struct fc_frame_header *fc_hdr; |
| 18374 | uint32_t sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18375 | uint32_t len, tot_len; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 18376 | struct ulp_bde64 *pbde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18377 | |
| 18378 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 18379 | /* remove from receive buffer list */ |
| 18380 | list_del_init(&seq_dmabuf->hbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 18381 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18382 | /* get the Remote Port's SID */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18383 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18384 | tot_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18385 | /* Get an iocbq struct to fill in. */ |
| 18386 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 18387 | if (first_iocbq) { |
| 18388 | /* Initialize the first IOCB. */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 18389 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18390 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18391 | first_iocbq->vport = vport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 18392 | |
| 18393 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ |
| 18394 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { |
| 18395 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; |
| 18396 | first_iocbq->iocb.un.rcvels.parmRo = |
| 18397 | sli4_did_from_fc_hdr(fc_hdr); |
| 18398 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; |
| 18399 | } else |
| 18400 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18401 | first_iocbq->iocb.ulpContext = NO_XRI; |
| 18402 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = |
| 18403 | be16_to_cpu(fc_hdr->fh_ox_id); |
| 18404 | /* iocbq is prepped for internal consumption. Physical vpi. */ |
| 18405 | first_iocbq->iocb.unsli3.rcvsli3.vpi = |
| 18406 | vport->phba->vpi_ids[vport->vpi]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18407 | /* put the first buffer into the first IOCBq */ |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 18408 | tot_len = bf_get(lpfc_rcqe_length, |
| 18409 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
| 18410 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18411 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
| 18412 | first_iocbq->context3 = NULL; |
| 18413 | first_iocbq->iocb.ulpBdeCount = 1; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 18414 | if (tot_len > LPFC_DATA_BUF_SIZE) |
| 18415 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18416 | LPFC_DATA_BUF_SIZE; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 18417 | else |
| 18418 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len; |
| 18419 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18420 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 18421 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18422 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18423 | } |
| 18424 | iocbq = first_iocbq; |
| 18425 | /* |
| 18426 | * Each IOCBq can have two Buffers assigned, so go through the list |
| 18427 | * of buffers for this sequence and save two buffers in each IOCBq |
| 18428 | */ |
| 18429 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { |
| 18430 | if (!iocbq) { |
| 18431 | lpfc_in_buf_free(vport->phba, d_buf); |
| 18432 | continue; |
| 18433 | } |
| 18434 | if (!iocbq->context3) { |
| 18435 | iocbq->context3 = d_buf; |
| 18436 | iocbq->iocb.ulpBdeCount++; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18437 | /* We need to get the size out of the right CQE */ |
| 18438 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 18439 | len = bf_get(lpfc_rcqe_length, |
| 18440 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 18441 | pbde = (struct ulp_bde64 *) |
| 18442 | &iocbq->iocb.unsli3.sli3Words[4]; |
| 18443 | if (len > LPFC_DATA_BUF_SIZE) |
| 18444 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; |
| 18445 | else |
| 18446 | pbde->tus.f.bdeSize = len; |
| 18447 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18448 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
| 18449 | tot_len += len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18450 | } else { |
| 18451 | iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 18452 | if (!iocbq) { |
| 18453 | if (first_iocbq) { |
| 18454 | first_iocbq->iocb.ulpStatus = |
| 18455 | IOSTAT_FCP_RSP_ERROR; |
| 18456 | first_iocbq->iocb.un.ulpWord[4] = |
| 18457 | IOERR_NO_RESOURCES; |
| 18458 | } |
| 18459 | lpfc_in_buf_free(vport->phba, d_buf); |
| 18460 | continue; |
| 18461 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18462 | /* We need to get the size out of the right CQE */ |
| 18463 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 18464 | len = bf_get(lpfc_rcqe_length, |
| 18465 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 18466 | iocbq->context2 = d_buf; |
| 18467 | iocbq->context3 = NULL; |
| 18468 | iocbq->iocb.ulpBdeCount = 1; |
| 18469 | if (len > LPFC_DATA_BUF_SIZE) |
| 18470 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 18471 | LPFC_DATA_BUF_SIZE; |
| 18472 | else |
| 18473 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = len; |
| 18474 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18475 | tot_len += len; |
| 18476 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
| 18477 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18478 | iocbq->iocb.un.rcvels.remoteID = sid; |
| 18479 | list_add_tail(&iocbq->list, &first_iocbq->list); |
| 18480 | } |
| 18481 | } |
James Smart | 39c4f1a | 2020-01-27 16:23:01 -0800 | [diff] [blame] | 18482 | /* Free the sequence's header buffer */ |
| 18483 | if (!first_iocbq) |
| 18484 | lpfc_in_buf_free(vport->phba, &seq_dmabuf->dbuf); |
| 18485 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18486 | return first_iocbq; |
| 18487 | } |
| 18488 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18489 | static void |
| 18490 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, |
| 18491 | struct hbq_dmabuf *seq_dmabuf) |
| 18492 | { |
| 18493 | struct fc_frame_header *fc_hdr; |
| 18494 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; |
| 18495 | struct lpfc_hba *phba = vport->phba; |
| 18496 | |
| 18497 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 18498 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); |
| 18499 | if (!iocbq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 18500 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18501 | "2707 Ring %d handler: Failed to allocate " |
| 18502 | "iocb Rctl x%x Type x%x received\n", |
| 18503 | LPFC_ELS_RING, |
| 18504 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 18505 | return; |
| 18506 | } |
| 18507 | if (!lpfc_complete_unsol_iocb(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18508 | phba->sli4_hba.els_wq->pring, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18509 | iocbq, fc_hdr->fh_r_ctl, |
| 18510 | fc_hdr->fh_type)) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 18511 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18512 | "2540 Ring %d handler: unexpected Rctl " |
| 18513 | "x%x Type x%x received\n", |
| 18514 | LPFC_ELS_RING, |
| 18515 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 18516 | |
| 18517 | /* Free iocb created in lpfc_prep_seq */ |
| 18518 | list_for_each_entry_safe(curr_iocb, next_iocb, |
| 18519 | &iocbq->list, list) { |
| 18520 | list_del_init(&curr_iocb->list); |
| 18521 | lpfc_sli_release_iocbq(phba, curr_iocb); |
| 18522 | } |
| 18523 | lpfc_sli_release_iocbq(phba, iocbq); |
| 18524 | } |
| 18525 | |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18526 | static void |
| 18527 | lpfc_sli4_mds_loopback_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 18528 | struct lpfc_iocbq *rspiocb) |
| 18529 | { |
| 18530 | struct lpfc_dmabuf *pcmd = cmdiocb->context2; |
| 18531 | |
| 18532 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 18533 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18534 | kfree(pcmd); |
| 18535 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 18536 | lpfc_drain_txq(phba); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18537 | } |
| 18538 | |
| 18539 | static void |
| 18540 | lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport, |
| 18541 | struct hbq_dmabuf *dmabuf) |
| 18542 | { |
| 18543 | struct fc_frame_header *fc_hdr; |
| 18544 | struct lpfc_hba *phba = vport->phba; |
| 18545 | struct lpfc_iocbq *iocbq = NULL; |
| 18546 | union lpfc_wqe *wqe; |
| 18547 | struct lpfc_dmabuf *pcmd = NULL; |
| 18548 | uint32_t frame_len; |
| 18549 | int rc; |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 18550 | unsigned long iflags; |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18551 | |
| 18552 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 18553 | frame_len = bf_get(lpfc_rcqe_length, &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 18554 | |
| 18555 | /* Send the received frame back */ |
| 18556 | iocbq = lpfc_sli_get_iocbq(phba); |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 18557 | if (!iocbq) { |
| 18558 | /* Queue cq event and wakeup worker thread to process it */ |
| 18559 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 18560 | list_add_tail(&dmabuf->cq_event.list, |
| 18561 | &phba->sli4_hba.sp_queue_event); |
| 18562 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
| 18563 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 18564 | lpfc_worker_wake_up(phba); |
| 18565 | return; |
| 18566 | } |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18567 | |
| 18568 | /* Allocate buffer for command payload */ |
| 18569 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 18570 | if (pcmd) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 18571 | pcmd->virt = dma_pool_alloc(phba->lpfc_drb_pool, GFP_KERNEL, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18572 | &pcmd->phys); |
| 18573 | if (!pcmd || !pcmd->virt) |
| 18574 | goto exit; |
| 18575 | |
| 18576 | INIT_LIST_HEAD(&pcmd->list); |
| 18577 | |
| 18578 | /* copyin the payload */ |
| 18579 | memcpy(pcmd->virt, dmabuf->dbuf.virt, frame_len); |
| 18580 | |
| 18581 | /* fill in BDE's for command */ |
| 18582 | iocbq->iocb.un.xseq64.bdl.addrHigh = putPaddrHigh(pcmd->phys); |
| 18583 | iocbq->iocb.un.xseq64.bdl.addrLow = putPaddrLow(pcmd->phys); |
| 18584 | iocbq->iocb.un.xseq64.bdl.bdeFlags = BUFF_TYPE_BDE_64; |
| 18585 | iocbq->iocb.un.xseq64.bdl.bdeSize = frame_len; |
| 18586 | |
| 18587 | iocbq->context2 = pcmd; |
| 18588 | iocbq->vport = vport; |
| 18589 | iocbq->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
| 18590 | iocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
| 18591 | |
| 18592 | /* |
| 18593 | * Setup rest of the iocb as though it were a WQE |
| 18594 | * Build the SEND_FRAME WQE |
| 18595 | */ |
| 18596 | wqe = (union lpfc_wqe *)&iocbq->iocb; |
| 18597 | |
| 18598 | wqe->send_frame.frame_len = frame_len; |
| 18599 | wqe->send_frame.fc_hdr_wd0 = be32_to_cpu(*((uint32_t *)fc_hdr)); |
| 18600 | wqe->send_frame.fc_hdr_wd1 = be32_to_cpu(*((uint32_t *)fc_hdr + 1)); |
| 18601 | wqe->send_frame.fc_hdr_wd2 = be32_to_cpu(*((uint32_t *)fc_hdr + 2)); |
| 18602 | wqe->send_frame.fc_hdr_wd3 = be32_to_cpu(*((uint32_t *)fc_hdr + 3)); |
| 18603 | wqe->send_frame.fc_hdr_wd4 = be32_to_cpu(*((uint32_t *)fc_hdr + 4)); |
| 18604 | wqe->send_frame.fc_hdr_wd5 = be32_to_cpu(*((uint32_t *)fc_hdr + 5)); |
| 18605 | |
| 18606 | iocbq->iocb.ulpCommand = CMD_SEND_FRAME; |
| 18607 | iocbq->iocb.ulpLe = 1; |
| 18608 | iocbq->iocb_cmpl = lpfc_sli4_mds_loopback_cmpl; |
| 18609 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocbq, 0); |
| 18610 | if (rc == IOCB_ERROR) |
| 18611 | goto exit; |
| 18612 | |
| 18613 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18614 | return; |
| 18615 | |
| 18616 | exit: |
| 18617 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 18618 | "2023 Unable to process MDS loopback frame\n"); |
| 18619 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 18620 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18621 | kfree(pcmd); |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 18622 | if (iocbq) |
| 18623 | lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18624 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18625 | } |
| 18626 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18627 | /** |
| 18628 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware |
| 18629 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 18630 | * @dmabuf: Pointer to a dmabuf that describes the FC sequence. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18631 | * |
| 18632 | * This function is called with no lock held. This function processes all |
| 18633 | * the received buffers and gives it to upper layers when a received buffer |
| 18634 | * indicates that it is the final frame in the sequence. The interrupt |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18635 | * service routine processes received buffers at interrupt contexts. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18636 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the |
| 18637 | * appropriate receive function when the final frame in a sequence is received. |
| 18638 | **/ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18639 | void |
| 18640 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, |
| 18641 | struct hbq_dmabuf *dmabuf) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18642 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18643 | struct hbq_dmabuf *seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18644 | struct fc_frame_header *fc_hdr; |
| 18645 | struct lpfc_vport *vport; |
| 18646 | uint32_t fcfi; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 18647 | uint32_t did; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18648 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18649 | /* Process each received buffer */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18650 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 18651 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 18652 | if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS || |
| 18653 | fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) { |
| 18654 | vport = phba->pport; |
| 18655 | /* Handle MDS Loopback frames */ |
Dick Kennedy | 24411fc | 2020-08-03 14:02:25 -0700 | [diff] [blame] | 18656 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 18657 | lpfc_sli4_handle_mds_loopback(vport, dmabuf); |
| 18658 | else |
| 18659 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 18660 | return; |
| 18661 | } |
| 18662 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18663 | /* check to see if this a valid type of frame */ |
| 18664 | if (lpfc_fc_frame_check(phba, fc_hdr)) { |
| 18665 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18666 | return; |
| 18667 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 18668 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18669 | if ((bf_get(lpfc_cqe_code, |
| 18670 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) |
| 18671 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, |
| 18672 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 18673 | else |
| 18674 | fcfi = bf_get(lpfc_rcqe_fcf_id, |
| 18675 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 18676 | |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 18677 | if (fc_hdr->fh_r_ctl == 0xF4 && fc_hdr->fh_type == 0xFF) { |
| 18678 | vport = phba->pport; |
| 18679 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 18680 | "2023 MDS Loopback %d bytes\n", |
| 18681 | bf_get(lpfc_rcqe_length, |
| 18682 | &dmabuf->cq_event.cqe.rcqe_cmpl)); |
| 18683 | /* Handle MDS Loopback frames */ |
| 18684 | lpfc_sli4_handle_mds_loopback(vport, dmabuf); |
| 18685 | return; |
| 18686 | } |
| 18687 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18688 | /* d_id this frame is directed to */ |
| 18689 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 18690 | |
| 18691 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi, did); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 18692 | if (!vport) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18693 | /* throw out the frame */ |
| 18694 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18695 | return; |
| 18696 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 18697 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 18698 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ |
| 18699 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && |
| 18700 | (did != Fabric_DID)) { |
| 18701 | /* |
| 18702 | * Throw out the frame if we are not pt2pt. |
| 18703 | * The pt2pt protocol allows for discovery frames |
| 18704 | * to be received without a registered VPI. |
| 18705 | */ |
| 18706 | if (!(vport->fc_flag & FC_PT2PT) || |
| 18707 | (phba->link_state == LPFC_HBA_READY)) { |
| 18708 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18709 | return; |
| 18710 | } |
| 18711 | } |
| 18712 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18713 | /* Handle the basic abort sequence (BA_ABTS) event */ |
| 18714 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 18715 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); |
| 18716 | return; |
| 18717 | } |
| 18718 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18719 | /* Link this frame */ |
| 18720 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); |
| 18721 | if (!seq_dmabuf) { |
| 18722 | /* unable to add frame to vport - throw it out */ |
| 18723 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18724 | return; |
| 18725 | } |
| 18726 | /* If not last frame in sequence continue processing frames. */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 18727 | if (!lpfc_seq_complete(seq_dmabuf)) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18728 | return; |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 18729 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18730 | /* Send the complete sequence to the upper layer protocol */ |
| 18731 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18732 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18733 | |
| 18734 | /** |
| 18735 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port |
| 18736 | * @phba: pointer to lpfc hba data structure. |
| 18737 | * |
| 18738 | * This routine is invoked to post rpi header templates to the |
| 18739 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 18740 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 18741 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18742 | * |
| 18743 | * This routine does not require any locks. It's usage is expected |
| 18744 | * to be driver load or reset recovery when the driver is |
| 18745 | * sequential. |
| 18746 | * |
| 18747 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 18748 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18749 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18750 | * When this error occurs, the driver is not guaranteed |
| 18751 | * to have any rpi regions posted to the device and |
| 18752 | * must either attempt to repost the regions or take a |
| 18753 | * fatal error. |
| 18754 | **/ |
| 18755 | int |
| 18756 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) |
| 18757 | { |
| 18758 | struct lpfc_rpi_hdr *rpi_page; |
| 18759 | uint32_t rc = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18760 | uint16_t lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18761 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18762 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 18763 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 18764 | goto exit; |
| 18765 | if (phba->sli4_hba.extents_in_use) |
| 18766 | return -EIO; |
| 18767 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18768 | 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] | 18769 | /* |
| 18770 | * Assign the rpi headers a physical rpi only if the driver |
| 18771 | * has not initialized those resources. A port reset only |
| 18772 | * needs the headers posted. |
| 18773 | */ |
| 18774 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != |
| 18775 | LPFC_RPI_RSRC_RDY) |
| 18776 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
| 18777 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18778 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
| 18779 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 18780 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18781 | "2008 Error %d posting all rpi " |
| 18782 | "headers\n", rc); |
| 18783 | rc = -EIO; |
| 18784 | break; |
| 18785 | } |
| 18786 | } |
| 18787 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18788 | exit: |
| 18789 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 18790 | LPFC_RPI_RSRC_RDY); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18791 | return rc; |
| 18792 | } |
| 18793 | |
| 18794 | /** |
| 18795 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port |
| 18796 | * @phba: pointer to lpfc hba data structure. |
| 18797 | * @rpi_page: pointer to the rpi memory region. |
| 18798 | * |
| 18799 | * This routine is invoked to post a single rpi header to the |
| 18800 | * HBA consistent with the SLI-4 interface spec. This memory region |
| 18801 | * maps up to 64 rpi context regions. |
| 18802 | * |
| 18803 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 18804 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18805 | * -ENOMEM - No available memory |
| 18806 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18807 | **/ |
| 18808 | int |
| 18809 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) |
| 18810 | { |
| 18811 | LPFC_MBOXQ_t *mboxq; |
| 18812 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; |
| 18813 | uint32_t rc = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18814 | uint32_t shdr_status, shdr_add_status; |
| 18815 | union lpfc_sli4_cfg_shdr *shdr; |
| 18816 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18817 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 18818 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 18819 | return rc; |
| 18820 | if (phba->sli4_hba.extents_in_use) |
| 18821 | return -EIO; |
| 18822 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18823 | /* The port is notified of the header region via a mailbox command. */ |
| 18824 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18825 | if (!mboxq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 18826 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18827 | "2001 Unable to allocate memory for issuing " |
| 18828 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 18829 | return -ENOMEM; |
| 18830 | } |
| 18831 | |
| 18832 | /* Post all rpi memory regions to the port. */ |
| 18833 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18834 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18835 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, |
| 18836 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 18837 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 18838 | LPFC_SLI4_MBX_EMBED); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18839 | |
| 18840 | |
| 18841 | /* Post the physical rpi to the port for this rpi header. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18842 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
| 18843 | rpi_page->start_rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18844 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
| 18845 | hdr_tmpl, rpi_page->page_count); |
| 18846 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18847 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
| 18848 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 18849 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18850 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
| 18851 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 18852 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 304ee43 | 2021-04-11 18:31:17 -0700 | [diff] [blame] | 18853 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18854 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 18855 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18856 | "2514 POST_RPI_HDR mailbox failed with " |
| 18857 | "status x%x add_status x%x, mbx status x%x\n", |
| 18858 | shdr_status, shdr_add_status, rc); |
| 18859 | rc = -ENXIO; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 18860 | } else { |
| 18861 | /* |
| 18862 | * The next_rpi stores the next logical module-64 rpi value used |
| 18863 | * to post physical rpis in subsequent rpi postings. |
| 18864 | */ |
| 18865 | spin_lock_irq(&phba->hbalock); |
| 18866 | phba->sli4_hba.next_rpi = rpi_page->next_rpi; |
| 18867 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18868 | } |
| 18869 | return rc; |
| 18870 | } |
| 18871 | |
| 18872 | /** |
| 18873 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range |
| 18874 | * @phba: pointer to lpfc hba data structure. |
| 18875 | * |
| 18876 | * This routine is invoked to post rpi header templates to the |
| 18877 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 18878 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 18879 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18880 | * |
| 18881 | * Returns |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 18882 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18883 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 18884 | **/ |
| 18885 | int |
| 18886 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) |
| 18887 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18888 | unsigned long rpi; |
| 18889 | uint16_t max_rpi, rpi_limit; |
| 18890 | uint16_t rpi_remaining, lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18891 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18892 | unsigned long iflag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18893 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18894 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18895 | * Fetch the next logical rpi. Because this index is logical, |
| 18896 | * the driver starts at 0 each time. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18897 | */ |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18898 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 18899 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
| 18900 | rpi_limit = phba->sli4_hba.next_rpi; |
| 18901 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18902 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
| 18903 | if (rpi >= rpi_limit) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18904 | rpi = LPFC_RPI_ALLOC_ERROR; |
| 18905 | else { |
| 18906 | set_bit(rpi, phba->sli4_hba.rpi_bmask); |
| 18907 | phba->sli4_hba.max_cfg_param.rpi_used++; |
| 18908 | phba->sli4_hba.rpi_count++; |
| 18909 | } |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 18910 | lpfc_printf_log(phba, KERN_INFO, |
| 18911 | LOG_NODE | LOG_DISCOVERY, |
| 18912 | "0001 Allocated rpi:x%x max:x%x lim:x%x\n", |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 18913 | (int) rpi, max_rpi, rpi_limit); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18914 | |
| 18915 | /* |
| 18916 | * 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] | 18917 | * has been exhausted. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18918 | */ |
| 18919 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && |
| 18920 | (phba->sli4_hba.rpi_count >= max_rpi)) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18921 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18922 | return rpi; |
| 18923 | } |
| 18924 | |
| 18925 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18926 | * RPI header postings are not required for SLI4 ports capable of |
| 18927 | * extents. |
| 18928 | */ |
| 18929 | if (!phba->sli4_hba.rpi_hdrs_in_use) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18930 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18931 | return rpi; |
| 18932 | } |
| 18933 | |
| 18934 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18935 | * If the driver is running low on rpi resources, allocate another |
| 18936 | * page now. Note that the next_rpi value is used because |
| 18937 | * it represents how many are actually in use whereas max_rpi notes |
| 18938 | * how many are supported max by the device. |
| 18939 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18940 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18941 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18942 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
| 18943 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 18944 | if (!rpi_hdr) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 18945 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18946 | "2002 Error Could not grow rpi " |
| 18947 | "count\n"); |
| 18948 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18949 | lrpi = rpi_hdr->start_rpi; |
| 18950 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18951 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
| 18952 | } |
| 18953 | } |
| 18954 | |
| 18955 | return rpi; |
| 18956 | } |
| 18957 | |
| 18958 | /** |
Lee Jones | 8514e2f | 2021-03-03 14:46:18 +0000 | [diff] [blame] | 18959 | * __lpfc_sli4_free_rpi - Release an rpi for reuse. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18960 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 18961 | * @rpi: rpi to free |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18962 | * |
| 18963 | * This routine is invoked to release an rpi to the pool of |
| 18964 | * available rpis maintained by the driver. |
| 18965 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18966 | static void |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18967 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 18968 | { |
James Smart | 7cfd563 | 2019-11-04 16:56:58 -0800 | [diff] [blame] | 18969 | /* |
| 18970 | * if the rpi value indicates a prior unreg has already |
| 18971 | * been done, skip the unreg. |
| 18972 | */ |
| 18973 | if (rpi == LPFC_RPI_ALLOC_ERROR) |
| 18974 | return; |
| 18975 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18976 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { |
| 18977 | phba->sli4_hba.rpi_count--; |
| 18978 | phba->sli4_hba.max_cfg_param.rpi_used--; |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 18979 | } else { |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 18980 | lpfc_printf_log(phba, KERN_INFO, |
| 18981 | LOG_NODE | LOG_DISCOVERY, |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 18982 | "2016 rpi %x not inuse\n", |
| 18983 | rpi); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18984 | } |
| 18985 | } |
| 18986 | |
| 18987 | /** |
| 18988 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 18989 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 18990 | * @rpi: rpi to free |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18991 | * |
| 18992 | * This routine is invoked to release an rpi to the pool of |
| 18993 | * available rpis maintained by the driver. |
| 18994 | **/ |
| 18995 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18996 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 18997 | { |
| 18998 | spin_lock_irq(&phba->hbalock); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18999 | __lpfc_sli4_free_rpi(phba, rpi); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19000 | spin_unlock_irq(&phba->hbalock); |
| 19001 | } |
| 19002 | |
| 19003 | /** |
| 19004 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region |
| 19005 | * @phba: pointer to lpfc hba data structure. |
| 19006 | * |
| 19007 | * This routine is invoked to remove the memory region that |
| 19008 | * provided rpi via a bitmask. |
| 19009 | **/ |
| 19010 | void |
| 19011 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) |
| 19012 | { |
| 19013 | kfree(phba->sli4_hba.rpi_bmask); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 19014 | kfree(phba->sli4_hba.rpi_ids); |
| 19015 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19016 | } |
| 19017 | |
| 19018 | /** |
| 19019 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 19020 | * @ndlp: pointer to lpfc nodelist data structure. |
| 19021 | * @cmpl: completion call-back. |
| 19022 | * @arg: data to load as MBox 'caller buffer information' |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19023 | * |
| 19024 | * This routine is invoked to remove the memory region that |
| 19025 | * provided rpi via a bitmask. |
| 19026 | **/ |
| 19027 | int |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 19028 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
| 19029 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19030 | { |
| 19031 | LPFC_MBOXQ_t *mboxq; |
| 19032 | struct lpfc_hba *phba = ndlp->phba; |
| 19033 | int rc; |
| 19034 | |
| 19035 | /* The port is notified of the header region via a mailbox command. */ |
| 19036 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19037 | if (!mboxq) |
| 19038 | return -ENOMEM; |
| 19039 | |
| 19040 | /* Post all rpi memory regions to the port. */ |
| 19041 | lpfc_resume_rpi(mboxq, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 19042 | if (cmpl) { |
| 19043 | mboxq->mbox_cmpl = cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19044 | mboxq->ctx_buf = arg; |
| 19045 | mboxq->ctx_ndlp = ndlp; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 19046 | } else |
| 19047 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 19048 | mboxq->vport = ndlp->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19049 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 19050 | if (rc == MBX_NOT_FINISHED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 19051 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19052 | "2010 Resume RPI Mailbox failed " |
| 19053 | "status %d, mbxStatus x%x\n", rc, |
| 19054 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 19055 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 19056 | return -EIO; |
| 19057 | } |
| 19058 | return 0; |
| 19059 | } |
| 19060 | |
| 19061 | /** |
| 19062 | * lpfc_sli4_init_vpi - Initialize a vpi with the port |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 19063 | * @vport: Pointer to the vport for which the vpi is being initialized |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19064 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 19065 | * This routine is invoked to activate a vpi with the port. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19066 | * |
| 19067 | * Returns: |
| 19068 | * 0 success |
| 19069 | * -Evalue otherwise |
| 19070 | **/ |
| 19071 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 19072 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19073 | { |
| 19074 | LPFC_MBOXQ_t *mboxq; |
| 19075 | int rc = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 19076 | int retval = MBX_SUCCESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19077 | uint32_t mbox_tmo; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 19078 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19079 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19080 | if (!mboxq) |
| 19081 | return -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 19082 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 19083 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19084 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19085 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 19086 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19087 | "2022 INIT VPI Mailbox failed " |
| 19088 | "status %d, mbxStatus x%x\n", rc, |
| 19089 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 19090 | retval = -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19091 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 19092 | if (rc != MBX_TIMEOUT) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 19093 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 19094 | |
| 19095 | return retval; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19096 | } |
| 19097 | |
| 19098 | /** |
| 19099 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. |
| 19100 | * @phba: pointer to lpfc hba data structure. |
| 19101 | * @mboxq: Pointer to mailbox object. |
| 19102 | * |
| 19103 | * This routine is invoked to manually add a single FCF record. The caller |
| 19104 | * must pass a completely initialized FCF_Record. This routine takes |
| 19105 | * care of the nonembedded mailbox operations. |
| 19106 | **/ |
| 19107 | static void |
| 19108 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 19109 | { |
| 19110 | void *virt_addr; |
| 19111 | union lpfc_sli4_cfg_shdr *shdr; |
| 19112 | uint32_t shdr_status, shdr_add_status; |
| 19113 | |
| 19114 | virt_addr = mboxq->sge_array->addr[0]; |
| 19115 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 19116 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; |
| 19117 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 19118 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 19119 | |
| 19120 | if ((shdr_status || shdr_add_status) && |
| 19121 | (shdr_status != STATUS_FCF_IN_USE)) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 19122 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19123 | "2558 ADD_FCF_RECORD mailbox failed with " |
| 19124 | "status x%x add_status x%x\n", |
| 19125 | shdr_status, shdr_add_status); |
| 19126 | |
| 19127 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 19128 | } |
| 19129 | |
| 19130 | /** |
| 19131 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. |
| 19132 | * @phba: pointer to lpfc hba data structure. |
| 19133 | * @fcf_record: pointer to the initialized fcf record to add. |
| 19134 | * |
| 19135 | * This routine is invoked to manually add a single FCF record. The caller |
| 19136 | * must pass a completely initialized FCF_Record. This routine takes |
| 19137 | * care of the nonembedded mailbox operations. |
| 19138 | **/ |
| 19139 | int |
| 19140 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) |
| 19141 | { |
| 19142 | int rc = 0; |
| 19143 | LPFC_MBOXQ_t *mboxq; |
| 19144 | uint8_t *bytep; |
| 19145 | void *virt_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19146 | struct lpfc_mbx_sge sge; |
| 19147 | uint32_t alloc_len, req_len; |
| 19148 | uint32_t fcfindex; |
| 19149 | |
| 19150 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19151 | if (!mboxq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 19152 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19153 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); |
| 19154 | return -ENOMEM; |
| 19155 | } |
| 19156 | |
| 19157 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + |
| 19158 | sizeof(uint32_t); |
| 19159 | |
| 19160 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 19161 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 19162 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, |
| 19163 | req_len, LPFC_SLI4_MBX_NEMBED); |
| 19164 | if (alloc_len < req_len) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 19165 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19166 | "2523 Allocated DMA memory size (x%x) is " |
| 19167 | "less than the requested DMA memory " |
| 19168 | "size (x%x)\n", alloc_len, req_len); |
| 19169 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 19170 | return -ENOMEM; |
| 19171 | } |
| 19172 | |
| 19173 | /* |
| 19174 | * Get the first SGE entry from the non-embedded DMA memory. This |
| 19175 | * routine only uses a single SGE. |
| 19176 | */ |
| 19177 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19178 | virt_addr = mboxq->sge_array->addr[0]; |
| 19179 | /* |
| 19180 | * Configure the FCF record for FCFI 0. This is the driver's |
| 19181 | * hardcoded default and gets used in nonFIP mode. |
| 19182 | */ |
| 19183 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); |
| 19184 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 19185 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); |
| 19186 | |
| 19187 | /* |
| 19188 | * Copy the fcf_index and the FCF Record Data. The data starts after |
| 19189 | * the FCoE header plus word10. The data copy needs to be endian |
| 19190 | * correct. |
| 19191 | */ |
| 19192 | bytep += sizeof(uint32_t); |
| 19193 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); |
| 19194 | mboxq->vport = phba->pport; |
| 19195 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; |
| 19196 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 19197 | if (rc == MBX_NOT_FINISHED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 19198 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19199 | "2515 ADD_FCF_RECORD mailbox failed with " |
| 19200 | "status 0x%x\n", rc); |
| 19201 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 19202 | rc = -EIO; |
| 19203 | } else |
| 19204 | rc = 0; |
| 19205 | |
| 19206 | return rc; |
| 19207 | } |
| 19208 | |
| 19209 | /** |
| 19210 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. |
| 19211 | * @phba: pointer to lpfc hba data structure. |
| 19212 | * @fcf_record: pointer to the fcf record to write the default data. |
| 19213 | * @fcf_index: FCF table entry index. |
| 19214 | * |
| 19215 | * This routine is invoked to build the driver's default FCF record. The |
| 19216 | * values used are hardcoded. This routine handles memory initialization. |
| 19217 | * |
| 19218 | **/ |
| 19219 | void |
| 19220 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, |
| 19221 | struct fcf_record *fcf_record, |
| 19222 | uint16_t fcf_index) |
| 19223 | { |
| 19224 | memset(fcf_record, 0, sizeof(struct fcf_record)); |
| 19225 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; |
| 19226 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; |
| 19227 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; |
| 19228 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); |
| 19229 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); |
| 19230 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); |
| 19231 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); |
| 19232 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); |
| 19233 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); |
| 19234 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); |
| 19235 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); |
| 19236 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); |
| 19237 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 19238 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19239 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
| 19240 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, |
| 19241 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); |
| 19242 | /* Set the VLAN bit map */ |
| 19243 | if (phba->valid_vlan) { |
| 19244 | fcf_record->vlan_bitmap[phba->vlan_id / 8] |
| 19245 | = 1 << (phba->vlan_id % 8); |
| 19246 | } |
| 19247 | } |
| 19248 | |
| 19249 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19250 | * 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] | 19251 | * @phba: pointer to lpfc hba data structure. |
| 19252 | * @fcf_index: FCF table entry offset. |
| 19253 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19254 | * This routine is invoked to scan the entire FCF table by reading FCF |
| 19255 | * record and processing it one at a time starting from the @fcf_index |
| 19256 | * for initial FCF discovery or fast FCF failover rediscovery. |
| 19257 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 19258 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19259 | * otherwise. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19260 | **/ |
| 19261 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19262 | 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] | 19263 | { |
| 19264 | int rc = 0, error; |
| 19265 | LPFC_MBOXQ_t *mboxq; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19266 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 19267 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 19268 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19269 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19270 | if (!mboxq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 19271 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19272 | "2000 Failed to allocate mbox for " |
| 19273 | "READ_FCF cmd\n"); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 19274 | error = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19275 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19276 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19277 | /* Construct the read FCF record mailbox command */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19278 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19279 | if (rc) { |
| 19280 | error = -EINVAL; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19281 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19282 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19283 | /* Issue the mailbox command asynchronously */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19284 | mboxq->vport = phba->pport; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19285 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19286 | |
| 19287 | spin_lock_irq(&phba->hbalock); |
| 19288 | phba->hba_flag |= FCF_TS_INPROG; |
| 19289 | spin_unlock_irq(&phba->hbalock); |
| 19290 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19291 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19292 | if (rc == MBX_NOT_FINISHED) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19293 | error = -EIO; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19294 | else { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 19295 | /* Reset eligible FCF count for new scan */ |
| 19296 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 19297 | phba->fcf.eligible_fcf_cnt = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19298 | error = 0; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 19299 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19300 | fail_fcf_scan: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 19301 | if (error) { |
| 19302 | if (mboxq) |
| 19303 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19304 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 19305 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19306 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 19307 | spin_unlock_irq(&phba->hbalock); |
| 19308 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 19309 | return error; |
| 19310 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19311 | |
| 19312 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19313 | * 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] | 19314 | * @phba: pointer to lpfc hba data structure. |
| 19315 | * @fcf_index: FCF table entry offset. |
| 19316 | * |
| 19317 | * 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] | 19318 | * and to use it for FLOGI roundrobin FCF failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19319 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 19320 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19321 | * otherwise. |
| 19322 | **/ |
| 19323 | int |
| 19324 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 19325 | { |
| 19326 | int rc = 0, error; |
| 19327 | LPFC_MBOXQ_t *mboxq; |
| 19328 | |
| 19329 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19330 | if (!mboxq) { |
| 19331 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 19332 | "2763 Failed to allocate mbox for " |
| 19333 | "READ_FCF cmd\n"); |
| 19334 | error = -ENOMEM; |
| 19335 | goto fail_fcf_read; |
| 19336 | } |
| 19337 | /* Construct the read FCF record mailbox command */ |
| 19338 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 19339 | if (rc) { |
| 19340 | error = -EINVAL; |
| 19341 | goto fail_fcf_read; |
| 19342 | } |
| 19343 | /* Issue the mailbox command asynchronously */ |
| 19344 | mboxq->vport = phba->pport; |
| 19345 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; |
| 19346 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 19347 | if (rc == MBX_NOT_FINISHED) |
| 19348 | error = -EIO; |
| 19349 | else |
| 19350 | error = 0; |
| 19351 | |
| 19352 | fail_fcf_read: |
| 19353 | if (error && mboxq) |
| 19354 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 19355 | return error; |
| 19356 | } |
| 19357 | |
| 19358 | /** |
| 19359 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. |
| 19360 | * @phba: pointer to lpfc hba data structure. |
| 19361 | * @fcf_index: FCF table entry offset. |
| 19362 | * |
| 19363 | * 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] | 19364 | * determine whether it's eligible for FLOGI roundrobin failover list. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19365 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 19366 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19367 | * otherwise. |
| 19368 | **/ |
| 19369 | int |
| 19370 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 19371 | { |
| 19372 | int rc = 0, error; |
| 19373 | LPFC_MBOXQ_t *mboxq; |
| 19374 | |
| 19375 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19376 | if (!mboxq) { |
| 19377 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 19378 | "2758 Failed to allocate mbox for " |
| 19379 | "READ_FCF cmd\n"); |
| 19380 | error = -ENOMEM; |
| 19381 | goto fail_fcf_read; |
| 19382 | } |
| 19383 | /* Construct the read FCF record mailbox command */ |
| 19384 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 19385 | if (rc) { |
| 19386 | error = -EINVAL; |
| 19387 | goto fail_fcf_read; |
| 19388 | } |
| 19389 | /* Issue the mailbox command asynchronously */ |
| 19390 | mboxq->vport = phba->pport; |
| 19391 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; |
| 19392 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 19393 | if (rc == MBX_NOT_FINISHED) |
| 19394 | error = -EIO; |
| 19395 | else |
| 19396 | error = 0; |
| 19397 | |
| 19398 | fail_fcf_read: |
| 19399 | if (error && mboxq) |
| 19400 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 19401 | return error; |
| 19402 | } |
| 19403 | |
| 19404 | /** |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 19405 | * lpfc_check_next_fcf_pri_level |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 19406 | * @phba: pointer to the lpfc_hba struct for this port. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19407 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get |
| 19408 | * routine when the rr_bmask is empty. The FCF indecies are put into the |
| 19409 | * rr_bmask based on their priority level. Starting from the highest priority |
| 19410 | * to the lowest. The most likely FCF candidate will be in the highest |
| 19411 | * priority group. When this routine is called it searches the fcf_pri list for |
| 19412 | * next lowest priority group and repopulates the rr_bmask with only those |
| 19413 | * fcf_indexes. |
| 19414 | * returns: |
| 19415 | * 1=success 0=failure |
| 19416 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 19417 | static int |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19418 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
| 19419 | { |
| 19420 | uint16_t next_fcf_pri; |
| 19421 | uint16_t last_index; |
| 19422 | struct lpfc_fcf_pri *fcf_pri; |
| 19423 | int rc; |
| 19424 | int ret = 0; |
| 19425 | |
| 19426 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 19427 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 19428 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 19429 | "3060 Last IDX %d\n", last_index); |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 19430 | |
| 19431 | /* Verify the priority list has 2 or more entries */ |
| 19432 | spin_lock_irq(&phba->hbalock); |
| 19433 | if (list_empty(&phba->fcf.fcf_pri_list) || |
| 19434 | list_is_singular(&phba->fcf.fcf_pri_list)) { |
| 19435 | spin_unlock_irq(&phba->hbalock); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19436 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 19437 | "3061 Last IDX %d\n", last_index); |
| 19438 | return 0; /* Empty rr list */ |
| 19439 | } |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 19440 | spin_unlock_irq(&phba->hbalock); |
| 19441 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19442 | next_fcf_pri = 0; |
| 19443 | /* |
| 19444 | * Clear the rr_bmask and set all of the bits that are at this |
| 19445 | * priority. |
| 19446 | */ |
| 19447 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 19448 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 19449 | spin_lock_irq(&phba->hbalock); |
| 19450 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 19451 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) |
| 19452 | continue; |
| 19453 | /* |
| 19454 | * the 1st priority that has not FLOGI failed |
| 19455 | * will be the highest. |
| 19456 | */ |
| 19457 | if (!next_fcf_pri) |
| 19458 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 19459 | spin_unlock_irq(&phba->hbalock); |
| 19460 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 19461 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 19462 | fcf_pri->fcf_rec.fcf_index); |
| 19463 | if (rc) |
| 19464 | return 0; |
| 19465 | } |
| 19466 | spin_lock_irq(&phba->hbalock); |
| 19467 | } |
| 19468 | /* |
| 19469 | * if next_fcf_pri was not set above and the list is not empty then |
| 19470 | * we have failed flogis on all of them. So reset flogi failed |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 19471 | * and start at the beginning. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19472 | */ |
| 19473 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { |
| 19474 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 19475 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; |
| 19476 | /* |
| 19477 | * the 1st priority that has not FLOGI failed |
| 19478 | * will be the highest. |
| 19479 | */ |
| 19480 | if (!next_fcf_pri) |
| 19481 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 19482 | spin_unlock_irq(&phba->hbalock); |
| 19483 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 19484 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 19485 | fcf_pri->fcf_rec.fcf_index); |
| 19486 | if (rc) |
| 19487 | return 0; |
| 19488 | } |
| 19489 | spin_lock_irq(&phba->hbalock); |
| 19490 | } |
| 19491 | } else |
| 19492 | ret = 1; |
| 19493 | spin_unlock_irq(&phba->hbalock); |
| 19494 | |
| 19495 | return ret; |
| 19496 | } |
| 19497 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19498 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index |
| 19499 | * @phba: pointer to lpfc hba data structure. |
| 19500 | * |
| 19501 | * This routine is to get the next eligible FCF record index in a round |
| 19502 | * robin fashion. If the next eligible FCF record index equals to the |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19503 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19504 | * shall be returned, otherwise, the next eligible FCF record's index |
| 19505 | * shall be returned. |
| 19506 | **/ |
| 19507 | uint16_t |
| 19508 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) |
| 19509 | { |
| 19510 | uint16_t next_fcf_index; |
| 19511 | |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 19512 | initial_priority: |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19513 | /* Search start from next bit of currently registered FCF index */ |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 19514 | next_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 19515 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19516 | next_priority: |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 19517 | /* Determine the next fcf index to check */ |
| 19518 | 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] | 19519 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 19520 | LPFC_SLI4_FCF_TBL_INDX_MAX, |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19521 | next_fcf_index); |
| 19522 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19523 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19524 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 19525 | /* |
| 19526 | * If we have wrapped then we need to clear the bits that |
| 19527 | * have been tested so that we can detect when we should |
| 19528 | * change the priority level. |
| 19529 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19530 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 19531 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19532 | } |
| 19533 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19534 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19535 | /* Check roundrobin failover list empty condition */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19536 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
| 19537 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 19538 | /* |
| 19539 | * If next fcf index is not found check if there are lower |
| 19540 | * Priority level fcf's in the fcf_priority list. |
| 19541 | * Set up the rr_bmask with all of the avaiable fcf bits |
| 19542 | * at that level and continue the selection process. |
| 19543 | */ |
| 19544 | if (lpfc_check_next_fcf_pri_level(phba)) |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 19545 | goto initial_priority; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19546 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 19547 | "2844 No roundrobin failover FCF available\n"); |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 19548 | |
| 19549 | return LPFC_FCOE_FCF_NEXT_NONE; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19550 | } |
| 19551 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19552 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
| 19553 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 19554 | LPFC_FCF_FLOGI_FAILED) { |
| 19555 | if (list_is_singular(&phba->fcf.fcf_pri_list)) |
| 19556 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 19557 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19558 | goto next_priority; |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 19559 | } |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19560 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19561 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19562 | "2845 Get next roundrobin failover FCF (x%x)\n", |
| 19563 | next_fcf_index); |
| 19564 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19565 | return next_fcf_index; |
| 19566 | } |
| 19567 | |
| 19568 | /** |
| 19569 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index |
| 19570 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 19571 | * @fcf_index: index into the FCF table to 'set' |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19572 | * |
| 19573 | * 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] | 19574 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19575 | * does not go beyond the range of the driver allocated bmask dimension |
| 19576 | * before setting the bit. |
| 19577 | * |
| 19578 | * Returns 0 if the index bit successfully set, otherwise, it returns |
| 19579 | * -EINVAL. |
| 19580 | **/ |
| 19581 | int |
| 19582 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) |
| 19583 | { |
| 19584 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 19585 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19586 | "2610 FCF (x%x) reached driver's book " |
| 19587 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19588 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 19589 | return -EINVAL; |
| 19590 | } |
| 19591 | /* Set the eligible FCF record index bmask */ |
| 19592 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
| 19593 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19594 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19595 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19596 | "bmask\n", fcf_index); |
| 19597 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19598 | return 0; |
| 19599 | } |
| 19600 | |
| 19601 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19602 | * 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] | 19603 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 19604 | * @fcf_index: index into the FCF table to 'clear' |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19605 | * |
| 19606 | * This routine clears the FCF record index from the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19607 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19608 | * does not go beyond the range of the driver allocated bmask dimension |
| 19609 | * before clearing the bit. |
| 19610 | **/ |
| 19611 | void |
| 19612 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) |
| 19613 | { |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 19614 | struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19615 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 19616 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19617 | "2762 FCF (x%x) reached driver's book " |
| 19618 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19619 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 19620 | return; |
| 19621 | } |
| 19622 | /* Clear the eligible FCF record index bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19623 | spin_lock_irq(&phba->hbalock); |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 19624 | list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list, |
| 19625 | list) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19626 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
| 19627 | list_del_init(&fcf_pri->list); |
| 19628 | break; |
| 19629 | } |
| 19630 | } |
| 19631 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19632 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19633 | |
| 19634 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19635 | "2791 Clear FCF (x%x) from roundrobin failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19636 | "bmask\n", fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19637 | } |
| 19638 | |
| 19639 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19640 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table |
| 19641 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 19642 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19643 | * |
| 19644 | * This routine is the completion routine for the rediscover FCF table mailbox |
| 19645 | * command. If the mailbox command returned failure, it will try to stop the |
| 19646 | * FCF rediscover wait timer. |
| 19647 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 19648 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19649 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 19650 | { |
| 19651 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 19652 | uint32_t shdr_status, shdr_add_status; |
| 19653 | |
| 19654 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 19655 | |
| 19656 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 19657 | &redisc_fcf->header.cfg_shdr.response); |
| 19658 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 19659 | &redisc_fcf->header.cfg_shdr.response); |
| 19660 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19661 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19662 | "2746 Requesting for FCF rediscovery failed " |
| 19663 | "status x%x add_status x%x\n", |
| 19664 | shdr_status, shdr_add_status); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19665 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 19666 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19667 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 19668 | spin_unlock_irq(&phba->hbalock); |
| 19669 | /* |
| 19670 | * CVL event triggered FCF rediscover request failed, |
| 19671 | * last resort to re-try current registered FCF entry. |
| 19672 | */ |
| 19673 | lpfc_retry_pport_discovery(phba); |
| 19674 | } else { |
| 19675 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19676 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 19677 | spin_unlock_irq(&phba->hbalock); |
| 19678 | /* |
| 19679 | * DEAD FCF event triggered FCF rediscover request |
| 19680 | * failed, last resort to fail over as a link down |
| 19681 | * to FCF registration. |
| 19682 | */ |
| 19683 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 19684 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19685 | } else { |
| 19686 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19687 | "2775 Start FCF rediscover quiescent timer\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19688 | /* |
| 19689 | * Start FCF rediscovery wait timer for pending FCF |
| 19690 | * before rescan FCF record table. |
| 19691 | */ |
| 19692 | lpfc_fcf_redisc_wait_start_timer(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19693 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19694 | |
| 19695 | mempool_free(mbox, phba->mbox_mem_pool); |
| 19696 | } |
| 19697 | |
| 19698 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19699 | * 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] | 19700 | * @phba: pointer to lpfc hba data structure. |
| 19701 | * |
| 19702 | * This routine is invoked to request for rediscovery of the entire FCF table |
| 19703 | * by the port. |
| 19704 | **/ |
| 19705 | int |
| 19706 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) |
| 19707 | { |
| 19708 | LPFC_MBOXQ_t *mbox; |
| 19709 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 19710 | int rc, length; |
| 19711 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19712 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
| 19713 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
| 19714 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19715 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19716 | if (!mbox) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 19717 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19718 | "2745 Failed to allocate mbox for " |
| 19719 | "requesting FCF rediscover.\n"); |
| 19720 | return -ENOMEM; |
| 19721 | } |
| 19722 | |
| 19723 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - |
| 19724 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 19725 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 19726 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, |
| 19727 | length, LPFC_SLI4_MBX_EMBED); |
| 19728 | |
| 19729 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 19730 | /* Set count to 0 for invalidating the entire FCF database */ |
| 19731 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); |
| 19732 | |
| 19733 | /* Issue the mailbox command asynchronously */ |
| 19734 | mbox->vport = phba->pport; |
| 19735 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; |
| 19736 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 19737 | |
| 19738 | if (rc == MBX_NOT_FINISHED) { |
| 19739 | mempool_free(mbox, phba->mbox_mem_pool); |
| 19740 | return -EIO; |
| 19741 | } |
| 19742 | return 0; |
| 19743 | } |
| 19744 | |
| 19745 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 19746 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event |
| 19747 | * @phba: pointer to lpfc hba data structure. |
| 19748 | * |
| 19749 | * This function is the failover routine as a last resort to the FCF DEAD |
| 19750 | * event when driver failed to perform fast FCF failover. |
| 19751 | **/ |
| 19752 | void |
| 19753 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) |
| 19754 | { |
| 19755 | uint32_t link_state; |
| 19756 | |
| 19757 | /* |
| 19758 | * Last resort as FCF DEAD event failover will treat this as |
| 19759 | * a link down, but save the link state because we don't want |
| 19760 | * it to be changed to Link Down unless it is already down. |
| 19761 | */ |
| 19762 | link_state = phba->link_state; |
| 19763 | lpfc_linkdown(phba); |
| 19764 | phba->link_state = link_state; |
| 19765 | |
| 19766 | /* Unregister FCF if no devices connected to it */ |
| 19767 | lpfc_unregister_unused_fcf(phba); |
| 19768 | } |
| 19769 | |
| 19770 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19771 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19772 | * @phba: pointer to lpfc hba data structure. |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19773 | * @rgn23_data: pointer to configure region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19774 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19775 | * This function gets SLI3 port configure region 23 data through memory dump |
| 19776 | * mailbox command. When it successfully retrieves data, the size of the data |
| 19777 | * will be returned, otherwise, 0 will be returned. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19778 | **/ |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19779 | static uint32_t |
| 19780 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19781 | { |
| 19782 | LPFC_MBOXQ_t *pmb = NULL; |
| 19783 | MAILBOX_t *mb; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19784 | uint32_t offset = 0; |
James Smart | e4ec102 | 2021-04-21 16:45:11 -0700 | [diff] [blame] | 19785 | int rc; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19786 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19787 | if (!rgn23_data) |
| 19788 | return 0; |
| 19789 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19790 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19791 | if (!pmb) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 19792 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19793 | "2600 failed to allocate mailbox memory\n"); |
| 19794 | return 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19795 | } |
| 19796 | mb = &pmb->u.mb; |
| 19797 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19798 | do { |
| 19799 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); |
| 19800 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 19801 | |
| 19802 | if (rc != MBX_SUCCESS) { |
| 19803 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19804 | "2601 failed to read config " |
| 19805 | "region 23, rc 0x%x Status 0x%x\n", |
| 19806 | rc, mb->mbxStatus); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19807 | mb->un.varDmp.word_cnt = 0; |
| 19808 | } |
| 19809 | /* |
| 19810 | * dump mem may return a zero when finished or we got a |
| 19811 | * mailbox error, either way we are done. |
| 19812 | */ |
| 19813 | if (mb->un.varDmp.word_cnt == 0) |
| 19814 | break; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19815 | |
James Smart | e4ec102 | 2021-04-21 16:45:11 -0700 | [diff] [blame] | 19816 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) |
| 19817 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; |
| 19818 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19819 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
James Smart | e4ec102 | 2021-04-21 16:45:11 -0700 | [diff] [blame] | 19820 | rgn23_data + offset, |
| 19821 | mb->un.varDmp.word_cnt); |
| 19822 | offset += mb->un.varDmp.word_cnt; |
| 19823 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19824 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19825 | mempool_free(pmb, phba->mbox_mem_pool); |
| 19826 | return offset; |
| 19827 | } |
| 19828 | |
| 19829 | /** |
| 19830 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. |
| 19831 | * @phba: pointer to lpfc hba data structure. |
| 19832 | * @rgn23_data: pointer to configure region 23 data. |
| 19833 | * |
| 19834 | * This function gets SLI4 port configure region 23 data through memory dump |
| 19835 | * mailbox command. When it successfully retrieves data, the size of the data |
| 19836 | * will be returned, otherwise, 0 will be returned. |
| 19837 | **/ |
| 19838 | static uint32_t |
| 19839 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
| 19840 | { |
| 19841 | LPFC_MBOXQ_t *mboxq = NULL; |
| 19842 | struct lpfc_dmabuf *mp = NULL; |
| 19843 | struct lpfc_mqe *mqe; |
| 19844 | uint32_t data_length = 0; |
| 19845 | int rc; |
| 19846 | |
| 19847 | if (!rgn23_data) |
| 19848 | return 0; |
| 19849 | |
| 19850 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19851 | if (!mboxq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 19852 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19853 | "3105 failed to allocate mailbox memory\n"); |
| 19854 | return 0; |
| 19855 | } |
| 19856 | |
| 19857 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) |
| 19858 | goto out; |
| 19859 | mqe = &mboxq->u.mqe; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19860 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19861 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 19862 | if (rc) |
| 19863 | goto out; |
| 19864 | data_length = mqe->un.mb_words[5]; |
| 19865 | if (data_length == 0) |
| 19866 | goto out; |
| 19867 | if (data_length > DMP_RGN23_SIZE) { |
| 19868 | data_length = 0; |
| 19869 | goto out; |
| 19870 | } |
| 19871 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); |
| 19872 | out: |
| 19873 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 19874 | if (mp) { |
| 19875 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 19876 | kfree(mp); |
| 19877 | } |
| 19878 | return data_length; |
| 19879 | } |
| 19880 | |
| 19881 | /** |
| 19882 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. |
| 19883 | * @phba: pointer to lpfc hba data structure. |
| 19884 | * |
| 19885 | * This function read region 23 and parse TLV for port status to |
| 19886 | * decide if the user disaled the port. If the TLV indicates the |
| 19887 | * port is disabled, the hba_flag is set accordingly. |
| 19888 | **/ |
| 19889 | void |
| 19890 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) |
| 19891 | { |
| 19892 | uint8_t *rgn23_data = NULL; |
| 19893 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; |
| 19894 | uint32_t offset = 0; |
| 19895 | |
| 19896 | /* Get adapter Region 23 data */ |
| 19897 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); |
| 19898 | if (!rgn23_data) |
| 19899 | goto out; |
| 19900 | |
| 19901 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 19902 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); |
| 19903 | else { |
| 19904 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 19905 | &phba->sli4_hba.sli_intf); |
| 19906 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) |
| 19907 | goto out; |
| 19908 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); |
| 19909 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19910 | |
| 19911 | if (!data_size) |
| 19912 | goto out; |
| 19913 | |
| 19914 | /* Check the region signature first */ |
| 19915 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 19916 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19917 | "2619 Config region 23 has bad signature\n"); |
| 19918 | goto out; |
| 19919 | } |
| 19920 | offset += 4; |
| 19921 | |
| 19922 | /* Check the data structure version */ |
| 19923 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 19924 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19925 | "2620 Config region 23 has bad version\n"); |
| 19926 | goto out; |
| 19927 | } |
| 19928 | offset += 4; |
| 19929 | |
| 19930 | /* Parse TLV entries in the region */ |
| 19931 | while (offset < data_size) { |
| 19932 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) |
| 19933 | break; |
| 19934 | /* |
| 19935 | * If the TLV is not driver specific TLV or driver id is |
| 19936 | * not linux driver id, skip the record. |
| 19937 | */ |
| 19938 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || |
| 19939 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || |
| 19940 | (rgn23_data[offset + 3] != 0)) { |
| 19941 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 19942 | continue; |
| 19943 | } |
| 19944 | |
| 19945 | /* Driver found a driver specific TLV in the config region */ |
| 19946 | sub_tlv_len = rgn23_data[offset + 1] * 4; |
| 19947 | offset += 4; |
| 19948 | tlv_offset = 0; |
| 19949 | |
| 19950 | /* |
| 19951 | * Search for configured port state sub-TLV. |
| 19952 | */ |
| 19953 | while ((offset < data_size) && |
| 19954 | (tlv_offset < sub_tlv_len)) { |
| 19955 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { |
| 19956 | offset += 4; |
| 19957 | tlv_offset += 4; |
| 19958 | break; |
| 19959 | } |
| 19960 | if (rgn23_data[offset] != PORT_STE_TYPE) { |
| 19961 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 19962 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; |
| 19963 | continue; |
| 19964 | } |
| 19965 | |
| 19966 | /* This HBA contains PORT_STE configured */ |
| 19967 | if (!rgn23_data[offset + 2]) |
| 19968 | phba->hba_flag |= LINK_DISABLED; |
| 19969 | |
| 19970 | goto out; |
| 19971 | } |
| 19972 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19973 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19974 | out: |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19975 | kfree(rgn23_data); |
| 19976 | return; |
| 19977 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19978 | |
| 19979 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19980 | * lpfc_wr_object - write an object to the firmware |
| 19981 | * @phba: HBA structure that indicates port to create a queue on. |
| 19982 | * @dmabuf_list: list of dmabufs to write to the port. |
| 19983 | * @size: the total byte value of the objects to write to the port. |
| 19984 | * @offset: the current offset to be used to start the transfer. |
| 19985 | * |
| 19986 | * This routine will create a wr_object mailbox command to send to the port. |
| 19987 | * the mailbox command will be constructed using the dma buffers described in |
| 19988 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many |
| 19989 | * BDEs that the imbedded mailbox can support. The @offset variable will be |
| 19990 | * used to indicate the starting offset of the transfer and will also return |
| 19991 | * the offset after the write object mailbox has completed. @size is used to |
| 19992 | * determine the end of the object and whether the eof bit should be set. |
| 19993 | * |
| 19994 | * Return 0 is successful and offset will contain the the new offset to use |
| 19995 | * for the next write. |
| 19996 | * Return negative value for error cases. |
| 19997 | **/ |
| 19998 | int |
| 19999 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, |
| 20000 | uint32_t size, uint32_t *offset) |
| 20001 | { |
| 20002 | struct lpfc_mbx_wr_object *wr_object; |
| 20003 | LPFC_MBOXQ_t *mbox; |
| 20004 | int rc = 0, i = 0; |
James Smart | f3d0a8a | 2019-12-18 15:58:01 -0800 | [diff] [blame] | 20005 | uint32_t shdr_status, shdr_add_status, shdr_change_status, shdr_csf; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 20006 | uint32_t mbox_tmo; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 20007 | struct lpfc_dmabuf *dmabuf; |
| 20008 | uint32_t written = 0; |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 20009 | bool check_change_status = false; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 20010 | |
| 20011 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 20012 | if (!mbox) |
| 20013 | return -ENOMEM; |
| 20014 | |
| 20015 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 20016 | LPFC_MBOX_OPCODE_WRITE_OBJECT, |
| 20017 | sizeof(struct lpfc_mbx_wr_object) - |
| 20018 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
| 20019 | |
| 20020 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; |
| 20021 | wr_object->u.request.write_offset = *offset; |
| 20022 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); |
| 20023 | wr_object->u.request.object_name[0] = |
| 20024 | cpu_to_le32(wr_object->u.request.object_name[0]); |
| 20025 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); |
| 20026 | list_for_each_entry(dmabuf, dmabuf_list, list) { |
| 20027 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) |
| 20028 | break; |
| 20029 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); |
| 20030 | wr_object->u.request.bde[i].addrHigh = |
| 20031 | putPaddrHigh(dmabuf->phys); |
| 20032 | if (written + SLI4_PAGE_SIZE >= size) { |
| 20033 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 20034 | (size - written); |
| 20035 | written += (size - written); |
| 20036 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 20037 | bf_set(lpfc_wr_object_eas, &wr_object->u.request, 1); |
| 20038 | check_change_status = true; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 20039 | } else { |
| 20040 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 20041 | SLI4_PAGE_SIZE; |
| 20042 | written += SLI4_PAGE_SIZE; |
| 20043 | } |
| 20044 | i++; |
| 20045 | } |
| 20046 | wr_object->u.request.bde_count = i; |
| 20047 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); |
| 20048 | if (!phba->sli4_hba.intr_enable) |
| 20049 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 20050 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 20051 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 20052 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 20053 | } |
| 20054 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 20055 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 20056 | &wr_object->header.cfg_shdr.response); |
| 20057 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 20058 | &wr_object->header.cfg_shdr.response); |
| 20059 | if (check_change_status) { |
| 20060 | shdr_change_status = bf_get(lpfc_wr_object_change_status, |
| 20061 | &wr_object->u.response); |
James Smart | f3d0a8a | 2019-12-18 15:58:01 -0800 | [diff] [blame] | 20062 | |
| 20063 | if (shdr_change_status == LPFC_CHANGE_STATUS_FW_RESET || |
| 20064 | shdr_change_status == LPFC_CHANGE_STATUS_PORT_MIGRATION) { |
| 20065 | shdr_csf = bf_get(lpfc_wr_object_csf, |
| 20066 | &wr_object->u.response); |
| 20067 | if (shdr_csf) |
| 20068 | shdr_change_status = |
| 20069 | LPFC_CHANGE_STATUS_PCI_RESET; |
| 20070 | } |
| 20071 | |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 20072 | switch (shdr_change_status) { |
| 20073 | case (LPFC_CHANGE_STATUS_PHYS_DEV_RESET): |
| 20074 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 20075 | "3198 Firmware write complete: System " |
| 20076 | "reboot required to instantiate\n"); |
| 20077 | break; |
| 20078 | case (LPFC_CHANGE_STATUS_FW_RESET): |
| 20079 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 20080 | "3199 Firmware write complete: Firmware" |
| 20081 | " reset required to instantiate\n"); |
| 20082 | break; |
| 20083 | case (LPFC_CHANGE_STATUS_PORT_MIGRATION): |
| 20084 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 20085 | "3200 Firmware write complete: Port " |
| 20086 | "Migration or PCI Reset required to " |
| 20087 | "instantiate\n"); |
| 20088 | break; |
| 20089 | case (LPFC_CHANGE_STATUS_PCI_RESET): |
| 20090 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 20091 | "3201 Firmware write complete: PCI " |
| 20092 | "Reset required to instantiate\n"); |
| 20093 | break; |
| 20094 | default: |
| 20095 | break; |
| 20096 | } |
| 20097 | } |
James Smart | 304ee43 | 2021-04-11 18:31:17 -0700 | [diff] [blame] | 20098 | if (!phba->sli4_hba.intr_enable) |
| 20099 | mempool_free(mbox, phba->mbox_mem_pool); |
| 20100 | else if (rc != MBX_TIMEOUT) |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 20101 | mempool_free(mbox, phba->mbox_mem_pool); |
| 20102 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 20103 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 20104 | "3025 Write Object mailbox failed with " |
| 20105 | "status x%x add_status x%x, mbx status x%x\n", |
| 20106 | shdr_status, shdr_add_status, rc); |
| 20107 | rc = -ENXIO; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 20108 | *offset = shdr_add_status; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 20109 | } else |
| 20110 | *offset += wr_object->u.response.actual_write_length; |
| 20111 | return rc; |
| 20112 | } |
| 20113 | |
| 20114 | /** |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 20115 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. |
| 20116 | * @vport: pointer to vport data structure. |
| 20117 | * |
| 20118 | * This function iterate through the mailboxq and clean up all REG_LOGIN |
| 20119 | * and REG_VPI mailbox commands associated with the vport. This function |
| 20120 | * is called when driver want to restart discovery of the vport due to |
| 20121 | * a Clear Virtual Link event. |
| 20122 | **/ |
| 20123 | void |
| 20124 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) |
| 20125 | { |
| 20126 | struct lpfc_hba *phba = vport->phba; |
| 20127 | LPFC_MBOXQ_t *mb, *nextmb; |
| 20128 | struct lpfc_dmabuf *mp; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 20129 | struct lpfc_nodelist *ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 20130 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 20131 | LIST_HEAD(mbox_cmd_list); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 20132 | uint8_t restart_loop; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 20133 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 20134 | /* Clean up internally queued mailbox commands with the vport */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 20135 | spin_lock_irq(&phba->hbalock); |
| 20136 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 20137 | if (mb->vport != vport) |
| 20138 | continue; |
| 20139 | |
| 20140 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 20141 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 20142 | continue; |
| 20143 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 20144 | list_del(&mb->list); |
| 20145 | list_add_tail(&mb->list, &mbox_cmd_list); |
| 20146 | } |
| 20147 | /* Clean up active mailbox command with the vport */ |
| 20148 | mb = phba->sli.mbox_active; |
| 20149 | if (mb && (mb->vport == vport)) { |
| 20150 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || |
| 20151 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) |
| 20152 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 20153 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 20154 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 20155 | /* Put reference count for delayed processing */ |
| 20156 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); |
| 20157 | /* Unregister the RPI when mailbox complete */ |
| 20158 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 20159 | } |
| 20160 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 20161 | /* Cleanup any mailbox completions which are not yet processed */ |
| 20162 | do { |
| 20163 | restart_loop = 0; |
| 20164 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 20165 | /* |
| 20166 | * If this mailox is already processed or it is |
| 20167 | * for another vport ignore it. |
| 20168 | */ |
| 20169 | if ((mb->vport != vport) || |
| 20170 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) |
| 20171 | continue; |
| 20172 | |
| 20173 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 20174 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 20175 | continue; |
| 20176 | |
| 20177 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 20178 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 20179 | ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 20180 | /* Unregister the RPI when mailbox complete */ |
| 20181 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 20182 | restart_loop = 1; |
| 20183 | spin_unlock_irq(&phba->hbalock); |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 20184 | spin_lock(&ndlp->lock); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 20185 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 20186 | spin_unlock(&ndlp->lock); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 20187 | spin_lock_irq(&phba->hbalock); |
| 20188 | break; |
| 20189 | } |
| 20190 | } |
| 20191 | } while (restart_loop); |
| 20192 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 20193 | spin_unlock_irq(&phba->hbalock); |
| 20194 | |
| 20195 | /* Release the cleaned-up mailbox commands */ |
| 20196 | while (!list_empty(&mbox_cmd_list)) { |
| 20197 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 20198 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 20199 | mp = (struct lpfc_dmabuf *)(mb->ctx_buf); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 20200 | if (mp) { |
| 20201 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 20202 | kfree(mp); |
| 20203 | } |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 20204 | mb->ctx_buf = NULL; |
| 20205 | ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
| 20206 | mb->ctx_ndlp = NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 20207 | if (ndlp) { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 20208 | spin_lock(&ndlp->lock); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 20209 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 20210 | spin_unlock(&ndlp->lock); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 20211 | lpfc_nlp_put(ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 20212 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 20213 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 20214 | mempool_free(mb, phba->mbox_mem_pool); |
| 20215 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 20216 | |
| 20217 | /* Release the ndlp with the cleaned-up active mailbox command */ |
| 20218 | if (act_mbx_ndlp) { |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 20219 | spin_lock(&act_mbx_ndlp->lock); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 20220 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 20221 | spin_unlock(&act_mbx_ndlp->lock); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 20222 | lpfc_nlp_put(act_mbx_ndlp); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 20223 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 20224 | } |
| 20225 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 20226 | /** |
| 20227 | * lpfc_drain_txq - Drain the txq |
| 20228 | * @phba: Pointer to HBA context object. |
| 20229 | * |
| 20230 | * This function attempt to submit IOCBs on the txq |
| 20231 | * to the adapter. For SLI4 adapters, the txq contains |
| 20232 | * ELS IOCBs that have been deferred because the there |
| 20233 | * are no SGLs. This congestion can occur with large |
| 20234 | * vport counts during node discovery. |
| 20235 | **/ |
| 20236 | |
| 20237 | uint32_t |
| 20238 | lpfc_drain_txq(struct lpfc_hba *phba) |
| 20239 | { |
| 20240 | LIST_HEAD(completions); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20241 | struct lpfc_sli_ring *pring; |
Daeseok Youn | 2e70637 | 2014-02-21 09:03:32 +0900 | [diff] [blame] | 20242 | struct lpfc_iocbq *piocbq = NULL; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 20243 | unsigned long iflags = 0; |
| 20244 | char *fail_msg = NULL; |
| 20245 | struct lpfc_sglq *sglq; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 20246 | union lpfc_wqe128 wqe; |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 20247 | uint32_t txq_cnt = 0; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 20248 | struct lpfc_queue *wq; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 20249 | |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 20250 | if (phba->link_flag & LS_MDS_LOOPBACK) { |
| 20251 | /* MDS WQE are posted only to first WQ*/ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20252 | wq = phba->sli4_hba.hdwq[0].io_wq; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 20253 | if (unlikely(!wq)) |
| 20254 | return 0; |
| 20255 | pring = wq->pring; |
| 20256 | } else { |
| 20257 | wq = phba->sli4_hba.els_wq; |
| 20258 | if (unlikely(!wq)) |
| 20259 | return 0; |
| 20260 | pring = lpfc_phba_elsring(phba); |
| 20261 | } |
| 20262 | |
| 20263 | if (unlikely(!pring) || list_empty(&pring->txq)) |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 20264 | return 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20265 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 20266 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 20267 | list_for_each_entry(piocbq, &pring->txq, list) { |
| 20268 | txq_cnt++; |
| 20269 | } |
| 20270 | |
| 20271 | if (txq_cnt > pring->txq_max) |
| 20272 | pring->txq_max = txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 20273 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 20274 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 20275 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 20276 | while (!list_empty(&pring->txq)) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 20277 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 20278 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 20279 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 20280 | if (!piocbq) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 20281 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 20282 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 20283 | "2823 txq empty and txq_cnt is %d\n ", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 20284 | txq_cnt); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 20285 | break; |
| 20286 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20287 | sglq = __lpfc_sli_get_els_sglq(phba, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 20288 | if (!sglq) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 20289 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 20290 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 20291 | break; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 20292 | } |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 20293 | txq_cnt--; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 20294 | |
| 20295 | /* The xri and iocb resources secured, |
| 20296 | * attempt to issue request |
| 20297 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 20298 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 20299 | piocbq->sli4_xritag = sglq->sli4_xritag; |
| 20300 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) |
| 20301 | fail_msg = "to convert bpl to sgl"; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 20302 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 20303 | fail_msg = "to convert iocb to wqe"; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 20304 | else if (lpfc_sli4_wq_put(wq, &wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 20305 | fail_msg = " - Wq is full"; |
| 20306 | else |
| 20307 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); |
| 20308 | |
| 20309 | if (fail_msg) { |
| 20310 | /* Failed means we can't issue and need to cancel */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 20311 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 20312 | "2822 IOCB failed %s iotag 0x%x " |
| 20313 | "xri 0x%x\n", |
| 20314 | fail_msg, |
| 20315 | piocbq->iotag, piocbq->sli4_xritag); |
| 20316 | list_add_tail(&piocbq->list, &completions); |
| 20317 | } |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 20318 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 20319 | } |
| 20320 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 20321 | /* Cancel all the IOCBs that cannot be issued */ |
| 20322 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 20323 | IOERR_SLI_ABORTED); |
| 20324 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 20325 | return txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 20326 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20327 | |
| 20328 | /** |
| 20329 | * lpfc_wqe_bpl2sgl - Convert the bpl/bde to a sgl. |
| 20330 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 20331 | * @pwqeq: Pointer to command WQE. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20332 | * @sglq: Pointer to the scatter gather queue object. |
| 20333 | * |
| 20334 | * This routine converts the bpl or bde that is in the WQE |
| 20335 | * to a sgl list for the sli4 hardware. The physical address |
| 20336 | * of the bpl/bde is converted back to a virtual address. |
| 20337 | * If the WQE contains a BPL then the list of BDE's is |
| 20338 | * converted to sli4_sge's. If the WQE contains a single |
| 20339 | * BDE then it is converted to a single sli_sge. |
| 20340 | * The WQE is still in cpu endianness so the contents of |
| 20341 | * the bpl can be used without byte swapping. |
| 20342 | * |
| 20343 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 20344 | */ |
| 20345 | static uint16_t |
| 20346 | lpfc_wqe_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeq, |
| 20347 | struct lpfc_sglq *sglq) |
| 20348 | { |
| 20349 | uint16_t xritag = NO_XRI; |
| 20350 | struct ulp_bde64 *bpl = NULL; |
| 20351 | struct ulp_bde64 bde; |
| 20352 | struct sli4_sge *sgl = NULL; |
| 20353 | struct lpfc_dmabuf *dmabuf; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 20354 | union lpfc_wqe128 *wqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20355 | int numBdes = 0; |
| 20356 | int i = 0; |
| 20357 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 20358 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
| 20359 | uint32_t cmd; |
| 20360 | |
| 20361 | if (!pwqeq || !sglq) |
| 20362 | return xritag; |
| 20363 | |
| 20364 | sgl = (struct sli4_sge *)sglq->sgl; |
| 20365 | wqe = &pwqeq->wqe; |
| 20366 | pwqeq->iocb.ulpIoTag = pwqeq->iotag; |
| 20367 | |
| 20368 | cmd = bf_get(wqe_cmnd, &wqe->generic.wqe_com); |
| 20369 | if (cmd == CMD_XMIT_BLS_RSP64_WQE) |
| 20370 | return sglq->sli4_xritag; |
| 20371 | numBdes = pwqeq->rsvd2; |
| 20372 | if (numBdes) { |
| 20373 | /* The addrHigh and addrLow fields within the WQE |
| 20374 | * have not been byteswapped yet so there is no |
| 20375 | * need to swap them back. |
| 20376 | */ |
| 20377 | if (pwqeq->context3) |
| 20378 | dmabuf = (struct lpfc_dmabuf *)pwqeq->context3; |
| 20379 | else |
| 20380 | return xritag; |
| 20381 | |
| 20382 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 20383 | if (!bpl) |
| 20384 | return xritag; |
| 20385 | |
| 20386 | for (i = 0; i < numBdes; i++) { |
| 20387 | /* Should already be byte swapped. */ |
| 20388 | sgl->addr_hi = bpl->addrHigh; |
| 20389 | sgl->addr_lo = bpl->addrLow; |
| 20390 | |
| 20391 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 20392 | if ((i+1) == numBdes) |
| 20393 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 20394 | else |
| 20395 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 20396 | /* swap the size field back to the cpu so we |
| 20397 | * can assign it to the sgl. |
| 20398 | */ |
| 20399 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 20400 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
| 20401 | /* The offsets in the sgl need to be accumulated |
| 20402 | * separately for the request and reply lists. |
| 20403 | * The request is always first, the reply follows. |
| 20404 | */ |
| 20405 | switch (cmd) { |
| 20406 | case CMD_GEN_REQUEST64_WQE: |
| 20407 | /* add up the reply sg entries */ |
| 20408 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 20409 | inbound++; |
| 20410 | /* first inbound? reset the offset */ |
| 20411 | if (inbound == 1) |
| 20412 | offset = 0; |
| 20413 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 20414 | bf_set(lpfc_sli4_sge_type, sgl, |
| 20415 | LPFC_SGE_TYPE_DATA); |
| 20416 | offset += bde.tus.f.bdeSize; |
| 20417 | break; |
| 20418 | case CMD_FCP_TRSP64_WQE: |
| 20419 | bf_set(lpfc_sli4_sge_offset, sgl, 0); |
| 20420 | bf_set(lpfc_sli4_sge_type, sgl, |
| 20421 | LPFC_SGE_TYPE_DATA); |
| 20422 | break; |
| 20423 | case CMD_FCP_TSEND64_WQE: |
| 20424 | case CMD_FCP_TRECEIVE64_WQE: |
| 20425 | bf_set(lpfc_sli4_sge_type, sgl, |
| 20426 | bpl->tus.f.bdeFlags); |
| 20427 | if (i < 3) |
| 20428 | offset = 0; |
| 20429 | else |
| 20430 | offset += bde.tus.f.bdeSize; |
| 20431 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 20432 | break; |
| 20433 | } |
| 20434 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 20435 | bpl++; |
| 20436 | sgl++; |
| 20437 | } |
| 20438 | } else if (wqe->gen_req.bde.tus.f.bdeFlags == BUFF_TYPE_BDE_64) { |
| 20439 | /* The addrHigh and addrLow fields of the BDE have not |
| 20440 | * been byteswapped yet so they need to be swapped |
| 20441 | * before putting them in the sgl. |
| 20442 | */ |
| 20443 | sgl->addr_hi = cpu_to_le32(wqe->gen_req.bde.addrHigh); |
| 20444 | sgl->addr_lo = cpu_to_le32(wqe->gen_req.bde.addrLow); |
| 20445 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 20446 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 20447 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 20448 | sgl->sge_len = cpu_to_le32(wqe->gen_req.bde.tus.f.bdeSize); |
| 20449 | } |
| 20450 | return sglq->sli4_xritag; |
| 20451 | } |
| 20452 | |
| 20453 | /** |
| 20454 | * lpfc_sli4_issue_wqe - Issue an SLI4 Work Queue Entry (WQE) |
| 20455 | * @phba: Pointer to HBA context object. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 20456 | * @qp: Pointer to HDW queue. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20457 | * @pwqe: Pointer to command WQE. |
| 20458 | **/ |
| 20459 | int |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 20460 | 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] | 20461 | struct lpfc_iocbq *pwqe) |
| 20462 | { |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 20463 | union lpfc_wqe128 *wqe = &pwqe->wqe; |
James Smart | 7cacae2 | 2020-03-31 09:50:03 -0700 | [diff] [blame] | 20464 | struct lpfc_async_xchg_ctx *ctxp; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20465 | struct lpfc_queue *wq; |
| 20466 | struct lpfc_sglq *sglq; |
| 20467 | struct lpfc_sli_ring *pring; |
| 20468 | unsigned long iflags; |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 20469 | uint32_t ret = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20470 | |
| 20471 | /* NVME_LS and NVME_LS ABTS requests. */ |
| 20472 | if (pwqe->iocb_flag & LPFC_IO_NVME_LS) { |
| 20473 | pring = phba->sli4_hba.nvmels_wq->pring; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20474 | lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags, |
| 20475 | qp, wq_access); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20476 | sglq = __lpfc_sli_get_els_sglq(phba, pwqe); |
| 20477 | if (!sglq) { |
| 20478 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 20479 | return WQE_BUSY; |
| 20480 | } |
| 20481 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 20482 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 20483 | if (lpfc_wqe_bpl2sgl(phba, pwqe, sglq) == NO_XRI) { |
| 20484 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 20485 | return WQE_ERROR; |
| 20486 | } |
| 20487 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 20488 | pwqe->sli4_xritag); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 20489 | ret = lpfc_sli4_wq_put(phba->sli4_hba.nvmels_wq, wqe); |
| 20490 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20491 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 20492 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20493 | } |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 20494 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20495 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 20496 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 20497 | |
| 20498 | lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20499 | return 0; |
| 20500 | } |
| 20501 | |
| 20502 | /* NVME_FCREQ and NVME_ABTS requests */ |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 20503 | if (pwqe->iocb_flag & LPFC_IO_NVME || |
| 20504 | pwqe->iocb_flag & LPFC_IO_FCP) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20505 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20506 | wq = qp->io_wq; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 20507 | pring = wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20508 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20509 | bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20510 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20511 | lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags, |
| 20512 | qp, wq_access); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 20513 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 20514 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20515 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 20516 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20517 | } |
| 20518 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 20519 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 20520 | |
| 20521 | lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20522 | return 0; |
| 20523 | } |
| 20524 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 20525 | /* NVMET requests */ |
| 20526 | if (pwqe->iocb_flag & LPFC_IO_NVMET) { |
| 20527 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20528 | wq = qp->io_wq; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 20529 | pring = wq->pring; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 20530 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 20531 | ctxp = pwqe->context2; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 20532 | sglq = ctxp->ctxbuf->sglq; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 20533 | if (pwqe->sli4_xritag == NO_XRI) { |
| 20534 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 20535 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 20536 | } |
| 20537 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 20538 | pwqe->sli4_xritag); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20539 | bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map); |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 20540 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20541 | lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags, |
| 20542 | qp, wq_access); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 20543 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 20544 | if (ret) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 20545 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 20546 | return ret; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 20547 | } |
| 20548 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 20549 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 20550 | |
| 20551 | lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 20552 | return 0; |
| 20553 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20554 | return WQE_ERROR; |
| 20555 | } |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20556 | |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 20557 | /** |
| 20558 | * lpfc_sli4_issue_abort_iotag - SLI-4 WQE init & issue for the Abort |
| 20559 | * @phba: Pointer to HBA context object. |
| 20560 | * @cmdiocb: Pointer to driver command iocb object. |
| 20561 | * @cmpl: completion function. |
| 20562 | * |
| 20563 | * Fill the appropriate fields for the abort WQE and call |
| 20564 | * internal routine lpfc_sli4_issue_wqe to send the WQE |
| 20565 | * This function is called with hbalock held and no ring_lock held. |
| 20566 | * |
| 20567 | * RETURNS 0 - SUCCESS |
| 20568 | **/ |
| 20569 | |
| 20570 | int |
| 20571 | lpfc_sli4_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 20572 | void *cmpl) |
| 20573 | { |
| 20574 | struct lpfc_vport *vport = cmdiocb->vport; |
| 20575 | struct lpfc_iocbq *abtsiocb = NULL; |
| 20576 | union lpfc_wqe128 *abtswqe; |
| 20577 | struct lpfc_io_buf *lpfc_cmd; |
| 20578 | int retval = IOCB_ERROR; |
| 20579 | u16 xritag = cmdiocb->sli4_xritag; |
| 20580 | |
| 20581 | /* |
| 20582 | * The scsi command can not be in txq and it is in flight because the |
| 20583 | * pCmd is still pointing at the SCSI command we have to abort. There |
| 20584 | * is no need to search the txcmplq. Just send an abort to the FW. |
| 20585 | */ |
| 20586 | |
| 20587 | abtsiocb = __lpfc_sli_get_iocbq(phba); |
| 20588 | if (!abtsiocb) |
| 20589 | return WQE_NORESOURCE; |
| 20590 | |
| 20591 | /* Indicate the IO is being aborted by the driver. */ |
| 20592 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 20593 | |
| 20594 | abtswqe = &abtsiocb->wqe; |
| 20595 | memset(abtswqe, 0, sizeof(*abtswqe)); |
| 20596 | |
| 20597 | if (lpfc_is_link_up(phba)) |
| 20598 | bf_set(abort_cmd_ia, &abtswqe->abort_cmd, 1); |
| 20599 | else |
| 20600 | bf_set(abort_cmd_ia, &abtswqe->abort_cmd, 0); |
| 20601 | bf_set(abort_cmd_criteria, &abtswqe->abort_cmd, T_XRI_TAG); |
| 20602 | abtswqe->abort_cmd.rsrvd5 = 0; |
| 20603 | abtswqe->abort_cmd.wqe_com.abort_tag = xritag; |
| 20604 | bf_set(wqe_reqtag, &abtswqe->abort_cmd.wqe_com, abtsiocb->iotag); |
| 20605 | bf_set(wqe_cmnd, &abtswqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 20606 | bf_set(wqe_xri_tag, &abtswqe->generic.wqe_com, 0); |
| 20607 | bf_set(wqe_qosd, &abtswqe->abort_cmd.wqe_com, 1); |
| 20608 | bf_set(wqe_lenloc, &abtswqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 20609 | bf_set(wqe_cmd_type, &abtswqe->abort_cmd.wqe_com, OTHER_COMMAND); |
| 20610 | |
| 20611 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 20612 | abtsiocb->hba_wqidx = cmdiocb->hba_wqidx; |
| 20613 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
| 20614 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
| 20615 | abtsiocb->iocb_flag |= LPFC_IO_FCP; |
| 20616 | if (cmdiocb->iocb_flag & LPFC_IO_NVME) |
| 20617 | abtsiocb->iocb_flag |= LPFC_IO_NVME; |
| 20618 | if (cmdiocb->iocb_flag & LPFC_IO_FOF) |
| 20619 | abtsiocb->iocb_flag |= LPFC_IO_FOF; |
| 20620 | abtsiocb->vport = vport; |
| 20621 | abtsiocb->wqe_cmpl = cmpl; |
| 20622 | |
| 20623 | lpfc_cmd = container_of(cmdiocb, struct lpfc_io_buf, cur_iocbq); |
| 20624 | retval = lpfc_sli4_issue_wqe(phba, lpfc_cmd->hdwq, abtsiocb); |
| 20625 | |
| 20626 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI | LOG_NVME_ABTS | LOG_FCP, |
| 20627 | "0359 Abort xri x%x, original iotag x%x, " |
| 20628 | "abort cmd iotag x%x retval x%x\n", |
| 20629 | xritag, cmdiocb->iotag, abtsiocb->iotag, retval); |
| 20630 | |
| 20631 | if (retval) { |
| 20632 | cmdiocb->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 20633 | __lpfc_sli_release_iocbq(phba, abtsiocb); |
| 20634 | } |
| 20635 | |
| 20636 | return retval; |
| 20637 | } |
| 20638 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20639 | #ifdef LPFC_MXP_STAT |
| 20640 | /** |
| 20641 | * lpfc_snapshot_mxp - Snapshot pbl, pvt and busy count |
| 20642 | * @phba: pointer to lpfc hba data structure. |
| 20643 | * @hwqid: belong to which HWQ. |
| 20644 | * |
| 20645 | * The purpose of this routine is to take a snapshot of pbl, pvt and busy count |
| 20646 | * 15 seconds after a test case is running. |
| 20647 | * |
| 20648 | * The user should call lpfc_debugfs_multixripools_write before running a test |
| 20649 | * case to clear stat_snapshot_taken. Then the user starts a test case. During |
| 20650 | * test case is running, stat_snapshot_taken is incremented by 1 every time when |
| 20651 | * this routine is called from heartbeat timer. When stat_snapshot_taken is |
| 20652 | * equal to LPFC_MXP_SNAPSHOT_TAKEN, a snapshot is taken. |
| 20653 | **/ |
| 20654 | void lpfc_snapshot_mxp(struct lpfc_hba *phba, u32 hwqid) |
| 20655 | { |
| 20656 | struct lpfc_sli4_hdw_queue *qp; |
| 20657 | struct lpfc_multixri_pool *multixri_pool; |
| 20658 | struct lpfc_pvt_pool *pvt_pool; |
| 20659 | struct lpfc_pbl_pool *pbl_pool; |
| 20660 | u32 txcmplq_cnt; |
| 20661 | |
| 20662 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20663 | multixri_pool = qp->p_multixri_pool; |
| 20664 | if (!multixri_pool) |
| 20665 | return; |
| 20666 | |
| 20667 | if (multixri_pool->stat_snapshot_taken == LPFC_MXP_SNAPSHOT_TAKEN) { |
| 20668 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
| 20669 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20670 | txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20671 | |
| 20672 | multixri_pool->stat_pbl_count = pbl_pool->count; |
| 20673 | multixri_pool->stat_pvt_count = pvt_pool->count; |
| 20674 | multixri_pool->stat_busy_count = txcmplq_cnt; |
| 20675 | } |
| 20676 | |
| 20677 | multixri_pool->stat_snapshot_taken++; |
| 20678 | } |
| 20679 | #endif |
| 20680 | |
| 20681 | /** |
| 20682 | * lpfc_adjust_pvt_pool_count - Adjust private pool count |
| 20683 | * @phba: pointer to lpfc hba data structure. |
| 20684 | * @hwqid: belong to which HWQ. |
| 20685 | * |
| 20686 | * This routine moves some XRIs from private to public pool when private pool |
| 20687 | * is not busy. |
| 20688 | **/ |
| 20689 | void lpfc_adjust_pvt_pool_count(struct lpfc_hba *phba, u32 hwqid) |
| 20690 | { |
| 20691 | struct lpfc_multixri_pool *multixri_pool; |
| 20692 | u32 io_req_count; |
| 20693 | u32 prev_io_req_count; |
| 20694 | |
| 20695 | multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool; |
| 20696 | if (!multixri_pool) |
| 20697 | return; |
| 20698 | io_req_count = multixri_pool->io_req_count; |
| 20699 | prev_io_req_count = multixri_pool->prev_io_req_count; |
| 20700 | |
| 20701 | if (prev_io_req_count != io_req_count) { |
| 20702 | /* Private pool is busy */ |
| 20703 | multixri_pool->prev_io_req_count = io_req_count; |
| 20704 | } else { |
| 20705 | /* Private pool is not busy. |
| 20706 | * Move XRIs from private to public pool. |
| 20707 | */ |
| 20708 | lpfc_move_xri_pvt_to_pbl(phba, hwqid); |
| 20709 | } |
| 20710 | } |
| 20711 | |
| 20712 | /** |
| 20713 | * lpfc_adjust_high_watermark - Adjust high watermark |
| 20714 | * @phba: pointer to lpfc hba data structure. |
| 20715 | * @hwqid: belong to which HWQ. |
| 20716 | * |
| 20717 | * This routine sets high watermark as number of outstanding XRIs, |
| 20718 | * but make sure the new value is between xri_limit/2 and xri_limit. |
| 20719 | **/ |
| 20720 | void lpfc_adjust_high_watermark(struct lpfc_hba *phba, u32 hwqid) |
| 20721 | { |
| 20722 | u32 new_watermark; |
| 20723 | u32 watermark_max; |
| 20724 | u32 watermark_min; |
| 20725 | u32 xri_limit; |
| 20726 | u32 txcmplq_cnt; |
| 20727 | u32 abts_io_bufs; |
| 20728 | struct lpfc_multixri_pool *multixri_pool; |
| 20729 | struct lpfc_sli4_hdw_queue *qp; |
| 20730 | |
| 20731 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20732 | multixri_pool = qp->p_multixri_pool; |
| 20733 | if (!multixri_pool) |
| 20734 | return; |
| 20735 | xri_limit = multixri_pool->xri_limit; |
| 20736 | |
| 20737 | watermark_max = xri_limit; |
| 20738 | watermark_min = xri_limit / 2; |
| 20739 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20740 | txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20741 | abts_io_bufs = qp->abts_scsi_io_bufs; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20742 | abts_io_bufs += qp->abts_nvme_io_bufs; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20743 | |
| 20744 | new_watermark = txcmplq_cnt + abts_io_bufs; |
| 20745 | new_watermark = min(watermark_max, new_watermark); |
| 20746 | new_watermark = max(watermark_min, new_watermark); |
| 20747 | multixri_pool->pvt_pool.high_watermark = new_watermark; |
| 20748 | |
| 20749 | #ifdef LPFC_MXP_STAT |
| 20750 | multixri_pool->stat_max_hwm = max(multixri_pool->stat_max_hwm, |
| 20751 | new_watermark); |
| 20752 | #endif |
| 20753 | } |
| 20754 | |
| 20755 | /** |
| 20756 | * lpfc_move_xri_pvt_to_pbl - Move some XRIs from private to public pool |
| 20757 | * @phba: pointer to lpfc hba data structure. |
| 20758 | * @hwqid: belong to which HWQ. |
| 20759 | * |
| 20760 | * This routine is called from hearbeat timer when pvt_pool is idle. |
| 20761 | * All free XRIs are moved from private to public pool on hwqid with 2 steps. |
| 20762 | * The first step moves (all - low_watermark) amount of XRIs. |
| 20763 | * The second step moves the rest of XRIs. |
| 20764 | **/ |
| 20765 | void lpfc_move_xri_pvt_to_pbl(struct lpfc_hba *phba, u32 hwqid) |
| 20766 | { |
| 20767 | struct lpfc_pbl_pool *pbl_pool; |
| 20768 | struct lpfc_pvt_pool *pvt_pool; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20769 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20770 | struct lpfc_io_buf *lpfc_ncmd; |
| 20771 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 20772 | unsigned long iflag; |
| 20773 | struct list_head tmp_list; |
| 20774 | u32 tmp_count; |
| 20775 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20776 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20777 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
| 20778 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20779 | tmp_count = 0; |
| 20780 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20781 | lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag, qp, mv_to_pub_pool); |
| 20782 | lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_from_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20783 | |
| 20784 | if (pvt_pool->count > pvt_pool->low_watermark) { |
| 20785 | /* Step 1: move (all - low_watermark) from pvt_pool |
| 20786 | * to pbl_pool |
| 20787 | */ |
| 20788 | |
| 20789 | /* Move low watermark of bufs from pvt_pool to tmp_list */ |
| 20790 | INIT_LIST_HEAD(&tmp_list); |
| 20791 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 20792 | &pvt_pool->list, list) { |
| 20793 | list_move_tail(&lpfc_ncmd->list, &tmp_list); |
| 20794 | tmp_count++; |
| 20795 | if (tmp_count >= pvt_pool->low_watermark) |
| 20796 | break; |
| 20797 | } |
| 20798 | |
| 20799 | /* Move all bufs from pvt_pool to pbl_pool */ |
| 20800 | list_splice_init(&pvt_pool->list, &pbl_pool->list); |
| 20801 | |
| 20802 | /* Move all bufs from tmp_list to pvt_pool */ |
| 20803 | list_splice(&tmp_list, &pvt_pool->list); |
| 20804 | |
| 20805 | pbl_pool->count += (pvt_pool->count - tmp_count); |
| 20806 | pvt_pool->count = tmp_count; |
| 20807 | } else { |
| 20808 | /* Step 2: move the rest from pvt_pool to pbl_pool */ |
| 20809 | list_splice_init(&pvt_pool->list, &pbl_pool->list); |
| 20810 | pbl_pool->count += pvt_pool->count; |
| 20811 | pvt_pool->count = 0; |
| 20812 | } |
| 20813 | |
| 20814 | spin_unlock(&pvt_pool->lock); |
| 20815 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 20816 | } |
| 20817 | |
| 20818 | /** |
| 20819 | * _lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool |
| 20820 | * @phba: pointer to lpfc hba data structure |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 20821 | * @qp: pointer to HDW queue |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20822 | * @pbl_pool: specified public free XRI pool |
| 20823 | * @pvt_pool: specified private free XRI pool |
| 20824 | * @count: number of XRIs to move |
| 20825 | * |
| 20826 | * This routine tries to move some free common bufs from the specified pbl_pool |
| 20827 | * to the specified pvt_pool. It might move less than count XRIs if there's not |
| 20828 | * enough in public pool. |
| 20829 | * |
| 20830 | * Return: |
| 20831 | * true - if XRIs are successfully moved from the specified pbl_pool to the |
| 20832 | * specified pvt_pool |
| 20833 | * false - if the specified pbl_pool is empty or locked by someone else |
| 20834 | **/ |
| 20835 | static bool |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20836 | _lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, struct lpfc_sli4_hdw_queue *qp, |
| 20837 | struct lpfc_pbl_pool *pbl_pool, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20838 | struct lpfc_pvt_pool *pvt_pool, u32 count) |
| 20839 | { |
| 20840 | struct lpfc_io_buf *lpfc_ncmd; |
| 20841 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 20842 | unsigned long iflag; |
| 20843 | int ret; |
| 20844 | |
| 20845 | ret = spin_trylock_irqsave(&pbl_pool->lock, iflag); |
| 20846 | if (ret) { |
| 20847 | if (pbl_pool->count) { |
| 20848 | /* Move a batch of XRIs from public to private pool */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20849 | lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_to_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20850 | list_for_each_entry_safe(lpfc_ncmd, |
| 20851 | lpfc_ncmd_next, |
| 20852 | &pbl_pool->list, |
| 20853 | list) { |
| 20854 | list_move_tail(&lpfc_ncmd->list, |
| 20855 | &pvt_pool->list); |
| 20856 | pvt_pool->count++; |
| 20857 | pbl_pool->count--; |
| 20858 | count--; |
| 20859 | if (count == 0) |
| 20860 | break; |
| 20861 | } |
| 20862 | |
| 20863 | spin_unlock(&pvt_pool->lock); |
| 20864 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 20865 | return true; |
| 20866 | } |
| 20867 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 20868 | } |
| 20869 | |
| 20870 | return false; |
| 20871 | } |
| 20872 | |
| 20873 | /** |
| 20874 | * lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool |
| 20875 | * @phba: pointer to lpfc hba data structure. |
| 20876 | * @hwqid: belong to which HWQ. |
| 20877 | * @count: number of XRIs to move |
| 20878 | * |
| 20879 | * This routine tries to find some free common bufs in one of public pools with |
| 20880 | * Round Robin method. The search always starts from local hwqid, then the next |
| 20881 | * HWQ which was found last time (rrb_next_hwqid). Once a public pool is found, |
| 20882 | * a batch of free common bufs are moved to private pool on hwqid. |
| 20883 | * It might move less than count XRIs if there's not enough in public pool. |
| 20884 | **/ |
| 20885 | void lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, u32 hwqid, u32 count) |
| 20886 | { |
| 20887 | struct lpfc_multixri_pool *multixri_pool; |
| 20888 | struct lpfc_multixri_pool *next_multixri_pool; |
| 20889 | struct lpfc_pvt_pool *pvt_pool; |
| 20890 | struct lpfc_pbl_pool *pbl_pool; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20891 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20892 | u32 next_hwqid; |
| 20893 | u32 hwq_count; |
| 20894 | int ret; |
| 20895 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20896 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20897 | multixri_pool = qp->p_multixri_pool; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20898 | pvt_pool = &multixri_pool->pvt_pool; |
| 20899 | pbl_pool = &multixri_pool->pbl_pool; |
| 20900 | |
| 20901 | /* Check if local pbl_pool is available */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20902 | 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] | 20903 | if (ret) { |
| 20904 | #ifdef LPFC_MXP_STAT |
| 20905 | multixri_pool->local_pbl_hit_count++; |
| 20906 | #endif |
| 20907 | return; |
| 20908 | } |
| 20909 | |
| 20910 | hwq_count = phba->cfg_hdw_queue; |
| 20911 | |
| 20912 | /* Get the next hwqid which was found last time */ |
| 20913 | next_hwqid = multixri_pool->rrb_next_hwqid; |
| 20914 | |
| 20915 | do { |
| 20916 | /* Go to next hwq */ |
| 20917 | next_hwqid = (next_hwqid + 1) % hwq_count; |
| 20918 | |
| 20919 | next_multixri_pool = |
| 20920 | phba->sli4_hba.hdwq[next_hwqid].p_multixri_pool; |
| 20921 | pbl_pool = &next_multixri_pool->pbl_pool; |
| 20922 | |
| 20923 | /* Check if the public free xri pool is available */ |
| 20924 | ret = _lpfc_move_xri_pbl_to_pvt( |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20925 | phba, qp, pbl_pool, pvt_pool, count); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20926 | |
| 20927 | /* Exit while-loop if success or all hwqid are checked */ |
| 20928 | } while (!ret && next_hwqid != multixri_pool->rrb_next_hwqid); |
| 20929 | |
| 20930 | /* Starting point for the next time */ |
| 20931 | multixri_pool->rrb_next_hwqid = next_hwqid; |
| 20932 | |
| 20933 | if (!ret) { |
| 20934 | /* stats: all public pools are empty*/ |
| 20935 | multixri_pool->pbl_empty_count++; |
| 20936 | } |
| 20937 | |
| 20938 | #ifdef LPFC_MXP_STAT |
| 20939 | if (ret) { |
| 20940 | if (next_hwqid == hwqid) |
| 20941 | multixri_pool->local_pbl_hit_count++; |
| 20942 | else |
| 20943 | multixri_pool->other_pbl_hit_count++; |
| 20944 | } |
| 20945 | #endif |
| 20946 | } |
| 20947 | |
| 20948 | /** |
| 20949 | * lpfc_keep_pvt_pool_above_lowwm - Keep pvt_pool above low watermark |
| 20950 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 20951 | * @hwqid: belong to which HWQ. |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20952 | * |
| 20953 | * This routine get a batch of XRIs from pbl_pool if pvt_pool is less than |
| 20954 | * low watermark. |
| 20955 | **/ |
| 20956 | void lpfc_keep_pvt_pool_above_lowwm(struct lpfc_hba *phba, u32 hwqid) |
| 20957 | { |
| 20958 | struct lpfc_multixri_pool *multixri_pool; |
| 20959 | struct lpfc_pvt_pool *pvt_pool; |
| 20960 | |
| 20961 | multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool; |
| 20962 | pvt_pool = &multixri_pool->pvt_pool; |
| 20963 | |
| 20964 | if (pvt_pool->count < pvt_pool->low_watermark) |
| 20965 | lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH); |
| 20966 | } |
| 20967 | |
| 20968 | /** |
| 20969 | * lpfc_release_io_buf - Return one IO buf back to free pool |
| 20970 | * @phba: pointer to lpfc hba data structure. |
| 20971 | * @lpfc_ncmd: IO buf to be returned. |
| 20972 | * @qp: belong to which HWQ. |
| 20973 | * |
| 20974 | * This routine returns one IO buf back to free pool. If this is an urgent IO, |
| 20975 | * the IO buf is returned to expedite pool. If cfg_xri_rebalancing==1, |
| 20976 | * the IO buf is returned to pbl_pool or pvt_pool based on watermark and |
| 20977 | * xri_limit. If cfg_xri_rebalancing==0, the IO buf is returned to |
| 20978 | * lpfc_io_buf_list_put. |
| 20979 | **/ |
| 20980 | void lpfc_release_io_buf(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_ncmd, |
| 20981 | struct lpfc_sli4_hdw_queue *qp) |
| 20982 | { |
| 20983 | unsigned long iflag; |
| 20984 | struct lpfc_pbl_pool *pbl_pool; |
| 20985 | struct lpfc_pvt_pool *pvt_pool; |
| 20986 | struct lpfc_epd_pool *epd_pool; |
| 20987 | u32 txcmplq_cnt; |
| 20988 | u32 xri_owned; |
| 20989 | u32 xri_limit; |
| 20990 | u32 abts_io_bufs; |
| 20991 | |
| 20992 | /* MUST zero fields if buffer is reused by another protocol */ |
| 20993 | lpfc_ncmd->nvmeCmd = NULL; |
| 20994 | lpfc_ncmd->cur_iocbq.wqe_cmpl = NULL; |
| 20995 | lpfc_ncmd->cur_iocbq.iocb_cmpl = NULL; |
| 20996 | |
James Smart | 35a635a | 2019-09-21 20:59:02 -0700 | [diff] [blame] | 20997 | if (phba->cfg_xpsgl && !phba->nvmet_support && |
| 20998 | !list_empty(&lpfc_ncmd->dma_sgl_xtra_list)) |
| 20999 | lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd); |
| 21000 | |
| 21001 | if (!list_empty(&lpfc_ncmd->dma_cmd_rsp_list)) |
| 21002 | lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd); |
| 21003 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21004 | if (phba->cfg_xri_rebalancing) { |
| 21005 | if (lpfc_ncmd->expedite) { |
| 21006 | /* Return to expedite pool */ |
| 21007 | epd_pool = &phba->epd_pool; |
| 21008 | spin_lock_irqsave(&epd_pool->lock, iflag); |
| 21009 | list_add_tail(&lpfc_ncmd->list, &epd_pool->list); |
| 21010 | epd_pool->count++; |
| 21011 | spin_unlock_irqrestore(&epd_pool->lock, iflag); |
| 21012 | return; |
| 21013 | } |
| 21014 | |
| 21015 | /* Avoid invalid access if an IO sneaks in and is being rejected |
| 21016 | * just _after_ xri pools are destroyed in lpfc_offline. |
| 21017 | * Nothing much can be done at this point. |
| 21018 | */ |
| 21019 | if (!qp->p_multixri_pool) |
| 21020 | return; |
| 21021 | |
| 21022 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
| 21023 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
| 21024 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 21025 | txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21026 | abts_io_bufs = qp->abts_scsi_io_bufs; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 21027 | abts_io_bufs += qp->abts_nvme_io_bufs; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21028 | |
| 21029 | xri_owned = pvt_pool->count + txcmplq_cnt + abts_io_bufs; |
| 21030 | xri_limit = qp->p_multixri_pool->xri_limit; |
| 21031 | |
| 21032 | #ifdef LPFC_MXP_STAT |
| 21033 | if (xri_owned <= xri_limit) |
| 21034 | qp->p_multixri_pool->below_limit_count++; |
| 21035 | else |
| 21036 | qp->p_multixri_pool->above_limit_count++; |
| 21037 | #endif |
| 21038 | |
| 21039 | /* XRI goes to either public or private free xri pool |
| 21040 | * based on watermark and xri_limit |
| 21041 | */ |
| 21042 | if ((pvt_pool->count < pvt_pool->low_watermark) || |
| 21043 | (xri_owned < xri_limit && |
| 21044 | pvt_pool->count < pvt_pool->high_watermark)) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 21045 | lpfc_qp_spin_lock_irqsave(&pvt_pool->lock, iflag, |
| 21046 | qp, free_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21047 | list_add_tail(&lpfc_ncmd->list, |
| 21048 | &pvt_pool->list); |
| 21049 | pvt_pool->count++; |
| 21050 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 21051 | } else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 21052 | lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag, |
| 21053 | qp, free_pub_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21054 | list_add_tail(&lpfc_ncmd->list, |
| 21055 | &pbl_pool->list); |
| 21056 | pbl_pool->count++; |
| 21057 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 21058 | } |
| 21059 | } else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 21060 | lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag, |
| 21061 | qp, free_xri); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21062 | list_add_tail(&lpfc_ncmd->list, |
| 21063 | &qp->lpfc_io_buf_list_put); |
| 21064 | qp->put_io_bufs++; |
| 21065 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, |
| 21066 | iflag); |
| 21067 | } |
| 21068 | } |
| 21069 | |
| 21070 | /** |
| 21071 | * lpfc_get_io_buf_from_private_pool - Get one free IO buf from private pool |
| 21072 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | 7af29d4 | 2020-07-21 17:41:31 +0100 | [diff] [blame] | 21073 | * @qp: pointer to HDW queue |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21074 | * @pvt_pool: pointer to private pool data structure. |
| 21075 | * @ndlp: pointer to lpfc nodelist data structure. |
| 21076 | * |
| 21077 | * This routine tries to get one free IO buf from private pool. |
| 21078 | * |
| 21079 | * Return: |
| 21080 | * pointer to one free IO buf - if private pool is not empty |
| 21081 | * NULL - if private pool is empty |
| 21082 | **/ |
| 21083 | static struct lpfc_io_buf * |
| 21084 | lpfc_get_io_buf_from_private_pool(struct lpfc_hba *phba, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 21085 | struct lpfc_sli4_hdw_queue *qp, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21086 | struct lpfc_pvt_pool *pvt_pool, |
| 21087 | struct lpfc_nodelist *ndlp) |
| 21088 | { |
| 21089 | struct lpfc_io_buf *lpfc_ncmd; |
| 21090 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 21091 | unsigned long iflag; |
| 21092 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 21093 | 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] | 21094 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 21095 | &pvt_pool->list, list) { |
| 21096 | if (lpfc_test_rrq_active( |
| 21097 | phba, ndlp, lpfc_ncmd->cur_iocbq.sli4_lxritag)) |
| 21098 | continue; |
| 21099 | list_del(&lpfc_ncmd->list); |
| 21100 | pvt_pool->count--; |
| 21101 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 21102 | return lpfc_ncmd; |
| 21103 | } |
| 21104 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 21105 | |
| 21106 | return NULL; |
| 21107 | } |
| 21108 | |
| 21109 | /** |
| 21110 | * lpfc_get_io_buf_from_expedite_pool - Get one free IO buf from expedite pool |
| 21111 | * @phba: pointer to lpfc hba data structure. |
| 21112 | * |
| 21113 | * This routine tries to get one free IO buf from expedite pool. |
| 21114 | * |
| 21115 | * Return: |
| 21116 | * pointer to one free IO buf - if expedite pool is not empty |
| 21117 | * NULL - if expedite pool is empty |
| 21118 | **/ |
| 21119 | static struct lpfc_io_buf * |
| 21120 | lpfc_get_io_buf_from_expedite_pool(struct lpfc_hba *phba) |
| 21121 | { |
| 21122 | struct lpfc_io_buf *lpfc_ncmd; |
| 21123 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 21124 | unsigned long iflag; |
| 21125 | struct lpfc_epd_pool *epd_pool; |
| 21126 | |
| 21127 | epd_pool = &phba->epd_pool; |
| 21128 | lpfc_ncmd = NULL; |
| 21129 | |
| 21130 | spin_lock_irqsave(&epd_pool->lock, iflag); |
| 21131 | if (epd_pool->count > 0) { |
| 21132 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 21133 | &epd_pool->list, list) { |
| 21134 | list_del(&lpfc_ncmd->list); |
| 21135 | epd_pool->count--; |
| 21136 | break; |
| 21137 | } |
| 21138 | } |
| 21139 | spin_unlock_irqrestore(&epd_pool->lock, iflag); |
| 21140 | |
| 21141 | return lpfc_ncmd; |
| 21142 | } |
| 21143 | |
| 21144 | /** |
| 21145 | * lpfc_get_io_buf_from_multixri_pools - Get one free IO bufs |
| 21146 | * @phba: pointer to lpfc hba data structure. |
| 21147 | * @ndlp: pointer to lpfc nodelist data structure. |
| 21148 | * @hwqid: belong to which HWQ |
| 21149 | * @expedite: 1 means this request is urgent. |
| 21150 | * |
| 21151 | * This routine will do the following actions and then return a pointer to |
| 21152 | * one free IO buf. |
| 21153 | * |
| 21154 | * 1. If private free xri count is empty, move some XRIs from public to |
| 21155 | * private pool. |
| 21156 | * 2. Get one XRI from private free xri pool. |
| 21157 | * 3. If we fail to get one from pvt_pool and this is an expedite request, |
| 21158 | * get one free xri from expedite pool. |
| 21159 | * |
| 21160 | * Note: ndlp is only used on SCSI side for RRQ testing. |
| 21161 | * The caller should pass NULL for ndlp on NVME side. |
| 21162 | * |
| 21163 | * Return: |
| 21164 | * pointer to one free IO buf - if private pool is not empty |
| 21165 | * NULL - if private pool is empty |
| 21166 | **/ |
| 21167 | static struct lpfc_io_buf * |
| 21168 | lpfc_get_io_buf_from_multixri_pools(struct lpfc_hba *phba, |
| 21169 | struct lpfc_nodelist *ndlp, |
| 21170 | int hwqid, int expedite) |
| 21171 | { |
| 21172 | struct lpfc_sli4_hdw_queue *qp; |
| 21173 | struct lpfc_multixri_pool *multixri_pool; |
| 21174 | struct lpfc_pvt_pool *pvt_pool; |
| 21175 | struct lpfc_io_buf *lpfc_ncmd; |
| 21176 | |
| 21177 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 21178 | lpfc_ncmd = NULL; |
| 21179 | multixri_pool = qp->p_multixri_pool; |
| 21180 | pvt_pool = &multixri_pool->pvt_pool; |
| 21181 | multixri_pool->io_req_count++; |
| 21182 | |
| 21183 | /* If pvt_pool is empty, move some XRIs from public to private pool */ |
| 21184 | if (pvt_pool->count == 0) |
| 21185 | lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH); |
| 21186 | |
| 21187 | /* Get one XRI from private free xri pool */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 21188 | 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] | 21189 | |
| 21190 | if (lpfc_ncmd) { |
| 21191 | lpfc_ncmd->hdwq = qp; |
| 21192 | lpfc_ncmd->hdwq_no = hwqid; |
| 21193 | } else if (expedite) { |
| 21194 | /* If we fail to get one from pvt_pool and this is an expedite |
| 21195 | * request, get one free xri from expedite pool. |
| 21196 | */ |
| 21197 | lpfc_ncmd = lpfc_get_io_buf_from_expedite_pool(phba); |
| 21198 | } |
| 21199 | |
| 21200 | return lpfc_ncmd; |
| 21201 | } |
| 21202 | |
| 21203 | static inline struct lpfc_io_buf * |
| 21204 | lpfc_io_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, int idx) |
| 21205 | { |
| 21206 | struct lpfc_sli4_hdw_queue *qp; |
| 21207 | struct lpfc_io_buf *lpfc_cmd, *lpfc_cmd_next; |
| 21208 | |
| 21209 | qp = &phba->sli4_hba.hdwq[idx]; |
| 21210 | list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next, |
| 21211 | &qp->lpfc_io_buf_list_get, list) { |
| 21212 | if (lpfc_test_rrq_active(phba, ndlp, |
| 21213 | lpfc_cmd->cur_iocbq.sli4_lxritag)) |
| 21214 | continue; |
| 21215 | |
| 21216 | if (lpfc_cmd->flags & LPFC_SBUF_NOT_POSTED) |
| 21217 | continue; |
| 21218 | |
| 21219 | list_del_init(&lpfc_cmd->list); |
| 21220 | qp->get_io_bufs--; |
| 21221 | lpfc_cmd->hdwq = qp; |
| 21222 | lpfc_cmd->hdwq_no = idx; |
| 21223 | return lpfc_cmd; |
| 21224 | } |
| 21225 | return NULL; |
| 21226 | } |
| 21227 | |
| 21228 | /** |
| 21229 | * lpfc_get_io_buf - Get one IO buffer from free pool |
| 21230 | * @phba: The HBA for which this call is being executed. |
| 21231 | * @ndlp: pointer to lpfc nodelist data structure. |
| 21232 | * @hwqid: belong to which HWQ |
| 21233 | * @expedite: 1 means this request is urgent. |
| 21234 | * |
| 21235 | * This routine gets one IO buffer from free pool. If cfg_xri_rebalancing==1, |
| 21236 | * removes a IO buffer from multiXRI pools. If cfg_xri_rebalancing==0, removes |
| 21237 | * a IO buffer from head of @hdwq io_buf_list and returns to caller. |
| 21238 | * |
| 21239 | * Note: ndlp is only used on SCSI side for RRQ testing. |
| 21240 | * The caller should pass NULL for ndlp on NVME side. |
| 21241 | * |
| 21242 | * Return codes: |
| 21243 | * NULL - Error |
| 21244 | * Pointer to lpfc_io_buf - Success |
| 21245 | **/ |
| 21246 | struct lpfc_io_buf *lpfc_get_io_buf(struct lpfc_hba *phba, |
| 21247 | struct lpfc_nodelist *ndlp, |
| 21248 | u32 hwqid, int expedite) |
| 21249 | { |
| 21250 | struct lpfc_sli4_hdw_queue *qp; |
| 21251 | unsigned long iflag; |
| 21252 | struct lpfc_io_buf *lpfc_cmd; |
| 21253 | |
| 21254 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 21255 | lpfc_cmd = NULL; |
| 21256 | |
| 21257 | if (phba->cfg_xri_rebalancing) |
| 21258 | lpfc_cmd = lpfc_get_io_buf_from_multixri_pools( |
| 21259 | phba, ndlp, hwqid, expedite); |
| 21260 | else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 21261 | lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_get_lock, iflag, |
| 21262 | qp, alloc_xri_get); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21263 | if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT || expedite) |
| 21264 | lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid); |
| 21265 | if (!lpfc_cmd) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 21266 | lpfc_qp_spin_lock(&qp->io_buf_list_put_lock, |
| 21267 | qp, alloc_xri_put); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 21268 | list_splice(&qp->lpfc_io_buf_list_put, |
| 21269 | &qp->lpfc_io_buf_list_get); |
| 21270 | qp->get_io_bufs += qp->put_io_bufs; |
| 21271 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put); |
| 21272 | qp->put_io_bufs = 0; |
| 21273 | spin_unlock(&qp->io_buf_list_put_lock); |
| 21274 | if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT || |
| 21275 | expedite) |
| 21276 | lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid); |
| 21277 | } |
| 21278 | spin_unlock_irqrestore(&qp->io_buf_list_get_lock, iflag); |
| 21279 | } |
| 21280 | |
| 21281 | return lpfc_cmd; |
| 21282 | } |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21283 | |
| 21284 | /** |
| 21285 | * lpfc_get_sgl_per_hdwq - Get one SGL chunk from hdwq's pool |
| 21286 | * @phba: The HBA for which this call is being executed. |
| 21287 | * @lpfc_buf: IO buf structure to append the SGL chunk |
| 21288 | * |
| 21289 | * This routine gets one SGL chunk buffer from hdwq's SGL chunk pool, |
| 21290 | * and will allocate an SGL chunk if the pool is empty. |
| 21291 | * |
| 21292 | * Return codes: |
| 21293 | * NULL - Error |
| 21294 | * Pointer to sli4_hybrid_sgl - Success |
| 21295 | **/ |
| 21296 | struct sli4_hybrid_sgl * |
| 21297 | lpfc_get_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf) |
| 21298 | { |
| 21299 | struct sli4_hybrid_sgl *list_entry = NULL; |
| 21300 | struct sli4_hybrid_sgl *tmp = NULL; |
| 21301 | struct sli4_hybrid_sgl *allocated_sgl = NULL; |
| 21302 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 21303 | struct list_head *buf_list = &hdwq->sgl_list; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21304 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21305 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21306 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21307 | |
| 21308 | if (likely(!list_empty(buf_list))) { |
| 21309 | /* break off 1 chunk from the sgl_list */ |
| 21310 | list_for_each_entry_safe(list_entry, tmp, |
| 21311 | buf_list, list_node) { |
| 21312 | list_move_tail(&list_entry->list_node, |
| 21313 | &lpfc_buf->dma_sgl_xtra_list); |
| 21314 | break; |
| 21315 | } |
| 21316 | } else { |
| 21317 | /* allocate more */ |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21318 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21319 | tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC, |
James Smart | 4583a4f | 2019-11-15 16:38:47 -0800 | [diff] [blame] | 21320 | cpu_to_node(hdwq->io_wq->chann)); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21321 | if (!tmp) { |
| 21322 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 21323 | "8353 error kmalloc memory for HDWQ " |
| 21324 | "%d %s\n", |
| 21325 | lpfc_buf->hdwq_no, __func__); |
| 21326 | return NULL; |
| 21327 | } |
| 21328 | |
| 21329 | tmp->dma_sgl = dma_pool_alloc(phba->lpfc_sg_dma_buf_pool, |
| 21330 | GFP_ATOMIC, &tmp->dma_phys_sgl); |
| 21331 | if (!tmp->dma_sgl) { |
| 21332 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 21333 | "8354 error pool_alloc memory for HDWQ " |
| 21334 | "%d %s\n", |
| 21335 | lpfc_buf->hdwq_no, __func__); |
| 21336 | kfree(tmp); |
| 21337 | return NULL; |
| 21338 | } |
| 21339 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21340 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21341 | list_add_tail(&tmp->list_node, &lpfc_buf->dma_sgl_xtra_list); |
| 21342 | } |
| 21343 | |
| 21344 | allocated_sgl = list_last_entry(&lpfc_buf->dma_sgl_xtra_list, |
| 21345 | struct sli4_hybrid_sgl, |
| 21346 | list_node); |
| 21347 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21348 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21349 | |
| 21350 | return allocated_sgl; |
| 21351 | } |
| 21352 | |
| 21353 | /** |
| 21354 | * lpfc_put_sgl_per_hdwq - Put one SGL chunk into hdwq pool |
| 21355 | * @phba: The HBA for which this call is being executed. |
| 21356 | * @lpfc_buf: IO buf structure with the SGL chunk |
| 21357 | * |
| 21358 | * This routine puts one SGL chunk buffer into hdwq's SGL chunk pool. |
| 21359 | * |
| 21360 | * Return codes: |
| 21361 | * 0 - Success |
| 21362 | * -EINVAL - Error |
| 21363 | **/ |
| 21364 | int |
| 21365 | lpfc_put_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf) |
| 21366 | { |
| 21367 | int rc = 0; |
| 21368 | struct sli4_hybrid_sgl *list_entry = NULL; |
| 21369 | struct sli4_hybrid_sgl *tmp = NULL; |
| 21370 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 21371 | struct list_head *buf_list = &hdwq->sgl_list; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21372 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21373 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21374 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21375 | |
| 21376 | if (likely(!list_empty(&lpfc_buf->dma_sgl_xtra_list))) { |
| 21377 | list_for_each_entry_safe(list_entry, tmp, |
| 21378 | &lpfc_buf->dma_sgl_xtra_list, |
| 21379 | list_node) { |
| 21380 | list_move_tail(&list_entry->list_node, |
| 21381 | buf_list); |
| 21382 | } |
| 21383 | } else { |
| 21384 | rc = -EINVAL; |
| 21385 | } |
| 21386 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21387 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21388 | return rc; |
| 21389 | } |
| 21390 | |
| 21391 | /** |
| 21392 | * lpfc_free_sgl_per_hdwq - Free all SGL chunks of hdwq pool |
| 21393 | * @phba: phba object |
| 21394 | * @hdwq: hdwq to cleanup sgl buff resources on |
| 21395 | * |
| 21396 | * This routine frees all SGL chunks of hdwq SGL chunk pool. |
| 21397 | * |
| 21398 | * Return codes: |
| 21399 | * None |
| 21400 | **/ |
| 21401 | void |
| 21402 | lpfc_free_sgl_per_hdwq(struct lpfc_hba *phba, |
| 21403 | struct lpfc_sli4_hdw_queue *hdwq) |
| 21404 | { |
| 21405 | struct list_head *buf_list = &hdwq->sgl_list; |
| 21406 | struct sli4_hybrid_sgl *list_entry = NULL; |
| 21407 | struct sli4_hybrid_sgl *tmp = NULL; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21408 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21409 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21410 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21411 | |
| 21412 | /* Free sgl pool */ |
| 21413 | list_for_each_entry_safe(list_entry, tmp, |
| 21414 | buf_list, list_node) { |
| 21415 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 21416 | list_entry->dma_sgl, |
| 21417 | list_entry->dma_phys_sgl); |
| 21418 | list_del(&list_entry->list_node); |
| 21419 | kfree(list_entry); |
| 21420 | } |
| 21421 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21422 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21423 | } |
| 21424 | |
| 21425 | /** |
| 21426 | * lpfc_get_cmd_rsp_buf_per_hdwq - Get one CMD/RSP buffer from hdwq |
| 21427 | * @phba: The HBA for which this call is being executed. |
| 21428 | * @lpfc_buf: IO buf structure to attach the CMD/RSP buffer |
| 21429 | * |
| 21430 | * This routine gets one CMD/RSP buffer from hdwq's CMD/RSP pool, |
| 21431 | * and will allocate an CMD/RSP buffer if the pool is empty. |
| 21432 | * |
| 21433 | * Return codes: |
| 21434 | * NULL - Error |
| 21435 | * Pointer to fcp_cmd_rsp_buf - Success |
| 21436 | **/ |
| 21437 | struct fcp_cmd_rsp_buf * |
| 21438 | lpfc_get_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba, |
| 21439 | struct lpfc_io_buf *lpfc_buf) |
| 21440 | { |
| 21441 | struct fcp_cmd_rsp_buf *list_entry = NULL; |
| 21442 | struct fcp_cmd_rsp_buf *tmp = NULL; |
| 21443 | struct fcp_cmd_rsp_buf *allocated_buf = NULL; |
| 21444 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 21445 | struct list_head *buf_list = &hdwq->cmd_rsp_buf_list; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21446 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21447 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21448 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21449 | |
| 21450 | if (likely(!list_empty(buf_list))) { |
| 21451 | /* break off 1 chunk from the list */ |
| 21452 | list_for_each_entry_safe(list_entry, tmp, |
| 21453 | buf_list, |
| 21454 | list_node) { |
| 21455 | list_move_tail(&list_entry->list_node, |
| 21456 | &lpfc_buf->dma_cmd_rsp_list); |
| 21457 | break; |
| 21458 | } |
| 21459 | } else { |
| 21460 | /* allocate more */ |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21461 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21462 | tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC, |
James Smart | 4583a4f | 2019-11-15 16:38:47 -0800 | [diff] [blame] | 21463 | cpu_to_node(hdwq->io_wq->chann)); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21464 | if (!tmp) { |
| 21465 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 21466 | "8355 error kmalloc memory for HDWQ " |
| 21467 | "%d %s\n", |
| 21468 | lpfc_buf->hdwq_no, __func__); |
| 21469 | return NULL; |
| 21470 | } |
| 21471 | |
| 21472 | tmp->fcp_cmnd = dma_pool_alloc(phba->lpfc_cmd_rsp_buf_pool, |
| 21473 | GFP_ATOMIC, |
| 21474 | &tmp->fcp_cmd_rsp_dma_handle); |
| 21475 | |
| 21476 | if (!tmp->fcp_cmnd) { |
| 21477 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 21478 | "8356 error pool_alloc memory for HDWQ " |
| 21479 | "%d %s\n", |
| 21480 | lpfc_buf->hdwq_no, __func__); |
| 21481 | kfree(tmp); |
| 21482 | return NULL; |
| 21483 | } |
| 21484 | |
| 21485 | tmp->fcp_rsp = (struct fcp_rsp *)((uint8_t *)tmp->fcp_cmnd + |
| 21486 | sizeof(struct fcp_cmnd)); |
| 21487 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21488 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21489 | list_add_tail(&tmp->list_node, &lpfc_buf->dma_cmd_rsp_list); |
| 21490 | } |
| 21491 | |
| 21492 | allocated_buf = list_last_entry(&lpfc_buf->dma_cmd_rsp_list, |
| 21493 | struct fcp_cmd_rsp_buf, |
| 21494 | list_node); |
| 21495 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21496 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21497 | |
| 21498 | return allocated_buf; |
| 21499 | } |
| 21500 | |
| 21501 | /** |
| 21502 | * lpfc_put_cmd_rsp_buf_per_hdwq - Put one CMD/RSP buffer into hdwq pool |
| 21503 | * @phba: The HBA for which this call is being executed. |
| 21504 | * @lpfc_buf: IO buf structure with the CMD/RSP buf |
| 21505 | * |
| 21506 | * This routine puts one CMD/RSP buffer into executing CPU's CMD/RSP pool. |
| 21507 | * |
| 21508 | * Return codes: |
| 21509 | * 0 - Success |
| 21510 | * -EINVAL - Error |
| 21511 | **/ |
| 21512 | int |
| 21513 | lpfc_put_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba, |
| 21514 | struct lpfc_io_buf *lpfc_buf) |
| 21515 | { |
| 21516 | int rc = 0; |
| 21517 | struct fcp_cmd_rsp_buf *list_entry = NULL; |
| 21518 | struct fcp_cmd_rsp_buf *tmp = NULL; |
| 21519 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 21520 | struct list_head *buf_list = &hdwq->cmd_rsp_buf_list; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21521 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21522 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21523 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21524 | |
| 21525 | if (likely(!list_empty(&lpfc_buf->dma_cmd_rsp_list))) { |
| 21526 | list_for_each_entry_safe(list_entry, tmp, |
| 21527 | &lpfc_buf->dma_cmd_rsp_list, |
| 21528 | list_node) { |
| 21529 | list_move_tail(&list_entry->list_node, |
| 21530 | buf_list); |
| 21531 | } |
| 21532 | } else { |
| 21533 | rc = -EINVAL; |
| 21534 | } |
| 21535 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21536 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21537 | return rc; |
| 21538 | } |
| 21539 | |
| 21540 | /** |
| 21541 | * lpfc_free_cmd_rsp_buf_per_hdwq - Free all CMD/RSP chunks of hdwq pool |
| 21542 | * @phba: phba object |
| 21543 | * @hdwq: hdwq to cleanup cmd rsp buff resources on |
| 21544 | * |
| 21545 | * This routine frees all CMD/RSP buffers of hdwq's CMD/RSP buf pool. |
| 21546 | * |
| 21547 | * Return codes: |
| 21548 | * None |
| 21549 | **/ |
| 21550 | void |
| 21551 | lpfc_free_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba, |
| 21552 | struct lpfc_sli4_hdw_queue *hdwq) |
| 21553 | { |
| 21554 | struct list_head *buf_list = &hdwq->cmd_rsp_buf_list; |
| 21555 | struct fcp_cmd_rsp_buf *list_entry = NULL; |
| 21556 | struct fcp_cmd_rsp_buf *tmp = NULL; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21557 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21558 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21559 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21560 | |
| 21561 | /* Free cmd_rsp buf pool */ |
| 21562 | list_for_each_entry_safe(list_entry, tmp, |
| 21563 | buf_list, |
| 21564 | list_node) { |
| 21565 | dma_pool_free(phba->lpfc_cmd_rsp_buf_pool, |
| 21566 | list_entry->fcp_cmnd, |
| 21567 | list_entry->fcp_cmd_rsp_dma_handle); |
| 21568 | list_del(&list_entry->list_node); |
| 21569 | kfree(list_entry); |
| 21570 | } |
| 21571 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 21572 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 21573 | } |