Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300     1) /*******************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300     2)  * This file is part of the Emulex Linux Device Driver for         *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300     3)  * Fibre Channel Host Bus Adapters.                                *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300     4)  * Copyright (C) 2017-2020 Broadcom. All Rights Reserved. The term *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300     5)  * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300     6)  * Copyright (C) 2004-2016 Emulex.  All rights reserved.           *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300     7)  * EMULEX and SLI are trademarks of Emulex.                        *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300     8)  * www.broadcom.com                                                *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300     9)  * Portions Copyright (C) 2004-2005 Christoph Hellwig              *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    10)  *                                                                 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    11)  * This program is free software; you can redistribute it and/or   *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    12)  * modify it under the terms of version 2 of the GNU General       *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    13)  * Public License as published by the Free Software Foundation.    *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    14)  * This program is distributed in the hope that it will be useful. *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    15)  * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    16)  * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    17)  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    18)  * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    19)  * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    20)  * more details, a copy of which can be found in the file COPYING  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    21)  * included with this package.                                     *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    22)  *******************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    24) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    25) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    26) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    27) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    28) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    29) #include <linux/lockdep.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    31) #include <scsi/scsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    32) #include <scsi/scsi_cmnd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    33) #include <scsi/scsi_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    34) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    35) #include <scsi/scsi_transport_fc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    36) #include <scsi/fc/fc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    37) #include <linux/aer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    38) #include <linux/crash_dump.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    39) #ifdef CONFIG_X86
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    40) #include <asm/set_memory.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    41) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    43) #include "lpfc_hw4.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    44) #include "lpfc_hw.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    45) #include "lpfc_sli.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    46) #include "lpfc_sli4.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    47) #include "lpfc_nl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    48) #include "lpfc_disc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    49) #include "lpfc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    50) #include "lpfc_scsi.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    51) #include "lpfc_nvme.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    52) #include "lpfc_crtn.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    53) #include "lpfc_logmsg.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    54) #include "lpfc_compat.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    55) #include "lpfc_debugfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    56) #include "lpfc_vport.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    57) #include "lpfc_version.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    59) /* There are only four IOCB completion types. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    60) typedef enum _lpfc_iocb_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    61) 	LPFC_UNKNOWN_IOCB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    62) 	LPFC_UNSOL_IOCB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    63) 	LPFC_SOL_IOCB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    64) 	LPFC_ABORT_IOCB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    65) } lpfc_iocb_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    68) /* Provide function prototypes local to this module. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    69) static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    70) 				  uint32_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    71) static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    72) 			      uint8_t *, uint32_t *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    73) static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    74) 							 struct lpfc_iocbq *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    75) static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    76) 				      struct hbq_dmabuf *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    77) static void lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    78) 					  struct hbq_dmabuf *dmabuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    79) static bool lpfc_sli4_fp_handle_cqe(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    80) 				   struct lpfc_queue *cq, struct lpfc_cqe *cqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    81) static int lpfc_sli4_post_sgl_list(struct lpfc_hba *, struct list_head *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    82) 				       int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    83) static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    84) 				     struct lpfc_queue *eq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    85) 				     struct lpfc_eqe *eqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    86) static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    87) static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    88) static struct lpfc_cqe *lpfc_sli4_cq_get(struct lpfc_queue *q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    89) static void __lpfc_sli4_consume_cqe(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    90) 				    struct lpfc_queue *cq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    91) 				    struct lpfc_cqe *cqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    93) static IOCB_t *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    94) lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    96) 	return &iocbq->iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    99) #if defined(CONFIG_64BIT) && defined(__LITTLE_ENDIAN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   100) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   101)  * lpfc_sli4_pcimem_bcopy - SLI4 memory copy function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   102)  * @srcp: Source memory pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   103)  * @destp: Destination memory pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   104)  * @cnt: Number of words required to be copied.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   105)  *       Must be a multiple of sizeof(uint64_t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   106)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   107)  * This function is used for copying data between driver memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   108)  * and the SLI WQ. This function also changes the endianness
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   109)  * of each word if native endianness is different from SLI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   110)  * endianness. This function can be called with or without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   111)  * lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   112)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   113) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   114) lpfc_sli4_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   116) 	uint64_t *src = srcp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   117) 	uint64_t *dest = destp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   118) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   120) 	for (i = 0; i < (int)cnt; i += sizeof(uint64_t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   121) 		*dest++ = *src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   123) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   124) #define lpfc_sli4_pcimem_bcopy(a, b, c) lpfc_sli_pcimem_bcopy(a, b, c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   125) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   127) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   128)  * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   129)  * @q: The Work Queue to operate on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   130)  * @wqe: The work Queue Entry to put on the Work queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   131)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   132)  * This routine will copy the contents of @wqe to the next available entry on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   133)  * the @q. This function will then ring the Work Queue Doorbell to signal the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   134)  * HBA to start processing the Work Queue Entry. This function returns 0 if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   135)  * successful. If no entries are available on @q then this function will return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   136)  * -ENOMEM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   137)  * The caller is expected to hold the hbalock when calling this routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   138)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   139) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   140) lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe128 *wqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   142) 	union lpfc_wqe *temp_wqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   143) 	struct lpfc_register doorbell;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   144) 	uint32_t host_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   145) 	uint32_t idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   146) 	uint32_t i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   147) 	uint8_t *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   148) 	u32 if_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   150) 	/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   151) 	if (unlikely(!q))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   152) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   153) 	temp_wqe = lpfc_sli4_qe(q, q->host_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   155) 	/* If the host has not yet processed the next entry then we are done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   156) 	idx = ((q->host_index + 1) % q->entry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   157) 	if (idx == q->hba_index) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   158) 		q->WQ_overflow++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   159) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   160) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   161) 	q->WQ_posted++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   162) 	/* set consumption flag every once in a while */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   163) 	if (!((q->host_index + 1) % q->notify_interval))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   164) 		bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   165) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   166) 		bf_set(wqe_wqec, &wqe->generic.wqe_com, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   167) 	if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   168) 		bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   169) 	lpfc_sli4_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   170) 	if (q->dpp_enable && q->phba->cfg_enable_dpp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   171) 		/* write to DPP aperture taking advatage of Combined Writes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   172) 		tmp = (uint8_t *)temp_wqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   173) #ifdef __raw_writeq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   174) 		for (i = 0; i < q->entry_size; i += sizeof(uint64_t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   175) 			__raw_writeq(*((uint64_t *)(tmp + i)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   176) 					q->dpp_regaddr + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   177) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   178) 		for (i = 0; i < q->entry_size; i += sizeof(uint32_t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   179) 			__raw_writel(*((uint32_t *)(tmp + i)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   180) 					q->dpp_regaddr + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   181) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   182) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   183) 	/* ensure WQE bcopy and DPP flushed before doorbell write */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   184) 	wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   186) 	/* Update the host index before invoking device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   187) 	host_index = q->host_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   189) 	q->host_index = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   191) 	/* Ring Doorbell */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   192) 	doorbell.word0 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   193) 	if (q->db_format == LPFC_DB_LIST_FORMAT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   194) 		if (q->dpp_enable && q->phba->cfg_enable_dpp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   195) 			bf_set(lpfc_if6_wq_db_list_fm_num_posted, &doorbell, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   196) 			bf_set(lpfc_if6_wq_db_list_fm_dpp, &doorbell, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   197) 			bf_set(lpfc_if6_wq_db_list_fm_dpp_id, &doorbell,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   198) 			    q->dpp_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   199) 			bf_set(lpfc_if6_wq_db_list_fm_id, &doorbell,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   200) 			    q->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   201) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   202) 			bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   203) 			bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   205) 			/* Leave bits <23:16> clear for if_type 6 dpp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   206) 			if_type = bf_get(lpfc_sli_intf_if_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   207) 					 &q->phba->sli4_hba.sli_intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   208) 			if (if_type != LPFC_SLI_INTF_IF_TYPE_6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   209) 				bf_set(lpfc_wq_db_list_fm_index, &doorbell,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   210) 				       host_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   211) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   212) 	} else if (q->db_format == LPFC_DB_RING_FORMAT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   213) 		bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   214) 		bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   215) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   216) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   217) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   218) 	writel(doorbell.word0, q->db_regaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   220) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   223) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   224)  * lpfc_sli4_wq_release - Updates internal hba index for WQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   225)  * @q: The Work Queue to operate on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   226)  * @index: The index to advance the hba index to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   227)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   228)  * This routine will update the HBA index of a queue to reflect consumption of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   229)  * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   230)  * an entry the host calls this function to update the queue's internal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   231)  * pointers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   232)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   233) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   234) lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   236) 	/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   237) 	if (unlikely(!q))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   238) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   240) 	q->hba_index = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   243) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   244)  * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   245)  * @q: The Mailbox Queue to operate on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   246)  * @mqe: The Mailbox Queue Entry to put on the Work queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   247)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   248)  * This routine will copy the contents of @mqe to the next available entry on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   249)  * the @q. This function will then ring the Work Queue Doorbell to signal the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   250)  * HBA to start processing the Work Queue Entry. This function returns 0 if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   251)  * successful. If no entries are available on @q then this function will return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   252)  * -ENOMEM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   253)  * The caller is expected to hold the hbalock when calling this routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   254)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   255) static uint32_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   256) lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   258) 	struct lpfc_mqe *temp_mqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   259) 	struct lpfc_register doorbell;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   261) 	/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   262) 	if (unlikely(!q))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   263) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   264) 	temp_mqe = lpfc_sli4_qe(q, q->host_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   266) 	/* If the host has not yet processed the next entry then we are done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   267) 	if (((q->host_index + 1) % q->entry_count) == q->hba_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   268) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   269) 	lpfc_sli4_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   270) 	/* Save off the mailbox pointer for completion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   271) 	q->phba->mbox = (MAILBOX_t *)temp_mqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   273) 	/* Update the host index before invoking device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   274) 	q->host_index = ((q->host_index + 1) % q->entry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   276) 	/* Ring Doorbell */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   277) 	doorbell.word0 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   278) 	bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   279) 	bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   280) 	writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   281) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   284) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   285)  * lpfc_sli4_mq_release - Updates internal hba index for MQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   286)  * @q: The Mailbox Queue to operate on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   287)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   288)  * This routine will update the HBA index of a queue to reflect consumption of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   289)  * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   290)  * an entry the host calls this function to update the queue's internal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   291)  * pointers. This routine returns the number of entries that were consumed by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   292)  * the HBA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   293)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   294) static uint32_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   295) lpfc_sli4_mq_release(struct lpfc_queue *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   297) 	/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   298) 	if (unlikely(!q))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   299) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   301) 	/* Clear the mailbox pointer for completion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   302) 	q->phba->mbox = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   303) 	q->hba_index = ((q->hba_index + 1) % q->entry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   304) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   307) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   308)  * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   309)  * @q: The Event Queue to get the first valid EQE from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   310)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   311)  * This routine will get the first valid Event Queue Entry from @q, update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   312)  * the queue's internal hba index, and return the EQE. If no valid EQEs are in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   313)  * the Queue (no more work to do), or the Queue is full of EQEs that have been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   314)  * processed, but not popped back to the HBA then this routine will return NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   315)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   316) static struct lpfc_eqe *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   317) lpfc_sli4_eq_get(struct lpfc_queue *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   319) 	struct lpfc_eqe *eqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   321) 	/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   322) 	if (unlikely(!q))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   323) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   324) 	eqe = lpfc_sli4_qe(q, q->host_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   326) 	/* If the next EQE is not valid then we are done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   327) 	if (bf_get_le32(lpfc_eqe_valid, eqe) != q->qe_valid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   328) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   330) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   331) 	 * insert barrier for instruction interlock : data from the hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   332) 	 * must have the valid bit checked before it can be copied and acted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   333) 	 * upon. Speculative instructions were allowing a bcopy at the start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   334) 	 * of lpfc_sli4_fp_handle_wcqe(), which is called immediately
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   335) 	 * after our return, to copy data before the valid bit check above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   336) 	 * was done. As such, some of the copied data was stale. The barrier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   337) 	 * ensures the check is before any data is copied.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   338) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   339) 	mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   340) 	return eqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   343) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   344)  * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   345)  * @q: The Event Queue to disable interrupts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   346)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   347)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   348) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   349) lpfc_sli4_eq_clr_intr(struct lpfc_queue *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   351) 	struct lpfc_register doorbell;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   353) 	doorbell.word0 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   354) 	bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   355) 	bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   356) 	bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   357) 		(q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   358) 	bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   359) 	writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   362) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   363)  * lpfc_sli4_if6_eq_clr_intr - Turn off interrupts from this EQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   364)  * @q: The Event Queue to disable interrupts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   365)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   366)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   367) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   368) lpfc_sli4_if6_eq_clr_intr(struct lpfc_queue *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   370) 	struct lpfc_register doorbell;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   372) 	doorbell.word0 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   373) 	bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   374) 	writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   377) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   378)  * lpfc_sli4_write_eq_db - write EQ DB for eqe's consumed or arm state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   379)  * @phba: adapter with EQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   380)  * @q: The Event Queue that the host has completed processing for.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   381)  * @count: Number of elements that have been consumed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   382)  * @arm: Indicates whether the host wants to arms this CQ.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   383)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   384)  * This routine will notify the HBA, by ringing the doorbell, that count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   385)  * number of EQEs have been processed. The @arm parameter indicates whether
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   386)  * the queue should be rearmed when ringing the doorbell.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   387)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   388) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   389) lpfc_sli4_write_eq_db(struct lpfc_hba *phba, struct lpfc_queue *q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   390) 		     uint32_t count, bool arm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   392) 	struct lpfc_register doorbell;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   394) 	/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   395) 	if (unlikely(!q || (count == 0 && !arm)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   396) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   398) 	/* ring doorbell for number popped */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   399) 	doorbell.word0 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   400) 	if (arm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   401) 		bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   402) 		bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   403) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   404) 	bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   405) 	bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   406) 	bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   407) 			(q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   408) 	bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   409) 	writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   410) 	/* PCI read to flush PCI pipeline on re-arming for INTx mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   411) 	if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   412) 		readl(q->phba->sli4_hba.EQDBregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   415) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   416)  * lpfc_sli4_if6_write_eq_db - write EQ DB for eqe's consumed or arm state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   417)  * @phba: adapter with EQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   418)  * @q: The Event Queue that the host has completed processing for.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   419)  * @count: Number of elements that have been consumed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   420)  * @arm: Indicates whether the host wants to arms this CQ.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   421)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   422)  * This routine will notify the HBA, by ringing the doorbell, that count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   423)  * number of EQEs have been processed. The @arm parameter indicates whether
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   424)  * the queue should be rearmed when ringing the doorbell.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   425)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   426) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   427) lpfc_sli4_if6_write_eq_db(struct lpfc_hba *phba, struct lpfc_queue *q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   428) 			  uint32_t count, bool arm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   430) 	struct lpfc_register doorbell;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   432) 	/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   433) 	if (unlikely(!q || (count == 0 && !arm)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   434) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   436) 	/* ring doorbell for number popped */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   437) 	doorbell.word0 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   438) 	if (arm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   439) 		bf_set(lpfc_if6_eq_doorbell_arm, &doorbell, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   440) 	bf_set(lpfc_if6_eq_doorbell_num_released, &doorbell, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   441) 	bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   442) 	writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   443) 	/* PCI read to flush PCI pipeline on re-arming for INTx mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   444) 	if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   445) 		readl(q->phba->sli4_hba.EQDBregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   448) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   449) __lpfc_sli4_consume_eqe(struct lpfc_hba *phba, struct lpfc_queue *eq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   450) 			struct lpfc_eqe *eqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   451) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   452) 	if (!phba->sli4_hba.pc_sli4_params.eqav)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   453) 		bf_set_le32(lpfc_eqe_valid, eqe, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   455) 	eq->host_index = ((eq->host_index + 1) % eq->entry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   457) 	/* if the index wrapped around, toggle the valid bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   458) 	if (phba->sli4_hba.pc_sli4_params.eqav && !eq->host_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   459) 		eq->qe_valid = (eq->qe_valid) ? 0 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   462) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   463) lpfc_sli4_eqcq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   464) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   465) 	struct lpfc_eqe *eqe = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   466) 	u32 eq_count = 0, cq_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   467) 	struct lpfc_cqe *cqe = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   468) 	struct lpfc_queue *cq = NULL, *childq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   469) 	int cqid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   471) 	/* walk all the EQ entries and drop on the floor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   472) 	eqe = lpfc_sli4_eq_get(eq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   473) 	while (eqe) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   474) 		/* Get the reference to the corresponding CQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   475) 		cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   476) 		cq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   478) 		list_for_each_entry(childq, &eq->child_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   479) 			if (childq->queue_id == cqid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   480) 				cq = childq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   481) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   482) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   483) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   484) 		/* If CQ is valid, iterate through it and drop all the CQEs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   485) 		if (cq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   486) 			cqe = lpfc_sli4_cq_get(cq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   487) 			while (cqe) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   488) 				__lpfc_sli4_consume_cqe(phba, cq, cqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   489) 				cq_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   490) 				cqe = lpfc_sli4_cq_get(cq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   491) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   492) 			/* Clear and re-arm the CQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   493) 			phba->sli4_hba.sli4_write_cq_db(phba, cq, cq_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   494) 			    LPFC_QUEUE_REARM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   495) 			cq_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   496) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   497) 		__lpfc_sli4_consume_eqe(phba, eq, eqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   498) 		eq_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   499) 		eqe = lpfc_sli4_eq_get(eq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   500) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   502) 	/* Clear and re-arm the EQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   503) 	phba->sli4_hba.sli4_write_eq_db(phba, eq, eq_count, LPFC_QUEUE_REARM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   506) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   507) lpfc_sli4_process_eq(struct lpfc_hba *phba, struct lpfc_queue *eq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   508) 		     uint8_t rearm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   510) 	struct lpfc_eqe *eqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   511) 	int count = 0, consumed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   513) 	if (cmpxchg(&eq->queue_claimed, 0, 1) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   514) 		goto rearm_and_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   516) 	eqe = lpfc_sli4_eq_get(eq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   517) 	while (eqe) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   518) 		lpfc_sli4_hba_handle_eqe(phba, eq, eqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   519) 		__lpfc_sli4_consume_eqe(phba, eq, eqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   521) 		consumed++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   522) 		if (!(++count % eq->max_proc_limit))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   523) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   525) 		if (!(count % eq->notify_interval)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   526) 			phba->sli4_hba.sli4_write_eq_db(phba, eq, consumed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   527) 							LPFC_QUEUE_NOARM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   528) 			consumed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   529) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   531) 		eqe = lpfc_sli4_eq_get(eq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   532) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   533) 	eq->EQ_processed += count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   535) 	/* Track the max number of EQEs processed in 1 intr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   536) 	if (count > eq->EQ_max_eqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   537) 		eq->EQ_max_eqe = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   539) 	xchg(&eq->queue_claimed, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   541) rearm_and_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   542) 	/* Always clear the EQ. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   543) 	phba->sli4_hba.sli4_write_eq_db(phba, eq, consumed, rearm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   545) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   546) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   548) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   549)  * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   550)  * @q: The Completion Queue to get the first valid CQE from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   551)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   552)  * This routine will get the first valid Completion Queue Entry from @q, update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   553)  * the queue's internal hba index, and return the CQE. If no valid CQEs are in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   554)  * the Queue (no more work to do), or the Queue is full of CQEs that have been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   555)  * processed, but not popped back to the HBA then this routine will return NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   556)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   557) static struct lpfc_cqe *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   558) lpfc_sli4_cq_get(struct lpfc_queue *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   559) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   560) 	struct lpfc_cqe *cqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   562) 	/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   563) 	if (unlikely(!q))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   564) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   565) 	cqe = lpfc_sli4_qe(q, q->host_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   567) 	/* If the next CQE is not valid then we are done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   568) 	if (bf_get_le32(lpfc_cqe_valid, cqe) != q->qe_valid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   569) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   571) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   572) 	 * insert barrier for instruction interlock : data from the hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   573) 	 * must have the valid bit checked before it can be copied and acted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   574) 	 * upon. Given what was seen in lpfc_sli4_cq_get() of speculative
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   575) 	 * instructions allowing action on content before valid bit checked,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   576) 	 * add barrier here as well. May not be needed as "content" is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   577) 	 * single 32-bit entity here (vs multi word structure for cq's).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   578) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   579) 	mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   580) 	return cqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   581) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   583) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   584) __lpfc_sli4_consume_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   585) 			struct lpfc_cqe *cqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   586) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   587) 	if (!phba->sli4_hba.pc_sli4_params.cqav)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   588) 		bf_set_le32(lpfc_cqe_valid, cqe, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   590) 	cq->host_index = ((cq->host_index + 1) % cq->entry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   592) 	/* if the index wrapped around, toggle the valid bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   593) 	if (phba->sli4_hba.pc_sli4_params.cqav && !cq->host_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   594) 		cq->qe_valid = (cq->qe_valid) ? 0 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   595) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   597) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   598)  * lpfc_sli4_write_cq_db - write cq DB for entries consumed or arm state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   599)  * @phba: the adapter with the CQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   600)  * @q: The Completion Queue that the host has completed processing for.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   601)  * @count: the number of elements that were consumed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   602)  * @arm: Indicates whether the host wants to arms this CQ.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   603)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   604)  * This routine will notify the HBA, by ringing the doorbell, that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   605)  * CQEs have been processed. The @arm parameter specifies whether the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   606)  * queue should be rearmed when ringing the doorbell.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   607)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   608) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   609) lpfc_sli4_write_cq_db(struct lpfc_hba *phba, struct lpfc_queue *q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   610) 		     uint32_t count, bool arm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   611) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   612) 	struct lpfc_register doorbell;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   614) 	/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   615) 	if (unlikely(!q || (count == 0 && !arm)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   616) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   618) 	/* ring doorbell for number popped */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   619) 	doorbell.word0 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   620) 	if (arm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   621) 		bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   622) 	bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   623) 	bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   624) 	bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   625) 			(q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   626) 	bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   627) 	writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   630) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   631)  * lpfc_sli4_if6_write_cq_db - write cq DB for entries consumed or arm state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   632)  * @phba: the adapter with the CQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   633)  * @q: The Completion Queue that the host has completed processing for.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   634)  * @count: the number of elements that were consumed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   635)  * @arm: Indicates whether the host wants to arms this CQ.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   636)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   637)  * This routine will notify the HBA, by ringing the doorbell, that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   638)  * CQEs have been processed. The @arm parameter specifies whether the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   639)  * queue should be rearmed when ringing the doorbell.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   640)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   641) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   642) lpfc_sli4_if6_write_cq_db(struct lpfc_hba *phba, struct lpfc_queue *q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   643) 			 uint32_t count, bool arm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   644) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   645) 	struct lpfc_register doorbell;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   647) 	/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   648) 	if (unlikely(!q || (count == 0 && !arm)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   649) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   651) 	/* ring doorbell for number popped */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   652) 	doorbell.word0 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   653) 	if (arm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   654) 		bf_set(lpfc_if6_cq_doorbell_arm, &doorbell, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   655) 	bf_set(lpfc_if6_cq_doorbell_num_released, &doorbell, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   656) 	bf_set(lpfc_if6_cq_doorbell_cqid, &doorbell, q->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   657) 	writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   658) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   660) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   661)  * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   662)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   663)  * This routine will copy the contents of @wqe to the next available entry on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   664)  * the @q. This function will then ring the Receive Queue Doorbell to signal the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   665)  * HBA to start processing the Receive Queue Entry. This function returns the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   666)  * index that the rqe was copied to if successful. If no entries are available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   667)  * on @q then this function will return -ENOMEM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   668)  * The caller is expected to hold the hbalock when calling this routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   669)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   670) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   671) lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   672) 		 struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   673) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   674) 	struct lpfc_rqe *temp_hrqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   675) 	struct lpfc_rqe *temp_drqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   676) 	struct lpfc_register doorbell;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   677) 	int hq_put_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   678) 	int dq_put_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   680) 	/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   681) 	if (unlikely(!hq) || unlikely(!dq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   682) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   683) 	hq_put_index = hq->host_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   684) 	dq_put_index = dq->host_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   685) 	temp_hrqe = lpfc_sli4_qe(hq, hq_put_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   686) 	temp_drqe = lpfc_sli4_qe(dq, dq_put_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   688) 	if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   689) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   690) 	if (hq_put_index != dq_put_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   691) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   692) 	/* If the host has not yet processed the next entry then we are done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   693) 	if (((hq_put_index + 1) % hq->entry_count) == hq->hba_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   694) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   695) 	lpfc_sli4_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   696) 	lpfc_sli4_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   698) 	/* Update the host index to point to the next slot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   699) 	hq->host_index = ((hq_put_index + 1) % hq->entry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   700) 	dq->host_index = ((dq_put_index + 1) % dq->entry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   701) 	hq->RQ_buf_posted++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   703) 	/* Ring The Header Receive Queue Doorbell */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   704) 	if (!(hq->host_index % hq->notify_interval)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   705) 		doorbell.word0 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   706) 		if (hq->db_format == LPFC_DB_RING_FORMAT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   707) 			bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   708) 			       hq->notify_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   709) 			bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   710) 		} else if (hq->db_format == LPFC_DB_LIST_FORMAT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   711) 			bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   712) 			       hq->notify_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   713) 			bf_set(lpfc_rq_db_list_fm_index, &doorbell,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   714) 			       hq->host_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   715) 			bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   716) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   717) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   718) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   719) 		writel(doorbell.word0, hq->db_regaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   720) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   721) 	return hq_put_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   722) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   724) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   725)  * lpfc_sli4_rq_release - Updates internal hba index for RQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   726)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   727)  * This routine will update the HBA index of a queue to reflect consumption of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   728)  * one Receive Queue Entry by the HBA. When the HBA indicates that it has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   729)  * consumed an entry the host calls this function to update the queue's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   730)  * internal pointers. This routine returns the number of entries that were
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   731)  * consumed by the HBA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   732)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   733) static uint32_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   734) lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   735) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   736) 	/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   737) 	if (unlikely(!hq) || unlikely(!dq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   738) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   740) 	if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   741) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   742) 	hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   743) 	dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   744) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   747) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   748)  * lpfc_cmd_iocb - Get next command iocb entry in the ring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   749)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   750)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   751)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   752)  * This function returns pointer to next command iocb entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   753)  * in the command ring. The caller must hold hbalock to prevent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   754)  * other threads consume the next command iocb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   755)  * SLI-2/SLI-3 provide different sized iocbs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   756)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   757) static inline IOCB_t *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   758) lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   759) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   760) 	return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   761) 			   pring->sli.sli3.cmdidx * phba->iocb_cmd_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   762) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   764) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   765)  * lpfc_resp_iocb - Get next response iocb entry in the ring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   766)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   767)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   768)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   769)  * This function returns pointer to next response iocb entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   770)  * in the response ring. The caller must hold hbalock to make sure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   771)  * that no other thread consume the next response iocb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   772)  * SLI-2/SLI-3 provide different sized iocbs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   773)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   774) static inline IOCB_t *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   775) lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   776) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   777) 	return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   778) 			   pring->sli.sli3.rspidx * phba->iocb_rsp_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   779) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   781) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   782)  * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   783)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   784)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   785)  * This function is called with hbalock held. This function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   786)  * allocates a new driver iocb object from the iocb pool. If the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   787)  * allocation is successful, it returns pointer to the newly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   788)  * allocated iocb object else it returns NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   789)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   790) struct lpfc_iocbq *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   791) __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   792) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   793) 	struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   794) 	struct lpfc_iocbq * iocbq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   796) 	lockdep_assert_held(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   798) 	list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   799) 	if (iocbq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   800) 		phba->iocb_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   801) 	if (phba->iocb_cnt > phba->iocb_max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   802) 		phba->iocb_max = phba->iocb_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   803) 	return iocbq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   804) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   806) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   807)  * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   808)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   809)  * @xritag: XRI value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   810)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   811)  * This function clears the sglq pointer from the array of acive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   812)  * sglq's. The xritag that is passed in is used to index into the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   813)  * array. Before the xritag can be used it needs to be adjusted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   814)  * by subtracting the xribase.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   815)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   816)  * Returns sglq ponter = success, NULL = Failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   817)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   818) struct lpfc_sglq *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   819) __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   820) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   821) 	struct lpfc_sglq *sglq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   823) 	sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   824) 	phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   825) 	return sglq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   826) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   828) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   829)  * __lpfc_get_active_sglq - Get the active sglq for this XRI.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   830)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   831)  * @xritag: XRI value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   832)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   833)  * This function returns the sglq pointer from the array of acive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   834)  * sglq's. The xritag that is passed in is used to index into the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   835)  * array. Before the xritag can be used it needs to be adjusted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   836)  * by subtracting the xribase.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   837)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   838)  * Returns sglq ponter = success, NULL = Failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   839)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   840) struct lpfc_sglq *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   841) __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   842) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   843) 	struct lpfc_sglq *sglq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   845) 	sglq =  phba->sli4_hba.lpfc_sglq_active_list[xritag];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   846) 	return sglq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   847) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   848) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   849) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   850)  * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   851)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   852)  * @xritag: xri used in this exchange.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   853)  * @rrq: The RRQ to be cleared.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   854)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   855)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   856) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   857) lpfc_clr_rrq_active(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   858) 		    uint16_t xritag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   859) 		    struct lpfc_node_rrq *rrq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   860) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   861) 	struct lpfc_nodelist *ndlp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   862) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   863) 	if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   864) 		ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   866) 	/* The target DID could have been swapped (cable swap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   867) 	 * we should use the ndlp from the findnode if it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   868) 	 * available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   869) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   870) 	if ((!ndlp) && rrq->ndlp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   871) 		ndlp = rrq->ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   873) 	if (!ndlp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   874) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   876) 	if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   877) 		rrq->send_rrq = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   878) 		rrq->xritag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   879) 		rrq->rrq_stop_time = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   880) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   881) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   882) 	mempool_free(rrq, phba->rrq_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   883) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   885) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   886)  * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   887)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   888)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   889)  * This function is called with hbalock held. This function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   890)  * Checks if stop_time (ratov from setting rrq active) has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   891)  * been reached, if it has and the send_rrq flag is set then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   892)  * it will call lpfc_send_rrq. If the send_rrq flag is not set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   893)  * then it will just call the routine to clear the rrq and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   894)  * free the rrq resource.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   895)  * The timer is set to the next rrq that is going to expire before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   896)  * leaving the routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   897)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   898)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   899) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   900) lpfc_handle_rrq_active(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   901) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   902) 	struct lpfc_node_rrq *rrq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   903) 	struct lpfc_node_rrq *nextrrq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   904) 	unsigned long next_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   905) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   906) 	LIST_HEAD(send_rrq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   908) 	spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   909) 	phba->hba_flag &= ~HBA_RRQ_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   910) 	next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   911) 	list_for_each_entry_safe(rrq, nextrrq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   912) 				 &phba->active_rrq_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   913) 		if (time_after(jiffies, rrq->rrq_stop_time))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   914) 			list_move(&rrq->list, &send_rrq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   915) 		else if (time_before(rrq->rrq_stop_time, next_time))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   916) 			next_time = rrq->rrq_stop_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   917) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   918) 	spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   919) 	if ((!list_empty(&phba->active_rrq_list)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   920) 	    (!(phba->pport->load_flag & FC_UNLOADING)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   921) 		mod_timer(&phba->rrq_tmr, next_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   922) 	list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   923) 		list_del(&rrq->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   924) 		if (!rrq->send_rrq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   925) 			/* this call will free the rrq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   926) 			lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   927) 		} else if (lpfc_send_rrq(phba, rrq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   928) 			/* if we send the rrq then the completion handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   929) 			*  will clear the bit in the xribitmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   930) 			*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   931) 			lpfc_clr_rrq_active(phba, rrq->xritag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   932) 					    rrq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   933) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   934) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   935) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   937) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   938)  * lpfc_get_active_rrq - Get the active RRQ for this exchange.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   939)  * @vport: Pointer to vport context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   940)  * @xri: The xri used in the exchange.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   941)  * @did: The targets DID for this exchange.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   942)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   943)  * returns NULL = rrq not found in the phba->active_rrq_list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   944)  *         rrq = rrq for this xri and target.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   945)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   946) struct lpfc_node_rrq *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   947) lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   948) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   949) 	struct lpfc_hba *phba = vport->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   950) 	struct lpfc_node_rrq *rrq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   951) 	struct lpfc_node_rrq *nextrrq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   952) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   953) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   954) 	if (phba->sli_rev != LPFC_SLI_REV4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   955) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   956) 	spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   957) 	list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   958) 		if (rrq->vport == vport && rrq->xritag == xri &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   959) 				rrq->nlp_DID == did){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   960) 			list_del(&rrq->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   961) 			spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   962) 			return rrq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   963) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   964) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   965) 	spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   966) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   967) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   969) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   970)  * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   971)  * @vport: Pointer to vport context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   972)  * @ndlp: Pointer to the lpfc_node_list structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   973)  * If ndlp is NULL Remove all active RRQs for this vport from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   974)  * phba->active_rrq_list and clear the rrq.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   975)  * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   976)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   977) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   978) lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   979) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   980) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   981) 	struct lpfc_hba *phba = vport->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   982) 	struct lpfc_node_rrq *rrq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   983) 	struct lpfc_node_rrq *nextrrq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   984) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   985) 	LIST_HEAD(rrq_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   986) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   987) 	if (phba->sli_rev != LPFC_SLI_REV4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   988) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   989) 	if (!ndlp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   990) 		lpfc_sli4_vport_delete_els_xri_aborted(vport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   991) 		lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   992) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   993) 	spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   994) 	list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   995) 		if ((rrq->vport == vport) && (!ndlp  || rrq->ndlp == ndlp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   996) 			list_move(&rrq->list, &rrq_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   997) 	spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   999) 	list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1000) 		list_del(&rrq->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1001) 		lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1002) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1003) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1004) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1005) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1006)  * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1007)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1008)  * @ndlp: Targets nodelist pointer for this exchange.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1009)  * @xritag: the xri in the bitmap to test.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1010)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1011)  * This function returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1012)  * 0 = rrq not active for this xri
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1013)  * 1 = rrq is valid for this xri.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1014)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1015) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1016) lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1017) 			uint16_t  xritag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1018) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1019) 	if (!ndlp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1020) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1021) 	if (!ndlp->active_rrqs_xri_bitmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1022) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1023) 	if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1024) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1025) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1026) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1027) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1028) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1029) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1030)  * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1031)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1032)  * @ndlp: nodelist pointer for this target.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1033)  * @xritag: xri used in this exchange.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1034)  * @rxid: Remote Exchange ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1035)  * @send_rrq: Flag used to determine if we should send rrq els cmd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1036)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1037)  * This function takes the hbalock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1038)  * The active bit is always set in the active rrq xri_bitmap even
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1039)  * if there is no slot avaiable for the other rrq information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1040)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1041)  * returns 0 rrq actived for this xri
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1042)  *         < 0 No memory or invalid ndlp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1043)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1044) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1045) lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1046) 		    uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1047) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1048) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1049) 	struct lpfc_node_rrq *rrq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1050) 	int empty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1051) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1052) 	if (!ndlp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1053) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1055) 	if (!phba->cfg_enable_rrq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1056) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1058) 	spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1059) 	if (phba->pport->load_flag & FC_UNLOADING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1060) 		phba->hba_flag &= ~HBA_RRQ_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1061) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1062) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1063) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1064) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1065) 	 * set the active bit even if there is no mem available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1066) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1067) 	if (NLP_CHK_FREE_REQ(ndlp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1068) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1070) 	if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1071) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1072) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1073) 	if (!ndlp->active_rrqs_xri_bitmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1074) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1075) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1076) 	if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1077) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1078) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1079) 	spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1080) 	rrq = mempool_alloc(phba->rrq_pool, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1081) 	if (!rrq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1082) 		lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1083) 				"3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1084) 				" DID:0x%x Send:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1085) 				xritag, rxid, ndlp->nlp_DID, send_rrq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1086) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1087) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1088) 	if (phba->cfg_enable_rrq == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1089) 		rrq->send_rrq = send_rrq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1090) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1091) 		rrq->send_rrq = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1092) 	rrq->xritag = xritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1093) 	rrq->rrq_stop_time = jiffies +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1094) 				msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1095) 	rrq->ndlp = ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1096) 	rrq->nlp_DID = ndlp->nlp_DID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1097) 	rrq->vport = ndlp->vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1098) 	rrq->rxid = rxid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1099) 	spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1100) 	empty = list_empty(&phba->active_rrq_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1101) 	list_add_tail(&rrq->list, &phba->active_rrq_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1102) 	phba->hba_flag |= HBA_RRQ_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1103) 	if (empty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1104) 		lpfc_worker_wake_up(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1105) 	spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1106) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1107) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1108) 	spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1109) 	lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1110) 			"2921 Can't set rrq active xri:0x%x rxid:0x%x"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1111) 			" DID:0x%x Send:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1112) 			xritag, rxid, ndlp->nlp_DID, send_rrq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1113) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1116) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1117)  * __lpfc_sli_get_els_sglq - Allocates an iocb object from sgl pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1118)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1119)  * @piocbq: Pointer to the iocbq.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1120)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1121)  * The driver calls this function with either the nvme ls ring lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1122)  * or the fc els ring lock held depending on the iocb usage.  This function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1123)  * gets a new driver sglq object from the sglq list. If the list is not empty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1124)  * then it is successful, it returns pointer to the newly allocated sglq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1125)  * object else it returns NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1126)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1127) static struct lpfc_sglq *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1128) __lpfc_sli_get_els_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1130) 	struct list_head *lpfc_els_sgl_list = &phba->sli4_hba.lpfc_els_sgl_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1131) 	struct lpfc_sglq *sglq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1132) 	struct lpfc_sglq *start_sglq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1133) 	struct lpfc_io_buf *lpfc_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1134) 	struct lpfc_nodelist *ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1135) 	struct lpfc_sli_ring *pring = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1136) 	int found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1138) 	if (piocbq->iocb_flag & LPFC_IO_NVME_LS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1139) 		pring =  phba->sli4_hba.nvmels_wq->pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1140) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1141) 		pring = lpfc_phba_elsring(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1143) 	lockdep_assert_held(&pring->ring_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1145) 	if (piocbq->iocb_flag &  LPFC_IO_FCP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1146) 		lpfc_cmd = (struct lpfc_io_buf *) piocbq->context1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1147) 		ndlp = lpfc_cmd->rdata->pnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1148) 	} else  if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1149) 			!(piocbq->iocb_flag & LPFC_IO_LIBDFC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1150) 		ndlp = piocbq->context_un.ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1151) 	} else  if (piocbq->iocb_flag & LPFC_IO_LIBDFC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1152) 		if (piocbq->iocb_flag & LPFC_IO_LOOPBACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1153) 			ndlp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1154) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1155) 			ndlp = piocbq->context_un.ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1156) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1157) 		ndlp = piocbq->context1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1158) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1160) 	spin_lock(&phba->sli4_hba.sgl_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1161) 	list_remove_head(lpfc_els_sgl_list, sglq, struct lpfc_sglq, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1162) 	start_sglq = sglq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1163) 	while (!found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1164) 		if (!sglq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1165) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1166) 		if (ndlp && ndlp->active_rrqs_xri_bitmap &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1167) 		    test_bit(sglq->sli4_lxritag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1168) 		    ndlp->active_rrqs_xri_bitmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1169) 			/* This xri has an rrq outstanding for this DID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1170) 			 * put it back in the list and get another xri.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1171) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1172) 			list_add_tail(&sglq->list, lpfc_els_sgl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1173) 			sglq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1174) 			list_remove_head(lpfc_els_sgl_list, sglq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1175) 						struct lpfc_sglq, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1176) 			if (sglq == start_sglq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1177) 				list_add_tail(&sglq->list, lpfc_els_sgl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1178) 				sglq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1179) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1180) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1181) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1182) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1183) 		sglq->ndlp = ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1184) 		found = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1185) 		phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1186) 		sglq->state = SGL_ALLOCATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1187) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1188) 	spin_unlock(&phba->sli4_hba.sgl_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1189) 	return sglq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1192) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1193)  * __lpfc_sli_get_nvmet_sglq - Allocates an iocb object from sgl pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1194)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1195)  * @piocbq: Pointer to the iocbq.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1196)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1197)  * This function is called with the sgl_list lock held. This function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1198)  * gets a new driver sglq object from the sglq list. If the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1199)  * list is not empty then it is successful, it returns pointer to the newly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1200)  * allocated sglq object else it returns NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1201)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1202) struct lpfc_sglq *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1203) __lpfc_sli_get_nvmet_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1205) 	struct list_head *lpfc_nvmet_sgl_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1206) 	struct lpfc_sglq *sglq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1208) 	lpfc_nvmet_sgl_list = &phba->sli4_hba.lpfc_nvmet_sgl_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1210) 	lockdep_assert_held(&phba->sli4_hba.sgl_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1212) 	list_remove_head(lpfc_nvmet_sgl_list, sglq, struct lpfc_sglq, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1213) 	if (!sglq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1214) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1215) 	phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1216) 	sglq->state = SGL_ALLOCATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1217) 	return sglq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1220) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1221)  * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1222)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1223)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1224)  * This function is called with no lock held. This function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1225)  * allocates a new driver iocb object from the iocb pool. If the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1226)  * allocation is successful, it returns pointer to the newly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1227)  * allocated iocb object else it returns NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1228)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1229) struct lpfc_iocbq *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1230) lpfc_sli_get_iocbq(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1232) 	struct lpfc_iocbq * iocbq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1233) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1235) 	spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1236) 	iocbq = __lpfc_sli_get_iocbq(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1237) 	spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1238) 	return iocbq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1241) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1242)  * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1243)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1244)  * @iocbq: Pointer to driver iocb object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1245)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1246)  * This function is called to release the driver iocb object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1247)  * to the iocb pool. The iotag in the iocb object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1248)  * does not change for each use of the iocb object. This function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1249)  * clears all other fields of the iocb object when it is freed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1250)  * The sqlq structure that holds the xritag and phys and virtual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1251)  * mappings for the scatter gather list is retrieved from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1252)  * active array of sglq. The get of the sglq pointer also clears
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1253)  * the entry in the array. If the status of the IO indiactes that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1254)  * this IO was aborted then the sglq entry it put on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1255)  * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1256)  * IO has good status or fails for any other reason then the sglq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1257)  * entry is added to the free list (lpfc_els_sgl_list). The hbalock is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1258)  *  asserted held in the code path calling this routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1259)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1260) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1261) __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1263) 	struct lpfc_sglq *sglq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1264) 	size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1265) 	unsigned long iflag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1266) 	struct lpfc_sli_ring *pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1268) 	if (iocbq->sli4_xritag == NO_XRI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1269) 		sglq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1270) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1271) 		sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1274) 	if (sglq)  {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1275) 		if (iocbq->iocb_flag & LPFC_IO_NVMET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1276) 			spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1277) 					  iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1278) 			sglq->state = SGL_FREED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1279) 			sglq->ndlp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1280) 			list_add_tail(&sglq->list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1281) 				      &phba->sli4_hba.lpfc_nvmet_sgl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1282) 			spin_unlock_irqrestore(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1283) 				&phba->sli4_hba.sgl_list_lock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1284) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1285) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1287) 		pring = phba->sli4_hba.els_wq->pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1288) 		if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1289) 			(sglq->state != SGL_XRI_ABORTED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1290) 			spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1291) 					  iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1292) 			list_add(&sglq->list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1293) 				 &phba->sli4_hba.lpfc_abts_els_sgl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1294) 			spin_unlock_irqrestore(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1295) 				&phba->sli4_hba.sgl_list_lock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1296) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1297) 			spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1298) 					  iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1299) 			sglq->state = SGL_FREED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1300) 			sglq->ndlp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1301) 			list_add_tail(&sglq->list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1302) 				      &phba->sli4_hba.lpfc_els_sgl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1303) 			spin_unlock_irqrestore(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1304) 				&phba->sli4_hba.sgl_list_lock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1306) 			/* Check if TXQ queue needs to be serviced */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1307) 			if (!list_empty(&pring->txq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1308) 				lpfc_worker_wake_up(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1309) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1310) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1312) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1313) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1314) 	 * Clean all volatile data fields, preserve iotag and node struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1315) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1316) 	memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1317) 	iocbq->sli4_lxritag = NO_XRI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1318) 	iocbq->sli4_xritag = NO_XRI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1319) 	iocbq->iocb_flag &= ~(LPFC_IO_NVME | LPFC_IO_NVMET |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1320) 			      LPFC_IO_NVME_LS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1321) 	list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1325) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1326)  * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1327)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1328)  * @iocbq: Pointer to driver iocb object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1329)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1330)  * This function is called to release the driver iocb object to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1331)  * iocb pool. The iotag in the iocb object does not change for each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1332)  * use of the iocb object. This function clears all other fields of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1333)  * the iocb object when it is freed. The hbalock is asserted held in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1334)  * the code path calling this routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1335)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1336) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1337) __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1338) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1339) 	size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1341) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1342) 	 * Clean all volatile data fields, preserve iotag and node struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1343) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1344) 	memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1345) 	iocbq->sli4_xritag = NO_XRI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1346) 	list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1349) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1350)  * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1351)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1352)  * @iocbq: Pointer to driver iocb object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1353)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1354)  * This function is called with hbalock held to release driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1355)  * iocb object to the iocb pool. The iotag in the iocb object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1356)  * does not change for each use of the iocb object. This function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1357)  * clears all other fields of the iocb object when it is freed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1358)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1359) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1360) __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1362) 	lockdep_assert_held(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1364) 	phba->__lpfc_sli_release_iocbq(phba, iocbq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1365) 	phba->iocb_cnt--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1368) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1369)  * lpfc_sli_release_iocbq - Release iocb to the iocb pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1370)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1371)  * @iocbq: Pointer to driver iocb object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1372)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1373)  * This function is called with no lock held to release the iocb to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1374)  * iocb pool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1375)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1376) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1377) lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1379) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1381) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1382) 	 * Clean all volatile data fields, preserve iotag and node struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1383) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1384) 	spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1385) 	__lpfc_sli_release_iocbq(phba, iocbq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1386) 	spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1389) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1390)  * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1391)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1392)  * @iocblist: List of IOCBs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1393)  * @ulpstatus: ULP status in IOCB command field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1394)  * @ulpWord4: ULP word-4 in IOCB command field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1395)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1396)  * This function is called with a list of IOCBs to cancel. It cancels the IOCB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1397)  * on the list by invoking the complete callback function associated with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1398)  * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1399)  * fields.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1400)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1401) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1402) lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1403) 		      uint32_t ulpstatus, uint32_t ulpWord4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1404) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1405) 	struct lpfc_iocbq *piocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1407) 	while (!list_empty(iocblist)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1408) 		list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1409) 		if (!piocb->iocb_cmpl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1410) 			if (piocb->iocb_flag & LPFC_IO_NVME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1411) 				lpfc_nvme_cancel_iocb(phba, piocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1412) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1413) 				lpfc_sli_release_iocbq(phba, piocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1414) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1415) 			piocb->iocb.ulpStatus = ulpstatus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1416) 			piocb->iocb.un.ulpWord[4] = ulpWord4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1417) 			(piocb->iocb_cmpl) (phba, piocb, piocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1418) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1419) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1420) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1423) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1424)  * lpfc_sli_iocb_cmd_type - Get the iocb type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1425)  * @iocb_cmnd: iocb command code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1426)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1427)  * This function is called by ring event handler function to get the iocb type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1428)  * This function translates the iocb command to an iocb command type used to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1429)  * decide the final disposition of each completed IOCB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1430)  * The function returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1431)  * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1432)  * LPFC_SOL_IOCB     if it is a solicited iocb completion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1433)  * LPFC_ABORT_IOCB   if it is an abort iocb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1434)  * LPFC_UNSOL_IOCB   if it is an unsolicited iocb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1435)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1436)  * The caller is not required to hold any lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1437)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1438) static lpfc_iocb_type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1439) lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1440) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1441) 	lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1443) 	if (iocb_cmnd > CMD_MAX_IOCB_CMD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1444) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1446) 	switch (iocb_cmnd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1447) 	case CMD_XMIT_SEQUENCE_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1448) 	case CMD_XMIT_SEQUENCE_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1449) 	case CMD_XMIT_BCAST_CN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1450) 	case CMD_XMIT_BCAST_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1451) 	case CMD_ELS_REQUEST_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1452) 	case CMD_ELS_REQUEST_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1453) 	case CMD_CREATE_XRI_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1454) 	case CMD_CREATE_XRI_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1455) 	case CMD_GET_RPI_CN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1456) 	case CMD_XMIT_ELS_RSP_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1457) 	case CMD_GET_RPI_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1458) 	case CMD_FCP_IWRITE_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1459) 	case CMD_FCP_IWRITE_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1460) 	case CMD_FCP_IREAD_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1461) 	case CMD_FCP_IREAD_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1462) 	case CMD_FCP_ICMND_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1463) 	case CMD_FCP_ICMND_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1464) 	case CMD_FCP_TSEND_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1465) 	case CMD_FCP_TRSP_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1466) 	case CMD_FCP_TRECEIVE_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1467) 	case CMD_FCP_AUTO_TRSP_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1468) 	case CMD_ADAPTER_MSG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1469) 	case CMD_ADAPTER_DUMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1470) 	case CMD_XMIT_SEQUENCE64_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1471) 	case CMD_XMIT_SEQUENCE64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1472) 	case CMD_XMIT_BCAST64_CN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1473) 	case CMD_XMIT_BCAST64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1474) 	case CMD_ELS_REQUEST64_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1475) 	case CMD_ELS_REQUEST64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1476) 	case CMD_FCP_IWRITE64_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1477) 	case CMD_FCP_IWRITE64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1478) 	case CMD_FCP_IREAD64_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1479) 	case CMD_FCP_IREAD64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1480) 	case CMD_FCP_ICMND64_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1481) 	case CMD_FCP_ICMND64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1482) 	case CMD_FCP_TSEND64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1483) 	case CMD_FCP_TRSP64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1484) 	case CMD_FCP_TRECEIVE64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1485) 	case CMD_GEN_REQUEST64_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1486) 	case CMD_GEN_REQUEST64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1487) 	case CMD_XMIT_ELS_RSP64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1488) 	case DSSCMD_IWRITE64_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1489) 	case DSSCMD_IWRITE64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1490) 	case DSSCMD_IREAD64_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1491) 	case DSSCMD_IREAD64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1492) 	case CMD_SEND_FRAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1493) 		type = LPFC_SOL_IOCB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1494) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1495) 	case CMD_ABORT_XRI_CN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1496) 	case CMD_ABORT_XRI_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1497) 	case CMD_CLOSE_XRI_CN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1498) 	case CMD_CLOSE_XRI_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1499) 	case CMD_XRI_ABORTED_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1500) 	case CMD_ABORT_MXRI64_CN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1501) 	case CMD_XMIT_BLS_RSP64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1502) 		type = LPFC_ABORT_IOCB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1503) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1504) 	case CMD_RCV_SEQUENCE_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1505) 	case CMD_RCV_ELS_REQ_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1506) 	case CMD_RCV_SEQUENCE64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1507) 	case CMD_RCV_ELS_REQ64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1508) 	case CMD_ASYNC_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1509) 	case CMD_IOCB_RCV_SEQ64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1510) 	case CMD_IOCB_RCV_ELS64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1511) 	case CMD_IOCB_RCV_CONT64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1512) 	case CMD_IOCB_RET_XRI64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1513) 		type = LPFC_UNSOL_IOCB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1514) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1515) 	case CMD_IOCB_XMIT_MSEQ64_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1516) 	case CMD_IOCB_XMIT_MSEQ64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1517) 	case CMD_IOCB_RCV_SEQ_LIST64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1518) 	case CMD_IOCB_RCV_ELS_LIST64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1519) 	case CMD_IOCB_CLOSE_EXTENDED_CN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1520) 	case CMD_IOCB_ABORT_EXTENDED_CN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1521) 	case CMD_IOCB_RET_HBQE64_CN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1522) 	case CMD_IOCB_FCP_IBIDIR64_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1523) 	case CMD_IOCB_FCP_IBIDIR64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1524) 	case CMD_IOCB_FCP_ITASKMGT64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1525) 	case CMD_IOCB_LOGENTRY_CN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1526) 	case CMD_IOCB_LOGENTRY_ASYNC_CN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1527) 		printk("%s - Unhandled SLI-3 Command x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1528) 				__func__, iocb_cmnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1529) 		type = LPFC_UNKNOWN_IOCB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1530) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1531) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1532) 		type = LPFC_UNKNOWN_IOCB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1533) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1534) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1536) 	return type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1539) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1540)  * lpfc_sli_ring_map - Issue config_ring mbox for all rings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1541)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1542)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1543)  * This function is called from SLI initialization code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1544)  * to configure every ring of the HBA's SLI interface. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1545)  * caller is not required to hold any lock. This function issues
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1546)  * a config_ring mailbox command for each ring.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1547)  * This function returns zero if successful else returns a negative
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1548)  * error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1549)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1550) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1551) lpfc_sli_ring_map(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1552) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1553) 	struct lpfc_sli *psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1554) 	LPFC_MBOXQ_t *pmb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1555) 	MAILBOX_t *pmbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1556) 	int i, rc, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1558) 	pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1559) 	if (!pmb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1560) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1561) 	pmbox = &pmb->u.mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1562) 	phba->link_state = LPFC_INIT_MBX_CMDS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1563) 	for (i = 0; i < psli->num_rings; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1564) 		lpfc_config_ring(phba, i, pmb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1565) 		rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1566) 		if (rc != MBX_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1567) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1568) 					"0446 Adapter failed to init (%d), "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1569) 					"mbxCmd x%x CFG_RING, mbxStatus x%x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1570) 					"ring %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1571) 					rc, pmbox->mbxCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1572) 					pmbox->mbxStatus, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1573) 			phba->link_state = LPFC_HBA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1574) 			ret = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1575) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1576) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1577) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1578) 	mempool_free(pmb, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1579) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1580) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1582) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1583)  * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1584)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1585)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1586)  * @piocb: Pointer to the driver iocb object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1587)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1588)  * The driver calls this function with the hbalock held for SLI3 ports or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1589)  * the ring lock held for SLI4 ports. The function adds the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1590)  * new iocb to txcmplq of the given ring. This function always returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1591)  * 0. If this function is called for ELS ring, this function checks if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1592)  * there is a vport associated with the ELS command. This function also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1593)  * starts els_tmofunc timer if this is an ELS command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1594)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1595) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1596) lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1597) 			struct lpfc_iocbq *piocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1598) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1599) 	if (phba->sli_rev == LPFC_SLI_REV4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1600) 		lockdep_assert_held(&pring->ring_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1601) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1602) 		lockdep_assert_held(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1604) 	BUG_ON(!piocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1606) 	list_add_tail(&piocb->list, &pring->txcmplq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1607) 	piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1608) 	pring->txcmplq_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1610) 	if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1611) 	   (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1612) 	   (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1613) 		BUG_ON(!piocb->vport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1614) 		if (!(piocb->vport->load_flag & FC_UNLOADING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1615) 			mod_timer(&piocb->vport->els_tmofunc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1616) 				  jiffies +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1617) 				  msecs_to_jiffies(1000 * (phba->fc_ratov << 1)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1618) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1620) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1623) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1624)  * lpfc_sli_ringtx_get - Get first element of the txq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1625)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1626)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1627)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1628)  * This function is called with hbalock held to get next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1629)  * iocb in txq of the given ring. If there is any iocb in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1630)  * the txq, the function returns first iocb in the list after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1631)  * removing the iocb from the list, else it returns NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1632)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1633) struct lpfc_iocbq *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1634) lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1635) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1636) 	struct lpfc_iocbq *cmd_iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1638) 	lockdep_assert_held(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1640) 	list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1641) 	return cmd_iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1644) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1645)  * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1646)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1647)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1648)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1649)  * This function is called with hbalock held and the caller must post the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1650)  * iocb without releasing the lock. If the caller releases the lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1651)  * iocb slot returned by the function is not guaranteed to be available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1652)  * The function returns pointer to the next available iocb slot if there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1653)  * is available slot in the ring, else it returns NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1654)  * If the get index of the ring is ahead of the put index, the function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1655)  * will post an error attention event to the worker thread to take the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1656)  * HBA to offline state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1657)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1658) static IOCB_t *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1659) lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1660) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1661) 	struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1662) 	uint32_t  max_cmd_idx = pring->sli.sli3.numCiocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1664) 	lockdep_assert_held(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1666) 	if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1667) 	   (++pring->sli.sli3.next_cmdidx >= max_cmd_idx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1668) 		pring->sli.sli3.next_cmdidx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1670) 	if (unlikely(pring->sli.sli3.local_getidx ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1671) 		pring->sli.sli3.next_cmdidx)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1673) 		pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1675) 		if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1676) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1677) 					"0315 Ring %d issue: portCmdGet %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1678) 					"is bigger than cmd ring %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1679) 					pring->ringno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1680) 					pring->sli.sli3.local_getidx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1681) 					max_cmd_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1683) 			phba->link_state = LPFC_HBA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1684) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1685) 			 * All error attention handlers are posted to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1686) 			 * worker thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1687) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1688) 			phba->work_ha |= HA_ERATT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1689) 			phba->work_hs = HS_FFER3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1691) 			lpfc_worker_wake_up(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1693) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1694) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1696) 		if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1697) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1698) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1700) 	return lpfc_cmd_iocb(phba, pring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1701) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1703) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1704)  * lpfc_sli_next_iotag - Get an iotag for the iocb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1705)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1706)  * @iocbq: Pointer to driver iocb object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1707)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1708)  * This function gets an iotag for the iocb. If there is no unused iotag and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1709)  * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1710)  * array and assigns a new iotag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1711)  * The function returns the allocated iotag if successful, else returns zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1712)  * Zero is not a valid iotag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1713)  * The caller is not required to hold any lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1714)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1715) uint16_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1716) lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1717) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1718) 	struct lpfc_iocbq **new_arr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1719) 	struct lpfc_iocbq **old_arr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1720) 	size_t new_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1721) 	struct lpfc_sli *psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1722) 	uint16_t iotag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1724) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1725) 	iotag = psli->last_iotag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1726) 	if(++iotag < psli->iocbq_lookup_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1727) 		psli->last_iotag = iotag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1728) 		psli->iocbq_lookup[iotag] = iocbq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1729) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1730) 		iocbq->iotag = iotag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1731) 		return iotag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1732) 	} else if (psli->iocbq_lookup_len < (0xffff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1733) 					   - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1734) 		new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1735) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1736) 		new_arr = kcalloc(new_len, sizeof(struct lpfc_iocbq *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1737) 				  GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1738) 		if (new_arr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1739) 			spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1740) 			old_arr = psli->iocbq_lookup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1741) 			if (new_len <= psli->iocbq_lookup_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1742) 				/* highly unprobable case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1743) 				kfree(new_arr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1744) 				iotag = psli->last_iotag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1745) 				if(++iotag < psli->iocbq_lookup_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1746) 					psli->last_iotag = iotag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1747) 					psli->iocbq_lookup[iotag] = iocbq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1748) 					spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1749) 					iocbq->iotag = iotag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1750) 					return iotag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1751) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1752) 				spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1753) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1754) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1755) 			if (psli->iocbq_lookup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1756) 				memcpy(new_arr, old_arr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1757) 				       ((psli->last_iotag  + 1) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1758) 					sizeof (struct lpfc_iocbq *)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1759) 			psli->iocbq_lookup = new_arr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1760) 			psli->iocbq_lookup_len = new_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1761) 			psli->last_iotag = iotag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1762) 			psli->iocbq_lookup[iotag] = iocbq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1763) 			spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1764) 			iocbq->iotag = iotag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1765) 			kfree(old_arr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1766) 			return iotag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1767) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1768) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1769) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1771) 	lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1772) 			"0318 Failed to allocate IOTAG.last IOTAG is %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1773) 			psli->last_iotag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1775) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1776) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1778) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1779)  * lpfc_sli_submit_iocb - Submit an iocb to the firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1780)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1781)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1782)  * @iocb: Pointer to iocb slot in the ring.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1783)  * @nextiocb: Pointer to driver iocb object which need to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1784)  *            posted to firmware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1785)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1786)  * This function is called to post a new iocb to the firmware. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1787)  * function copies the new iocb to ring iocb slot and updates the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1788)  * ring pointers. It adds the new iocb to txcmplq if there is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1789)  * a completion call back for this iocb else the function will free the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1790)  * iocb object.  The hbalock is asserted held in the code path calling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1791)  * this routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1792)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1793) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1794) lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1795) 		IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1796) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1797) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1798) 	 * Set up an iotag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1799) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1800) 	nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1803) 	if (pring->ringno == LPFC_ELS_RING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1804) 		lpfc_debugfs_slow_ring_trc(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1805) 			"IOCB cmd ring:   wd4:x%08x wd6:x%08x wd7:x%08x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1806) 			*(((uint32_t *) &nextiocb->iocb) + 4),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1807) 			*(((uint32_t *) &nextiocb->iocb) + 6),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1808) 			*(((uint32_t *) &nextiocb->iocb) + 7));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1809) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1811) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1812) 	 * Issue iocb command to adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1813) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1814) 	lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1815) 	wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1816) 	pring->stats.iocb_cmd++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1818) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1819) 	 * If there is no completion routine to call, we can release the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1820) 	 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1821) 	 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1822) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1823) 	if (nextiocb->iocb_cmpl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1824) 		lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1825) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1826) 		__lpfc_sli_release_iocbq(phba, nextiocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1828) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1829) 	 * Let the HBA know what IOCB slot will be the next one the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1830) 	 * driver will put a command into.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1831) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1832) 	pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1833) 	writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1836) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1837)  * lpfc_sli_update_full_ring - Update the chip attention register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1838)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1839)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1840)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1841)  * The caller is not required to hold any lock for calling this function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1842)  * This function updates the chip attention bits for the ring to inform firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1843)  * that there are pending work to be done for this ring and requests an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1844)  * interrupt when there is space available in the ring. This function is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1845)  * called when the driver is unable to post more iocbs to the ring due
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1846)  * to unavailability of space in the ring.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1847)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1848) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1849) lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1850) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1851) 	int ringno = pring->ringno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1853) 	pring->flag |= LPFC_CALL_RING_AVAILABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1854) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1855) 	wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1857) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1858) 	 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1859) 	 * The HBA will tell us when an IOCB entry is available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1860) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1861) 	writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1862) 	readl(phba->CAregaddr); /* flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1864) 	pring->stats.iocb_cmd_full++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1867) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1868)  * lpfc_sli_update_ring - Update chip attention register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1869)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1870)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1871)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1872)  * This function updates the chip attention register bit for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1873)  * given ring to inform HBA that there is more work to be done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1874)  * in this ring. The caller is not required to hold any lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1875)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1876) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1877) lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1878) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1879) 	int ringno = pring->ringno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1881) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1882) 	 * Tell the HBA that there is work to do in this ring.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1883) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1884) 	if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1885) 		wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1886) 		writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1887) 		readl(phba->CAregaddr); /* flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1888) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1889) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1891) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1892)  * lpfc_sli_resume_iocb - Process iocbs in the txq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1893)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1894)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1895)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1896)  * This function is called with hbalock held to post pending iocbs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1897)  * in the txq to the firmware. This function is called when driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1898)  * detects space available in the ring.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1899)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1900) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1901) lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1902) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1903) 	IOCB_t *iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1904) 	struct lpfc_iocbq *nextiocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1906) 	lockdep_assert_held(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1908) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1909) 	 * Check to see if:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1910) 	 *  (a) there is anything on the txq to send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1911) 	 *  (b) link is up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1912) 	 *  (c) link attention events can be processed (fcp ring only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1913) 	 *  (d) IOCB processing is not blocked by the outstanding mbox command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1914) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1916) 	if (lpfc_is_link_up(phba) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1917) 	    (!list_empty(&pring->txq)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1918) 	    (pring->ringno != LPFC_FCP_RING ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1919) 	     phba->sli.sli_flag & LPFC_PROCESS_LA)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1921) 		while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1922) 		       (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1923) 			lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1925) 		if (iocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1926) 			lpfc_sli_update_ring(phba, pring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1927) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1928) 			lpfc_sli_update_full_ring(phba, pring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1929) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1931) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1932) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1934) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1935)  * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1936)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1937)  * @hbqno: HBQ number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1938)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1939)  * This function is called with hbalock held to get the next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1940)  * available slot for the given HBQ. If there is free slot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1941)  * available for the HBQ it will return pointer to the next available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1942)  * HBQ entry else it will return NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1943)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1944) static struct lpfc_hbq_entry *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1945) lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1946) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1947) 	struct hbq_s *hbqp = &phba->hbqs[hbqno];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1949) 	lockdep_assert_held(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1951) 	if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1952) 	    ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1953) 		hbqp->next_hbqPutIdx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1955) 	if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1956) 		uint32_t raw_index = phba->hbq_get[hbqno];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1957) 		uint32_t getidx = le32_to_cpu(raw_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1959) 		hbqp->local_hbqGetIdx = getidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1961) 		if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1962) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1963) 					"1802 HBQ %d: local_hbqGetIdx "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1964) 					"%u is > than hbqp->entry_count %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1965) 					hbqno, hbqp->local_hbqGetIdx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1966) 					hbqp->entry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1968) 			phba->link_state = LPFC_HBA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1969) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1970) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1972) 		if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1973) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1974) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1976) 	return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1977) 			hbqp->hbqPutIdx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1978) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1979) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1980) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1981)  * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1982)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1983)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1984)  * This function is called with no lock held to free all the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1985)  * hbq buffers while uninitializing the SLI interface. It also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1986)  * frees the HBQ buffers returned by the firmware but not yet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1987)  * processed by the upper layers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1988)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1989) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1990) lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1991) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1992) 	struct lpfc_dmabuf *dmabuf, *next_dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1993) 	struct hbq_dmabuf *hbq_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1994) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1995) 	int i, hbq_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1996) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1997) 	hbq_count = lpfc_sli_hbq_count();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1998) 	/* Return all memory used by all HBQs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1999) 	spin_lock_irqsave(&phba->hbalock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2000) 	for (i = 0; i < hbq_count; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2001) 		list_for_each_entry_safe(dmabuf, next_dmabuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2002) 				&phba->hbqs[i].hbq_buffer_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2003) 			hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2004) 			list_del(&hbq_buf->dbuf.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2005) 			(phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2006) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2007) 		phba->hbqs[i].buffer_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2008) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2010) 	/* Mark the HBQs not in use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2011) 	phba->hbq_in_use = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2012) 	spin_unlock_irqrestore(&phba->hbalock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2013) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2015) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2016)  * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2017)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2018)  * @hbqno: HBQ number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2019)  * @hbq_buf: Pointer to HBQ buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2020)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2021)  * This function is called with the hbalock held to post a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2022)  * hbq buffer to the firmware. If the function finds an empty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2023)  * slot in the HBQ, it will post the buffer. The function will return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2024)  * pointer to the hbq entry if it successfully post the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2025)  * else it will return NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2026)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2027) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2028) lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2029) 			 struct hbq_dmabuf *hbq_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2030) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2031) 	lockdep_assert_held(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2032) 	return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2033) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2035) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2036)  * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2037)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2038)  * @hbqno: HBQ number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2039)  * @hbq_buf: Pointer to HBQ buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2040)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2041)  * This function is called with the hbalock held to post a hbq buffer to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2042)  * firmware. If the function finds an empty slot in the HBQ, it will post the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2043)  * buffer and place it on the hbq_buffer_list. The function will return zero if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2044)  * it successfully post the buffer else it will return an error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2045)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2046) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2047) lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2048) 			    struct hbq_dmabuf *hbq_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2049) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2050) 	struct lpfc_hbq_entry *hbqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2051) 	dma_addr_t physaddr = hbq_buf->dbuf.phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2052) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2053) 	lockdep_assert_held(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2054) 	/* Get next HBQ entry slot to use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2055) 	hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2056) 	if (hbqe) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2057) 		struct hbq_s *hbqp = &phba->hbqs[hbqno];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2058) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2059) 		hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2060) 		hbqe->bde.addrLow  = le32_to_cpu(putPaddrLow(physaddr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2061) 		hbqe->bde.tus.f.bdeSize = hbq_buf->total_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2062) 		hbqe->bde.tus.f.bdeFlags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2063) 		hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2064) 		hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2065) 				/* Sync SLIM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2066) 		hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2067) 		writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2068) 				/* flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2069) 		readl(phba->hbq_put + hbqno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2070) 		list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2071) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2072) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2073) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2074) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2075) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2076) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2077)  * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2078)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2079)  * @hbqno: HBQ number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2080)  * @hbq_buf: Pointer to HBQ buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2081)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2082)  * This function is called with the hbalock held to post an RQE to the SLI4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2083)  * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2084)  * the hbq_buffer_list and return zero, otherwise it will return an error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2085)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2086) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2087) lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2088) 			    struct hbq_dmabuf *hbq_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2089) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2090) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2091) 	struct lpfc_rqe hrqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2092) 	struct lpfc_rqe drqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2093) 	struct lpfc_queue *hrq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2094) 	struct lpfc_queue *drq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2095) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2096) 	if (hbqno != LPFC_ELS_HBQ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2097) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2098) 	hrq = phba->sli4_hba.hdr_rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2099) 	drq = phba->sli4_hba.dat_rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2101) 	lockdep_assert_held(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2102) 	hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2103) 	hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2104) 	drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2105) 	drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2106) 	rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2107) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2108) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2109) 	hbq_buf->tag = (rc | (hbqno << 16));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2110) 	list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2111) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2114) /* HBQ for ELS and CT traffic. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2115) static struct lpfc_hbq_init lpfc_els_hbq = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2116) 	.rn = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2117) 	.entry_count = 256,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2118) 	.mask_count = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2119) 	.profile = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2120) 	.ring_mask = (1 << LPFC_ELS_RING),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2121) 	.buffer_count = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2122) 	.init_count = 40,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2123) 	.add_count = 40,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2124) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2126) /* Array of HBQs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2127) struct lpfc_hbq_init *lpfc_hbq_defs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2128) 	&lpfc_els_hbq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2129) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2131) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2132)  * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2133)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2134)  * @hbqno: HBQ number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2135)  * @count: Number of HBQ buffers to be posted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2136)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2137)  * This function is called with no lock held to post more hbq buffers to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2138)  * given HBQ. The function returns the number of HBQ buffers successfully
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2139)  * posted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2140)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2141) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2142) lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2144) 	uint32_t i, posted = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2145) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2146) 	struct hbq_dmabuf *hbq_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2147) 	LIST_HEAD(hbq_buf_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2148) 	if (!phba->hbqs[hbqno].hbq_alloc_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2149) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2151) 	if ((phba->hbqs[hbqno].buffer_count + count) >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2152) 	    lpfc_hbq_defs[hbqno]->entry_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2153) 		count = lpfc_hbq_defs[hbqno]->entry_count -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2154) 					phba->hbqs[hbqno].buffer_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2155) 	if (!count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2156) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2157) 	/* Allocate HBQ entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2158) 	for (i = 0; i < count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2159) 		hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2160) 		if (!hbq_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2161) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2162) 		list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2163) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2164) 	/* Check whether HBQ is still in use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2165) 	spin_lock_irqsave(&phba->hbalock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2166) 	if (!phba->hbq_in_use)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2167) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2168) 	while (!list_empty(&hbq_buf_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2169) 		list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2170) 				 dbuf.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2171) 		hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2172) 				      (hbqno << 16));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2173) 		if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2174) 			phba->hbqs[hbqno].buffer_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2175) 			posted++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2176) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2177) 			(phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2178) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2179) 	spin_unlock_irqrestore(&phba->hbalock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2180) 	return posted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2181) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2182) 	spin_unlock_irqrestore(&phba->hbalock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2183) 	while (!list_empty(&hbq_buf_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2184) 		list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2185) 				 dbuf.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2186) 		(phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2187) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2188) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2191) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2192)  * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2193)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2194)  * @qno: HBQ number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2195)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2196)  * This function posts more buffers to the HBQ. This function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2197)  * is called with no lock held. The function returns the number of HBQ entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2198)  * successfully allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2199)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2200) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2201) lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2203) 	if (phba->sli_rev == LPFC_SLI_REV4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2204) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2205) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2206) 		return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2207) 					 lpfc_hbq_defs[qno]->add_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2210) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2211)  * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2212)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2213)  * @qno:  HBQ queue number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2214)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2215)  * This function is called from SLI initialization code path with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2216)  * no lock held to post initial HBQ buffers to firmware. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2217)  * function returns the number of HBQ entries successfully allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2218)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2219) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2220) lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2222) 	if (phba->sli_rev == LPFC_SLI_REV4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2223) 		return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2224) 					lpfc_hbq_defs[qno]->entry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2225) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2226) 		return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2227) 					 lpfc_hbq_defs[qno]->init_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2230) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2231)  * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2232)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2233)  * This function removes the first hbq buffer on an hbq list and returns a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2234)  * pointer to that buffer. If it finds no buffers on the list it returns NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2235)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2236) static struct hbq_dmabuf *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2237) lpfc_sli_hbqbuf_get(struct list_head *rb_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2239) 	struct lpfc_dmabuf *d_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2241) 	list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2242) 	if (!d_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2243) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2244) 	return container_of(d_buf, struct hbq_dmabuf, dbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2247) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2248)  * lpfc_sli_rqbuf_get - Remove the first dma buffer off of an RQ list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2249)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2250)  * @hrq: HBQ number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2251)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2252)  * This function removes the first RQ buffer on an RQ buffer list and returns a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2253)  * pointer to that buffer. If it finds no buffers on the list it returns NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2254)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2255) static struct rqb_dmabuf *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2256) lpfc_sli_rqbuf_get(struct lpfc_hba *phba, struct lpfc_queue *hrq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2258) 	struct lpfc_dmabuf *h_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2259) 	struct lpfc_rqb *rqbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2261) 	rqbp = hrq->rqbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2262) 	list_remove_head(&rqbp->rqb_buffer_list, h_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2263) 			 struct lpfc_dmabuf, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2264) 	if (!h_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2265) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2266) 	rqbp->buffer_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2267) 	return container_of(h_buf, struct rqb_dmabuf, hbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2270) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2271)  * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2272)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2273)  * @tag: Tag of the hbq buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2274)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2275)  * This function searches for the hbq buffer associated with the given tag in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2276)  * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2277)  * otherwise it returns NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2278)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2279) static struct hbq_dmabuf *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2280) lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2282) 	struct lpfc_dmabuf *d_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2283) 	struct hbq_dmabuf *hbq_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2284) 	uint32_t hbqno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2286) 	hbqno = tag >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2287) 	if (hbqno >= LPFC_MAX_HBQS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2288) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2290) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2291) 	list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2292) 		hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2293) 		if (hbq_buf->tag == tag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2294) 			spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2295) 			return hbq_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2296) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2297) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2298) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2299) 	lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2300) 			"1803 Bad hbq tag. Data: x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2301) 			tag, phba->hbqs[tag >> 16].buffer_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2302) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2305) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2306)  * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2307)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2308)  * @hbq_buffer: Pointer to HBQ buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2309)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2310)  * This function is called with hbalock. This function gives back
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2311)  * the hbq buffer to firmware. If the HBQ does not have space to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2312)  * post the buffer, it will free the buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2313)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2314) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2315) lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2316) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2317) 	uint32_t hbqno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2319) 	if (hbq_buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2320) 		hbqno = hbq_buffer->tag >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2321) 		if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2322) 			(phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2323) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2326) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2327)  * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2328)  * @mbxCommand: mailbox command code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2329)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2330)  * This function is called by the mailbox event handler function to verify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2331)  * that the completed mailbox command is a legitimate mailbox command. If the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2332)  * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2333)  * and the mailbox event handler will take the HBA offline.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2334)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2335) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2336) lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2338) 	uint8_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2340) 	switch (mbxCommand) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2341) 	case MBX_LOAD_SM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2342) 	case MBX_READ_NV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2343) 	case MBX_WRITE_NV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2344) 	case MBX_WRITE_VPARMS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2345) 	case MBX_RUN_BIU_DIAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2346) 	case MBX_INIT_LINK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2347) 	case MBX_DOWN_LINK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2348) 	case MBX_CONFIG_LINK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2349) 	case MBX_CONFIG_RING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2350) 	case MBX_RESET_RING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2351) 	case MBX_READ_CONFIG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2352) 	case MBX_READ_RCONFIG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2353) 	case MBX_READ_SPARM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2354) 	case MBX_READ_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2355) 	case MBX_READ_RPI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2356) 	case MBX_READ_XRI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2357) 	case MBX_READ_REV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2358) 	case MBX_READ_LNK_STAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2359) 	case MBX_REG_LOGIN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2360) 	case MBX_UNREG_LOGIN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2361) 	case MBX_CLEAR_LA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2362) 	case MBX_DUMP_MEMORY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2363) 	case MBX_DUMP_CONTEXT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2364) 	case MBX_RUN_DIAGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2365) 	case MBX_RESTART:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2366) 	case MBX_UPDATE_CFG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2367) 	case MBX_DOWN_LOAD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2368) 	case MBX_DEL_LD_ENTRY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2369) 	case MBX_RUN_PROGRAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2370) 	case MBX_SET_MASK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2371) 	case MBX_SET_VARIABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2372) 	case MBX_UNREG_D_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2373) 	case MBX_KILL_BOARD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2374) 	case MBX_CONFIG_FARP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2375) 	case MBX_BEACON:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2376) 	case MBX_LOAD_AREA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2377) 	case MBX_RUN_BIU_DIAG64:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2378) 	case MBX_CONFIG_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2379) 	case MBX_READ_SPARM64:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2380) 	case MBX_READ_RPI64:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2381) 	case MBX_REG_LOGIN64:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2382) 	case MBX_READ_TOPOLOGY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2383) 	case MBX_WRITE_WWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2384) 	case MBX_SET_DEBUG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2385) 	case MBX_LOAD_EXP_ROM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2386) 	case MBX_ASYNCEVT_ENABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2387) 	case MBX_REG_VPI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2388) 	case MBX_UNREG_VPI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2389) 	case MBX_HEARTBEAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2390) 	case MBX_PORT_CAPABILITIES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2391) 	case MBX_PORT_IOV_CONTROL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2392) 	case MBX_SLI4_CONFIG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2393) 	case MBX_SLI4_REQ_FTRS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2394) 	case MBX_REG_FCFI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2395) 	case MBX_UNREG_FCFI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2396) 	case MBX_REG_VFI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2397) 	case MBX_UNREG_VFI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2398) 	case MBX_INIT_VPI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2399) 	case MBX_INIT_VFI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2400) 	case MBX_RESUME_RPI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2401) 	case MBX_READ_EVENT_LOG_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2402) 	case MBX_READ_EVENT_LOG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2403) 	case MBX_SECURITY_MGMT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2404) 	case MBX_AUTH_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2405) 	case MBX_ACCESS_VDATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2406) 		ret = mbxCommand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2407) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2408) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2409) 		ret = MBX_SHUTDOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2410) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2411) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2412) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2415) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2416)  * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2417)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2418)  * @pmboxq: Pointer to mailbox command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2419)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2420)  * This is completion handler function for mailbox commands issued from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2421)  * lpfc_sli_issue_mbox_wait function. This function is called by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2422)  * mailbox event handler function with no lock held. This function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2423)  * will wake up thread waiting on the wait queue pointed by context1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2424)  * of the mailbox.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2425)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2426) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2427) lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2429) 	unsigned long drvr_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2430) 	struct completion *pmbox_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2432) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2433) 	 * If pmbox_done is empty, the driver thread gave up waiting and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2434) 	 * continued running.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2435) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2436) 	pmboxq->mbox_flag |= LPFC_MBX_WAKE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2437) 	spin_lock_irqsave(&phba->hbalock, drvr_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2438) 	pmbox_done = (struct completion *)pmboxq->context3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2439) 	if (pmbox_done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2440) 		complete(pmbox_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2441) 	spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2442) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2445) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2446) __lpfc_sli_rpi_release(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2447) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2448) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2450) 	if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2451) 		lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2452) 		spin_lock_irqsave(&vport->phba->ndlp_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2453) 		ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2454) 		ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2455) 		spin_unlock_irqrestore(&vport->phba->ndlp_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2456) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2457) 	ndlp->nlp_flag &= ~NLP_UNREG_INP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2460) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2461)  * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2462)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2463)  * @pmb: Pointer to mailbox object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2464)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2465)  * This function is the default mailbox completion handler. It
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2466)  * frees the memory resources associated with the completed mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2467)  * command. If the completed command is a REG_LOGIN mailbox command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2468)  * this function will issue a UREG_LOGIN to re-claim the RPI.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2469)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2470) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2471) lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2472) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2473) 	struct lpfc_vport  *vport = pmb->vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2474) 	struct lpfc_dmabuf *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2475) 	struct lpfc_nodelist *ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2476) 	struct Scsi_Host *shost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2477) 	uint16_t rpi, vpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2478) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2480) 	mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2482) 	if (mp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2483) 		lpfc_mbuf_free(phba, mp->virt, mp->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2484) 		kfree(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2485) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2487) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2488) 	 * If a REG_LOGIN succeeded  after node is destroyed or node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2489) 	 * is in re-discovery driver need to cleanup the RPI.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2490) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2491) 	if (!(phba->pport->load_flag & FC_UNLOADING) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2492) 	    pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2493) 	    !pmb->u.mb.mbxStatus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2494) 		rpi = pmb->u.mb.un.varWords[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2495) 		vpi = pmb->u.mb.un.varRegLogin.vpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2496) 		if (phba->sli_rev == LPFC_SLI_REV4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2497) 			vpi -= phba->sli4_hba.max_cfg_param.vpi_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2498) 		lpfc_unreg_login(phba, vpi, rpi, pmb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2499) 		pmb->vport = vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2500) 		pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2501) 		rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2502) 		if (rc != MBX_NOT_FINISHED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2503) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2504) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2506) 	if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2507) 		!(phba->pport->load_flag & FC_UNLOADING) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2508) 		!pmb->u.mb.mbxStatus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2509) 		shost = lpfc_shost_from_vport(vport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2510) 		spin_lock_irq(shost->host_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2511) 		vport->vpi_state |= LPFC_VPI_REGISTERED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2512) 		vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2513) 		spin_unlock_irq(shost->host_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2514) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2516) 	if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2517) 		ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2518) 		lpfc_nlp_put(ndlp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2519) 		pmb->ctx_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2520) 		pmb->ctx_ndlp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2521) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2523) 	if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2524) 		ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2526) 		/* Check to see if there are any deferred events to process */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2527) 		if (ndlp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2528) 			lpfc_printf_vlog(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2529) 				vport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2530) 				KERN_INFO, LOG_MBOX | LOG_DISCOVERY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2531) 				"1438 UNREG cmpl deferred mbox x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2532) 				"on NPort x%x Data: x%x x%x %px\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2533) 				ndlp->nlp_rpi, ndlp->nlp_DID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2534) 				ndlp->nlp_flag, ndlp->nlp_defer_did, ndlp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2536) 			if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2537) 			    (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2538) 				ndlp->nlp_flag &= ~NLP_UNREG_INP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2539) 				ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2540) 				lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2541) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2542) 				__lpfc_sli_rpi_release(vport, ndlp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2543) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2544) 			if (vport->load_flag & FC_UNLOADING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2545) 				lpfc_nlp_put(ndlp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2546) 			pmb->ctx_ndlp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2547) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2548) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2550) 	/* Check security permission status on INIT_LINK mailbox command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2551) 	if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2552) 	    (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2553) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2554) 				"2860 SLI authentication is required "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2555) 				"for INIT_LINK but has not done yet\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2557) 	if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2558) 		lpfc_sli4_mbox_cmd_free(phba, pmb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2559) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2560) 		mempool_free(pmb, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2561) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2562)  /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2563)  * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2564)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2565)  * @pmb: Pointer to mailbox object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2566)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2567)  * This function is the unreg rpi mailbox completion handler. It
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2568)  * frees the memory resources associated with the completed mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2569)  * command. An additional refrenece is put on the ndlp to prevent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2570)  * lpfc_nlp_release from freeing the rpi bit in the bitmask before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2571)  * the unreg mailbox command completes, this routine puts the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2572)  * reference back.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2573)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2574)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2575) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2576) lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2577) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2578) 	struct lpfc_vport  *vport = pmb->vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2579) 	struct lpfc_nodelist *ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2581) 	ndlp = pmb->ctx_ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2582) 	if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2583) 		if (phba->sli_rev == LPFC_SLI_REV4 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2584) 		    (bf_get(lpfc_sli_intf_if_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2585) 		     &phba->sli4_hba.sli_intf) >=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2586) 		     LPFC_SLI_INTF_IF_TYPE_2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2587) 			if (ndlp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2588) 				lpfc_printf_vlog(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2589) 					vport, KERN_INFO, LOG_MBOX | LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2590) 					 "0010 UNREG_LOGIN vpi:%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2591) 					 "rpi:%x DID:%x defer x%x flg x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2592) 					 "map:%x %px\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2593) 					 vport->vpi, ndlp->nlp_rpi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2594) 					 ndlp->nlp_DID, ndlp->nlp_defer_did,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2595) 					 ndlp->nlp_flag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2596) 					 ndlp->nlp_usg_map, ndlp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2597) 				ndlp->nlp_flag &= ~NLP_LOGO_ACC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2598) 				lpfc_nlp_put(ndlp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2600) 				/* Check to see if there are any deferred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2601) 				 * events to process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2602) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2603) 				if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2604) 				    (ndlp->nlp_defer_did !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2605) 				    NLP_EVT_NOTHING_PENDING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2606) 					lpfc_printf_vlog(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2607) 						vport, KERN_INFO, LOG_DISCOVERY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2608) 						"4111 UNREG cmpl deferred "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2609) 						"clr x%x on "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2610) 						"NPort x%x Data: x%x x%px\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2611) 						ndlp->nlp_rpi, ndlp->nlp_DID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2612) 						ndlp->nlp_defer_did, ndlp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2613) 					ndlp->nlp_flag &= ~NLP_UNREG_INP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2614) 					ndlp->nlp_defer_did =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2615) 						NLP_EVT_NOTHING_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2616) 					lpfc_issue_els_plogi(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2617) 						vport, ndlp->nlp_DID, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2618) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2619) 					__lpfc_sli_rpi_release(vport, ndlp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2620) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2621) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2622) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2623) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2625) 	mempool_free(pmb, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2626) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2628) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2629)  * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2630)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2631)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2632)  * This function is called with no lock held. This function processes all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2633)  * the completed mailbox commands and gives it to upper layers. The interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2634)  * service routine processes mailbox completion interrupt and adds completed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2635)  * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2636)  * Worker thread call lpfc_sli_handle_mb_event, which will return the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2637)  * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2638)  * function returns the mailbox commands to the upper layer by calling the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2639)  * completion handler function of each mailbox.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2640)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2641) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2642) lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2643) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2644) 	MAILBOX_t *pmbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2645) 	LPFC_MBOXQ_t *pmb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2646) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2647) 	LIST_HEAD(cmplq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2649) 	phba->sli.slistat.mbox_event++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2651) 	/* Get all completed mailboxe buffers into the cmplq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2652) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2653) 	list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2654) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2656) 	/* Get a Mailbox buffer to setup mailbox commands for callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2657) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2658) 		list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2659) 		if (pmb == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2660) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2662) 		pmbox = &pmb->u.mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2664) 		if (pmbox->mbxCommand != MBX_HEARTBEAT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2665) 			if (pmb->vport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2666) 				lpfc_debugfs_disc_trc(pmb->vport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2667) 					LPFC_DISC_TRC_MBOX_VPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2668) 					"MBOX cmpl vport: cmd:x%x mb:x%x x%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2669) 					(uint32_t)pmbox->mbxCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2670) 					pmbox->un.varWords[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2671) 					pmbox->un.varWords[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2672) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2673) 			else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2674) 				lpfc_debugfs_disc_trc(phba->pport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2675) 					LPFC_DISC_TRC_MBOX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2676) 					"MBOX cmpl:       cmd:x%x mb:x%x x%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2677) 					(uint32_t)pmbox->mbxCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2678) 					pmbox->un.varWords[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2679) 					pmbox->un.varWords[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2680) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2681) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2683) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2684) 		 * It is a fatal error if unknown mbox command completion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2685) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2686) 		if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2687) 		    MBX_SHUTDOWN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2688) 			/* Unknown mailbox command compl */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2689) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2690) 					"(%d):0323 Unknown Mailbox command "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2691) 					"x%x (x%x/x%x) Cmpl\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2692) 					pmb->vport ? pmb->vport->vpi :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2693) 					LPFC_VPORT_UNKNOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2694) 					pmbox->mbxCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2695) 					lpfc_sli_config_mbox_subsys_get(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2696) 									pmb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2697) 					lpfc_sli_config_mbox_opcode_get(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2698) 									pmb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2699) 			phba->link_state = LPFC_HBA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2700) 			phba->work_hs = HS_FFER3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2701) 			lpfc_handle_eratt(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2702) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2703) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2705) 		if (pmbox->mbxStatus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2706) 			phba->sli.slistat.mbox_stat_err++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2707) 			if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2708) 				/* Mbox cmd cmpl error - RETRYing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2709) 				lpfc_printf_log(phba, KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2710) 					LOG_MBOX | LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2711) 					"(%d):0305 Mbox cmd cmpl "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2712) 					"error - RETRYing Data: x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2713) 					"(x%x/x%x) x%x x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2714) 					pmb->vport ? pmb->vport->vpi :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2715) 					LPFC_VPORT_UNKNOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2716) 					pmbox->mbxCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2717) 					lpfc_sli_config_mbox_subsys_get(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2718) 									pmb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2719) 					lpfc_sli_config_mbox_opcode_get(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2720) 									pmb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2721) 					pmbox->mbxStatus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2722) 					pmbox->un.varWords[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2723) 					pmb->vport ? pmb->vport->port_state :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2724) 					LPFC_VPORT_UNKNOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2725) 				pmbox->mbxStatus = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2726) 				pmbox->mbxOwner = OWN_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2727) 				rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2728) 				if (rc != MBX_NOT_FINISHED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2729) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2730) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2731) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2733) 		/* Mailbox cmd <cmd> Cmpl <cmpl> */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2734) 		lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2735) 				"(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl %ps "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2736) 				"Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2737) 				"x%x x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2738) 				pmb->vport ? pmb->vport->vpi : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2739) 				pmbox->mbxCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2740) 				lpfc_sli_config_mbox_subsys_get(phba, pmb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2741) 				lpfc_sli_config_mbox_opcode_get(phba, pmb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2742) 				pmb->mbox_cmpl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2743) 				*((uint32_t *) pmbox),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2744) 				pmbox->un.varWords[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2745) 				pmbox->un.varWords[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2746) 				pmbox->un.varWords[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2747) 				pmbox->un.varWords[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2748) 				pmbox->un.varWords[4],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2749) 				pmbox->un.varWords[5],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2750) 				pmbox->un.varWords[6],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2751) 				pmbox->un.varWords[7],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2752) 				pmbox->un.varWords[8],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2753) 				pmbox->un.varWords[9],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2754) 				pmbox->un.varWords[10]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2756) 		if (pmb->mbox_cmpl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2757) 			pmb->mbox_cmpl(phba,pmb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2758) 	} while (1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2759) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2760) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2762) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2763)  * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2764)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2765)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2766)  * @tag: buffer tag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2767)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2768)  * This function is called with no lock held. When QUE_BUFTAG_BIT bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2769)  * is set in the tag the buffer is posted for a particular exchange,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2770)  * the function will return the buffer without replacing the buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2771)  * If the buffer is for unsolicited ELS or CT traffic, this function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2772)  * returns the buffer and also posts another buffer to the firmware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2773)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2774) static struct lpfc_dmabuf *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2775) lpfc_sli_get_buff(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2776) 		  struct lpfc_sli_ring *pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2777) 		  uint32_t tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2778) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2779) 	struct hbq_dmabuf *hbq_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2781) 	if (tag & QUE_BUFTAG_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2782) 		return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2783) 	hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2784) 	if (!hbq_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2785) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2786) 	return &hbq_entry->dbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2787) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2789) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2790)  * lpfc_nvme_unsol_ls_handler - Process an unsolicited event data buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2791)  *                              containing a NVME LS request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2792)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2793)  * @piocb: pointer to the iocbq struct representing the sequence starting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2794)  *        frame.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2795)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2796)  * This routine initially validates the NVME LS, validates there is a login
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2797)  * with the port that sent the LS, and then calls the appropriate nvme host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2798)  * or target LS request handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2799)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2800) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2801) lpfc_nvme_unsol_ls_handler(struct lpfc_hba *phba, struct lpfc_iocbq *piocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2802) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2803) 	struct lpfc_nodelist *ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2804) 	struct lpfc_dmabuf *d_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2805) 	struct hbq_dmabuf *nvmebuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2806) 	struct fc_frame_header *fc_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2807) 	struct lpfc_async_xchg_ctx *axchg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2808) 	char *failwhy = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2809) 	uint32_t oxid, sid, did, fctl, size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2810) 	int ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2812) 	d_buf = piocb->context2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2814) 	nvmebuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2815) 	fc_hdr = nvmebuf->hbuf.virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2816) 	oxid = be16_to_cpu(fc_hdr->fh_ox_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2817) 	sid = sli4_sid_from_fc_hdr(fc_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2818) 	did = sli4_did_from_fc_hdr(fc_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2819) 	fctl = (fc_hdr->fh_f_ctl[0] << 16 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2820) 		fc_hdr->fh_f_ctl[1] << 8 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2821) 		fc_hdr->fh_f_ctl[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2822) 	size = bf_get(lpfc_rcqe_length, &nvmebuf->cq_event.cqe.rcqe_cmpl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2823) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2824) 	lpfc_nvmeio_data(phba, "NVME LS    RCV: xri x%x sz %d from %06x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2825) 			 oxid, size, sid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2827) 	if (phba->pport->load_flag & FC_UNLOADING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2828) 		failwhy = "Driver Unloading";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2829) 	} else if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2830) 		failwhy = "NVME FC4 Disabled";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2831) 	} else if (!phba->nvmet_support && !phba->pport->localport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2832) 		failwhy = "No Localport";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2833) 	} else if (phba->nvmet_support && !phba->targetport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2834) 		failwhy = "No Targetport";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2835) 	} else if (unlikely(fc_hdr->fh_r_ctl != FC_RCTL_ELS4_REQ)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2836) 		failwhy = "Bad NVME LS R_CTL";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2837) 	} else if (unlikely((fctl & 0x00FF0000) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2838) 			(FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2839) 		failwhy = "Bad NVME LS F_CTL";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2840) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2841) 		axchg = kzalloc(sizeof(*axchg), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2842) 		if (!axchg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2843) 			failwhy = "No CTX memory";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2844) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2846) 	if (unlikely(failwhy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2847) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2848) 				"6154 Drop NVME LS: SID %06X OXID x%X: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2849) 				sid, oxid, failwhy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2850) 		goto out_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2851) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2853) 	/* validate the source of the LS is logged in */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2854) 	ndlp = lpfc_findnode_did(phba->pport, sid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2855) 	if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2856) 	    ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2857) 	     (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2858) 		lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2859) 				"6216 NVME Unsol rcv: No ndlp: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2860) 				"NPort_ID x%x oxid x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2861) 				sid, oxid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2862) 		goto out_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2863) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2865) 	axchg->phba = phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2866) 	axchg->ndlp = ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2867) 	axchg->size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2868) 	axchg->oxid = oxid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2869) 	axchg->sid = sid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2870) 	axchg->wqeq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2871) 	axchg->state = LPFC_NVME_STE_LS_RCV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2872) 	axchg->entry_cnt = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2873) 	axchg->rqb_buffer = (void *)nvmebuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2874) 	axchg->hdwq = &phba->sli4_hba.hdwq[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2875) 	axchg->payload = nvmebuf->dbuf.virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2876) 	INIT_LIST_HEAD(&axchg->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2878) 	if (phba->nvmet_support)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2879) 		ret = lpfc_nvmet_handle_lsreq(phba, axchg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2880) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2881) 		ret = lpfc_nvme_handle_lsreq(phba, axchg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2883) 	/* if zero, LS was successfully handled. If non-zero, LS not handled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2884) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2885) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2887) 	lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2888) 			"6155 Drop NVME LS from DID %06X: SID %06X OXID x%X "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2889) 			"NVMe%s handler failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2890) 			did, sid, oxid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2891) 			(phba->nvmet_support) ? "T" : "I", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2893) out_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2895) 	/* recycle receive buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2896) 	lpfc_in_buf_free(phba, &nvmebuf->dbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2898) 	/* If start of new exchange, abort it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2899) 	if (axchg && (fctl & FC_FC_FIRST_SEQ && !(fctl & FC_FC_EX_CTX)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2900) 		ret = lpfc_nvme_unsol_ls_issue_abort(phba, axchg, sid, oxid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2902) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2903) 		kfree(axchg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2904) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2906) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2907)  * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2908)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2909)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2910)  * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2911)  * @fch_r_ctl: the r_ctl for the first frame of the sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2912)  * @fch_type: the type for the first frame of the sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2913)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2914)  * This function is called with no lock held. This function uses the r_ctl and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2915)  * type of the received sequence to find the correct callback function to call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2916)  * to process the sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2917)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2918) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2919) lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2920) 			 struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2921) 			 uint32_t fch_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2922) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2923) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2925) 	switch (fch_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2926) 	case FC_TYPE_NVME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2927) 		lpfc_nvme_unsol_ls_handler(phba, saveq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2928) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2929) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2930) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2931) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2933) 	/* unSolicited Responses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2934) 	if (pring->prt[0].profile) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2935) 		if (pring->prt[0].lpfc_sli_rcv_unsol_event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2936) 			(pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2937) 									saveq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2938) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2939) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2940) 	/* We must search, based on rctl / type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2941) 	   for the right routine */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2942) 	for (i = 0; i < pring->num_mask; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2943) 		if ((pring->prt[i].rctl == fch_r_ctl) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2944) 		    (pring->prt[i].type == fch_type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2945) 			if (pring->prt[i].lpfc_sli_rcv_unsol_event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2946) 				(pring->prt[i].lpfc_sli_rcv_unsol_event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2947) 						(phba, pring, saveq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2948) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2949) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2950) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2951) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2952) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2953) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2954) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2955)  * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2956)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2957)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2958)  * @saveq: Pointer to the unsolicited iocb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2959)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2960)  * This function is called with no lock held by the ring event handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2961)  * when there is an unsolicited iocb posted to the response ring by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2962)  * firmware. This function gets the buffer associated with the iocbs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2963)  * and calls the event handler for the ring. This function handles both
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2964)  * qring buffers and hbq buffers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2965)  * When the function returns 1 the caller can free the iocb object otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2966)  * upper layer functions will free the iocb objects.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2967)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2968) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2969) lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2970) 			    struct lpfc_iocbq *saveq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2971) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2972) 	IOCB_t           * irsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2973) 	WORD5            * w5p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2974) 	uint32_t           Rctl, Type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2975) 	struct lpfc_iocbq *iocbq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2976) 	struct lpfc_dmabuf *dmzbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2977) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2978) 	irsp = &(saveq->iocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2979) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2980) 	if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2981) 		if (pring->lpfc_sli_rcv_async_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2982) 			pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2983) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2984) 			lpfc_printf_log(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2985) 					KERN_WARNING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2986) 					LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2987) 					"0316 Ring %d handler: unexpected "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2988) 					"ASYNC_STATUS iocb received evt_code "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2989) 					"0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2990) 					pring->ringno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2991) 					irsp->un.asyncstat.evt_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2992) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2993) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2994) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2995) 	if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2996) 		(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2997) 		if (irsp->ulpBdeCount > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2998) 			dmzbuf = lpfc_sli_get_buff(phba, pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2999) 					irsp->un.ulpWord[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3000) 			lpfc_in_buf_free(phba, dmzbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3001) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3003) 		if (irsp->ulpBdeCount > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3004) 			dmzbuf = lpfc_sli_get_buff(phba, pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3005) 					irsp->unsli3.sli3Words[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3006) 			lpfc_in_buf_free(phba, dmzbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3007) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3008) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3009) 		if (irsp->ulpBdeCount > 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3010) 			dmzbuf = lpfc_sli_get_buff(phba, pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3011) 				irsp->unsli3.sli3Words[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3012) 			lpfc_in_buf_free(phba, dmzbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3013) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3015) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3016) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3017) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3018) 	if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3019) 		if (irsp->ulpBdeCount != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3020) 			saveq->context2 = lpfc_sli_get_buff(phba, pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3021) 						irsp->un.ulpWord[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3022) 			if (!saveq->context2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3023) 				lpfc_printf_log(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3024) 					KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3025) 					LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3026) 					"0341 Ring %d Cannot find buffer for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3027) 					"an unsolicited iocb. tag 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3028) 					pring->ringno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3029) 					irsp->un.ulpWord[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3030) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3031) 		if (irsp->ulpBdeCount == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3032) 			saveq->context3 = lpfc_sli_get_buff(phba, pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3033) 						irsp->unsli3.sli3Words[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3034) 			if (!saveq->context3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3035) 				lpfc_printf_log(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3036) 					KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3037) 					LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3038) 					"0342 Ring %d Cannot find buffer for an"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3039) 					" unsolicited iocb. tag 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3040) 					pring->ringno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3041) 					irsp->unsli3.sli3Words[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3042) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3043) 		list_for_each_entry(iocbq, &saveq->list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3044) 			irsp = &(iocbq->iocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3045) 			if (irsp->ulpBdeCount != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3046) 				iocbq->context2 = lpfc_sli_get_buff(phba, pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3047) 							irsp->un.ulpWord[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3048) 				if (!iocbq->context2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3049) 					lpfc_printf_log(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3050) 						KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3051) 						LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3052) 						"0343 Ring %d Cannot find "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3053) 						"buffer for an unsolicited iocb"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3054) 						". tag 0x%x\n", pring->ringno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3055) 						irsp->un.ulpWord[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3056) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3057) 			if (irsp->ulpBdeCount == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3058) 				iocbq->context3 = lpfc_sli_get_buff(phba, pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3059) 						irsp->unsli3.sli3Words[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3060) 				if (!iocbq->context3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3061) 					lpfc_printf_log(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3062) 						KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3063) 						LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3064) 						"0344 Ring %d Cannot find "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3065) 						"buffer for an unsolicited "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3066) 						"iocb. tag 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3067) 						pring->ringno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3068) 						irsp->unsli3.sli3Words[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3069) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3070) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3071) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3072) 	if (irsp->ulpBdeCount != 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3073) 	    (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3074) 	     irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3075) 		int found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3077) 		/* search continue save q for same XRI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3078) 		list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3079) 			if (iocbq->iocb.unsli3.rcvsli3.ox_id ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3080) 				saveq->iocb.unsli3.rcvsli3.ox_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3081) 				list_add_tail(&saveq->list, &iocbq->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3082) 				found = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3083) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3084) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3085) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3086) 		if (!found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3087) 			list_add_tail(&saveq->clist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3088) 				      &pring->iocb_continue_saveq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3089) 		if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3090) 			list_del_init(&iocbq->clist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3091) 			saveq = iocbq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3092) 			irsp = &(saveq->iocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3093) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3094) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3095) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3096) 	if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3097) 	    (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3098) 	    (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3099) 		Rctl = FC_RCTL_ELS_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3100) 		Type = FC_TYPE_ELS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3101) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3102) 		w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3103) 		Rctl = w5p->hcsw.Rctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3104) 		Type = w5p->hcsw.Type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3106) 		/* Firmware Workaround */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3107) 		if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3108) 			(irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3109) 			 irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3110) 			Rctl = FC_RCTL_ELS_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3111) 			Type = FC_TYPE_ELS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3112) 			w5p->hcsw.Rctl = Rctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3113) 			w5p->hcsw.Type = Type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3114) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3115) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3117) 	if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3118) 		lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3119) 				"0313 Ring %d handler: unexpected Rctl x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3120) 				"Type x%x received\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3121) 				pring->ringno, Rctl, Type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3123) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3126) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3127)  * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3128)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3129)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3130)  * @prspiocb: Pointer to response iocb object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3131)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3132)  * This function looks up the iocb_lookup table to get the command iocb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3133)  * corresponding to the given response iocb using the iotag of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3134)  * response iocb. The driver calls this function with the hbalock held
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3135)  * for SLI3 ports or the ring lock held for SLI4 ports.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3136)  * This function returns the command iocb object if it finds the command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3137)  * iocb else returns NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3138)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3139) static struct lpfc_iocbq *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3140) lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3141) 		      struct lpfc_sli_ring *pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3142) 		      struct lpfc_iocbq *prspiocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3144) 	struct lpfc_iocbq *cmd_iocb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3145) 	uint16_t iotag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3146) 	spinlock_t *temp_lock = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3147) 	unsigned long iflag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3149) 	if (phba->sli_rev == LPFC_SLI_REV4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3150) 		temp_lock = &pring->ring_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3151) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3152) 		temp_lock = &phba->hbalock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3154) 	spin_lock_irqsave(temp_lock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3155) 	iotag = prspiocb->iocb.ulpIoTag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3157) 	if (iotag != 0 && iotag <= phba->sli.last_iotag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3158) 		cmd_iocb = phba->sli.iocbq_lookup[iotag];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3159) 		if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3160) 			/* remove from txcmpl queue list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3161) 			list_del_init(&cmd_iocb->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3162) 			cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3163) 			pring->txcmplq_cnt--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3164) 			spin_unlock_irqrestore(temp_lock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3165) 			return cmd_iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3166) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3167) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3169) 	spin_unlock_irqrestore(temp_lock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3170) 	lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3171) 			"0317 iotag x%x is out of "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3172) 			"range: max iotag x%x wd0 x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3173) 			iotag, phba->sli.last_iotag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3174) 			*(((uint32_t *) &prspiocb->iocb) + 7));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3175) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3178) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3179)  * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3180)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3181)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3182)  * @iotag: IOCB tag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3183)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3184)  * This function looks up the iocb_lookup table to get the command iocb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3185)  * corresponding to the given iotag. The driver calls this function with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3186)  * the ring lock held because this function is an SLI4 port only helper.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3187)  * This function returns the command iocb object if it finds the command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3188)  * iocb else returns NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3189)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3190) static struct lpfc_iocbq *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3191) lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3192) 			     struct lpfc_sli_ring *pring, uint16_t iotag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3194) 	struct lpfc_iocbq *cmd_iocb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3195) 	spinlock_t *temp_lock = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3196) 	unsigned long iflag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3198) 	if (phba->sli_rev == LPFC_SLI_REV4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3199) 		temp_lock = &pring->ring_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3200) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3201) 		temp_lock = &phba->hbalock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3203) 	spin_lock_irqsave(temp_lock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3204) 	if (iotag != 0 && iotag <= phba->sli.last_iotag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3205) 		cmd_iocb = phba->sli.iocbq_lookup[iotag];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3206) 		if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3207) 			/* remove from txcmpl queue list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3208) 			list_del_init(&cmd_iocb->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3209) 			cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3210) 			pring->txcmplq_cnt--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3211) 			spin_unlock_irqrestore(temp_lock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3212) 			return cmd_iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3213) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3214) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3216) 	spin_unlock_irqrestore(temp_lock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3217) 	lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3218) 			"0372 iotag x%x lookup error: max iotag (x%x) "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3219) 			"iocb_flag x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3220) 			iotag, phba->sli.last_iotag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3221) 			cmd_iocb ? cmd_iocb->iocb_flag : 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3222) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3225) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3226)  * lpfc_sli_process_sol_iocb - process solicited iocb completion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3227)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3228)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3229)  * @saveq: Pointer to the response iocb to be processed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3230)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3231)  * This function is called by the ring event handler for non-fcp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3232)  * rings when there is a new response iocb in the response ring.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3233)  * The caller is not required to hold any locks. This function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3234)  * gets the command iocb associated with the response iocb and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3235)  * calls the completion handler for the command iocb. If there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3236)  * is no completion handler, the function will free the resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3237)  * associated with command iocb. If the response iocb is for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3238)  * an already aborted command iocb, the status of the completion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3239)  * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3240)  * This function always returns 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3241)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3242) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3243) lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3244) 			  struct lpfc_iocbq *saveq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3246) 	struct lpfc_iocbq *cmdiocbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3247) 	int rc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3248) 	unsigned long iflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3250) 	cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3251) 	if (cmdiocbp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3252) 		if (cmdiocbp->iocb_cmpl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3253) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3254) 			 * If an ELS command failed send an event to mgmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3255) 			 * application.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3256) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3257) 			if (saveq->iocb.ulpStatus &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3258) 			     (pring->ringno == LPFC_ELS_RING) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3259) 			     (cmdiocbp->iocb.ulpCommand ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3260) 				CMD_ELS_REQUEST64_CR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3261) 				lpfc_send_els_failure_event(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3262) 					cmdiocbp, saveq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3264) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3265) 			 * Post all ELS completions to the worker thread.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3266) 			 * All other are passed to the completion callback.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3267) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3268) 			if (pring->ringno == LPFC_ELS_RING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3269) 				if ((phba->sli_rev < LPFC_SLI_REV4) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3270) 				    (cmdiocbp->iocb_flag &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3271) 							LPFC_DRIVER_ABORTED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3272) 					spin_lock_irqsave(&phba->hbalock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3273) 							  iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3274) 					cmdiocbp->iocb_flag &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3275) 						~LPFC_DRIVER_ABORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3276) 					spin_unlock_irqrestore(&phba->hbalock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3277) 							       iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3278) 					saveq->iocb.ulpStatus =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3279) 						IOSTAT_LOCAL_REJECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3280) 					saveq->iocb.un.ulpWord[4] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3281) 						IOERR_SLI_ABORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3283) 					/* Firmware could still be in progress
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3284) 					 * of DMAing payload, so don't free data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3285) 					 * buffer till after a hbeat.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3286) 					 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3287) 					spin_lock_irqsave(&phba->hbalock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3288) 							  iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3289) 					saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3290) 					spin_unlock_irqrestore(&phba->hbalock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3291) 							       iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3292) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3293) 				if (phba->sli_rev == LPFC_SLI_REV4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3294) 					if (saveq->iocb_flag &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3295) 					    LPFC_EXCHANGE_BUSY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3296) 						/* Set cmdiocb flag for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3297) 						 * exchange busy so sgl (xri)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3298) 						 * will not be released until
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3299) 						 * the abort xri is received
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3300) 						 * from hba.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3301) 						 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3302) 						spin_lock_irqsave(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3303) 							&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3304) 						cmdiocbp->iocb_flag |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3305) 							LPFC_EXCHANGE_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3306) 						spin_unlock_irqrestore(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3307) 							&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3308) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3309) 					if (cmdiocbp->iocb_flag &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3310) 					    LPFC_DRIVER_ABORTED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3311) 						/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3312) 						 * Clear LPFC_DRIVER_ABORTED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3313) 						 * bit in case it was driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3314) 						 * initiated abort.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3315) 						 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3316) 						spin_lock_irqsave(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3317) 							&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3318) 						cmdiocbp->iocb_flag &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3319) 							~LPFC_DRIVER_ABORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3320) 						spin_unlock_irqrestore(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3321) 							&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3322) 						cmdiocbp->iocb.ulpStatus =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3323) 							IOSTAT_LOCAL_REJECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3324) 						cmdiocbp->iocb.un.ulpWord[4] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3325) 							IOERR_ABORT_REQUESTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3326) 						/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3327) 						 * For SLI4, irsiocb contains
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3328) 						 * NO_XRI in sli_xritag, it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3329) 						 * shall not affect releasing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3330) 						 * sgl (xri) process.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3331) 						 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3332) 						saveq->iocb.ulpStatus =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3333) 							IOSTAT_LOCAL_REJECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3334) 						saveq->iocb.un.ulpWord[4] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3335) 							IOERR_SLI_ABORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3336) 						spin_lock_irqsave(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3337) 							&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3338) 						saveq->iocb_flag |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3339) 							LPFC_DELAY_MEM_FREE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3340) 						spin_unlock_irqrestore(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3341) 							&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3342) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3343) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3344) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3345) 			(cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3346) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3347) 			lpfc_sli_release_iocbq(phba, cmdiocbp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3348) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3349) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3350) 		 * Unknown initiating command based on the response iotag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3351) 		 * This could be the case on the ELS ring because of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3352) 		 * lpfc_els_abort().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3353) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3354) 		if (pring->ringno != LPFC_ELS_RING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3355) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3356) 			 * Ring <ringno> handler: unexpected completion IoTag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3357) 			 * <IoTag>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3358) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3359) 			lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3360) 					 "0322 Ring %d handler: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3361) 					 "unexpected completion IoTag x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3362) 					 "Data: x%x x%x x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3363) 					 pring->ringno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3364) 					 saveq->iocb.ulpIoTag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3365) 					 saveq->iocb.ulpStatus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3366) 					 saveq->iocb.un.ulpWord[4],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3367) 					 saveq->iocb.ulpCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3368) 					 saveq->iocb.ulpContext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3369) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3370) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3372) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3375) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3376)  * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3377)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3378)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3379)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3380)  * This function is called from the iocb ring event handlers when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3381)  * put pointer is ahead of the get pointer for a ring. This function signal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3382)  * an error attention condition to the worker thread and the worker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3383)  * thread will transition the HBA to offline state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3384)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3385) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3386) lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3388) 	struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3389) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3390) 	 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3391) 	 * rsp ring <portRspMax>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3392) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3393) 	lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3394) 			"0312 Ring %d handler: portRspPut %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3395) 			"is bigger than rsp ring %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3396) 			pring->ringno, le32_to_cpu(pgp->rspPutInx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3397) 			pring->sli.sli3.numRiocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3399) 	phba->link_state = LPFC_HBA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3401) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3402) 	 * All error attention handlers are posted to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3403) 	 * worker thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3404) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3405) 	phba->work_ha |= HA_ERATT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3406) 	phba->work_hs = HS_FFER3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3408) 	lpfc_worker_wake_up(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3410) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3413) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3414)  * lpfc_poll_eratt - Error attention polling timer timeout handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3415)  * @t: Context to fetch pointer to address of HBA context object from.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3416)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3417)  * This function is invoked by the Error Attention polling timer when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3418)  * timer times out. It will check the SLI Error Attention register for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3419)  * possible attention events. If so, it will post an Error Attention event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3420)  * and wake up worker thread to process it. Otherwise, it will set up the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3421)  * Error Attention polling timer for the next poll.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3422)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3423) void lpfc_poll_eratt(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3425) 	struct lpfc_hba *phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3426) 	uint32_t eratt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3427) 	uint64_t sli_intr, cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3429) 	phba = from_timer(phba, t, eratt_poll);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3431) 	/* Here we will also keep track of interrupts per sec of the hba */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3432) 	sli_intr = phba->sli.slistat.sli_intr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3434) 	if (phba->sli.slistat.sli_prev_intr > sli_intr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3435) 		cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3436) 			sli_intr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3437) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3438) 		cnt = (sli_intr - phba->sli.slistat.sli_prev_intr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3440) 	/* 64-bit integer division not supported on 32-bit x86 - use do_div */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3441) 	do_div(cnt, phba->eratt_poll_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3442) 	phba->sli.slistat.sli_ips = cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3444) 	phba->sli.slistat.sli_prev_intr = sli_intr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3446) 	/* Check chip HA register for error event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3447) 	eratt = lpfc_sli_check_eratt(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3449) 	if (eratt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3450) 		/* Tell the worker thread there is work to do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3451) 		lpfc_worker_wake_up(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3452) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3453) 		/* Restart the timer for next eratt poll */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3454) 		mod_timer(&phba->eratt_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3455) 			  jiffies +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3456) 			  msecs_to_jiffies(1000 * phba->eratt_poll_interval));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3457) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3461) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3462)  * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3463)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3464)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3465)  * @mask: Host attention register mask for this ring.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3466)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3467)  * This function is called from the interrupt context when there is a ring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3468)  * event for the fcp ring. The caller does not hold any lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3469)  * The function processes each response iocb in the response ring until it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3470)  * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3471)  * LE bit set. The function will call the completion handler of the command iocb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3472)  * if the response iocb indicates a completion for a command iocb or it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3473)  * an abort completion. The function will call lpfc_sli_process_unsol_iocb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3474)  * function if this is an unsolicited iocb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3475)  * This routine presumes LPFC_FCP_RING handling and doesn't bother
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3476)  * to check it explicitly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3477)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3478) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3479) lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3480) 				struct lpfc_sli_ring *pring, uint32_t mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3481) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3482) 	struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3483) 	IOCB_t *irsp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3484) 	IOCB_t *entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3485) 	struct lpfc_iocbq *cmdiocbq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3486) 	struct lpfc_iocbq rspiocbq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3487) 	uint32_t status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3488) 	uint32_t portRspPut, portRspMax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3489) 	int rc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3490) 	lpfc_iocb_type type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3491) 	unsigned long iflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3492) 	uint32_t rsp_cmpl = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3494) 	spin_lock_irqsave(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3495) 	pring->stats.iocb_event++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3497) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3498) 	 * The next available response entry should never exceed the maximum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3499) 	 * entries.  If it does, treat it as an adapter hardware error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3500) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3501) 	portRspMax = pring->sli.sli3.numRiocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3502) 	portRspPut = le32_to_cpu(pgp->rspPutInx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3503) 	if (unlikely(portRspPut >= portRspMax)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3504) 		lpfc_sli_rsp_pointers_error(phba, pring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3505) 		spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3506) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3507) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3508) 	if (phba->fcp_ring_in_use) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3509) 		spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3510) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3511) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3512) 		phba->fcp_ring_in_use = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3514) 	rmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3515) 	while (pring->sli.sli3.rspidx != portRspPut) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3516) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3517) 		 * Fetch an entry off the ring and copy it into a local data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3518) 		 * structure.  The copy involves a byte-swap since the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3519) 		 * network byte order and pci byte orders are different.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3520) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3521) 		entry = lpfc_resp_iocb(phba, pring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3522) 		phba->last_completion_time = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3524) 		if (++pring->sli.sli3.rspidx >= portRspMax)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3525) 			pring->sli.sli3.rspidx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3527) 		lpfc_sli_pcimem_bcopy((uint32_t *) entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3528) 				      (uint32_t *) &rspiocbq.iocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3529) 				      phba->iocb_rsp_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3530) 		INIT_LIST_HEAD(&(rspiocbq.list));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3531) 		irsp = &rspiocbq.iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3533) 		type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3534) 		pring->stats.iocb_rsp++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3535) 		rsp_cmpl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3537) 		if (unlikely(irsp->ulpStatus)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3538) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3539) 			 * If resource errors reported from HBA, reduce
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3540) 			 * queuedepths of the SCSI device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3541) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3542) 			if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3543) 			    ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3544) 			     IOERR_NO_RESOURCES)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3545) 				spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3546) 				phba->lpfc_rampdown_queue_depth(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3547) 				spin_lock_irqsave(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3548) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3550) 			/* Rsp ring <ringno> error: IOCB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3551) 			lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3552) 					"0336 Rsp Ring %d error: IOCB Data: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3553) 					"x%x x%x x%x x%x x%x x%x x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3554) 					pring->ringno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3555) 					irsp->un.ulpWord[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3556) 					irsp->un.ulpWord[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3557) 					irsp->un.ulpWord[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3558) 					irsp->un.ulpWord[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3559) 					irsp->un.ulpWord[4],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3560) 					irsp->un.ulpWord[5],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3561) 					*(uint32_t *)&irsp->un1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3562) 					*((uint32_t *)&irsp->un1 + 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3563) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3565) 		switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3566) 		case LPFC_ABORT_IOCB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3567) 		case LPFC_SOL_IOCB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3568) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3569) 			 * Idle exchange closed via ABTS from port.  No iocb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3570) 			 * resources need to be recovered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3571) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3572) 			if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3573) 				lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3574) 						"0333 IOCB cmd 0x%x"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3575) 						" processed. Skipping"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3576) 						" completion\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3577) 						irsp->ulpCommand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3578) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3579) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3581) 			spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3582) 			cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3583) 							 &rspiocbq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3584) 			spin_lock_irqsave(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3585) 			if (unlikely(!cmdiocbq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3586) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3587) 			if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3588) 				cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3589) 			if (cmdiocbq->iocb_cmpl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3590) 				spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3591) 				(cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3592) 						      &rspiocbq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3593) 				spin_lock_irqsave(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3594) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3595) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3596) 		case LPFC_UNSOL_IOCB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3597) 			spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3598) 			lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3599) 			spin_lock_irqsave(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3600) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3601) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3602) 			if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3603) 				char adaptermsg[LPFC_MAX_ADPTMSG];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3604) 				memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3605) 				memcpy(&adaptermsg[0], (uint8_t *) irsp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3606) 				       MAX_MSG_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3607) 				dev_warn(&((phba->pcidev)->dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3608) 					 "lpfc%d: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3609) 					 phba->brd_no, adaptermsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3610) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3611) 				/* Unknown IOCB command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3612) 				lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3613) 						"0334 Unknown IOCB command "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3614) 						"Data: x%x, x%x x%x x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3615) 						type, irsp->ulpCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3616) 						irsp->ulpStatus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3617) 						irsp->ulpIoTag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3618) 						irsp->ulpContext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3619) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3620) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3621) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3623) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3624) 		 * The response IOCB has been processed.  Update the ring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3625) 		 * pointer in SLIM.  If the port response put pointer has not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3626) 		 * been updated, sync the pgp->rspPutInx and fetch the new port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3627) 		 * response put pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3628) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3629) 		writel(pring->sli.sli3.rspidx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3630) 			&phba->host_gp[pring->ringno].rspGetInx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3632) 		if (pring->sli.sli3.rspidx == portRspPut)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3633) 			portRspPut = le32_to_cpu(pgp->rspPutInx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3634) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3636) 	if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3637) 		pring->stats.iocb_rsp_full++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3638) 		status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3639) 		writel(status, phba->CAregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3640) 		readl(phba->CAregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3641) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3642) 	if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3643) 		pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3644) 		pring->stats.iocb_cmd_empty++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3646) 		/* Force update of the local copy of cmdGetInx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3647) 		pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3648) 		lpfc_sli_resume_iocb(phba, pring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3650) 		if ((pring->lpfc_sli_cmd_available))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3651) 			(pring->lpfc_sli_cmd_available) (phba, pring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3653) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3655) 	phba->fcp_ring_in_use = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3656) 	spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3657) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3658) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3660) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3661)  * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3662)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3663)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3664)  * @rspiocbp: Pointer to driver response IOCB object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3665)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3666)  * This function is called from the worker thread when there is a slow-path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3667)  * response IOCB to process. This function chains all the response iocbs until
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3668)  * seeing the iocb with the LE bit set. The function will call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3669)  * lpfc_sli_process_sol_iocb function if the response iocb indicates a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3670)  * completion of a command iocb. The function will call the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3671)  * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3672)  * The function frees the resources or calls the completion handler if this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3673)  * iocb is an abort completion. The function returns NULL when the response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3674)  * iocb has the LE bit set and all the chained iocbs are processed, otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3675)  * this function shall chain the iocb on to the iocb_continueq and return the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3676)  * response iocb passed in.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3677)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3678) static struct lpfc_iocbq *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3679) lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3680) 			struct lpfc_iocbq *rspiocbp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3681) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3682) 	struct lpfc_iocbq *saveq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3683) 	struct lpfc_iocbq *cmdiocbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3684) 	struct lpfc_iocbq *next_iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3685) 	IOCB_t *irsp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3686) 	uint32_t free_saveq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3687) 	uint8_t iocb_cmd_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3688) 	lpfc_iocb_type type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3689) 	unsigned long iflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3690) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3692) 	spin_lock_irqsave(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3693) 	/* First add the response iocb to the countinueq list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3694) 	list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3695) 	pring->iocb_continueq_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3697) 	/* Now, determine whether the list is completed for processing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3698) 	irsp = &rspiocbp->iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3699) 	if (irsp->ulpLe) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3700) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3701) 		 * By default, the driver expects to free all resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3702) 		 * associated with this iocb completion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3703) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3704) 		free_saveq = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3705) 		saveq = list_get_first(&pring->iocb_continueq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3706) 				       struct lpfc_iocbq, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3707) 		irsp = &(saveq->iocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3708) 		list_del_init(&pring->iocb_continueq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3709) 		pring->iocb_continueq_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3711) 		pring->stats.iocb_rsp++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3713) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3714) 		 * If resource errors reported from HBA, reduce
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3715) 		 * queuedepths of the SCSI device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3716) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3717) 		if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3718) 		    ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3719) 		     IOERR_NO_RESOURCES)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3720) 			spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3721) 			phba->lpfc_rampdown_queue_depth(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3722) 			spin_lock_irqsave(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3723) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3725) 		if (irsp->ulpStatus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3726) 			/* Rsp ring <ringno> error: IOCB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3727) 			lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3728) 					"0328 Rsp Ring %d error: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3729) 					"IOCB Data: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3730) 					"x%x x%x x%x x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3731) 					"x%x x%x x%x x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3732) 					"x%x x%x x%x x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3733) 					"x%x x%x x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3734) 					pring->ringno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3735) 					irsp->un.ulpWord[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3736) 					irsp->un.ulpWord[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3737) 					irsp->un.ulpWord[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3738) 					irsp->un.ulpWord[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3739) 					irsp->un.ulpWord[4],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3740) 					irsp->un.ulpWord[5],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3741) 					*(((uint32_t *) irsp) + 6),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3742) 					*(((uint32_t *) irsp) + 7),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3743) 					*(((uint32_t *) irsp) + 8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3744) 					*(((uint32_t *) irsp) + 9),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3745) 					*(((uint32_t *) irsp) + 10),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3746) 					*(((uint32_t *) irsp) + 11),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3747) 					*(((uint32_t *) irsp) + 12),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3748) 					*(((uint32_t *) irsp) + 13),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3749) 					*(((uint32_t *) irsp) + 14),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3750) 					*(((uint32_t *) irsp) + 15));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3751) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3753) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3754) 		 * Fetch the IOCB command type and call the correct completion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3755) 		 * routine. Solicited and Unsolicited IOCBs on the ELS ring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3756) 		 * get freed back to the lpfc_iocb_list by the discovery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3757) 		 * kernel thread.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3758) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3759) 		iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3760) 		type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3761) 		switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3762) 		case LPFC_SOL_IOCB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3763) 			spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3764) 			rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3765) 			spin_lock_irqsave(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3766) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3768) 		case LPFC_UNSOL_IOCB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3769) 			spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3770) 			rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3771) 			spin_lock_irqsave(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3772) 			if (!rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3773) 				free_saveq = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3774) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3776) 		case LPFC_ABORT_IOCB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3777) 			cmdiocbp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3778) 			if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3779) 				spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3780) 				cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3781) 								 saveq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3782) 				spin_lock_irqsave(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3783) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3784) 			if (cmdiocbp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3785) 				/* Call the specified completion routine */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3786) 				if (cmdiocbp->iocb_cmpl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3787) 					spin_unlock_irqrestore(&phba->hbalock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3788) 							       iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3789) 					(cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3790) 							      saveq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3791) 					spin_lock_irqsave(&phba->hbalock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3792) 							  iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3793) 				} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3794) 					__lpfc_sli_release_iocbq(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3795) 								 cmdiocbp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3796) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3797) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3799) 		case LPFC_UNKNOWN_IOCB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3800) 			if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3801) 				char adaptermsg[LPFC_MAX_ADPTMSG];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3802) 				memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3803) 				memcpy(&adaptermsg[0], (uint8_t *)irsp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3804) 				       MAX_MSG_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3805) 				dev_warn(&((phba->pcidev)->dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3806) 					 "lpfc%d: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3807) 					 phba->brd_no, adaptermsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3808) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3809) 				/* Unknown IOCB command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3810) 				lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3811) 						"0335 Unknown IOCB "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3812) 						"command Data: x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3813) 						"x%x x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3814) 						irsp->ulpCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3815) 						irsp->ulpStatus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3816) 						irsp->ulpIoTag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3817) 						irsp->ulpContext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3818) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3819) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3820) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3822) 		if (free_saveq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3823) 			list_for_each_entry_safe(rspiocbp, next_iocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3824) 						 &saveq->list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3825) 				list_del_init(&rspiocbp->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3826) 				__lpfc_sli_release_iocbq(phba, rspiocbp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3827) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3828) 			__lpfc_sli_release_iocbq(phba, saveq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3829) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3830) 		rspiocbp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3831) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3832) 	spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3833) 	return rspiocbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3836) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3837)  * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3838)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3839)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3840)  * @mask: Host attention register mask for this ring.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3841)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3842)  * This routine wraps the actual slow_ring event process routine from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3843)  * API jump table function pointer from the lpfc_hba struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3844)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3845) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3846) lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3847) 				struct lpfc_sli_ring *pring, uint32_t mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3848) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3849) 	phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3850) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3852) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3853)  * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3854)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3855)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3856)  * @mask: Host attention register mask for this ring.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3857)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3858)  * This function is called from the worker thread when there is a ring event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3859)  * for non-fcp rings. The caller does not hold any lock. The function will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3860)  * remove each response iocb in the response ring and calls the handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3861)  * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3862)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3863) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3864) lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3865) 				   struct lpfc_sli_ring *pring, uint32_t mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3866) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3867) 	struct lpfc_pgp *pgp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3868) 	IOCB_t *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3869) 	IOCB_t *irsp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3870) 	struct lpfc_iocbq *rspiocbp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3871) 	uint32_t portRspPut, portRspMax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3872) 	unsigned long iflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3873) 	uint32_t status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3875) 	pgp = &phba->port_gp[pring->ringno];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3876) 	spin_lock_irqsave(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3877) 	pring->stats.iocb_event++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3879) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3880) 	 * The next available response entry should never exceed the maximum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3881) 	 * entries.  If it does, treat it as an adapter hardware error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3882) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3883) 	portRspMax = pring->sli.sli3.numRiocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3884) 	portRspPut = le32_to_cpu(pgp->rspPutInx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3885) 	if (portRspPut >= portRspMax) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3886) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3887) 		 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3888) 		 * rsp ring <portRspMax>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3889) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3890) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3891) 				"0303 Ring %d handler: portRspPut %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3892) 				"is bigger than rsp ring %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3893) 				pring->ringno, portRspPut, portRspMax);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3895) 		phba->link_state = LPFC_HBA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3896) 		spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3898) 		phba->work_hs = HS_FFER3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3899) 		lpfc_handle_eratt(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3901) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3902) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3904) 	rmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3905) 	while (pring->sli.sli3.rspidx != portRspPut) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3906) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3907) 		 * Build a completion list and call the appropriate handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3908) 		 * The process is to get the next available response iocb, get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3909) 		 * a free iocb from the list, copy the response data into the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3910) 		 * free iocb, insert to the continuation list, and update the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3911) 		 * next response index to slim.  This process makes response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3912) 		 * iocb's in the ring available to DMA as fast as possible but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3913) 		 * pays a penalty for a copy operation.  Since the iocb is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3914) 		 * only 32 bytes, this penalty is considered small relative to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3915) 		 * the PCI reads for register values and a slim write.  When
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3916) 		 * the ulpLe field is set, the entire Command has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3917) 		 * received.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3918) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3919) 		entry = lpfc_resp_iocb(phba, pring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3921) 		phba->last_completion_time = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3922) 		rspiocbp = __lpfc_sli_get_iocbq(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3923) 		if (rspiocbp == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3924) 			printk(KERN_ERR "%s: out of buffers! Failing "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3925) 			       "completion.\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3926) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3927) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3928) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3929) 		lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3930) 				      phba->iocb_rsp_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3931) 		irsp = &rspiocbp->iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3933) 		if (++pring->sli.sli3.rspidx >= portRspMax)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3934) 			pring->sli.sli3.rspidx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3936) 		if (pring->ringno == LPFC_ELS_RING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3937) 			lpfc_debugfs_slow_ring_trc(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3938) 			"IOCB rsp ring:   wd4:x%08x wd6:x%08x wd7:x%08x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3939) 				*(((uint32_t *) irsp) + 4),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3940) 				*(((uint32_t *) irsp) + 6),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3941) 				*(((uint32_t *) irsp) + 7));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3942) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3944) 		writel(pring->sli.sli3.rspidx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3945) 			&phba->host_gp[pring->ringno].rspGetInx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3947) 		spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3948) 		/* Handle the response IOCB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3949) 		rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3950) 		spin_lock_irqsave(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3952) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3953) 		 * If the port response put pointer has not been updated, sync
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3954) 		 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3955) 		 * response put pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3956) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3957) 		if (pring->sli.sli3.rspidx == portRspPut) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3958) 			portRspPut = le32_to_cpu(pgp->rspPutInx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3959) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3960) 	} /* while (pring->sli.sli3.rspidx != portRspPut) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3962) 	if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3963) 		/* At least one response entry has been freed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3964) 		pring->stats.iocb_rsp_full++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3965) 		/* SET RxRE_RSP in Chip Att register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3966) 		status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3967) 		writel(status, phba->CAregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3968) 		readl(phba->CAregaddr); /* flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3969) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3970) 	if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3971) 		pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3972) 		pring->stats.iocb_cmd_empty++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3973) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3974) 		/* Force update of the local copy of cmdGetInx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3975) 		pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3976) 		lpfc_sli_resume_iocb(phba, pring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3977) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3978) 		if ((pring->lpfc_sli_cmd_available))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3979) 			(pring->lpfc_sli_cmd_available) (phba, pring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3981) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3982) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3983) 	spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3984) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3985) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3986) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3987) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3988)  * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3989)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3990)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3991)  * @mask: Host attention register mask for this ring.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3992)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3993)  * This function is called from the worker thread when there is a pending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3994)  * ELS response iocb on the driver internal slow-path response iocb worker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3995)  * queue. The caller does not hold any lock. The function will remove each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3996)  * response iocb from the response worker queue and calls the handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3997)  * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3998)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3999) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4000) lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4001) 				   struct lpfc_sli_ring *pring, uint32_t mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4002) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4003) 	struct lpfc_iocbq *irspiocbq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4004) 	struct hbq_dmabuf *dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4005) 	struct lpfc_cq_event *cq_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4006) 	unsigned long iflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4007) 	int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4008) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4009) 	spin_lock_irqsave(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4010) 	phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4011) 	spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4012) 	while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4013) 		/* Get the response iocb from the head of work queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4014) 		spin_lock_irqsave(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4015) 		list_remove_head(&phba->sli4_hba.sp_queue_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4016) 				 cq_event, struct lpfc_cq_event, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4017) 		spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4018) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4019) 		switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4020) 		case CQE_CODE_COMPL_WQE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4021) 			irspiocbq = container_of(cq_event, struct lpfc_iocbq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4022) 						 cq_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4023) 			/* Translate ELS WCQE to response IOCBQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4024) 			irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4025) 								   irspiocbq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4026) 			if (irspiocbq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4027) 				lpfc_sli_sp_handle_rspiocb(phba, pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4028) 							   irspiocbq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4029) 			count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4030) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4031) 		case CQE_CODE_RECEIVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4032) 		case CQE_CODE_RECEIVE_V1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4033) 			dmabuf = container_of(cq_event, struct hbq_dmabuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4034) 					      cq_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4035) 			lpfc_sli4_handle_received_buffer(phba, dmabuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4036) 			count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4037) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4038) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4039) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4040) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4041) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4042) 		/* Limit the number of events to 64 to avoid soft lockups */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4043) 		if (count == 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4044) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4045) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4046) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4047) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4048) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4049)  * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4050)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4051)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4052)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4053)  * This function aborts all iocbs in the given ring and frees all the iocb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4054)  * objects in txq. This function issues an abort iocb for all the iocb commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4055)  * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4056)  * the return of this function. The caller is not required to hold any locks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4057)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4058) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4059) lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4060) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4061) 	LIST_HEAD(completions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4062) 	struct lpfc_iocbq *iocb, *next_iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4063) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4064) 	if (pring->ringno == LPFC_ELS_RING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4065) 		lpfc_fabric_abort_hba(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4066) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4067) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4068) 	/* Error everything on txq and txcmplq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4069) 	 * First do the txq.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4070) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4071) 	if (phba->sli_rev >= LPFC_SLI_REV4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4072) 		spin_lock_irq(&pring->ring_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4073) 		list_splice_init(&pring->txq, &completions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4074) 		pring->txq_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4075) 		spin_unlock_irq(&pring->ring_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4077) 		spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4078) 		/* Next issue ABTS for everything on the txcmplq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4079) 		list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4080) 			lpfc_sli_issue_abort_iotag(phba, pring, iocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4081) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4082) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4083) 		spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4084) 		list_splice_init(&pring->txq, &completions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4085) 		pring->txq_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4087) 		/* Next issue ABTS for everything on the txcmplq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4088) 		list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4089) 			lpfc_sli_issue_abort_iotag(phba, pring, iocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4090) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4091) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4093) 	/* Cancel all the IOCBs from the completions list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4094) 	lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4095) 			      IOERR_SLI_ABORTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4096) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4097) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4098) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4099)  * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4100)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4101)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4102)  * This function aborts all iocbs in FCP rings and frees all the iocb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4103)  * objects in txq. This function issues an abort iocb for all the iocb commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4104)  * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4105)  * the return of this function. The caller is not required to hold any locks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4106)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4107) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4108) lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4110) 	struct lpfc_sli *psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4111) 	struct lpfc_sli_ring  *pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4112) 	uint32_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4114) 	/* Look on all the FCP Rings for the iotag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4115) 	if (phba->sli_rev >= LPFC_SLI_REV4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4116) 		for (i = 0; i < phba->cfg_hdw_queue; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4117) 			pring = phba->sli4_hba.hdwq[i].io_wq->pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4118) 			lpfc_sli_abort_iocb_ring(phba, pring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4119) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4120) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4121) 		pring = &psli->sli3_ring[LPFC_FCP_RING];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4122) 		lpfc_sli_abort_iocb_ring(phba, pring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4123) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4126) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4127)  * lpfc_sli_flush_io_rings - flush all iocbs in the IO ring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4128)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4129)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4130)  * This function flushes all iocbs in the IO ring and frees all the iocb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4131)  * objects in txq and txcmplq. This function will not issue abort iocbs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4132)  * for all the iocb commands in txcmplq, they will just be returned with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4133)  * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4134)  * slot has been permanently disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4135)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4136) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4137) lpfc_sli_flush_io_rings(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4139) 	LIST_HEAD(txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4140) 	LIST_HEAD(txcmplq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4141) 	struct lpfc_sli *psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4142) 	struct lpfc_sli_ring  *pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4143) 	uint32_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4144) 	struct lpfc_iocbq *piocb, *next_iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4146) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4147) 	if (phba->hba_flag & HBA_IOQ_FLUSH ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4148) 	    !phba->sli4_hba.hdwq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4149) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4150) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4151) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4152) 	/* Indicate the I/O queues are flushed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4153) 	phba->hba_flag |= HBA_IOQ_FLUSH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4154) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4156) 	/* Look on all the FCP Rings for the iotag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4157) 	if (phba->sli_rev >= LPFC_SLI_REV4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4158) 		for (i = 0; i < phba->cfg_hdw_queue; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4159) 			pring = phba->sli4_hba.hdwq[i].io_wq->pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4161) 			spin_lock_irq(&pring->ring_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4162) 			/* Retrieve everything on txq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4163) 			list_splice_init(&pring->txq, &txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4164) 			list_for_each_entry_safe(piocb, next_iocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4165) 						 &pring->txcmplq, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4166) 				piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4167) 			/* Retrieve everything on the txcmplq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4168) 			list_splice_init(&pring->txcmplq, &txcmplq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4169) 			pring->txq_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4170) 			pring->txcmplq_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4171) 			spin_unlock_irq(&pring->ring_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4173) 			/* Flush the txq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4174) 			lpfc_sli_cancel_iocbs(phba, &txq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4175) 					      IOSTAT_LOCAL_REJECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4176) 					      IOERR_SLI_DOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4177) 			/* Flush the txcmpq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4178) 			lpfc_sli_cancel_iocbs(phba, &txcmplq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4179) 					      IOSTAT_LOCAL_REJECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4180) 					      IOERR_SLI_DOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4181) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4182) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4183) 		pring = &psli->sli3_ring[LPFC_FCP_RING];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4185) 		spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4186) 		/* Retrieve everything on txq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4187) 		list_splice_init(&pring->txq, &txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4188) 		list_for_each_entry_safe(piocb, next_iocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4189) 					 &pring->txcmplq, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4190) 			piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4191) 		/* Retrieve everything on the txcmplq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4192) 		list_splice_init(&pring->txcmplq, &txcmplq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4193) 		pring->txq_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4194) 		pring->txcmplq_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4195) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4197) 		/* Flush the txq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4198) 		lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4199) 				      IOERR_SLI_DOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4200) 		/* Flush the txcmpq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4201) 		lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4202) 				      IOERR_SLI_DOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4203) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4206) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4207)  * lpfc_sli_brdready_s3 - Check for sli3 host ready status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4208)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4209)  * @mask: Bit mask to be checked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4210)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4211)  * This function reads the host status register and compares
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4212)  * with the provided bit mask to check if HBA completed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4213)  * the restart. This function will wait in a loop for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4214)  * HBA to complete restart. If the HBA does not restart within
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4215)  * 15 iterations, the function will reset the HBA again. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4216)  * function returns 1 when HBA fail to restart otherwise returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4217)  * zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4218)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4219) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4220) lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4222) 	uint32_t status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4223) 	int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4224) 	int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4226) 	/* Read the HBA Host Status Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4227) 	if (lpfc_readl(phba->HSregaddr, &status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4228) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4230) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4231) 	 * Check status register every 100ms for 5 retries, then every
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4232) 	 * 500ms for 5, then every 2.5 sec for 5, then reset board and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4233) 	 * every 2.5 sec for 4.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4234) 	 * Break our of the loop if errors occurred during init.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4235) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4236) 	while (((status & mask) != mask) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4237) 	       !(status & HS_FFERM) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4238) 	       i++ < 20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4240) 		if (i <= 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4241) 			msleep(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4242) 		else if (i <= 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4243) 			msleep(500);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4244) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4245) 			msleep(2500);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4247) 		if (i == 15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4248) 				/* Do post */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4249) 			phba->pport->port_state = LPFC_VPORT_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4250) 			lpfc_sli_brdrestart(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4251) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4252) 		/* Read the HBA Host Status Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4253) 		if (lpfc_readl(phba->HSregaddr, &status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4254) 			retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4255) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4256) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4257) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4259) 	/* Check to see if any errors occurred during init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4260) 	if ((status & HS_FFERM) || (i >= 20)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4261) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4262) 				"2751 Adapter failed to restart, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4263) 				"status reg x%x, FW Data: A8 x%x AC x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4264) 				status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4265) 				readl(phba->MBslimaddr + 0xa8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4266) 				readl(phba->MBslimaddr + 0xac));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4267) 		phba->link_state = LPFC_HBA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4268) 		retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4269) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4271) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4274) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4275)  * lpfc_sli_brdready_s4 - Check for sli4 host ready status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4276)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4277)  * @mask: Bit mask to be checked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4278)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4279)  * This function checks the host status register to check if HBA is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4280)  * ready. This function will wait in a loop for the HBA to be ready
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4281)  * If the HBA is not ready , the function will will reset the HBA PCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4282)  * function again. The function returns 1 when HBA fail to be ready
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4283)  * otherwise returns zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4284)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4285) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4286) lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4288) 	uint32_t status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4289) 	int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4291) 	/* Read the HBA Host Status Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4292) 	status = lpfc_sli4_post_status_check(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4294) 	if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4295) 		phba->pport->port_state = LPFC_VPORT_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4296) 		lpfc_sli_brdrestart(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4297) 		status = lpfc_sli4_post_status_check(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4298) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4300) 	/* Check to see if any errors occurred during init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4301) 	if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4302) 		phba->link_state = LPFC_HBA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4303) 		retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4304) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4305) 		phba->sli4_hba.intr_enable = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4307) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4310) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4311)  * lpfc_sli_brdready - Wrapper func for checking the hba readyness
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4312)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4313)  * @mask: Bit mask to be checked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4314)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4315)  * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4316)  * from the API jump table function pointer from the lpfc_hba struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4317)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4318) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4319) lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4321) 	return phba->lpfc_sli_brdready(phba, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4324) #define BARRIER_TEST_PATTERN (0xdeadbeef)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4326) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4327)  * lpfc_reset_barrier - Make HBA ready for HBA reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4328)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4329)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4330)  * This function is called before resetting an HBA. This function is called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4331)  * with hbalock held and requests HBA to quiesce DMAs before a reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4332)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4333) void lpfc_reset_barrier(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4335) 	uint32_t __iomem *resp_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4336) 	uint32_t __iomem *mbox_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4337) 	volatile uint32_t mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4338) 	uint32_t hc_copy, ha_copy, resp_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4339) 	int  i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4340) 	uint8_t hdrtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4342) 	lockdep_assert_held(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4344) 	pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4345) 	if (hdrtype != 0x80 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4346) 	    (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4347) 	     FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4348) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4350) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4351) 	 * Tell the other part of the chip to suspend temporarily all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4352) 	 * its DMA activity.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4353) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4354) 	resp_buf = phba->MBslimaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4356) 	/* Disable the error attention */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4357) 	if (lpfc_readl(phba->HCregaddr, &hc_copy))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4358) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4359) 	writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4360) 	readl(phba->HCregaddr); /* flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4361) 	phba->link_flag |= LS_IGNORE_ERATT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4363) 	if (lpfc_readl(phba->HAregaddr, &ha_copy))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4364) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4365) 	if (ha_copy & HA_ERATT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4366) 		/* Clear Chip error bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4367) 		writel(HA_ERATT, phba->HAregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4368) 		phba->pport->stopped = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4369) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4371) 	mbox = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4372) 	((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4373) 	((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4375) 	writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4376) 	mbox_buf = phba->MBslimaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4377) 	writel(mbox, mbox_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4379) 	for (i = 0; i < 50; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4380) 		if (lpfc_readl((resp_buf + 1), &resp_data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4381) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4382) 		if (resp_data != ~(BARRIER_TEST_PATTERN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4383) 			mdelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4384) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4385) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4386) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4387) 	resp_data = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4388) 	if (lpfc_readl((resp_buf + 1), &resp_data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4389) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4390) 	if (resp_data  != ~(BARRIER_TEST_PATTERN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4391) 		if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4392) 		    phba->pport->stopped)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4393) 			goto restore_hc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4394) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4395) 			goto clear_errat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4396) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4398) 	((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4399) 	resp_data = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4400) 	for (i = 0; i < 500; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4401) 		if (lpfc_readl(resp_buf, &resp_data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4402) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4403) 		if (resp_data != mbox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4404) 			mdelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4405) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4406) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4407) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4409) clear_errat:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4411) 	while (++i < 500) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4412) 		if (lpfc_readl(phba->HAregaddr, &ha_copy))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4413) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4414) 		if (!(ha_copy & HA_ERATT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4415) 			mdelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4416) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4417) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4418) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4420) 	if (readl(phba->HAregaddr) & HA_ERATT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4421) 		writel(HA_ERATT, phba->HAregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4422) 		phba->pport->stopped = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4423) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4425) restore_hc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4426) 	phba->link_flag &= ~LS_IGNORE_ERATT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4427) 	writel(hc_copy, phba->HCregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4428) 	readl(phba->HCregaddr); /* flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4431) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4432)  * lpfc_sli_brdkill - Issue a kill_board mailbox command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4433)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4434)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4435)  * This function issues a kill_board mailbox command and waits for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4436)  * the error attention interrupt. This function is called for stopping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4437)  * the firmware processing. The caller is not required to hold any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4438)  * locks. This function calls lpfc_hba_down_post function to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4439)  * any pending commands after the kill. The function will return 1 when it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4440)  * fails to kill the board else will return 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4441)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4442) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4443) lpfc_sli_brdkill(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4444) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4445) 	struct lpfc_sli *psli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4446) 	LPFC_MBOXQ_t *pmb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4447) 	uint32_t status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4448) 	uint32_t ha_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4449) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4450) 	int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4452) 	psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4454) 	/* Kill HBA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4455) 	lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4456) 			"0329 Kill HBA Data: x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4457) 			phba->pport->port_state, psli->sli_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4459) 	pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4460) 	if (!pmb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4461) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4463) 	/* Disable the error attention */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4464) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4465) 	if (lpfc_readl(phba->HCregaddr, &status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4466) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4467) 		mempool_free(pmb, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4468) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4469) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4470) 	status &= ~HC_ERINT_ENA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4471) 	writel(status, phba->HCregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4472) 	readl(phba->HCregaddr); /* flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4473) 	phba->link_flag |= LS_IGNORE_ERATT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4474) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4476) 	lpfc_kill_board(phba, pmb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4477) 	pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4478) 	retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4480) 	if (retval != MBX_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4481) 		if (retval != MBX_BUSY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4482) 			mempool_free(pmb, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4483) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4484) 				"2752 KILL_BOARD command failed retval %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4485) 				retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4486) 		spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4487) 		phba->link_flag &= ~LS_IGNORE_ERATT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4488) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4489) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4490) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4492) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4493) 	psli->sli_flag &= ~LPFC_SLI_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4494) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4496) 	mempool_free(pmb, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4498) 	/* There is no completion for a KILL_BOARD mbox cmd. Check for an error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4499) 	 * attention every 100ms for 3 seconds. If we don't get ERATT after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4500) 	 * 3 seconds we still set HBA_ERROR state because the status of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4501) 	 * board is now undefined.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4502) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4503) 	if (lpfc_readl(phba->HAregaddr, &ha_copy))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4504) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4505) 	while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4506) 		mdelay(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4507) 		if (lpfc_readl(phba->HAregaddr, &ha_copy))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4508) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4509) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4511) 	del_timer_sync(&psli->mbox_tmo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4512) 	if (ha_copy & HA_ERATT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4513) 		writel(HA_ERATT, phba->HAregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4514) 		phba->pport->stopped = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4515) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4516) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4517) 	psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4518) 	psli->mbox_active = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4519) 	phba->link_flag &= ~LS_IGNORE_ERATT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4520) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4522) 	lpfc_hba_down_post(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4523) 	phba->link_state = LPFC_HBA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4525) 	return ha_copy & HA_ERATT ? 0 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4528) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4529)  * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4530)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4531)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4532)  * This function resets the HBA by writing HC_INITFF to the control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4533)  * register. After the HBA resets, this function resets all the iocb ring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4534)  * indices. This function disables PCI layer parity checking during
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4535)  * the reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4536)  * This function returns 0 always.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4537)  * The caller is not required to hold any locks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4538)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4539) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4540) lpfc_sli_brdreset(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4541) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4542) 	struct lpfc_sli *psli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4543) 	struct lpfc_sli_ring *pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4544) 	uint16_t cfg_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4545) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4547) 	psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4549) 	/* Reset HBA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4550) 	lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4551) 			"0325 Reset HBA Data: x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4552) 			(phba->pport) ? phba->pport->port_state : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4553) 			psli->sli_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4555) 	/* perform board reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4556) 	phba->fc_eventTag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4557) 	phba->link_events = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4558) 	if (phba->pport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4559) 		phba->pport->fc_myDID = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4560) 		phba->pport->fc_prevDID = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4561) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4563) 	/* Turn off parity checking and serr during the physical reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4564) 	if (pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4565) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4567) 	pci_write_config_word(phba->pcidev, PCI_COMMAND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4568) 			      (cfg_value &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4569) 			       ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4571) 	psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4573) 	/* Now toggle INITFF bit in the Host Control Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4574) 	writel(HC_INITFF, phba->HCregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4575) 	mdelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4576) 	readl(phba->HCregaddr); /* flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4577) 	writel(0, phba->HCregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4578) 	readl(phba->HCregaddr); /* flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4580) 	/* Restore PCI cmd register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4581) 	pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4583) 	/* Initialize relevant SLI info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4584) 	for (i = 0; i < psli->num_rings; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4585) 		pring = &psli->sli3_ring[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4586) 		pring->flag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4587) 		pring->sli.sli3.rspidx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4588) 		pring->sli.sli3.next_cmdidx  = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4589) 		pring->sli.sli3.local_getidx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4590) 		pring->sli.sli3.cmdidx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4591) 		pring->missbufcnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4592) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4594) 	phba->link_state = LPFC_WARM_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4595) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4598) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4599)  * lpfc_sli4_brdreset - Reset a sli-4 HBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4600)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4601)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4602)  * This function resets a SLI4 HBA. This function disables PCI layer parity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4603)  * checking during resets the device. The caller is not required to hold
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4604)  * any locks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4605)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4606)  * This function returns 0 on success else returns negative error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4607)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4608) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4609) lpfc_sli4_brdreset(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4610) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4611) 	struct lpfc_sli *psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4612) 	uint16_t cfg_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4613) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4615) 	/* Reset HBA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4616) 	lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4617) 			"0295 Reset HBA Data: x%x x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4618) 			phba->pport->port_state, psli->sli_flag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4619) 			phba->hba_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4621) 	/* perform board reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4622) 	phba->fc_eventTag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4623) 	phba->link_events = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4624) 	phba->pport->fc_myDID = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4625) 	phba->pport->fc_prevDID = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4627) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4628) 	psli->sli_flag &= ~(LPFC_PROCESS_LA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4629) 	phba->fcf.fcf_flag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4630) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4632) 	/* Now physically reset the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4633) 	lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4634) 			"0389 Performing PCI function reset!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4636) 	/* Turn off parity checking and serr during the physical reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4637) 	if (pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4638) 		lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4639) 				"3205 PCI read Config failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4640) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4641) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4643) 	pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4644) 			      ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4646) 	/* Perform FCoE PCI function reset before freeing queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4647) 	rc = lpfc_pci_function_reset(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4649) 	/* Restore PCI cmd register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4650) 	pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4652) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4653) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4655) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4656)  * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4657)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4658)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4659)  * This function is called in the SLI initialization code path to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4660)  * restart the HBA. The caller is not required to hold any lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4661)  * This function writes MBX_RESTART mailbox command to the SLIM and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4662)  * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4663)  * function to free any pending commands. The function enables
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4664)  * POST only during the first initialization. The function returns zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4665)  * The function does not guarantee completion of MBX_RESTART mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4666)  * command before the return of this function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4667)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4668) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4669) lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4670) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4671) 	MAILBOX_t *mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4672) 	struct lpfc_sli *psli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4673) 	volatile uint32_t word0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4674) 	void __iomem *to_slim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4675) 	uint32_t hba_aer_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4677) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4679) 	/* Take PCIe device Advanced Error Reporting (AER) state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4680) 	hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4682) 	psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4684) 	/* Restart HBA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4685) 	lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4686) 			"0337 Restart HBA Data: x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4687) 			(phba->pport) ? phba->pport->port_state : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4688) 			psli->sli_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4690) 	word0 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4691) 	mb = (MAILBOX_t *) &word0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4692) 	mb->mbxCommand = MBX_RESTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4693) 	mb->mbxHc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4695) 	lpfc_reset_barrier(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4697) 	to_slim = phba->MBslimaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4698) 	writel(*(uint32_t *) mb, to_slim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4699) 	readl(to_slim); /* flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4701) 	/* Only skip post after fc_ffinit is completed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4702) 	if (phba->pport && phba->pport->port_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4703) 		word0 = 1;	/* This is really setting up word1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4704) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4705) 		word0 = 0;	/* This is really setting up word1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4706) 	to_slim = phba->MBslimaddr + sizeof (uint32_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4707) 	writel(*(uint32_t *) mb, to_slim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4708) 	readl(to_slim); /* flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4710) 	lpfc_sli_brdreset(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4711) 	if (phba->pport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4712) 		phba->pport->stopped = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4713) 	phba->link_state = LPFC_INIT_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4714) 	phba->hba_flag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4715) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4717) 	memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4718) 	psli->stats_start = ktime_get_seconds();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4720) 	/* Give the INITFF and Post time to settle. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4721) 	mdelay(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4723) 	/* Reset HBA AER if it was enabled, note hba_flag was reset above */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4724) 	if (hba_aer_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4725) 		pci_disable_pcie_error_reporting(phba->pcidev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4727) 	lpfc_hba_down_post(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4729) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4732) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4733)  * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4734)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4735)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4736)  * This function is called in the SLI initialization code path to restart
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4737)  * a SLI4 HBA. The caller is not required to hold any lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4738)  * At the end of the function, it calls lpfc_hba_down_post function to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4739)  * free any pending commands.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4740)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4741) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4742) lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4743) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4744) 	struct lpfc_sli *psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4745) 	uint32_t hba_aer_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4746) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4748) 	/* Restart HBA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4749) 	lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4750) 			"0296 Restart HBA Data: x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4751) 			phba->pport->port_state, psli->sli_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4753) 	/* Take PCIe device Advanced Error Reporting (AER) state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4754) 	hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4756) 	rc = lpfc_sli4_brdreset(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4757) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4758) 		phba->link_state = LPFC_HBA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4759) 		goto hba_down_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4760) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4762) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4763) 	phba->pport->stopped = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4764) 	phba->link_state = LPFC_INIT_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4765) 	phba->hba_flag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4766) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4768) 	memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4769) 	psli->stats_start = ktime_get_seconds();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4771) 	/* Reset HBA AER if it was enabled, note hba_flag was reset above */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4772) 	if (hba_aer_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4773) 		pci_disable_pcie_error_reporting(phba->pcidev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4775) hba_down_queue:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4776) 	lpfc_hba_down_post(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4777) 	lpfc_sli4_queue_destroy(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4779) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4782) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4783)  * lpfc_sli_brdrestart - Wrapper func for restarting hba
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4784)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4785)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4786)  * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4787)  * API jump table function pointer from the lpfc_hba struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4788) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4789) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4790) lpfc_sli_brdrestart(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4791) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4792) 	return phba->lpfc_sli_brdrestart(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4795) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4796)  * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4797)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4798)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4799)  * This function is called after a HBA restart to wait for successful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4800)  * restart of the HBA. Successful restart of the HBA is indicated by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4801)  * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4802)  * iteration, the function will restart the HBA again. The function returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4803)  * zero if HBA successfully restarted else returns negative error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4804)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4805) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4806) lpfc_sli_chipset_init(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4807) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4808) 	uint32_t status, i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4810) 	/* Read the HBA Host Status Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4811) 	if (lpfc_readl(phba->HSregaddr, &status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4812) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4814) 	/* Check status register to see what current state is */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4815) 	i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4816) 	while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4818) 		/* Check every 10ms for 10 retries, then every 100ms for 90
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4819) 		 * retries, then every 1 sec for 50 retires for a total of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4820) 		 * ~60 seconds before reset the board again and check every
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4821) 		 * 1 sec for 50 retries. The up to 60 seconds before the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4822) 		 * board ready is required by the Falcon FIPS zeroization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4823) 		 * complete, and any reset the board in between shall cause
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4824) 		 * restart of zeroization, further delay the board ready.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4825) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4826) 		if (i++ >= 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4827) 			/* Adapter failed to init, timeout, status reg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4828) 			   <status> */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4829) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4830) 					"0436 Adapter failed to init, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4831) 					"timeout, status reg x%x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4832) 					"FW Data: A8 x%x AC x%x\n", status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4833) 					readl(phba->MBslimaddr + 0xa8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4834) 					readl(phba->MBslimaddr + 0xac));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4835) 			phba->link_state = LPFC_HBA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4836) 			return -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4837) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4839) 		/* Check to see if any errors occurred during init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4840) 		if (status & HS_FFERM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4841) 			/* ERROR: During chipset initialization */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4842) 			/* Adapter failed to init, chipset, status reg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4843) 			   <status> */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4844) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4845) 					"0437 Adapter failed to init, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4846) 					"chipset, status reg x%x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4847) 					"FW Data: A8 x%x AC x%x\n", status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4848) 					readl(phba->MBslimaddr + 0xa8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4849) 					readl(phba->MBslimaddr + 0xac));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4850) 			phba->link_state = LPFC_HBA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4851) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4852) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4854) 		if (i <= 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4855) 			msleep(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4856) 		else if (i <= 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4857) 			msleep(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4858) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4859) 			msleep(1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4861) 		if (i == 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4862) 			/* Do post */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4863) 			phba->pport->port_state = LPFC_VPORT_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4864) 			lpfc_sli_brdrestart(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4865) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4866) 		/* Read the HBA Host Status Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4867) 		if (lpfc_readl(phba->HSregaddr, &status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4868) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4869) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4871) 	/* Check to see if any errors occurred during init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4872) 	if (status & HS_FFERM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4873) 		/* ERROR: During chipset initialization */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4874) 		/* Adapter failed to init, chipset, status reg <status> */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4875) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4876) 				"0438 Adapter failed to init, chipset, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4877) 				"status reg x%x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4878) 				"FW Data: A8 x%x AC x%x\n", status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4879) 				readl(phba->MBslimaddr + 0xa8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4880) 				readl(phba->MBslimaddr + 0xac));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4881) 		phba->link_state = LPFC_HBA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4882) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4883) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4885) 	/* Clear all interrupt enable conditions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4886) 	writel(0, phba->HCregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4887) 	readl(phba->HCregaddr); /* flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4888) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4889) 	/* setup host attn register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4890) 	writel(0xffffffff, phba->HAregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4891) 	readl(phba->HAregaddr); /* flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4892) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4893) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4895) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4896)  * lpfc_sli_hbq_count - Get the number of HBQs to be configured
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4897)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4898)  * This function calculates and returns the number of HBQs required to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4899)  * configured.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4900)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4901) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4902) lpfc_sli_hbq_count(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4903) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4904) 	return ARRAY_SIZE(lpfc_hbq_defs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4905) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4907) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4908)  * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4909)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4910)  * This function adds the number of hbq entries in every HBQ to get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4911)  * the total number of hbq entries required for the HBA and returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4912)  * the total count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4913)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4914) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4915) lpfc_sli_hbq_entry_count(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4916) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4917) 	int  hbq_count = lpfc_sli_hbq_count();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4918) 	int  count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4919) 	int  i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4921) 	for (i = 0; i < hbq_count; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4922) 		count += lpfc_hbq_defs[i]->entry_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4923) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4924) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4926) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4927)  * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4928)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4929)  * This function calculates amount of memory required for all hbq entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4930)  * to be configured and returns the total memory required.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4931)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4932) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4933) lpfc_sli_hbq_size(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4934) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4935) 	return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4936) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4937) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4938) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4939)  * lpfc_sli_hbq_setup - configure and initialize HBQs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4940)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4941)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4942)  * This function is called during the SLI initialization to configure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4943)  * all the HBQs and post buffers to the HBQ. The caller is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4944)  * required to hold any locks. This function will return zero if successful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4945)  * else it will return negative error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4946)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4947) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4948) lpfc_sli_hbq_setup(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4949) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4950) 	int  hbq_count = lpfc_sli_hbq_count();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4951) 	LPFC_MBOXQ_t *pmb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4952) 	MAILBOX_t *pmbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4953) 	uint32_t hbqno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4954) 	uint32_t hbq_entry_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4955) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4956) 				/* Get a Mailbox buffer to setup mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4957) 				 * commands for HBA initialization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4958) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4959) 	pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4961) 	if (!pmb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4962) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4964) 	pmbox = &pmb->u.mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4965) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4966) 	/* Initialize the struct lpfc_sli_hbq structure for each hbq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4967) 	phba->link_state = LPFC_INIT_MBX_CMDS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4968) 	phba->hbq_in_use = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4969) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4970) 	hbq_entry_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4971) 	for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4972) 		phba->hbqs[hbqno].next_hbqPutIdx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4973) 		phba->hbqs[hbqno].hbqPutIdx      = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4974) 		phba->hbqs[hbqno].local_hbqGetIdx   = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4975) 		phba->hbqs[hbqno].entry_count =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4976) 			lpfc_hbq_defs[hbqno]->entry_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4977) 		lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4978) 			hbq_entry_index, pmb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4979) 		hbq_entry_index += phba->hbqs[hbqno].entry_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4981) 		if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4982) 			/* Adapter failed to init, mbxCmd <cmd> CFG_RING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4983) 			   mbxStatus <status>, ring <num> */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4984) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4985) 			lpfc_printf_log(phba, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4986) 					LOG_SLI | LOG_VPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4987) 					"1805 Adapter failed to init. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4988) 					"Data: x%x x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4989) 					pmbox->mbxCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4990) 					pmbox->mbxStatus, hbqno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4992) 			phba->link_state = LPFC_HBA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4993) 			mempool_free(pmb, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4994) 			return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4995) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4996) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4997) 	phba->hbq_count = hbq_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4999) 	mempool_free(pmb, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5001) 	/* Initially populate or replenish the HBQs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5002) 	for (hbqno = 0; hbqno < hbq_count; ++hbqno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5003) 		lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5004) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5005) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5007) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5008)  * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5009)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5010)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5011)  * This function is called during the SLI initialization to configure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5012)  * all the HBQs and post buffers to the HBQ. The caller is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5013)  * required to hold any locks. This function will return zero if successful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5014)  * else it will return negative error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5015)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5016) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5017) lpfc_sli4_rb_setup(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5018) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5019) 	phba->hbq_in_use = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5020) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5021) 	 * Specific case when the MDS diagnostics is enabled and supported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5022) 	 * The receive buffer count is truncated to manage the incoming
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5023) 	 * traffic.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5024) 	 **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5025) 	if (phba->cfg_enable_mds_diags && phba->mds_diags_support)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5026) 		phba->hbqs[LPFC_ELS_HBQ].entry_count =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5027) 			lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5028) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5029) 		phba->hbqs[LPFC_ELS_HBQ].entry_count =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5030) 			lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5031) 	phba->hbq_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5032) 	lpfc_sli_hbqbuf_init_hbqs(phba, LPFC_ELS_HBQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5033) 	/* Initially populate or replenish the HBQs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5034) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5035) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5037) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5038)  * lpfc_sli_config_port - Issue config port mailbox command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5039)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5040)  * @sli_mode: sli mode - 2/3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5041)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5042)  * This function is called by the sli initialization code path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5043)  * to issue config_port mailbox command. This function restarts the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5044)  * HBA firmware and issues a config_port mailbox command to configure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5045)  * the SLI interface in the sli mode specified by sli_mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5046)  * variable. The caller is not required to hold any locks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5047)  * The function returns 0 if successful, else returns negative error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5048)  * code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5049)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5050) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5051) lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5052) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5053) 	LPFC_MBOXQ_t *pmb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5054) 	uint32_t resetcount = 0, rc = 0, done = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5056) 	pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5057) 	if (!pmb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5058) 		phba->link_state = LPFC_HBA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5059) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5060) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5061) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5062) 	phba->sli_rev = sli_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5063) 	while (resetcount < 2 && !done) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5064) 		spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5065) 		phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5066) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5067) 		phba->pport->port_state = LPFC_VPORT_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5068) 		lpfc_sli_brdrestart(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5069) 		rc = lpfc_sli_chipset_init(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5070) 		if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5071) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5072) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5073) 		spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5074) 		phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5075) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5076) 		resetcount++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5077) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5078) 		/* Call pre CONFIG_PORT mailbox command initialization.  A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5079) 		 * value of 0 means the call was successful.  Any other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5080) 		 * nonzero value is a failure, but if ERESTART is returned,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5081) 		 * the driver may reset the HBA and try again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5082) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5083) 		rc = lpfc_config_port_prep(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5084) 		if (rc == -ERESTART) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5085) 			phba->link_state = LPFC_LINK_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5086) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5087) 		} else if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5088) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5089) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5090) 		phba->link_state = LPFC_INIT_MBX_CMDS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5091) 		lpfc_config_port(phba, pmb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5092) 		rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5093) 		phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5094) 					LPFC_SLI3_HBQ_ENABLED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5095) 					LPFC_SLI3_CRP_ENABLED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5096) 					LPFC_SLI3_DSS_ENABLED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5097) 		if (rc != MBX_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5098) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5099) 				"0442 Adapter failed to init, mbxCmd x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5100) 				"CONFIG_PORT, mbxStatus x%x Data: x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5101) 				pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5102) 			spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5103) 			phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5104) 			spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5105) 			rc = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5106) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5107) 			/* Allow asynchronous mailbox command to go through */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5108) 			spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5109) 			phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5110) 			spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5111) 			done = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5113) 			if ((pmb->u.mb.un.varCfgPort.casabt == 1) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5114) 			    (pmb->u.mb.un.varCfgPort.gasabt == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5115) 				lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5116) 					"3110 Port did not grant ASABT\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5117) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5118) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5119) 	if (!done) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5120) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5121) 		goto do_prep_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5122) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5123) 	if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5124) 		if (!pmb->u.mb.un.varCfgPort.cMA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5125) 			rc = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5126) 			goto do_prep_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5127) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5128) 		if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5129) 			phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5130) 			phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5131) 			phba->max_vports = (phba->max_vpi > phba->max_vports) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5132) 				phba->max_vpi : phba->max_vports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5134) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5135) 			phba->max_vpi = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5136) 		if (pmb->u.mb.un.varCfgPort.gerbm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5137) 			phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5138) 		if (pmb->u.mb.un.varCfgPort.gcrp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5139) 			phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5141) 		phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5142) 		phba->port_gp = phba->mbox->us.s3_pgp.port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5144) 		if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5145) 			if (pmb->u.mb.un.varCfgPort.gbg == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5146) 				phba->cfg_enable_bg = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5147) 				phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5148) 				lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5149) 						"0443 Adapter did not grant "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5150) 						"BlockGuard\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5151) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5152) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5153) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5154) 		phba->hbq_get = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5155) 		phba->port_gp = phba->mbox->us.s2.port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5156) 		phba->max_vpi = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5157) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5158) do_prep_failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5159) 	mempool_free(pmb, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5160) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5164) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5165)  * lpfc_sli_hba_setup - SLI initialization function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5166)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5167)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5168)  * This function is the main SLI initialization function. This function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5169)  * is called by the HBA initialization code, HBA reset code and HBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5170)  * error attention handler code. Caller is not required to hold any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5171)  * locks. This function issues config_port mailbox command to configure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5172)  * the SLI, setup iocb rings and HBQ rings. In the end the function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5173)  * calls the config_port_post function to issue init_link mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5174)  * command and to start the discovery. The function will return zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5175)  * if successful, else it will return negative error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5176)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5177) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5178) lpfc_sli_hba_setup(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5180) 	uint32_t rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5181) 	int  mode = 3, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5182) 	int longs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5184) 	switch (phba->cfg_sli_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5185) 	case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5186) 		if (phba->cfg_enable_npiv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5187) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5188) 				"1824 NPIV enabled: Override sli_mode "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5189) 				"parameter (%d) to auto (0).\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5190) 				phba->cfg_sli_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5191) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5192) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5193) 		mode = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5194) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5195) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5196) 	case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5197) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5198) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5199) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5200) 				"1819 Unrecognized sli_mode parameter: %d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5201) 				phba->cfg_sli_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5203) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5204) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5205) 	phba->fcp_embed_io = 0;	/* SLI4 FC support only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5207) 	rc = lpfc_sli_config_port(phba, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5209) 	if (rc && phba->cfg_sli_mode == 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5210) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5211) 				"1820 Unable to select SLI-3.  "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5212) 				"Not supported by adapter.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5213) 	if (rc && mode != 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5214) 		rc = lpfc_sli_config_port(phba, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5215) 	else if (rc && mode == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5216) 		rc = lpfc_sli_config_port(phba, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5217) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5218) 		goto lpfc_sli_hba_setup_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5220) 	/* Enable PCIe device Advanced Error Reporting (AER) if configured */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5221) 	if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5222) 		rc = pci_enable_pcie_error_reporting(phba->pcidev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5223) 		if (!rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5224) 			lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5225) 					"2709 This device supports "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5226) 					"Advanced Error Reporting (AER)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5227) 			spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5228) 			phba->hba_flag |= HBA_AER_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5229) 			spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5230) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5231) 			lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5232) 					"2708 This device does not support "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5233) 					"Advanced Error Reporting (AER): %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5234) 					rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5235) 			phba->cfg_aer_support = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5236) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5237) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5239) 	if (phba->sli_rev == 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5240) 		phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5241) 		phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5242) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5243) 		phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5244) 		phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5245) 		phba->sli3_options = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5246) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5248) 	lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5249) 			"0444 Firmware in SLI %x mode. Max_vpi %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5250) 			phba->sli_rev, phba->max_vpi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5251) 	rc = lpfc_sli_ring_map(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5253) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5254) 		goto lpfc_sli_hba_setup_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5256) 	/* Initialize VPIs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5257) 	if (phba->sli_rev == LPFC_SLI_REV3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5258) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5259) 		 * The VPI bitmask and physical ID array are allocated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5260) 		 * and initialized once only - at driver load.  A port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5261) 		 * reset doesn't need to reinitialize this memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5262) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5263) 		if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5264) 			longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5265) 			phba->vpi_bmask = kcalloc(longs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5266) 						  sizeof(unsigned long),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5267) 						  GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5268) 			if (!phba->vpi_bmask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5269) 				rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5270) 				goto lpfc_sli_hba_setup_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5271) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5273) 			phba->vpi_ids = kcalloc(phba->max_vpi + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5274) 						sizeof(uint16_t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5275) 						GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5276) 			if (!phba->vpi_ids) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5277) 				kfree(phba->vpi_bmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5278) 				rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5279) 				goto lpfc_sli_hba_setup_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5280) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5281) 			for (i = 0; i < phba->max_vpi; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5282) 				phba->vpi_ids[i] = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5283) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5284) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5286) 	/* Init HBQs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5287) 	if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5288) 		rc = lpfc_sli_hbq_setup(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5289) 		if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5290) 			goto lpfc_sli_hba_setup_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5291) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5292) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5293) 	phba->sli.sli_flag |= LPFC_PROCESS_LA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5294) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5296) 	rc = lpfc_config_port_post(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5297) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5298) 		goto lpfc_sli_hba_setup_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5300) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5302) lpfc_sli_hba_setup_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5303) 	phba->link_state = LPFC_HBA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5304) 	lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5305) 			"0445 Firmware initialization failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5306) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5309) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5310)  * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5311)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5312)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5313)  * This function issue a dump mailbox command to read config region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5314)  * 23 and parse the records in the region and populate driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5315)  * data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5316)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5317) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5318) lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5320) 	LPFC_MBOXQ_t *mboxq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5321) 	struct lpfc_dmabuf *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5322) 	struct lpfc_mqe *mqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5323) 	uint32_t data_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5324) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5326) 	/* Program the default value of vlan_id and fc_map */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5327) 	phba->valid_vlan = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5328) 	phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5329) 	phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5330) 	phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5332) 	mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5333) 	if (!mboxq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5334) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5336) 	mqe = &mboxq->u.mqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5337) 	if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5338) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5339) 		goto out_free_mboxq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5340) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5342) 	mp = (struct lpfc_dmabuf *)mboxq->ctx_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5343) 	rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5345) 	lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5346) 			"(%d):2571 Mailbox cmd x%x Status x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5347) 			"Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5348) 			"x%x x%x x%x x%x x%x x%x x%x x%x x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5349) 			"CQ: x%x x%x x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5350) 			mboxq->vport ? mboxq->vport->vpi : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5351) 			bf_get(lpfc_mqe_command, mqe),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5352) 			bf_get(lpfc_mqe_status, mqe),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5353) 			mqe->un.mb_words[0], mqe->un.mb_words[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5354) 			mqe->un.mb_words[2], mqe->un.mb_words[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5355) 			mqe->un.mb_words[4], mqe->un.mb_words[5],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5356) 			mqe->un.mb_words[6], mqe->un.mb_words[7],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5357) 			mqe->un.mb_words[8], mqe->un.mb_words[9],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5358) 			mqe->un.mb_words[10], mqe->un.mb_words[11],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5359) 			mqe->un.mb_words[12], mqe->un.mb_words[13],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5360) 			mqe->un.mb_words[14], mqe->un.mb_words[15],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5361) 			mqe->un.mb_words[16], mqe->un.mb_words[50],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5362) 			mboxq->mcqe.word0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5363) 			mboxq->mcqe.mcqe_tag0, 	mboxq->mcqe.mcqe_tag1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5364) 			mboxq->mcqe.trailer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5366) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5367) 		lpfc_mbuf_free(phba, mp->virt, mp->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5368) 		kfree(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5369) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5370) 		goto out_free_mboxq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5371) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5372) 	data_length = mqe->un.mb_words[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5373) 	if (data_length > DMP_RGN23_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5374) 		lpfc_mbuf_free(phba, mp->virt, mp->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5375) 		kfree(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5376) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5377) 		goto out_free_mboxq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5378) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5380) 	lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5381) 	lpfc_mbuf_free(phba, mp->virt, mp->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5382) 	kfree(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5383) 	rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5385) out_free_mboxq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5386) 	mempool_free(mboxq, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5387) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5390) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5391)  * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5392)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5393)  * @mboxq: pointer to the LPFC_MBOXQ_t structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5394)  * @vpd: pointer to the memory to hold resulting port vpd data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5395)  * @vpd_size: On input, the number of bytes allocated to @vpd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5396)  *	      On output, the number of data bytes in @vpd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5397)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5398)  * This routine executes a READ_REV SLI4 mailbox command.  In
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5399)  * addition, this routine gets the port vpd data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5400)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5401)  * Return codes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5402)  * 	0 - successful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5403)  * 	-ENOMEM - could not allocated memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5404)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5405) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5406) lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5407) 		    uint8_t *vpd, uint32_t *vpd_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5409) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5410) 	uint32_t dma_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5411) 	struct lpfc_dmabuf *dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5412) 	struct lpfc_mqe *mqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5414) 	dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5415) 	if (!dmabuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5416) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5418) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5419) 	 * Get a DMA buffer for the vpd data resulting from the READ_REV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5420) 	 * mailbox command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5421) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5422) 	dma_size = *vpd_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5423) 	dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, dma_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5424) 					  &dmabuf->phys, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5425) 	if (!dmabuf->virt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5426) 		kfree(dmabuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5427) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5428) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5430) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5431) 	 * The SLI4 implementation of READ_REV conflicts at word1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5432) 	 * bits 31:16 and SLI4 adds vpd functionality not present
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5433) 	 * in SLI3.  This code corrects the conflicts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5434) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5435) 	lpfc_read_rev(phba, mboxq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5436) 	mqe = &mboxq->u.mqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5437) 	mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5438) 	mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5439) 	mqe->un.read_rev.word1 &= 0x0000FFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5440) 	bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5441) 	bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5443) 	rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5444) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5445) 		dma_free_coherent(&phba->pcidev->dev, dma_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5446) 				  dmabuf->virt, dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5447) 		kfree(dmabuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5448) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5449) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5451) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5452) 	 * The available vpd length cannot be bigger than the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5453) 	 * DMA buffer passed to the port.  Catch the less than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5454) 	 * case and update the caller's size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5455) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5456) 	if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5457) 		*vpd_size = mqe->un.read_rev.avail_vpd_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5459) 	memcpy(vpd, dmabuf->virt, *vpd_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5461) 	dma_free_coherent(&phba->pcidev->dev, dma_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5462) 			  dmabuf->virt, dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5463) 	kfree(dmabuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5464) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5467) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5468)  * lpfc_sli4_get_ctl_attr - Retrieve SLI4 device controller attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5469)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5470)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5471)  * This routine retrieves SLI4 device physical port name this PCI function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5472)  * is attached to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5473)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5474)  * Return codes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5475)  *      0 - successful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5476)  *      otherwise - failed to retrieve controller attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5477)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5478) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5479) lpfc_sli4_get_ctl_attr(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5480) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5481) 	LPFC_MBOXQ_t *mboxq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5482) 	struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5483) 	struct lpfc_controller_attribute *cntl_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5484) 	void *virtaddr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5485) 	uint32_t alloclen, reqlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5486) 	uint32_t shdr_status, shdr_add_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5487) 	union lpfc_sli4_cfg_shdr *shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5488) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5490) 	mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5491) 	if (!mboxq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5492) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5494) 	/* Send COMMON_GET_CNTL_ATTRIBUTES mbox cmd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5495) 	reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5496) 	alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5497) 			LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5498) 			LPFC_SLI4_MBX_NEMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5500) 	if (alloclen < reqlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5501) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5502) 				"3084 Allocated DMA memory size (%d) is "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5503) 				"less than the requested DMA memory size "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5504) 				"(%d)\n", alloclen, reqlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5505) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5506) 		goto out_free_mboxq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5507) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5508) 	rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5509) 	virtaddr = mboxq->sge_array->addr[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5510) 	mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5511) 	shdr = &mbx_cntl_attr->cfg_shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5512) 	shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5513) 	shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5514) 	if (shdr_status || shdr_add_status || rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5515) 		lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5516) 				"3085 Mailbox x%x (x%x/x%x) failed, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5517) 				"rc:x%x, status:x%x, add_status:x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5518) 				bf_get(lpfc_mqe_command, &mboxq->u.mqe),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5519) 				lpfc_sli_config_mbox_subsys_get(phba, mboxq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5520) 				lpfc_sli_config_mbox_opcode_get(phba, mboxq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5521) 				rc, shdr_status, shdr_add_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5522) 		rc = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5523) 		goto out_free_mboxq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5524) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5526) 	cntl_attr = &mbx_cntl_attr->cntl_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5527) 	phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5528) 	phba->sli4_hba.lnk_info.lnk_tp =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5529) 		bf_get(lpfc_cntl_attr_lnk_type, cntl_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5530) 	phba->sli4_hba.lnk_info.lnk_no =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5531) 		bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5533) 	memset(phba->BIOSVersion, 0, sizeof(phba->BIOSVersion));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5534) 	strlcat(phba->BIOSVersion, (char *)cntl_attr->bios_ver_str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5535) 		sizeof(phba->BIOSVersion));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5537) 	lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5538) 			"3086 lnk_type:%d, lnk_numb:%d, bios_ver:%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5539) 			phba->sli4_hba.lnk_info.lnk_tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5540) 			phba->sli4_hba.lnk_info.lnk_no,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5541) 			phba->BIOSVersion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5542) out_free_mboxq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5543) 	if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5544) 		lpfc_sli4_mbox_cmd_free(phba, mboxq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5545) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5546) 		mempool_free(mboxq, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5547) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5550) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5551)  * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5552)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5553)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5554)  * This routine retrieves SLI4 device physical port name this PCI function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5555)  * is attached to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5556)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5557)  * Return codes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5558)  *      0 - successful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5559)  *      otherwise - failed to retrieve physical port name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5560)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5561) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5562) lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5563) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5564) 	LPFC_MBOXQ_t *mboxq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5565) 	struct lpfc_mbx_get_port_name *get_port_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5566) 	uint32_t shdr_status, shdr_add_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5567) 	union lpfc_sli4_cfg_shdr *shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5568) 	char cport_name = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5569) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5571) 	/* We assume nothing at this point */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5572) 	phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5573) 	phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5575) 	mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5576) 	if (!mboxq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5577) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5578) 	/* obtain link type and link number via READ_CONFIG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5579) 	phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5580) 	lpfc_sli4_read_config(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5581) 	if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5582) 		goto retrieve_ppname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5584) 	/* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5585) 	rc = lpfc_sli4_get_ctl_attr(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5586) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5587) 		goto out_free_mboxq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5589) retrieve_ppname:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5590) 	lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5591) 		LPFC_MBOX_OPCODE_GET_PORT_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5592) 		sizeof(struct lpfc_mbx_get_port_name) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5593) 		sizeof(struct lpfc_sli4_cfg_mhdr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5594) 		LPFC_SLI4_MBX_EMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5595) 	get_port_name = &mboxq->u.mqe.un.get_port_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5596) 	shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5597) 	bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5598) 	bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5599) 		phba->sli4_hba.lnk_info.lnk_tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5600) 	rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5601) 	shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5602) 	shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5603) 	if (shdr_status || shdr_add_status || rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5604) 		lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5605) 				"3087 Mailbox x%x (x%x/x%x) failed: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5606) 				"rc:x%x, status:x%x, add_status:x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5607) 				bf_get(lpfc_mqe_command, &mboxq->u.mqe),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5608) 				lpfc_sli_config_mbox_subsys_get(phba, mboxq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5609) 				lpfc_sli_config_mbox_opcode_get(phba, mboxq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5610) 				rc, shdr_status, shdr_add_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5611) 		rc = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5612) 		goto out_free_mboxq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5613) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5614) 	switch (phba->sli4_hba.lnk_info.lnk_no) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5615) 	case LPFC_LINK_NUMBER_0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5616) 		cport_name = bf_get(lpfc_mbx_get_port_name_name0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5617) 				&get_port_name->u.response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5618) 		phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5619) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5620) 	case LPFC_LINK_NUMBER_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5621) 		cport_name = bf_get(lpfc_mbx_get_port_name_name1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5622) 				&get_port_name->u.response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5623) 		phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5624) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5625) 	case LPFC_LINK_NUMBER_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5626) 		cport_name = bf_get(lpfc_mbx_get_port_name_name2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5627) 				&get_port_name->u.response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5628) 		phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5629) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5630) 	case LPFC_LINK_NUMBER_3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5631) 		cport_name = bf_get(lpfc_mbx_get_port_name_name3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5632) 				&get_port_name->u.response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5633) 		phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5634) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5635) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5636) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5637) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5639) 	if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5640) 		phba->Port[0] = cport_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5641) 		phba->Port[1] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5642) 		lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5643) 				"3091 SLI get port name: %s\n", phba->Port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5644) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5646) out_free_mboxq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5647) 	if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5648) 		lpfc_sli4_mbox_cmd_free(phba, mboxq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5649) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5650) 		mempool_free(mboxq, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5651) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5654) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5655)  * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5656)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5657)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5658)  * This routine is called to explicitly arm the SLI4 device's completion and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5659)  * event queues
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5660)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5661) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5662) lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5663) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5664) 	int qidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5665) 	struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5666) 	struct lpfc_sli4_hdw_queue *qp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5667) 	struct lpfc_queue *eq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5669) 	sli4_hba->sli4_write_cq_db(phba, sli4_hba->mbx_cq, 0, LPFC_QUEUE_REARM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5670) 	sli4_hba->sli4_write_cq_db(phba, sli4_hba->els_cq, 0, LPFC_QUEUE_REARM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5671) 	if (sli4_hba->nvmels_cq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5672) 		sli4_hba->sli4_write_cq_db(phba, sli4_hba->nvmels_cq, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5673) 					   LPFC_QUEUE_REARM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5675) 	if (sli4_hba->hdwq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5676) 		/* Loop thru all Hardware Queues */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5677) 		for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5678) 			qp = &sli4_hba->hdwq[qidx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5679) 			/* ARM the corresponding CQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5680) 			sli4_hba->sli4_write_cq_db(phba, qp->io_cq, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5681) 						LPFC_QUEUE_REARM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5682) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5684) 		/* Loop thru all IRQ vectors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5685) 		for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5686) 			eq = sli4_hba->hba_eq_hdl[qidx].eq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5687) 			/* ARM the corresponding EQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5688) 			sli4_hba->sli4_write_eq_db(phba, eq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5689) 						   0, LPFC_QUEUE_REARM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5690) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5691) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5693) 	if (phba->nvmet_support) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5694) 		for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5695) 			sli4_hba->sli4_write_cq_db(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5696) 				sli4_hba->nvmet_cqset[qidx], 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5697) 				LPFC_QUEUE_REARM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5698) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5699) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5700) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5702) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5703)  * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5704)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5705)  * @type: The resource extent type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5706)  * @extnt_count: buffer to hold port available extent count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5707)  * @extnt_size: buffer to hold element count per extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5708)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5709)  * This function calls the port and retrievs the number of available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5710)  * extents and their size for a particular extent type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5711)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5712)  * Returns: 0 if successful.  Nonzero otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5713)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5714) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5715) lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5716) 			       uint16_t *extnt_count, uint16_t *extnt_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5717) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5718) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5719) 	uint32_t length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5720) 	uint32_t mbox_tmo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5721) 	struct lpfc_mbx_get_rsrc_extent_info *rsrc_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5722) 	LPFC_MBOXQ_t *mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5724) 	mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5725) 	if (!mbox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5726) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5728) 	/* Find out how many extents are available for this resource type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5729) 	length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5730) 		  sizeof(struct lpfc_sli4_cfg_mhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5731) 	lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5732) 			 LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5733) 			 length, LPFC_SLI4_MBX_EMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5735) 	/* Send an extents count of 0 - the GET doesn't use it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5736) 	rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5737) 					LPFC_SLI4_MBX_EMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5738) 	if (unlikely(rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5739) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5740) 		goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5741) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5743) 	if (!phba->sli4_hba.intr_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5744) 		rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5745) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5746) 		mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5747) 		rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5748) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5749) 	if (unlikely(rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5750) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5751) 		goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5752) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5754) 	rsrc_info = &mbox->u.mqe.un.rsrc_extent_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5755) 	if (bf_get(lpfc_mbox_hdr_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5756) 		   &rsrc_info->header.cfg_shdr.response)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5757) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5758) 				"2930 Failed to get resource extents "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5759) 				"Status 0x%x Add'l Status 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5760) 				bf_get(lpfc_mbox_hdr_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5761) 				       &rsrc_info->header.cfg_shdr.response),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5762) 				bf_get(lpfc_mbox_hdr_add_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5763) 				       &rsrc_info->header.cfg_shdr.response));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5764) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5765) 		goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5766) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5768) 	*extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5769) 			      &rsrc_info->u.rsp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5770) 	*extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5771) 			     &rsrc_info->u.rsp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5773) 	lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5774) 			"3162 Retrieved extents type-%d from port: count:%d, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5775) 			"size:%d\n", type, *extnt_count, *extnt_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5777) err_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5778) 	mempool_free(mbox, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5779) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5782) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5783)  * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5784)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5785)  * @type: The extent type to check.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5786)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5787)  * This function reads the current available extents from the port and checks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5788)  * if the extent count or extent size has changed since the last access.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5789)  * Callers use this routine post port reset to understand if there is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5790)  * extent reprovisioning requirement.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5791)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5792)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5793)  *   -Error: error indicates problem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5794)  *   1: Extent count or size has changed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5795)  *   0: No changes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5796)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5797) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5798) lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5799) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5800) 	uint16_t curr_ext_cnt, rsrc_ext_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5801) 	uint16_t size_diff, rsrc_ext_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5802) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5803) 	struct lpfc_rsrc_blks *rsrc_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5804) 	struct list_head *rsrc_blk_list = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5806) 	size_diff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5807) 	curr_ext_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5808) 	rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5809) 					    &rsrc_ext_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5810) 					    &rsrc_ext_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5811) 	if (unlikely(rc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5812) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5814) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5815) 	case LPFC_RSC_TYPE_FCOE_RPI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5816) 		rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5817) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5818) 	case LPFC_RSC_TYPE_FCOE_VPI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5819) 		rsrc_blk_list = &phba->lpfc_vpi_blk_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5820) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5821) 	case LPFC_RSC_TYPE_FCOE_XRI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5822) 		rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5823) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5824) 	case LPFC_RSC_TYPE_FCOE_VFI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5825) 		rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5826) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5827) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5828) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5829) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5831) 	list_for_each_entry(rsrc_entry, rsrc_blk_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5832) 		curr_ext_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5833) 		if (rsrc_entry->rsrc_size != rsrc_ext_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5834) 			size_diff++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5835) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5837) 	if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5838) 		rc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5840) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5841) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5843) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5844)  * lpfc_sli4_cfg_post_extnts -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5845)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5846)  * @extnt_cnt: number of available extents.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5847)  * @type: the extent type (rpi, xri, vfi, vpi).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5848)  * @emb: buffer to hold either MBX_EMBED or MBX_NEMBED operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5849)  * @mbox: pointer to the caller's allocated mailbox structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5850)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5851)  * This function executes the extents allocation request.  It also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5852)  * takes care of the amount of memory needed to allocate or get the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5853)  * allocated extents. It is the caller's responsibility to evaluate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5854)  * the response.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5855)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5856)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5857)  *   -Error:  Error value describes the condition found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5858)  *   0: if successful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5859)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5860) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5861) lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5862) 			  uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5863) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5864) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5865) 	uint32_t req_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5866) 	uint32_t emb_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5867) 	uint32_t alloc_len, mbox_tmo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5869) 	/* Calculate the total requested length of the dma memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5870) 	req_len = extnt_cnt * sizeof(uint16_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5872) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5873) 	 * Calculate the size of an embedded mailbox.  The uint32_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5874) 	 * accounts for extents-specific word.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5875) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5876) 	emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5877) 		sizeof(uint32_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5879) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5880) 	 * Presume the allocation and response will fit into an embedded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5881) 	 * mailbox.  If not true, reconfigure to a non-embedded mailbox.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5882) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5883) 	*emb = LPFC_SLI4_MBX_EMBED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5884) 	if (req_len > emb_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5885) 		req_len = extnt_cnt * sizeof(uint16_t) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5886) 			sizeof(union lpfc_sli4_cfg_shdr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5887) 			sizeof(uint32_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5888) 		*emb = LPFC_SLI4_MBX_NEMBED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5889) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5891) 	alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5892) 				     LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5893) 				     req_len, *emb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5894) 	if (alloc_len < req_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5895) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5896) 			"2982 Allocated DMA memory size (x%x) is "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5897) 			"less than the requested DMA memory "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5898) 			"size (x%x)\n", alloc_len, req_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5899) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5900) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5901) 	rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5902) 	if (unlikely(rc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5903) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5905) 	if (!phba->sli4_hba.intr_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5906) 		rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5907) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5908) 		mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5909) 		rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5910) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5912) 	if (unlikely(rc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5913) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5914) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5915) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5917) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5918)  * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5919)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5920)  * @type:  The resource extent type to allocate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5921)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5922)  * This function allocates the number of elements for the specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5923)  * resource type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5924)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5925) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5926) lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5927) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5928) 	bool emb = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5929) 	uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5930) 	uint16_t rsrc_id, rsrc_start, j, k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5931) 	uint16_t *ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5932) 	int i, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5933) 	unsigned long longs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5934) 	unsigned long *bmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5935) 	struct lpfc_rsrc_blks *rsrc_blks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5936) 	LPFC_MBOXQ_t *mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5937) 	uint32_t length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5938) 	struct lpfc_id_range *id_array = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5939) 	void *virtaddr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5940) 	struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5941) 	struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5942) 	struct list_head *ext_blk_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5944) 	rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5945) 					    &rsrc_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5946) 					    &rsrc_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5947) 	if (unlikely(rc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5948) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5949) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5950) 	if ((rsrc_cnt == 0) || (rsrc_size == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5951) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5952) 			"3009 No available Resource Extents "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5953) 			"for resource type 0x%x: Count: 0x%x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5954) 			"Size 0x%x\n", type, rsrc_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5955) 			rsrc_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5956) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5957) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5959) 	lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5960) 			"2903 Post resource extents type-0x%x: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5961) 			"count:%d, size %d\n", type, rsrc_cnt, rsrc_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5962) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5963) 	mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5964) 	if (!mbox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5965) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5967) 	rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5968) 	if (unlikely(rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5969) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5970) 		goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5971) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5973) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5974) 	 * Figure out where the response is located.  Then get local pointers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5975) 	 * to the response data.  The port does not guarantee to respond to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5976) 	 * all extents counts request so update the local variable with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5977) 	 * allocated count from the port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5978) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5979) 	if (emb == LPFC_SLI4_MBX_EMBED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5980) 		rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5981) 		id_array = &rsrc_ext->u.rsp.id[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5982) 		rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5983) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5984) 		virtaddr = mbox->sge_array->addr[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5985) 		n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5986) 		rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5987) 		id_array = &n_rsrc->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5988) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5989) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5990) 	longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5991) 	rsrc_id_cnt = rsrc_cnt * rsrc_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5992) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5993) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5994) 	 * Based on the resource size and count, correct the base and max
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5995) 	 * resource values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5996) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5997) 	length = sizeof(struct lpfc_rsrc_blks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5998) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5999) 	case LPFC_RSC_TYPE_FCOE_RPI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6000) 		phba->sli4_hba.rpi_bmask = kcalloc(longs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6001) 						   sizeof(unsigned long),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6002) 						   GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6003) 		if (unlikely(!phba->sli4_hba.rpi_bmask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6004) 			rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6005) 			goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6006) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6007) 		phba->sli4_hba.rpi_ids = kcalloc(rsrc_id_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6008) 						 sizeof(uint16_t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6009) 						 GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6010) 		if (unlikely(!phba->sli4_hba.rpi_ids)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6011) 			kfree(phba->sli4_hba.rpi_bmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6012) 			rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6013) 			goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6014) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6015) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6016) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6017) 		 * The next_rpi was initialized with the maximum available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6018) 		 * count but the port may allocate a smaller number.  Catch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6019) 		 * that case and update the next_rpi.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6020) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6021) 		phba->sli4_hba.next_rpi = rsrc_id_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6022) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6023) 		/* Initialize local ptrs for common extent processing later. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6024) 		bmask = phba->sli4_hba.rpi_bmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6025) 		ids = phba->sli4_hba.rpi_ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6026) 		ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6027) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6028) 	case LPFC_RSC_TYPE_FCOE_VPI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6029) 		phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6030) 					  GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6031) 		if (unlikely(!phba->vpi_bmask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6032) 			rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6033) 			goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6034) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6035) 		phba->vpi_ids = kcalloc(rsrc_id_cnt, sizeof(uint16_t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6036) 					 GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6037) 		if (unlikely(!phba->vpi_ids)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6038) 			kfree(phba->vpi_bmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6039) 			rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6040) 			goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6041) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6043) 		/* Initialize local ptrs for common extent processing later. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6044) 		bmask = phba->vpi_bmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6045) 		ids = phba->vpi_ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6046) 		ext_blk_list = &phba->lpfc_vpi_blk_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6047) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6048) 	case LPFC_RSC_TYPE_FCOE_XRI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6049) 		phba->sli4_hba.xri_bmask = kcalloc(longs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6050) 						   sizeof(unsigned long),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6051) 						   GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6052) 		if (unlikely(!phba->sli4_hba.xri_bmask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6053) 			rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6054) 			goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6055) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6056) 		phba->sli4_hba.max_cfg_param.xri_used = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6057) 		phba->sli4_hba.xri_ids = kcalloc(rsrc_id_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6058) 						 sizeof(uint16_t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6059) 						 GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6060) 		if (unlikely(!phba->sli4_hba.xri_ids)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6061) 			kfree(phba->sli4_hba.xri_bmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6062) 			rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6063) 			goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6064) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6066) 		/* Initialize local ptrs for common extent processing later. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6067) 		bmask = phba->sli4_hba.xri_bmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6068) 		ids = phba->sli4_hba.xri_ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6069) 		ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6070) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6071) 	case LPFC_RSC_TYPE_FCOE_VFI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6072) 		phba->sli4_hba.vfi_bmask = kcalloc(longs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6073) 						   sizeof(unsigned long),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6074) 						   GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6075) 		if (unlikely(!phba->sli4_hba.vfi_bmask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6076) 			rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6077) 			goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6078) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6079) 		phba->sli4_hba.vfi_ids = kcalloc(rsrc_id_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6080) 						 sizeof(uint16_t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6081) 						 GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6082) 		if (unlikely(!phba->sli4_hba.vfi_ids)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6083) 			kfree(phba->sli4_hba.vfi_bmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6084) 			rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6085) 			goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6086) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6088) 		/* Initialize local ptrs for common extent processing later. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6089) 		bmask = phba->sli4_hba.vfi_bmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6090) 		ids = phba->sli4_hba.vfi_ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6091) 		ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6092) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6093) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6094) 		/* Unsupported Opcode.  Fail call. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6095) 		id_array = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6096) 		bmask = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6097) 		ids = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6098) 		ext_blk_list = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6099) 		goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6100) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6102) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6103) 	 * Complete initializing the extent configuration with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6104) 	 * allocated ids assigned to this function.  The bitmask serves
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6105) 	 * as an index into the array and manages the available ids.  The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6106) 	 * array just stores the ids communicated to the port via the wqes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6107) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6108) 	for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6109) 		if ((i % 2) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6110) 			rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6111) 					 &id_array[k]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6112) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6113) 			rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6114) 					 &id_array[k]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6116) 		rsrc_blks = kzalloc(length, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6117) 		if (unlikely(!rsrc_blks)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6118) 			rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6119) 			kfree(bmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6120) 			kfree(ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6121) 			goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6122) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6123) 		rsrc_blks->rsrc_start = rsrc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6124) 		rsrc_blks->rsrc_size = rsrc_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6125) 		list_add_tail(&rsrc_blks->list, ext_blk_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6126) 		rsrc_start = rsrc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6127) 		if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6128) 			phba->sli4_hba.io_xri_start = rsrc_start +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6129) 				lpfc_sli4_get_iocb_cnt(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6130) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6132) 		while (rsrc_id < (rsrc_start + rsrc_size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6133) 			ids[j] = rsrc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6134) 			rsrc_id++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6135) 			j++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6136) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6137) 		/* Entire word processed.  Get next word.*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6138) 		if ((i % 2) == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6139) 			k++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6140) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6141)  err_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6142) 	lpfc_sli4_mbox_cmd_free(phba, mbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6143) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6148) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6149)  * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6150)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6151)  * @type: the extent's type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6152)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6153)  * This function deallocates all extents of a particular resource type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6154)  * SLI4 does not allow for deallocating a particular extent range.  It
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6155)  * is the caller's responsibility to release all kernel memory resources.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6156)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6157) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6158) lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6160) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6161) 	uint32_t length, mbox_tmo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6162) 	LPFC_MBOXQ_t *mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6163) 	struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6164) 	struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6166) 	mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6167) 	if (!mbox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6168) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6170) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6171) 	 * This function sends an embedded mailbox because it only sends the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6172) 	 * the resource type.  All extents of this type are released by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6173) 	 * port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6174) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6175) 	length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6176) 		  sizeof(struct lpfc_sli4_cfg_mhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6177) 	lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6178) 			 LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6179) 			 length, LPFC_SLI4_MBX_EMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6181) 	/* Send an extents count of 0 - the dealloc doesn't use it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6182) 	rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6183) 					LPFC_SLI4_MBX_EMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6184) 	if (unlikely(rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6185) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6186) 		goto out_free_mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6187) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6188) 	if (!phba->sli4_hba.intr_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6189) 		rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6190) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6191) 		mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6192) 		rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6193) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6194) 	if (unlikely(rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6195) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6196) 		goto out_free_mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6197) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6199) 	dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6200) 	if (bf_get(lpfc_mbox_hdr_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6201) 		   &dealloc_rsrc->header.cfg_shdr.response)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6202) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6203) 				"2919 Failed to release resource extents "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6204) 				"for type %d - Status 0x%x Add'l Status 0x%x. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6205) 				"Resource memory not released.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6206) 				type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6207) 				bf_get(lpfc_mbox_hdr_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6208) 				    &dealloc_rsrc->header.cfg_shdr.response),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6209) 				bf_get(lpfc_mbox_hdr_add_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6210) 				    &dealloc_rsrc->header.cfg_shdr.response));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6211) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6212) 		goto out_free_mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6213) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6215) 	/* Release kernel memory resources for the specific type. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6216) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6217) 	case LPFC_RSC_TYPE_FCOE_VPI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6218) 		kfree(phba->vpi_bmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6219) 		kfree(phba->vpi_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6220) 		bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6221) 		list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6222) 				    &phba->lpfc_vpi_blk_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6223) 			list_del_init(&rsrc_blk->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6224) 			kfree(rsrc_blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6225) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6226) 		phba->sli4_hba.max_cfg_param.vpi_used = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6227) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6228) 	case LPFC_RSC_TYPE_FCOE_XRI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6229) 		kfree(phba->sli4_hba.xri_bmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6230) 		kfree(phba->sli4_hba.xri_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6231) 		list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6232) 				    &phba->sli4_hba.lpfc_xri_blk_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6233) 			list_del_init(&rsrc_blk->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6234) 			kfree(rsrc_blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6235) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6236) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6237) 	case LPFC_RSC_TYPE_FCOE_VFI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6238) 		kfree(phba->sli4_hba.vfi_bmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6239) 		kfree(phba->sli4_hba.vfi_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6240) 		bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6241) 		list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6242) 				    &phba->sli4_hba.lpfc_vfi_blk_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6243) 			list_del_init(&rsrc_blk->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6244) 			kfree(rsrc_blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6245) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6246) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6247) 	case LPFC_RSC_TYPE_FCOE_RPI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6248) 		/* RPI bitmask and physical id array are cleaned up earlier. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6249) 		list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6250) 				    &phba->sli4_hba.lpfc_rpi_blk_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6251) 			list_del_init(&rsrc_blk->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6252) 			kfree(rsrc_blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6253) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6254) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6255) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6256) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6257) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6259) 	bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6261)  out_free_mbox:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6262) 	mempool_free(mbox, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6263) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6266) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6267) lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6268) 		  uint32_t feature)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6270) 	uint32_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6272) 	len = sizeof(struct lpfc_mbx_set_feature) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6273) 		sizeof(struct lpfc_sli4_cfg_mhdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6274) 	lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6275) 			 LPFC_MBOX_OPCODE_SET_FEATURES, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6276) 			 LPFC_SLI4_MBX_EMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6278) 	switch (feature) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6279) 	case LPFC_SET_UE_RECOVERY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6280) 		bf_set(lpfc_mbx_set_feature_UER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6281) 		       &mbox->u.mqe.un.set_feature, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6282) 		mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6283) 		mbox->u.mqe.un.set_feature.param_len = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6284) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6285) 	case LPFC_SET_MDS_DIAGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6286) 		bf_set(lpfc_mbx_set_feature_mds,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6287) 		       &mbox->u.mqe.un.set_feature, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6288) 		bf_set(lpfc_mbx_set_feature_mds_deep_loopbk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6289) 		       &mbox->u.mqe.un.set_feature, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6290) 		mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6291) 		mbox->u.mqe.un.set_feature.param_len = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6292) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6293) 	case LPFC_SET_DUAL_DUMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6294) 		bf_set(lpfc_mbx_set_feature_dd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6295) 		       &mbox->u.mqe.un.set_feature, LPFC_ENABLE_DUAL_DUMP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6296) 		bf_set(lpfc_mbx_set_feature_ddquery,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6297) 		       &mbox->u.mqe.un.set_feature, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6298) 		mbox->u.mqe.un.set_feature.feature = LPFC_SET_DUAL_DUMP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6299) 		mbox->u.mqe.un.set_feature.param_len = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6300) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6301) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6303) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6306) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6307)  * lpfc_ras_stop_fwlog: Disable FW logging by the adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6308)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6309)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6310)  * Disable FW logging into host memory on the adapter. To
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6311)  * be done before reading logs from the host memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6312)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6313) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6314) lpfc_ras_stop_fwlog(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6315) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6316) 	struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6318) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6319) 	ras_fwlog->state = INACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6320) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6322) 	/* Disable FW logging to host memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6323) 	writel(LPFC_CTL_PDEV_CTL_DDL_RAS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6324) 	       phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6326) 	/* Wait 10ms for firmware to stop using DMA buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6327) 	usleep_range(10 * 1000, 20 * 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6330) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6331)  * lpfc_sli4_ras_dma_free - Free memory allocated for FW logging.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6332)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6333)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6334)  * This function is called to free memory allocated for RAS FW logging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6335)  * support in the driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6336)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6337) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6338) lpfc_sli4_ras_dma_free(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6340) 	struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6341) 	struct lpfc_dmabuf *dmabuf, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6343) 	if (!list_empty(&ras_fwlog->fwlog_buff_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6344) 		list_for_each_entry_safe(dmabuf, next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6345) 				    &ras_fwlog->fwlog_buff_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6346) 				    list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6347) 			list_del(&dmabuf->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6348) 			dma_free_coherent(&phba->pcidev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6349) 					  LPFC_RAS_MAX_ENTRY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6350) 					  dmabuf->virt, dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6351) 			kfree(dmabuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6352) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6353) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6355) 	if (ras_fwlog->lwpd.virt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6356) 		dma_free_coherent(&phba->pcidev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6357) 				  sizeof(uint32_t) * 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6358) 				  ras_fwlog->lwpd.virt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6359) 				  ras_fwlog->lwpd.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6360) 		ras_fwlog->lwpd.virt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6361) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6363) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6364) 	ras_fwlog->state = INACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6365) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6368) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6369)  * lpfc_sli4_ras_dma_alloc: Allocate memory for FW support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6370)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6371)  * @fwlog_buff_count: Count of buffers to be created.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6372)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6373)  * This routine DMA memory for Log Write Position Data[LPWD] and buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6374)  * to update FW log is posted to the adapter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6375)  * Buffer count is calculated based on module param ras_fwlog_buffsize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6376)  * Size of each buffer posted to FW is 64K.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6377)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6379) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6380) lpfc_sli4_ras_dma_alloc(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6381) 			uint32_t fwlog_buff_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6382) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6383) 	struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6384) 	struct lpfc_dmabuf *dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6385) 	int rc = 0, i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6387) 	/* Initialize List */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6388) 	INIT_LIST_HEAD(&ras_fwlog->fwlog_buff_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6390) 	/* Allocate memory for the LWPD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6391) 	ras_fwlog->lwpd.virt = dma_alloc_coherent(&phba->pcidev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6392) 					    sizeof(uint32_t) * 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6393) 					    &ras_fwlog->lwpd.phys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6394) 					    GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6395) 	if (!ras_fwlog->lwpd.virt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6396) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6397) 				"6185 LWPD Memory Alloc Failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6399) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6400) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6402) 	ras_fwlog->fw_buffcount = fwlog_buff_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6403) 	for (i = 0; i < ras_fwlog->fw_buffcount; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6404) 		dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6405) 				 GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6406) 		if (!dmabuf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6407) 			rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6408) 			lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6409) 					"6186 Memory Alloc failed FW logging");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6410) 			goto free_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6411) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6413) 		dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6414) 						  LPFC_RAS_MAX_ENTRY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6415) 						  &dmabuf->phys, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6416) 		if (!dmabuf->virt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6417) 			kfree(dmabuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6418) 			rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6419) 			lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6420) 					"6187 DMA Alloc Failed FW logging");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6421) 			goto free_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6422) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6423) 		dmabuf->buffer_tag = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6424) 		list_add_tail(&dmabuf->list, &ras_fwlog->fwlog_buff_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6425) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6427) free_mem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6428) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6429) 		lpfc_sli4_ras_dma_free(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6431) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6434) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6435)  * lpfc_sli4_ras_mbox_cmpl: Completion handler for RAS MBX command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6436)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6437)  * @pmb: pointer to the driver internal queue element for mailbox command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6438)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6439)  * Completion handler for driver's RAS MBX command to the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6440)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6441) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6442) lpfc_sli4_ras_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6444) 	MAILBOX_t *mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6445) 	union lpfc_sli4_cfg_shdr *shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6446) 	uint32_t shdr_status, shdr_add_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6447) 	struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6449) 	mb = &pmb->u.mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6451) 	shdr = (union lpfc_sli4_cfg_shdr *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6452) 		&pmb->u.mqe.un.ras_fwlog.header.cfg_shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6453) 	shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6454) 	shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6456) 	if (mb->mbxStatus != MBX_SUCCESS || shdr_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6457) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6458) 				"6188 FW LOG mailbox "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6459) 				"completed with status x%x add_status x%x,"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6460) 				" mbx status x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6461) 				shdr_status, shdr_add_status, mb->mbxStatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6463) 		ras_fwlog->ras_hwsupport = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6464) 		goto disable_ras;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6465) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6467) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6468) 	ras_fwlog->state = ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6469) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6470) 	mempool_free(pmb, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6472) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6474) disable_ras:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6475) 	/* Free RAS DMA memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6476) 	lpfc_sli4_ras_dma_free(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6477) 	mempool_free(pmb, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6480) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6481)  * lpfc_sli4_ras_fwlog_init: Initialize memory and post RAS MBX command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6482)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6483)  * @fwlog_level: Logging verbosity level.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6484)  * @fwlog_enable: Enable/Disable logging.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6485)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6486)  * Initialize memory and post mailbox command to enable FW logging in host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6487)  * memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6488)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6489) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6490) lpfc_sli4_ras_fwlog_init(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6491) 			 uint32_t fwlog_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6492) 			 uint32_t fwlog_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6493) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6494) 	struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6495) 	struct lpfc_mbx_set_ras_fwlog *mbx_fwlog = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6496) 	struct lpfc_dmabuf *dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6497) 	LPFC_MBOXQ_t *mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6498) 	uint32_t len = 0, fwlog_buffsize, fwlog_entry_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6499) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6501) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6502) 	ras_fwlog->state = INACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6503) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6505) 	fwlog_buffsize = (LPFC_RAS_MIN_BUFF_POST_SIZE *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6506) 			  phba->cfg_ras_fwlog_buffsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6507) 	fwlog_entry_count = (fwlog_buffsize/LPFC_RAS_MAX_ENTRY_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6509) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6510) 	 * If re-enabling FW logging support use earlier allocated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6511) 	 * DMA buffers while posting MBX command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6512) 	 **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6513) 	if (!ras_fwlog->lwpd.virt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6514) 		rc = lpfc_sli4_ras_dma_alloc(phba, fwlog_entry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6515) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6516) 			lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6517) 					"6189 FW Log Memory Allocation Failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6518) 			return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6519) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6520) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6522) 	/* Setup Mailbox command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6523) 	mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6524) 	if (!mbox) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6525) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6526) 				"6190 RAS MBX Alloc Failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6527) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6528) 		goto mem_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6529) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6531) 	ras_fwlog->fw_loglevel = fwlog_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6532) 	len = (sizeof(struct lpfc_mbx_set_ras_fwlog) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6533) 		sizeof(struct lpfc_sli4_cfg_mhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6535) 	lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_LOWLEVEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6536) 			 LPFC_MBOX_OPCODE_SET_DIAG_LOG_OPTION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6537) 			 len, LPFC_SLI4_MBX_EMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6539) 	mbx_fwlog = (struct lpfc_mbx_set_ras_fwlog *)&mbox->u.mqe.un.ras_fwlog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6540) 	bf_set(lpfc_fwlog_enable, &mbx_fwlog->u.request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6541) 	       fwlog_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6542) 	bf_set(lpfc_fwlog_loglvl, &mbx_fwlog->u.request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6543) 	       ras_fwlog->fw_loglevel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6544) 	bf_set(lpfc_fwlog_buffcnt, &mbx_fwlog->u.request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6545) 	       ras_fwlog->fw_buffcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6546) 	bf_set(lpfc_fwlog_buffsz, &mbx_fwlog->u.request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6547) 	       LPFC_RAS_MAX_ENTRY_SIZE/SLI4_PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6549) 	/* Update DMA buffer address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6550) 	list_for_each_entry(dmabuf, &ras_fwlog->fwlog_buff_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6551) 		memset(dmabuf->virt, 0, LPFC_RAS_MAX_ENTRY_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6553) 		mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_lo =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6554) 			putPaddrLow(dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6556) 		mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_hi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6557) 			putPaddrHigh(dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6558) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6560) 	/* Update LPWD address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6561) 	mbx_fwlog->u.request.lwpd.addr_lo = putPaddrLow(ras_fwlog->lwpd.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6562) 	mbx_fwlog->u.request.lwpd.addr_hi = putPaddrHigh(ras_fwlog->lwpd.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6564) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6565) 	ras_fwlog->state = REG_INPROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6566) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6567) 	mbox->vport = phba->pport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6568) 	mbox->mbox_cmpl = lpfc_sli4_ras_mbox_cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6570) 	rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6572) 	if (rc == MBX_NOT_FINISHED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6573) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6574) 				"6191 FW-Log Mailbox failed. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6575) 				"status %d mbxStatus : x%x", rc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6576) 				bf_get(lpfc_mqe_status, &mbox->u.mqe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6577) 		mempool_free(mbox, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6578) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6579) 		goto mem_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6580) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6581) 		rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6582) mem_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6583) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6584) 		lpfc_sli4_ras_dma_free(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6586) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6589) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6590)  * lpfc_sli4_ras_setup - Check if RAS supported on the adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6591)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6592)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6593)  * Check if RAS is supported on the adapter and initialize it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6594)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6595) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6596) lpfc_sli4_ras_setup(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6597) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6598) 	/* Check RAS FW Log needs to be enabled or not */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6599) 	if (lpfc_check_fwlog_support(phba))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6600) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6602) 	lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6603) 				 LPFC_RAS_ENABLE_LOGGING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6606) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6607)  * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6608)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6609)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6610)  * This function allocates all SLI4 resource identifiers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6611)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6612) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6613) lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6614) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6615) 	int i, rc, error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6616) 	uint16_t count, base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6617) 	unsigned long longs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6619) 	if (!phba->sli4_hba.rpi_hdrs_in_use)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6620) 		phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6621) 	if (phba->sli4_hba.extents_in_use) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6622) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6623) 		 * The port supports resource extents. The XRI, VPI, VFI, RPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6624) 		 * resource extent count must be read and allocated before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6625) 		 * provisioning the resource id arrays.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6626) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6627) 		if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6628) 		    LPFC_IDX_RSRC_RDY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6629) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6630) 			 * Extent-based resources are set - the driver could
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6631) 			 * be in a port reset. Figure out if any corrective
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6632) 			 * actions need to be taken.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6633) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6634) 			rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6635) 						 LPFC_RSC_TYPE_FCOE_VFI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6636) 			if (rc != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6637) 				error++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6638) 			rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6639) 						 LPFC_RSC_TYPE_FCOE_VPI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6640) 			if (rc != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6641) 				error++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6642) 			rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6643) 						 LPFC_RSC_TYPE_FCOE_XRI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6644) 			if (rc != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6645) 				error++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6646) 			rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6647) 						 LPFC_RSC_TYPE_FCOE_RPI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6648) 			if (rc != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6649) 				error++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6651) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6652) 			 * It's possible that the number of resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6653) 			 * provided to this port instance changed between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6654) 			 * resets.  Detect this condition and reallocate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6655) 			 * resources.  Otherwise, there is no action.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6656) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6657) 			if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6658) 				lpfc_printf_log(phba, KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6659) 						LOG_MBOX | LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6660) 						"2931 Detected extent resource "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6661) 						"change.  Reallocating all "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6662) 						"extents.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6663) 				rc = lpfc_sli4_dealloc_extent(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6664) 						 LPFC_RSC_TYPE_FCOE_VFI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6665) 				rc = lpfc_sli4_dealloc_extent(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6666) 						 LPFC_RSC_TYPE_FCOE_VPI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6667) 				rc = lpfc_sli4_dealloc_extent(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6668) 						 LPFC_RSC_TYPE_FCOE_XRI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6669) 				rc = lpfc_sli4_dealloc_extent(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6670) 						 LPFC_RSC_TYPE_FCOE_RPI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6671) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6672) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6673) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6675) 		rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6676) 		if (unlikely(rc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6677) 			goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6679) 		rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6680) 		if (unlikely(rc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6681) 			goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6683) 		rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6684) 		if (unlikely(rc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6685) 			goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6687) 		rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6688) 		if (unlikely(rc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6689) 			goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6690) 		bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6691) 		       LPFC_IDX_RSRC_RDY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6692) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6693) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6694) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6695) 		 * The port does not support resource extents.  The XRI, VPI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6696) 		 * VFI, RPI resource ids were determined from READ_CONFIG.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6697) 		 * Just allocate the bitmasks and provision the resource id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6698) 		 * arrays.  If a port reset is active, the resources don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6699) 		 * need any action - just exit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6700) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6701) 		if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6702) 		    LPFC_IDX_RSRC_RDY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6703) 			lpfc_sli4_dealloc_resource_identifiers(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6704) 			lpfc_sli4_remove_rpis(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6705) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6706) 		/* RPIs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6707) 		count = phba->sli4_hba.max_cfg_param.max_rpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6708) 		if (count <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6709) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6710) 					"3279 Invalid provisioning of "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6711) 					"rpi:%d\n", count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6712) 			rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6713) 			goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6714) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6715) 		base = phba->sli4_hba.max_cfg_param.rpi_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6716) 		longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6717) 		phba->sli4_hba.rpi_bmask = kcalloc(longs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6718) 						   sizeof(unsigned long),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6719) 						   GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6720) 		if (unlikely(!phba->sli4_hba.rpi_bmask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6721) 			rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6722) 			goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6723) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6724) 		phba->sli4_hba.rpi_ids = kcalloc(count, sizeof(uint16_t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6725) 						 GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6726) 		if (unlikely(!phba->sli4_hba.rpi_ids)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6727) 			rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6728) 			goto free_rpi_bmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6729) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6731) 		for (i = 0; i < count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6732) 			phba->sli4_hba.rpi_ids[i] = base + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6734) 		/* VPIs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6735) 		count = phba->sli4_hba.max_cfg_param.max_vpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6736) 		if (count <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6737) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6738) 					"3280 Invalid provisioning of "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6739) 					"vpi:%d\n", count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6740) 			rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6741) 			goto free_rpi_ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6742) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6743) 		base = phba->sli4_hba.max_cfg_param.vpi_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6744) 		longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6745) 		phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6746) 					  GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6747) 		if (unlikely(!phba->vpi_bmask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6748) 			rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6749) 			goto free_rpi_ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6750) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6751) 		phba->vpi_ids = kcalloc(count, sizeof(uint16_t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6752) 					GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6753) 		if (unlikely(!phba->vpi_ids)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6754) 			rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6755) 			goto free_vpi_bmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6756) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6758) 		for (i = 0; i < count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6759) 			phba->vpi_ids[i] = base + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6761) 		/* XRIs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6762) 		count = phba->sli4_hba.max_cfg_param.max_xri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6763) 		if (count <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6764) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6765) 					"3281 Invalid provisioning of "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6766) 					"xri:%d\n", count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6767) 			rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6768) 			goto free_vpi_ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6769) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6770) 		base = phba->sli4_hba.max_cfg_param.xri_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6771) 		longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6772) 		phba->sli4_hba.xri_bmask = kcalloc(longs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6773) 						   sizeof(unsigned long),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6774) 						   GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6775) 		if (unlikely(!phba->sli4_hba.xri_bmask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6776) 			rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6777) 			goto free_vpi_ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6778) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6779) 		phba->sli4_hba.max_cfg_param.xri_used = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6780) 		phba->sli4_hba.xri_ids = kcalloc(count, sizeof(uint16_t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6781) 						 GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6782) 		if (unlikely(!phba->sli4_hba.xri_ids)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6783) 			rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6784) 			goto free_xri_bmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6785) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6787) 		for (i = 0; i < count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6788) 			phba->sli4_hba.xri_ids[i] = base + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6790) 		/* VFIs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6791) 		count = phba->sli4_hba.max_cfg_param.max_vfi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6792) 		if (count <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6793) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6794) 					"3282 Invalid provisioning of "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6795) 					"vfi:%d\n", count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6796) 			rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6797) 			goto free_xri_ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6798) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6799) 		base = phba->sli4_hba.max_cfg_param.vfi_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6800) 		longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6801) 		phba->sli4_hba.vfi_bmask = kcalloc(longs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6802) 						   sizeof(unsigned long),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6803) 						   GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6804) 		if (unlikely(!phba->sli4_hba.vfi_bmask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6805) 			rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6806) 			goto free_xri_ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6807) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6808) 		phba->sli4_hba.vfi_ids = kcalloc(count, sizeof(uint16_t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6809) 						 GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6810) 		if (unlikely(!phba->sli4_hba.vfi_ids)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6811) 			rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6812) 			goto free_vfi_bmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6813) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6815) 		for (i = 0; i < count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6816) 			phba->sli4_hba.vfi_ids[i] = base + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6818) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6819) 		 * Mark all resources ready.  An HBA reset doesn't need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6820) 		 * to reset the initialization.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6821) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6822) 		bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6823) 		       LPFC_IDX_RSRC_RDY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6824) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6825) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6827)  free_vfi_bmask:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6828) 	kfree(phba->sli4_hba.vfi_bmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6829) 	phba->sli4_hba.vfi_bmask = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6830)  free_xri_ids:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6831) 	kfree(phba->sli4_hba.xri_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6832) 	phba->sli4_hba.xri_ids = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6833)  free_xri_bmask:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6834) 	kfree(phba->sli4_hba.xri_bmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6835) 	phba->sli4_hba.xri_bmask = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6836)  free_vpi_ids:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6837) 	kfree(phba->vpi_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6838) 	phba->vpi_ids = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6839)  free_vpi_bmask:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6840) 	kfree(phba->vpi_bmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6841) 	phba->vpi_bmask = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6842)  free_rpi_ids:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6843) 	kfree(phba->sli4_hba.rpi_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6844) 	phba->sli4_hba.rpi_ids = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6845)  free_rpi_bmask:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6846) 	kfree(phba->sli4_hba.rpi_bmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6847) 	phba->sli4_hba.rpi_bmask = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6848)  err_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6849) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6850) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6852) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6853)  * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6854)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6855)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6856)  * This function allocates the number of elements for the specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6857)  * resource type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6858)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6859) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6860) lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6861) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6862) 	if (phba->sli4_hba.extents_in_use) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6863) 		lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6864) 		lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6865) 		lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6866) 		lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6867) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6868) 		kfree(phba->vpi_bmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6869) 		phba->sli4_hba.max_cfg_param.vpi_used = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6870) 		kfree(phba->vpi_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6871) 		bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6872) 		kfree(phba->sli4_hba.xri_bmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6873) 		kfree(phba->sli4_hba.xri_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6874) 		kfree(phba->sli4_hba.vfi_bmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6875) 		kfree(phba->sli4_hba.vfi_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6876) 		bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6877) 		bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6878) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6880) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6881) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6883) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6884)  * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6885)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6886)  * @type: The resource extent type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6887)  * @extnt_cnt: buffer to hold port extent count response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6888)  * @extnt_size: buffer to hold port extent size response.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6889)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6890)  * This function calls the port to read the host allocated extents
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6891)  * for a particular type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6892)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6893) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6894) lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6895) 			       uint16_t *extnt_cnt, uint16_t *extnt_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6896) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6897) 	bool emb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6898) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6899) 	uint16_t curr_blks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6900) 	uint32_t req_len, emb_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6901) 	uint32_t alloc_len, mbox_tmo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6902) 	struct list_head *blk_list_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6903) 	struct lpfc_rsrc_blks *rsrc_blk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6904) 	LPFC_MBOXQ_t *mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6905) 	void *virtaddr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6906) 	struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6907) 	struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6908) 	union  lpfc_sli4_cfg_shdr *shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6910) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6911) 	case LPFC_RSC_TYPE_FCOE_VPI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6912) 		blk_list_head = &phba->lpfc_vpi_blk_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6913) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6914) 	case LPFC_RSC_TYPE_FCOE_XRI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6915) 		blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6916) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6917) 	case LPFC_RSC_TYPE_FCOE_VFI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6918) 		blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6919) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6920) 	case LPFC_RSC_TYPE_FCOE_RPI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6921) 		blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6922) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6923) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6924) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6925) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6927) 	/* Count the number of extents currently allocatd for this type. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6928) 	list_for_each_entry(rsrc_blk, blk_list_head, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6929) 		if (curr_blks == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6930) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6931) 			 * The GET_ALLOCATED mailbox does not return the size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6932) 			 * just the count.  The size should be just the size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6933) 			 * stored in the current allocated block and all sizes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6934) 			 * for an extent type are the same so set the return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6935) 			 * value now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6936) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6937) 			*extnt_size = rsrc_blk->rsrc_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6938) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6939) 		curr_blks++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6940) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6942) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6943) 	 * Calculate the size of an embedded mailbox.  The uint32_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6944) 	 * accounts for extents-specific word.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6945) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6946) 	emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6947) 		sizeof(uint32_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6949) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6950) 	 * Presume the allocation and response will fit into an embedded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6951) 	 * mailbox.  If not true, reconfigure to a non-embedded mailbox.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6952) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6953) 	emb = LPFC_SLI4_MBX_EMBED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6954) 	req_len = emb_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6955) 	if (req_len > emb_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6956) 		req_len = curr_blks * sizeof(uint16_t) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6957) 			sizeof(union lpfc_sli4_cfg_shdr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6958) 			sizeof(uint32_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6959) 		emb = LPFC_SLI4_MBX_NEMBED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6960) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6962) 	mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6963) 	if (!mbox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6964) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6965) 	memset(mbox, 0, sizeof(LPFC_MBOXQ_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6967) 	alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6968) 				     LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6969) 				     req_len, emb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6970) 	if (alloc_len < req_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6971) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6972) 			"2983 Allocated DMA memory size (x%x) is "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6973) 			"less than the requested DMA memory "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6974) 			"size (x%x)\n", alloc_len, req_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6975) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6976) 		goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6977) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6978) 	rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6979) 	if (unlikely(rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6980) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6981) 		goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6982) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6984) 	if (!phba->sli4_hba.intr_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6985) 		rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6986) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6987) 		mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6988) 		rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6989) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6991) 	if (unlikely(rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6992) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6993) 		goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6994) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6995) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6996) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6997) 	 * Figure out where the response is located.  Then get local pointers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6998) 	 * to the response data.  The port does not guarantee to respond to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6999) 	 * all extents counts request so update the local variable with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7000) 	 * allocated count from the port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7001) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7002) 	if (emb == LPFC_SLI4_MBX_EMBED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7003) 		rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7004) 		shdr = &rsrc_ext->header.cfg_shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7005) 		*extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7006) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7007) 		virtaddr = mbox->sge_array->addr[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7008) 		n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7009) 		shdr = &n_rsrc->cfg_shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7010) 		*extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7011) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7013) 	if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7014) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7015) 			"2984 Failed to read allocated resources "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7016) 			"for type %d - Status 0x%x Add'l Status 0x%x.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7017) 			type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7018) 			bf_get(lpfc_mbox_hdr_status, &shdr->response),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7019) 			bf_get(lpfc_mbox_hdr_add_status, &shdr->response));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7020) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7021) 		goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7022) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7023)  err_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7024) 	lpfc_sli4_mbox_cmd_free(phba, mbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7025) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7026) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7028) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7029)  * lpfc_sli4_repost_sgl_list - Repost the buffers sgl pages as block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7030)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7031)  * @sgl_list: linked link of sgl buffers to post
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7032)  * @cnt: number of linked list buffers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7033)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7034)  * This routine walks the list of buffers that have been allocated and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7035)  * repost them to the port by using SGL block post. This is needed after a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7036)  * pci_function_reset/warm_start or start. It attempts to construct blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7037)  * of buffer sgls which contains contiguous xris and uses the non-embedded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7038)  * SGL block post mailbox commands to post them to the port. For single
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7039)  * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7040)  * mailbox command for posting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7041)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7042)  * Returns: 0 = success, non-zero failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7043)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7044) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7045) lpfc_sli4_repost_sgl_list(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7046) 			  struct list_head *sgl_list, int cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7047) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7048) 	struct lpfc_sglq *sglq_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7049) 	struct lpfc_sglq *sglq_entry_next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7050) 	struct lpfc_sglq *sglq_entry_first = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7051) 	int status, total_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7052) 	int post_cnt = 0, num_posted = 0, block_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7053) 	int last_xritag = NO_XRI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7054) 	LIST_HEAD(prep_sgl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7055) 	LIST_HEAD(blck_sgl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7056) 	LIST_HEAD(allc_sgl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7057) 	LIST_HEAD(post_sgl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7058) 	LIST_HEAD(free_sgl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7060) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7061) 	spin_lock(&phba->sli4_hba.sgl_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7062) 	list_splice_init(sgl_list, &allc_sgl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7063) 	spin_unlock(&phba->sli4_hba.sgl_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7064) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7066) 	total_cnt = cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7067) 	list_for_each_entry_safe(sglq_entry, sglq_entry_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7068) 				 &allc_sgl_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7069) 		list_del_init(&sglq_entry->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7070) 		block_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7071) 		if ((last_xritag != NO_XRI) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7072) 		    (sglq_entry->sli4_xritag != last_xritag + 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7073) 			/* a hole in xri block, form a sgl posting block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7074) 			list_splice_init(&prep_sgl_list, &blck_sgl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7075) 			post_cnt = block_cnt - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7076) 			/* prepare list for next posting block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7077) 			list_add_tail(&sglq_entry->list, &prep_sgl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7078) 			block_cnt = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7079) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7080) 			/* prepare list for next posting block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7081) 			list_add_tail(&sglq_entry->list, &prep_sgl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7082) 			/* enough sgls for non-embed sgl mbox command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7083) 			if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7084) 				list_splice_init(&prep_sgl_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7085) 						 &blck_sgl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7086) 				post_cnt = block_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7087) 				block_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7088) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7089) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7090) 		num_posted++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7091) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7092) 		/* keep track of last sgl's xritag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7093) 		last_xritag = sglq_entry->sli4_xritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7095) 		/* end of repost sgl list condition for buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7096) 		if (num_posted == total_cnt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7097) 			if (post_cnt == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7098) 				list_splice_init(&prep_sgl_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7099) 						 &blck_sgl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7100) 				post_cnt = block_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7101) 			} else if (block_cnt == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7102) 				status = lpfc_sli4_post_sgl(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7103) 						sglq_entry->phys, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7104) 						sglq_entry->sli4_xritag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7105) 				if (!status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7106) 					/* successful, put sgl to posted list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7107) 					list_add_tail(&sglq_entry->list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7108) 						      &post_sgl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7109) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7110) 					/* Failure, put sgl to free list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7111) 					lpfc_printf_log(phba, KERN_WARNING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7112) 						LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7113) 						"3159 Failed to post "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7114) 						"sgl, xritag:x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7115) 						sglq_entry->sli4_xritag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7116) 					list_add_tail(&sglq_entry->list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7117) 						      &free_sgl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7118) 					total_cnt--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7119) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7120) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7121) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7123) 		/* continue until a nembed page worth of sgls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7124) 		if (post_cnt == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7125) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7127) 		/* post the buffer list sgls as a block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7128) 		status = lpfc_sli4_post_sgl_list(phba, &blck_sgl_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7129) 						 post_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7131) 		if (!status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7132) 			/* success, put sgl list to posted sgl list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7133) 			list_splice_init(&blck_sgl_list, &post_sgl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7134) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7135) 			/* Failure, put sgl list to free sgl list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7136) 			sglq_entry_first = list_first_entry(&blck_sgl_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7137) 							    struct lpfc_sglq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7138) 							    list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7139) 			lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7140) 					"3160 Failed to post sgl-list, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7141) 					"xritag:x%x-x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7142) 					sglq_entry_first->sli4_xritag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7143) 					(sglq_entry_first->sli4_xritag +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7144) 					 post_cnt - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7145) 			list_splice_init(&blck_sgl_list, &free_sgl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7146) 			total_cnt -= post_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7147) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7149) 		/* don't reset xirtag due to hole in xri block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7150) 		if (block_cnt == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7151) 			last_xritag = NO_XRI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7153) 		/* reset sgl post count for next round of posting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7154) 		post_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7155) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7157) 	/* free the sgls failed to post */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7158) 	lpfc_free_sgl_list(phba, &free_sgl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7160) 	/* push sgls posted to the available list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7161) 	if (!list_empty(&post_sgl_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7162) 		spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7163) 		spin_lock(&phba->sli4_hba.sgl_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7164) 		list_splice_init(&post_sgl_list, sgl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7165) 		spin_unlock(&phba->sli4_hba.sgl_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7166) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7167) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7168) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7169) 				"3161 Failure to post sgl to port.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7170) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7171) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7173) 	/* return the number of XRIs actually posted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7174) 	return total_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7177) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7178)  * lpfc_sli4_repost_io_sgl_list - Repost all the allocated nvme buffer sgls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7179)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7180)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7181)  * This routine walks the list of nvme buffers that have been allocated and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7182)  * repost them to the port by using SGL block post. This is needed after a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7183)  * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7184)  * is responsible for moving all nvme buffers on the lpfc_abts_nvme_sgl_list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7185)  * to the lpfc_io_buf_list. If the repost fails, reject all nvme buffers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7186)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7187)  * Returns: 0 = success, non-zero failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7188)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7189) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7190) lpfc_sli4_repost_io_sgl_list(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7192) 	LIST_HEAD(post_nblist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7193) 	int num_posted, rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7195) 	/* get all NVME buffers need to repost to a local list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7196) 	lpfc_io_buf_flush(phba, &post_nblist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7198) 	/* post the list of nvme buffer sgls to port if available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7199) 	if (!list_empty(&post_nblist)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7200) 		num_posted = lpfc_sli4_post_io_sgl_list(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7201) 			phba, &post_nblist, phba->sli4_hba.io_xri_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7202) 		/* failed to post any nvme buffer, return error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7203) 		if (num_posted == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7204) 			rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7205) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7206) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7209) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7210) lpfc_set_host_data(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7212) 	uint32_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7214) 	len = sizeof(struct lpfc_mbx_set_host_data) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7215) 		sizeof(struct lpfc_sli4_cfg_mhdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7216) 	lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7217) 			 LPFC_MBOX_OPCODE_SET_HOST_DATA, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7218) 			 LPFC_SLI4_MBX_EMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7220) 	mbox->u.mqe.un.set_host_data.param_id = LPFC_SET_HOST_OS_DRIVER_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7221) 	mbox->u.mqe.un.set_host_data.param_len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7222) 					LPFC_HOST_OS_DRIVER_VERSION_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7223) 	snprintf(mbox->u.mqe.un.set_host_data.data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7224) 		 LPFC_HOST_OS_DRIVER_VERSION_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7225) 		 "Linux %s v"LPFC_DRIVER_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7226) 		 (phba->hba_flag & HBA_FCOE_MODE) ? "FCoE" : "FC");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7229) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7230) lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7231) 		    struct lpfc_queue *drq, int count, int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7233) 	int rc, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7234) 	struct lpfc_rqe hrqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7235) 	struct lpfc_rqe drqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7236) 	struct lpfc_rqb *rqbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7237) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7238) 	struct rqb_dmabuf *rqb_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7239) 	LIST_HEAD(rqb_buf_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7241) 	rqbp = hrq->rqbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7242) 	for (i = 0; i < count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7243) 		spin_lock_irqsave(&phba->hbalock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7244) 		/* IF RQ is already full, don't bother */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7245) 		if (rqbp->buffer_count + i >= rqbp->entry_count - 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7246) 			spin_unlock_irqrestore(&phba->hbalock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7247) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7248) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7249) 		spin_unlock_irqrestore(&phba->hbalock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7251) 		rqb_buffer = rqbp->rqb_alloc_buffer(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7252) 		if (!rqb_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7253) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7254) 		rqb_buffer->hrq = hrq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7255) 		rqb_buffer->drq = drq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7256) 		rqb_buffer->idx = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7257) 		list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7258) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7260) 	spin_lock_irqsave(&phba->hbalock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7261) 	while (!list_empty(&rqb_buf_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7262) 		list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7263) 				 hbuf.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7265) 		hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7266) 		hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7267) 		drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7268) 		drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7269) 		rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7270) 		if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7271) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7272) 					"6421 Cannot post to HRQ %d: %x %x %x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7273) 					"DRQ %x %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7274) 					hrq->queue_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7275) 					hrq->host_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7276) 					hrq->hba_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7277) 					hrq->entry_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7278) 					drq->host_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7279) 					drq->hba_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7280) 			rqbp->rqb_free_buffer(phba, rqb_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7281) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7282) 			list_add_tail(&rqb_buffer->hbuf.list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7283) 				      &rqbp->rqb_buffer_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7284) 			rqbp->buffer_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7285) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7286) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7287) 	spin_unlock_irqrestore(&phba->hbalock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7288) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7291) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7292)  * lpfc_init_idle_stat_hb - Initialize idle_stat tracking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7293)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7294)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7295)  * This routine initializes the per-cq idle_stat to dynamically dictate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7296)  * polling decisions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7297)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7298)  * Return codes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7299)  *   None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7300)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7301) static void lpfc_init_idle_stat_hb(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7303) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7304) 	struct lpfc_sli4_hdw_queue *hdwq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7305) 	struct lpfc_queue *cq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7306) 	struct lpfc_idle_stat *idle_stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7307) 	u64 wall;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7309) 	for_each_present_cpu(i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7310) 		hdwq = &phba->sli4_hba.hdwq[phba->sli4_hba.cpu_map[i].hdwq];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7311) 		cq = hdwq->io_cq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7313) 		/* Skip if we've already handled this cq's primary CPU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7314) 		if (cq->chann != i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7315) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7317) 		idle_stat = &phba->sli4_hba.idle_stat[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7319) 		idle_stat->prev_idle = get_cpu_idle_time(i, &wall, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7320) 		idle_stat->prev_wall = wall;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7322) 		if (phba->nvmet_support)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7323) 			cq->poll_mode = LPFC_QUEUE_WORK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7324) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7325) 			cq->poll_mode = LPFC_IRQ_POLL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7326) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7328) 	if (!phba->nvmet_support)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7329) 		schedule_delayed_work(&phba->idle_stat_delay_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7330) 				      msecs_to_jiffies(LPFC_IDLE_STAT_DELAY));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7333) static void lpfc_sli4_dip(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7335) 	uint32_t if_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7337) 	if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7338) 	if (if_type == LPFC_SLI_INTF_IF_TYPE_2 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7339) 	    if_type == LPFC_SLI_INTF_IF_TYPE_6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7340) 		struct lpfc_register reg_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7342) 		if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7343) 			       &reg_data.word0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7344) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7346) 		if (bf_get(lpfc_sliport_status_dip, &reg_data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7347) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7348) 					"2904 Firmware Dump Image Present"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7349) 					" on Adapter");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7350) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7353) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7354)  * lpfc_sli4_hba_setup - SLI4 device initialization PCI function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7355)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7356)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7357)  * This function is the main SLI4 device initialization PCI function. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7358)  * function is called by the HBA initialization code, HBA reset code and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7359)  * HBA error attention handler code. Caller is not required to hold any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7360)  * locks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7361)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7362) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7363) lpfc_sli4_hba_setup(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7365) 	int rc, i, cnt, len, dd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7366) 	LPFC_MBOXQ_t *mboxq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7367) 	struct lpfc_mqe *mqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7368) 	uint8_t *vpd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7369) 	uint32_t vpd_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7370) 	uint32_t ftr_rsp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7371) 	struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7372) 	struct lpfc_vport *vport = phba->pport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7373) 	struct lpfc_dmabuf *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7374) 	struct lpfc_rqb *rqbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7375) 	u32 flg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7377) 	/* Perform a PCI function reset to start from clean */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7378) 	rc = lpfc_pci_function_reset(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7379) 	if (unlikely(rc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7380) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7382) 	/* Check the HBA Host Status Register for readyness */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7383) 	rc = lpfc_sli4_post_status_check(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7384) 	if (unlikely(rc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7385) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7386) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7387) 		spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7388) 		phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7389) 		flg = phba->sli.sli_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7390) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7391) 		/* Allow a little time after setting SLI_ACTIVE for any polled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7392) 		 * MBX commands to complete via BSG.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7393) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7394) 		for (i = 0; i < 50 && (flg & LPFC_SLI_MBOX_ACTIVE); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7395) 			msleep(20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7396) 			spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7397) 			flg = phba->sli.sli_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7398) 			spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7399) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7400) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7402) 	lpfc_sli4_dip(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7404) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7405) 	 * Allocate a single mailbox container for initializing the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7406) 	 * port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7407) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7408) 	mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7409) 	if (!mboxq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7410) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7412) 	/* Issue READ_REV to collect vpd and FW information. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7413) 	vpd_size = SLI4_PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7414) 	vpd = kzalloc(vpd_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7415) 	if (!vpd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7416) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7417) 		goto out_free_mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7418) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7420) 	rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7421) 	if (unlikely(rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7422) 		kfree(vpd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7423) 		goto out_free_mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7424) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7426) 	mqe = &mboxq->u.mqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7427) 	phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7428) 	if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7429) 		phba->hba_flag |= HBA_FCOE_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7430) 		phba->fcp_embed_io = 0;	/* SLI4 FC support only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7431) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7432) 		phba->hba_flag &= ~HBA_FCOE_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7433) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7435) 	if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7436) 		LPFC_DCBX_CEE_MODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7437) 		phba->hba_flag |= HBA_FIP_SUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7438) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7439) 		phba->hba_flag &= ~HBA_FIP_SUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7441) 	phba->hba_flag &= ~HBA_IOQ_FLUSH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7443) 	if (phba->sli_rev != LPFC_SLI_REV4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7444) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7445) 			"0376 READ_REV Error. SLI Level %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7446) 			"FCoE enabled %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7447) 			phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7448) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7449) 		kfree(vpd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7450) 		goto out_free_mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7451) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7453) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7454) 	 * Continue initialization with default values even if driver failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7455) 	 * to read FCoE param config regions, only read parameters if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7456) 	 * board is FCoE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7457) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7458) 	if (phba->hba_flag & HBA_FCOE_MODE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7459) 	    lpfc_sli4_read_fcoe_params(phba))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7460) 		lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7461) 			"2570 Failed to read FCoE parameters\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7463) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7464) 	 * Retrieve sli4 device physical port name, failure of doing it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7465) 	 * is considered as non-fatal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7466) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7467) 	rc = lpfc_sli4_retrieve_pport_name(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7468) 	if (!rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7469) 		lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7470) 				"3080 Successful retrieving SLI4 device "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7471) 				"physical port name: %s.\n", phba->Port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7473) 	rc = lpfc_sli4_get_ctl_attr(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7474) 	if (!rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7475) 		lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7476) 				"8351 Successful retrieving SLI4 device "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7477) 				"CTL ATTR\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7479) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7480) 	 * Evaluate the read rev and vpd data. Populate the driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7481) 	 * state with the results. If this routine fails, the failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7482) 	 * is not fatal as the driver will use generic values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7483) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7484) 	rc = lpfc_parse_vpd(phba, vpd, vpd_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7485) 	if (unlikely(!rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7486) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7487) 				"0377 Error %d parsing vpd. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7488) 				"Using defaults.\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7489) 		rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7490) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7491) 	kfree(vpd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7493) 	/* Save information as VPD data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7494) 	phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7495) 	phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7497) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7498) 	 * This is because first G7 ASIC doesn't support the standard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7499) 	 * 0x5a NVME cmd descriptor type/subtype
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7500) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7501) 	if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7502) 			LPFC_SLI_INTF_IF_TYPE_6) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7503) 	    (phba->vpd.rev.biuRev == LPFC_G7_ASIC_1) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7504) 	    (phba->vpd.rev.smRev == 0) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7505) 	    (phba->cfg_nvme_embed_cmd == 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7506) 		phba->cfg_nvme_embed_cmd = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7508) 	phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7509) 	phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7510) 					 &mqe->un.read_rev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7511) 	phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7512) 				       &mqe->un.read_rev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7513) 	phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7514) 					    &mqe->un.read_rev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7515) 	phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7516) 					   &mqe->un.read_rev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7517) 	phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7518) 	memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7519) 	phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7520) 	memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7521) 	phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7522) 	memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7523) 	lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7524) 			"(%d):0380 READ_REV Status x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7525) 			"fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7526) 			mboxq->vport ? mboxq->vport->vpi : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7527) 			bf_get(lpfc_mqe_status, mqe),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7528) 			phba->vpd.rev.opFwName,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7529) 			phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7530) 			phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7532) 	if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7533) 	    LPFC_SLI_INTF_IF_TYPE_0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7534) 		lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7535) 		rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7536) 		if (rc == MBX_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7537) 			phba->hba_flag |= HBA_RECOVERABLE_UE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7538) 			/* Set 1Sec interval to detect UE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7539) 			phba->eratt_poll_interval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7540) 			phba->sli4_hba.ue_to_sr = bf_get(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7541) 					lpfc_mbx_set_feature_UESR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7542) 					&mboxq->u.mqe.un.set_feature);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7543) 			phba->sli4_hba.ue_to_rp = bf_get(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7544) 					lpfc_mbx_set_feature_UERP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7545) 					&mboxq->u.mqe.un.set_feature);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7546) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7547) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7549) 	if (phba->cfg_enable_mds_diags && phba->mds_diags_support) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7550) 		/* Enable MDS Diagnostics only if the SLI Port supports it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7551) 		lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7552) 		rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7553) 		if (rc != MBX_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7554) 			phba->mds_diags_support = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7555) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7557) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7558) 	 * Discover the port's supported feature set and match it against the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7559) 	 * hosts requests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7560) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7561) 	lpfc_request_features(phba, mboxq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7562) 	rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7563) 	if (unlikely(rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7564) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7565) 		goto out_free_mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7566) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7568) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7569) 	 * The port must support FCP initiator mode as this is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7570) 	 * only mode running in the host.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7571) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7572) 	if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7573) 		lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7574) 				"0378 No support for fcpi mode.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7575) 		ftr_rsp++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7576) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7578) 	/* Performance Hints are ONLY for FCoE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7579) 	if (phba->hba_flag & HBA_FCOE_MODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7580) 		if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7581) 			phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7582) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7583) 			phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7584) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7586) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7587) 	 * If the port cannot support the host's requested features
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7588) 	 * then turn off the global config parameters to disable the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7589) 	 * feature in the driver.  This is not a fatal error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7590) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7591) 	if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7592) 		if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7593) 			phba->cfg_enable_bg = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7594) 			phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7595) 			ftr_rsp++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7596) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7597) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7599) 	if (phba->max_vpi && phba->cfg_enable_npiv &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7600) 	    !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7601) 		ftr_rsp++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7603) 	if (ftr_rsp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7604) 		lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7605) 				"0379 Feature Mismatch Data: x%08x %08x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7606) 				"x%x x%x x%x\n", mqe->un.req_ftrs.word2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7607) 				mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7608) 				phba->cfg_enable_npiv, phba->max_vpi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7609) 		if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7610) 			phba->cfg_enable_bg = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7611) 		if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7612) 			phba->cfg_enable_npiv = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7613) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7615) 	/* These SLI3 features are assumed in SLI4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7616) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7617) 	phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7618) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7620) 	/* Always try to enable dual dump feature if we can */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7621) 	lpfc_set_features(phba, mboxq, LPFC_SET_DUAL_DUMP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7622) 	rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7623) 	dd = bf_get(lpfc_mbx_set_feature_dd, &mboxq->u.mqe.un.set_feature);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7624) 	if ((rc == MBX_SUCCESS) && (dd == LPFC_ENABLE_DUAL_DUMP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7625) 		lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7626) 				"6448 Dual Dump is enabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7627) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7628) 		lpfc_printf_log(phba, KERN_INFO, LOG_SLI | LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7629) 				"6447 Dual Dump Mailbox x%x (x%x/x%x) failed, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7630) 				"rc:x%x dd:x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7631) 				bf_get(lpfc_mqe_command, &mboxq->u.mqe),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7632) 				lpfc_sli_config_mbox_subsys_get(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7633) 					phba, mboxq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7634) 				lpfc_sli_config_mbox_opcode_get(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7635) 					phba, mboxq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7636) 				rc, dd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7637) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7638) 	 * Allocate all resources (xri,rpi,vpi,vfi) now.  Subsequent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7639) 	 * calls depends on these resources to complete port setup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7640) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7641) 	rc = lpfc_sli4_alloc_resource_identifiers(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7642) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7643) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7644) 				"2920 Failed to alloc Resource IDs "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7645) 				"rc = x%x\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7646) 		goto out_free_mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7647) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7649) 	lpfc_set_host_data(phba, mboxq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7651) 	rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7652) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7653) 		lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7654) 				"2134 Failed to set host os driver version %x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7655) 				rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7656) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7658) 	/* Read the port's service parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7659) 	rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7660) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7661) 		phba->link_state = LPFC_HBA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7662) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7663) 		goto out_free_mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7664) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7666) 	mboxq->vport = vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7667) 	rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7668) 	mp = (struct lpfc_dmabuf *)mboxq->ctx_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7669) 	if (rc == MBX_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7670) 		memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7671) 		rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7672) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7674) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7675) 	 * This memory was allocated by the lpfc_read_sparam routine. Release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7676) 	 * it to the mbuf pool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7677) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7678) 	lpfc_mbuf_free(phba, mp->virt, mp->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7679) 	kfree(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7680) 	mboxq->ctx_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7681) 	if (unlikely(rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7682) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7683) 				"0382 READ_SPARAM command failed "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7684) 				"status %d, mbxStatus x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7685) 				rc, bf_get(lpfc_mqe_status, mqe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7686) 		phba->link_state = LPFC_HBA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7687) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7688) 		goto out_free_mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7689) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7691) 	lpfc_update_vport_wwn(vport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7693) 	/* Update the fc_host data structures with new wwn. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7694) 	fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7695) 	fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7697) 	/* Create all the SLI4 queues */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7698) 	rc = lpfc_sli4_queue_create(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7699) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7700) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7701) 				"3089 Failed to allocate queues\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7702) 		rc = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7703) 		goto out_free_mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7704) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7705) 	/* Set up all the queues to the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7706) 	rc = lpfc_sli4_queue_setup(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7707) 	if (unlikely(rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7708) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7709) 				"0381 Error %d during queue setup.\n ", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7710) 		goto out_stop_timers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7711) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7712) 	/* Initialize the driver internal SLI layer lists. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7713) 	lpfc_sli4_setup(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7714) 	lpfc_sli4_queue_init(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7716) 	/* update host els xri-sgl sizes and mappings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7717) 	rc = lpfc_sli4_els_sgl_update(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7718) 	if (unlikely(rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7719) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7720) 				"1400 Failed to update xri-sgl size and "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7721) 				"mapping: %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7722) 		goto out_destroy_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7723) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7725) 	/* register the els sgl pool to the port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7726) 	rc = lpfc_sli4_repost_sgl_list(phba, &phba->sli4_hba.lpfc_els_sgl_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7727) 				       phba->sli4_hba.els_xri_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7728) 	if (unlikely(rc < 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7729) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7730) 				"0582 Error %d during els sgl post "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7731) 				"operation\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7732) 		rc = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7733) 		goto out_destroy_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7734) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7735) 	phba->sli4_hba.els_xri_cnt = rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7737) 	if (phba->nvmet_support) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7738) 		/* update host nvmet xri-sgl sizes and mappings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7739) 		rc = lpfc_sli4_nvmet_sgl_update(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7740) 		if (unlikely(rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7741) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7742) 					"6308 Failed to update nvmet-sgl size "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7743) 					"and mapping: %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7744) 			goto out_destroy_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7745) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7747) 		/* register the nvmet sgl pool to the port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7748) 		rc = lpfc_sli4_repost_sgl_list(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7749) 			phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7750) 			&phba->sli4_hba.lpfc_nvmet_sgl_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7751) 			phba->sli4_hba.nvmet_xri_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7752) 		if (unlikely(rc < 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7753) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7754) 					"3117 Error %d during nvmet "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7755) 					"sgl post\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7756) 			rc = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7757) 			goto out_destroy_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7758) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7759) 		phba->sli4_hba.nvmet_xri_cnt = rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7761) 		/* We allocate an iocbq for every receive context SGL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7762) 		 * The additional allocation is for abort and ls handling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7763) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7764) 		cnt = phba->sli4_hba.nvmet_xri_cnt +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7765) 			phba->sli4_hba.max_cfg_param.max_xri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7766) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7767) 		/* update host common xri-sgl sizes and mappings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7768) 		rc = lpfc_sli4_io_sgl_update(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7769) 		if (unlikely(rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7770) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7771) 					"6082 Failed to update nvme-sgl size "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7772) 					"and mapping: %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7773) 			goto out_destroy_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7774) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7776) 		/* register the allocated common sgl pool to the port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7777) 		rc = lpfc_sli4_repost_io_sgl_list(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7778) 		if (unlikely(rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7779) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7780) 					"6116 Error %d during nvme sgl post "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7781) 					"operation\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7782) 			/* Some NVME buffers were moved to abort nvme list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7783) 			/* A pci function reset will repost them */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7784) 			rc = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7785) 			goto out_destroy_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7786) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7787) 		/* Each lpfc_io_buf job structure has an iocbq element.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7788) 		 * This cnt provides for abort, els, ct and ls requests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7789) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7790) 		cnt = phba->sli4_hba.max_cfg_param.max_xri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7791) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7793) 	if (!phba->sli.iocbq_lookup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7794) 		/* Initialize and populate the iocb list per host */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7795) 		lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7796) 				"2821 initialize iocb list with %d entries\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7797) 				cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7798) 		rc = lpfc_init_iocb_list(phba, cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7799) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7800) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7801) 					"1413 Failed to init iocb list.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7802) 			goto out_destroy_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7803) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7804) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7806) 	if (phba->nvmet_support)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7807) 		lpfc_nvmet_create_targetport(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7809) 	if (phba->nvmet_support && phba->cfg_nvmet_mrq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7810) 		/* Post initial buffers to all RQs created */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7811) 		for (i = 0; i < phba->cfg_nvmet_mrq; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7812) 			rqbp = phba->sli4_hba.nvmet_mrq_hdr[i]->rqbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7813) 			INIT_LIST_HEAD(&rqbp->rqb_buffer_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7814) 			rqbp->rqb_alloc_buffer = lpfc_sli4_nvmet_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7815) 			rqbp->rqb_free_buffer = lpfc_sli4_nvmet_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7816) 			rqbp->entry_count = LPFC_NVMET_RQE_DEF_COUNT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7817) 			rqbp->buffer_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7819) 			lpfc_post_rq_buffer(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7820) 				phba, phba->sli4_hba.nvmet_mrq_hdr[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7821) 				phba->sli4_hba.nvmet_mrq_data[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7822) 				phba->cfg_nvmet_mrq_post, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7823) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7824) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7826) 	/* Post the rpi header region to the device. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7827) 	rc = lpfc_sli4_post_all_rpi_hdrs(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7828) 	if (unlikely(rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7829) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7830) 				"0393 Error %d during rpi post operation\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7831) 				rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7832) 		rc = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7833) 		goto out_free_iocblist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7834) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7835) 	lpfc_sli4_node_prep(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7837) 	if (!(phba->hba_flag & HBA_FCOE_MODE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7838) 		if ((phba->nvmet_support == 0) || (phba->cfg_nvmet_mrq == 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7839) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7840) 			 * The FC Port needs to register FCFI (index 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7841) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7842) 			lpfc_reg_fcfi(phba, mboxq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7843) 			mboxq->vport = phba->pport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7844) 			rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7845) 			if (rc != MBX_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7846) 				goto out_unset_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7847) 			rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7848) 			phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7849) 						&mboxq->u.mqe.un.reg_fcfi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7850) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7851) 			/* We are a NVME Target mode with MRQ > 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7853) 			/* First register the FCFI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7854) 			lpfc_reg_fcfi_mrq(phba, mboxq, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7855) 			mboxq->vport = phba->pport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7856) 			rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7857) 			if (rc != MBX_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7858) 				goto out_unset_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7859) 			rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7860) 			phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_mrq_fcfi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7861) 						&mboxq->u.mqe.un.reg_fcfi_mrq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7862) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7863) 			/* Next register the MRQs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7864) 			lpfc_reg_fcfi_mrq(phba, mboxq, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7865) 			mboxq->vport = phba->pport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7866) 			rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7867) 			if (rc != MBX_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7868) 				goto out_unset_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7869) 			rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7870) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7871) 		/* Check if the port is configured to be disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7872) 		lpfc_sli_read_link_ste(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7873) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7875) 	/* Don't post more new bufs if repost already recovered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7876) 	 * the nvme sgls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7877) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7878) 	if (phba->nvmet_support == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7879) 		if (phba->sli4_hba.io_xri_cnt == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7880) 			len = lpfc_new_io_buf(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7881) 					      phba, phba->sli4_hba.io_xri_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7882) 			if (len == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7883) 				rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7884) 				goto out_unset_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7885) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7887) 			if (phba->cfg_xri_rebalancing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7888) 				lpfc_create_multixri_pools(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7889) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7890) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7891) 		phba->cfg_xri_rebalancing = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7892) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7893) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7894) 	/* Allow asynchronous mailbox command to go through */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7895) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7896) 	phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7897) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7898) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7899) 	/* Post receive buffers to the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7900) 	lpfc_sli4_rb_setup(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7902) 	/* Reset HBA FCF states after HBA reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7903) 	phba->fcf.fcf_flag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7904) 	phba->fcf.current_rec.flag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7906) 	/* Start the ELS watchdog timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7907) 	mod_timer(&vport->els_tmofunc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7908) 		  jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7910) 	/* Start heart beat timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7911) 	mod_timer(&phba->hb_tmofunc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7912) 		  jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7913) 	phba->hb_outstanding = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7914) 	phba->last_completion_time = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7916) 	/* start eq_delay heartbeat */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7917) 	if (phba->cfg_auto_imax)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7918) 		queue_delayed_work(phba->wq, &phba->eq_delay_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7919) 				   msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7921) 	/* start per phba idle_stat_delay heartbeat */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7922) 	lpfc_init_idle_stat_hb(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7924) 	/* Start error attention (ERATT) polling timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7925) 	mod_timer(&phba->eratt_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7926) 		  jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7928) 	/* Enable PCIe device Advanced Error Reporting (AER) if configured */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7929) 	if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7930) 		rc = pci_enable_pcie_error_reporting(phba->pcidev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7931) 		if (!rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7932) 			lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7933) 					"2829 This device supports "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7934) 					"Advanced Error Reporting (AER)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7935) 			spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7936) 			phba->hba_flag |= HBA_AER_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7937) 			spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7938) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7939) 			lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7940) 					"2830 This device does not support "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7941) 					"Advanced Error Reporting (AER)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7942) 			phba->cfg_aer_support = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7943) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7944) 		rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7945) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7947) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7948) 	 * The port is ready, set the host's link state to LINK_DOWN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7949) 	 * in preparation for link interrupts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7950) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7951) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7952) 	phba->link_state = LPFC_LINK_DOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7953) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7954) 	/* Check if physical ports are trunked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7955) 	if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7956) 		phba->trunk_link.link0.state = LPFC_LINK_DOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7957) 	if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7958) 		phba->trunk_link.link1.state = LPFC_LINK_DOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7959) 	if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7960) 		phba->trunk_link.link2.state = LPFC_LINK_DOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7961) 	if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7962) 		phba->trunk_link.link3.state = LPFC_LINK_DOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7963) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7965) 	/* Arm the CQs and then EQs on device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7966) 	lpfc_sli4_arm_cqeq_intr(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7968) 	/* Indicate device interrupt mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7969) 	phba->sli4_hba.intr_enable = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7971) 	if (!(phba->hba_flag & HBA_FCOE_MODE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7972) 	    (phba->hba_flag & LINK_DISABLED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7973) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7974) 				"3103 Adapter Link is disabled.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7975) 		lpfc_down_link(phba, mboxq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7976) 		rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7977) 		if (rc != MBX_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7978) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7979) 					"3104 Adapter failed to issue "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7980) 					"DOWN_LINK mbox cmd, rc:x%x\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7981) 			goto out_io_buff_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7982) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7983) 	} else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7984) 		/* don't perform init_link on SLI4 FC port loopback test */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7985) 		if (!(phba->link_flag & LS_LOOPBACK_MODE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7986) 			rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7987) 			if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7988) 				goto out_io_buff_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7989) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7990) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7991) 	mempool_free(mboxq, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7992) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7993) out_io_buff_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7994) 	/* Free allocated IO Buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7995) 	lpfc_io_free(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7996) out_unset_queue:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7997) 	/* Unset all the queues set up in this routine when error out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7998) 	lpfc_sli4_queue_unset(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7999) out_free_iocblist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8000) 	lpfc_free_iocb_list(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8001) out_destroy_queue:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8002) 	lpfc_sli4_queue_destroy(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8003) out_stop_timers:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8004) 	lpfc_stop_hba_timers(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8005) out_free_mbox:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8006) 	mempool_free(mboxq, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8007) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8008) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8010) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8011)  * lpfc_mbox_timeout - Timeout call back function for mbox timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8012)  * @t: Context to fetch pointer to hba structure from.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8013)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8014)  * This is the callback function for mailbox timer. The mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8015)  * timer is armed when a new mailbox command is issued and the timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8016)  * is deleted when the mailbox complete. The function is called by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8017)  * the kernel timer code when a mailbox does not complete within
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8018)  * expected time. This function wakes up the worker thread to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8019)  * process the mailbox timeout and returns. All the processing is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8020)  * done by the worker thread function lpfc_mbox_timeout_handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8021)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8022) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8023) lpfc_mbox_timeout(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8024) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8025) 	struct lpfc_hba  *phba = from_timer(phba, t, sli.mbox_tmo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8026) 	unsigned long iflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8027) 	uint32_t tmo_posted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8028) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8029) 	spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8030) 	tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8031) 	if (!tmo_posted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8032) 		phba->pport->work_port_events |= WORKER_MBOX_TMO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8033) 	spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8035) 	if (!tmo_posted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8036) 		lpfc_worker_wake_up(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8037) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8038) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8039) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8040) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8041)  * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8042)  *                                    are pending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8043)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8044)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8045)  * This function checks if any mailbox completions are present on the mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8046)  * completion queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8047)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8048) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8049) lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8050) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8051) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8052) 	uint32_t idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8053) 	struct lpfc_queue *mcq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8054) 	struct lpfc_mcqe *mcqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8055) 	bool pending_completions = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8056) 	uint8_t	qe_valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8058) 	if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8059) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8060) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8061) 	/* Check for completions on mailbox completion queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8063) 	mcq = phba->sli4_hba.mbx_cq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8064) 	idx = mcq->hba_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8065) 	qe_valid = mcq->qe_valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8066) 	while (bf_get_le32(lpfc_cqe_valid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8067) 	       (struct lpfc_cqe *)lpfc_sli4_qe(mcq, idx)) == qe_valid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8068) 		mcqe = (struct lpfc_mcqe *)(lpfc_sli4_qe(mcq, idx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8069) 		if (bf_get_le32(lpfc_trailer_completed, mcqe) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8070) 		    (!bf_get_le32(lpfc_trailer_async, mcqe))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8071) 			pending_completions = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8072) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8073) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8074) 		idx = (idx + 1) % mcq->entry_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8075) 		if (mcq->hba_index == idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8076) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8077) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8078) 		/* if the index wrapped around, toggle the valid bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8079) 		if (phba->sli4_hba.pc_sli4_params.cqav && !idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8080) 			qe_valid = (qe_valid) ? 0 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8081) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8082) 	return pending_completions;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8083) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8084) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8086) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8087)  * lpfc_sli4_process_missed_mbox_completions - process mbox completions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8088)  *					      that were missed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8089)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8090)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8091)  * For sli4, it is possible to miss an interrupt. As such mbox completions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8092)  * maybe missed causing erroneous mailbox timeouts to occur. This function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8093)  * checks to see if mbox completions are on the mailbox completion queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8094)  * and will process all the completions associated with the eq for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8095)  * mailbox completion queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8096)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8097) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8098) lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8099) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8100) 	struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8101) 	uint32_t eqidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8102) 	struct lpfc_queue *fpeq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8103) 	struct lpfc_queue *eq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8104) 	bool mbox_pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8106) 	if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8107) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8109) 	/* Find the EQ associated with the mbox CQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8110) 	if (sli4_hba->hdwq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8111) 		for (eqidx = 0; eqidx < phba->cfg_irq_chann; eqidx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8112) 			eq = phba->sli4_hba.hba_eq_hdl[eqidx].eq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8113) 			if (eq && eq->queue_id == sli4_hba->mbx_cq->assoc_qid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8114) 				fpeq = eq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8115) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8116) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8117) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8118) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8119) 	if (!fpeq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8120) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8122) 	/* Turn off interrupts from this EQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8124) 	sli4_hba->sli4_eq_clr_intr(fpeq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8126) 	/* Check to see if a mbox completion is pending */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8128) 	mbox_pending = lpfc_sli4_mbox_completions_pending(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8130) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8131) 	 * If a mbox completion is pending, process all the events on EQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8132) 	 * associated with the mbox completion queue (this could include
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8133) 	 * mailbox commands, async events, els commands, receive queue data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8134) 	 * and fcp commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8135) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8137) 	if (mbox_pending)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8138) 		/* process and rearm the EQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8139) 		lpfc_sli4_process_eq(phba, fpeq, LPFC_QUEUE_REARM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8140) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8141) 		/* Always clear and re-arm the EQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8142) 		sli4_hba->sli4_write_eq_db(phba, fpeq, 0, LPFC_QUEUE_REARM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8144) 	return mbox_pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8148) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8149)  * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8150)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8151)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8152)  * This function is called from worker thread when a mailbox command times out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8153)  * The caller is not required to hold any locks. This function will reset the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8154)  * HBA and recover all the pending commands.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8155)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8156) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8157) lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8159) 	LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8160) 	MAILBOX_t *mb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8162) 	struct lpfc_sli *psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8164) 	/* If the mailbox completed, process the completion and return */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8165) 	if (lpfc_sli4_process_missed_mbox_completions(phba))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8166) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8168) 	if (pmbox != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8169) 		mb = &pmbox->u.mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8170) 	/* Check the pmbox pointer first.  There is a race condition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8171) 	 * between the mbox timeout handler getting executed in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8172) 	 * worklist and the mailbox actually completing. When this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8173) 	 * race condition occurs, the mbox_active will be NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8174) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8175) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8176) 	if (pmbox == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8177) 		lpfc_printf_log(phba, KERN_WARNING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8178) 				LOG_MBOX | LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8179) 				"0353 Active Mailbox cleared - mailbox timeout "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8180) 				"exiting\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8181) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8182) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8183) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8185) 	/* Mbox cmd <mbxCommand> timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8186) 	lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8187) 			"0310 Mailbox command x%x timeout Data: x%x x%x x%px\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8188) 			mb->mbxCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8189) 			phba->pport->port_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8190) 			phba->sli.sli_flag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8191) 			phba->sli.mbox_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8192) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8194) 	/* Setting state unknown so lpfc_sli_abort_iocb_ring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8195) 	 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8196) 	 * it to fail all outstanding SCSI IO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8197) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8198) 	spin_lock_irq(&phba->pport->work_port_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8199) 	phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8200) 	spin_unlock_irq(&phba->pport->work_port_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8201) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8202) 	phba->link_state = LPFC_LINK_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8203) 	psli->sli_flag &= ~LPFC_SLI_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8204) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8206) 	lpfc_sli_abort_fcp_rings(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8208) 	lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8209) 			"0345 Resetting board due to mailbox timeout\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8211) 	/* Reset the HBA device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8212) 	lpfc_reset_hba(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8215) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8216)  * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8217)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8218)  * @pmbox: Pointer to mailbox object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8219)  * @flag: Flag indicating how the mailbox need to be processed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8220)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8221)  * This function is called by discovery code and HBA management code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8222)  * to submit a mailbox command to firmware with SLI-3 interface spec. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8223)  * function gets the hbalock to protect the data structures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8224)  * The mailbox command can be submitted in polling mode, in which case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8225)  * this function will wait in a polling loop for the completion of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8226)  * mailbox.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8227)  * If the mailbox is submitted in no_wait mode (not polling) the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8228)  * function will submit the command and returns immediately without waiting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8229)  * for the mailbox completion. The no_wait is supported only when HBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8230)  * is in SLI2/SLI3 mode - interrupts are enabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8231)  * The SLI interface allows only one mailbox pending at a time. If the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8232)  * mailbox is issued in polling mode and there is already a mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8233)  * pending, then the function will return an error. If the mailbox is issued
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8234)  * in NO_WAIT mode and there is a mailbox pending already, the function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8235)  * will return MBX_BUSY after queuing the mailbox into mailbox queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8236)  * The sli layer owns the mailbox object until the completion of mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8237)  * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8238)  * return codes the caller owns the mailbox command after the return of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8239)  * the function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8240)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8241) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8242) lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8243) 		       uint32_t flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8245) 	MAILBOX_t *mbx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8246) 	struct lpfc_sli *psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8247) 	uint32_t status, evtctr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8248) 	uint32_t ha_copy, hc_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8249) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8250) 	unsigned long timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8251) 	unsigned long drvr_flag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8252) 	uint32_t word0, ldata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8253) 	void __iomem *to_slim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8254) 	int processing_queue = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8256) 	spin_lock_irqsave(&phba->hbalock, drvr_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8257) 	if (!pmbox) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8258) 		phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8259) 		/* processing mbox queue from intr_handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8260) 		if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8261) 			spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8262) 			return MBX_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8263) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8264) 		processing_queue = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8265) 		pmbox = lpfc_mbox_get(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8266) 		if (!pmbox) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8267) 			spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8268) 			return MBX_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8269) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8270) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8272) 	if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8273) 		pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8274) 		if(!pmbox->vport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8275) 			spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8276) 			lpfc_printf_log(phba, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8277) 					LOG_MBOX | LOG_VPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8278) 					"1806 Mbox x%x failed. No vport\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8279) 					pmbox->u.mb.mbxCommand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8280) 			dump_stack();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8281) 			goto out_not_finished;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8282) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8283) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8285) 	/* If the PCI channel is in offline state, do not post mbox. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8286) 	if (unlikely(pci_channel_offline(phba->pcidev))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8287) 		spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8288) 		goto out_not_finished;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8289) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8291) 	/* If HBA has a deferred error attention, fail the iocb. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8292) 	if (unlikely(phba->hba_flag & DEFER_ERATT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8293) 		spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8294) 		goto out_not_finished;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8295) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8297) 	psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8299) 	mbx = &pmbox->u.mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8300) 	status = MBX_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8302) 	if (phba->link_state == LPFC_HBA_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8303) 		spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8305) 		/* Mbox command <mbxCommand> cannot issue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8306) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8307) 				"(%d):0311 Mailbox command x%x cannot "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8308) 				"issue Data: x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8309) 				pmbox->vport ? pmbox->vport->vpi : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8310) 				pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8311) 		goto out_not_finished;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8312) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8314) 	if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8315) 		if (lpfc_readl(phba->HCregaddr, &hc_copy) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8316) 			!(hc_copy & HC_MBINT_ENA)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8317) 			spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8318) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8319) 				"(%d):2528 Mailbox command x%x cannot "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8320) 				"issue Data: x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8321) 				pmbox->vport ? pmbox->vport->vpi : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8322) 				pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8323) 			goto out_not_finished;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8324) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8325) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8327) 	if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8328) 		/* Polling for a mbox command when another one is already active
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8329) 		 * is not allowed in SLI. Also, the driver must have established
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8330) 		 * SLI2 mode to queue and process multiple mbox commands.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8331) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8333) 		if (flag & MBX_POLL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8334) 			spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8336) 			/* Mbox command <mbxCommand> cannot issue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8337) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8338) 					"(%d):2529 Mailbox command x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8339) 					"cannot issue Data: x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8340) 					pmbox->vport ? pmbox->vport->vpi : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8341) 					pmbox->u.mb.mbxCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8342) 					psli->sli_flag, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8343) 			goto out_not_finished;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8344) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8346) 		if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8347) 			spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8348) 			/* Mbox command <mbxCommand> cannot issue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8349) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8350) 					"(%d):2530 Mailbox command x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8351) 					"cannot issue Data: x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8352) 					pmbox->vport ? pmbox->vport->vpi : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8353) 					pmbox->u.mb.mbxCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8354) 					psli->sli_flag, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8355) 			goto out_not_finished;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8356) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8358) 		/* Another mailbox command is still being processed, queue this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8359) 		 * command to be processed later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8360) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8361) 		lpfc_mbox_put(phba, pmbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8363) 		/* Mbox cmd issue - BUSY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8364) 		lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8365) 				"(%d):0308 Mbox cmd issue - BUSY Data: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8366) 				"x%x x%x x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8367) 				pmbox->vport ? pmbox->vport->vpi : 0xffffff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8368) 				mbx->mbxCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8369) 				phba->pport ? phba->pport->port_state : 0xff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8370) 				psli->sli_flag, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8372) 		psli->slistat.mbox_busy++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8373) 		spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8375) 		if (pmbox->vport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8376) 			lpfc_debugfs_disc_trc(pmbox->vport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8377) 				LPFC_DISC_TRC_MBOX_VPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8378) 				"MBOX Bsy vport:  cmd:x%x mb:x%x x%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8379) 				(uint32_t)mbx->mbxCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8380) 				mbx->un.varWords[0], mbx->un.varWords[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8381) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8382) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8383) 			lpfc_debugfs_disc_trc(phba->pport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8384) 				LPFC_DISC_TRC_MBOX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8385) 				"MBOX Bsy:        cmd:x%x mb:x%x x%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8386) 				(uint32_t)mbx->mbxCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8387) 				mbx->un.varWords[0], mbx->un.varWords[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8388) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8390) 		return MBX_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8391) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8393) 	psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8395) 	/* If we are not polling, we MUST be in SLI2 mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8396) 	if (flag != MBX_POLL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8397) 		if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8398) 		    (mbx->mbxCommand != MBX_KILL_BOARD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8399) 			psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8400) 			spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8401) 			/* Mbox command <mbxCommand> cannot issue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8402) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8403) 					"(%d):2531 Mailbox command x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8404) 					"cannot issue Data: x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8405) 					pmbox->vport ? pmbox->vport->vpi : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8406) 					pmbox->u.mb.mbxCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8407) 					psli->sli_flag, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8408) 			goto out_not_finished;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8409) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8410) 		/* timeout active mbox command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8411) 		timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8412) 					   1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8413) 		mod_timer(&psli->mbox_tmo, jiffies + timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8414) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8416) 	/* Mailbox cmd <cmd> issue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8417) 	lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8418) 			"(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8419) 			"x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8420) 			pmbox->vport ? pmbox->vport->vpi : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8421) 			mbx->mbxCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8422) 			phba->pport ? phba->pport->port_state : 0xff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8423) 			psli->sli_flag, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8425) 	if (mbx->mbxCommand != MBX_HEARTBEAT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8426) 		if (pmbox->vport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8427) 			lpfc_debugfs_disc_trc(pmbox->vport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8428) 				LPFC_DISC_TRC_MBOX_VPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8429) 				"MBOX Send vport: cmd:x%x mb:x%x x%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8430) 				(uint32_t)mbx->mbxCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8431) 				mbx->un.varWords[0], mbx->un.varWords[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8432) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8433) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8434) 			lpfc_debugfs_disc_trc(phba->pport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8435) 				LPFC_DISC_TRC_MBOX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8436) 				"MBOX Send:       cmd:x%x mb:x%x x%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8437) 				(uint32_t)mbx->mbxCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8438) 				mbx->un.varWords[0], mbx->un.varWords[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8439) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8440) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8442) 	psli->slistat.mbox_cmd++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8443) 	evtctr = psli->slistat.mbox_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8445) 	/* next set own bit for the adapter and copy over command word */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8446) 	mbx->mbxOwner = OWN_CHIP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8448) 	if (psli->sli_flag & LPFC_SLI_ACTIVE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8449) 		/* Populate mbox extension offset word. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8450) 		if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8451) 			*(((uint32_t *)mbx) + pmbox->mbox_offset_word)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8452) 				= (uint8_t *)phba->mbox_ext
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8453) 				  - (uint8_t *)phba->mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8454) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8456) 		/* Copy the mailbox extension data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8457) 		if (pmbox->in_ext_byte_len && pmbox->ctx_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8458) 			lpfc_sli_pcimem_bcopy(pmbox->ctx_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8459) 					      (uint8_t *)phba->mbox_ext,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8460) 					      pmbox->in_ext_byte_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8461) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8462) 		/* Copy command data to host SLIM area */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8463) 		lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8464) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8465) 		/* Populate mbox extension offset word. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8466) 		if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8467) 			*(((uint32_t *)mbx) + pmbox->mbox_offset_word)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8468) 				= MAILBOX_HBA_EXT_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8470) 		/* Copy the mailbox extension data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8471) 		if (pmbox->in_ext_byte_len && pmbox->ctx_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8472) 			lpfc_memcpy_to_slim(phba->MBslimaddr +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8473) 				MAILBOX_HBA_EXT_OFFSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8474) 				pmbox->ctx_buf, pmbox->in_ext_byte_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8476) 		if (mbx->mbxCommand == MBX_CONFIG_PORT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8477) 			/* copy command data into host mbox for cmpl */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8478) 			lpfc_sli_pcimem_bcopy(mbx, phba->mbox,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8479) 					      MAILBOX_CMD_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8481) 		/* First copy mbox command data to HBA SLIM, skip past first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8482) 		   word */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8483) 		to_slim = phba->MBslimaddr + sizeof (uint32_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8484) 		lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8485) 			    MAILBOX_CMD_SIZE - sizeof (uint32_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8487) 		/* Next copy over first word, with mbxOwner set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8488) 		ldata = *((uint32_t *)mbx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8489) 		to_slim = phba->MBslimaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8490) 		writel(ldata, to_slim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8491) 		readl(to_slim); /* flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8493) 		if (mbx->mbxCommand == MBX_CONFIG_PORT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8494) 			/* switch over to host mailbox */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8495) 			psli->sli_flag |= LPFC_SLI_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8496) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8498) 	wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8500) 	switch (flag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8501) 	case MBX_NOWAIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8502) 		/* Set up reference to mailbox command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8503) 		psli->mbox_active = pmbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8504) 		/* Interrupt board to do it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8505) 		writel(CA_MBATT, phba->CAregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8506) 		readl(phba->CAregaddr); /* flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8507) 		/* Don't wait for it to finish, just return */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8508) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8510) 	case MBX_POLL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8511) 		/* Set up null reference to mailbox command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8512) 		psli->mbox_active = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8513) 		/* Interrupt board to do it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8514) 		writel(CA_MBATT, phba->CAregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8515) 		readl(phba->CAregaddr); /* flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8517) 		if (psli->sli_flag & LPFC_SLI_ACTIVE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8518) 			/* First read mbox status word */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8519) 			word0 = *((uint32_t *)phba->mbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8520) 			word0 = le32_to_cpu(word0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8521) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8522) 			/* First read mbox status word */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8523) 			if (lpfc_readl(phba->MBslimaddr, &word0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8524) 				spin_unlock_irqrestore(&phba->hbalock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8525) 						       drvr_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8526) 				goto out_not_finished;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8527) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8528) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8530) 		/* Read the HBA Host Attention Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8531) 		if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8532) 			spin_unlock_irqrestore(&phba->hbalock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8533) 						       drvr_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8534) 			goto out_not_finished;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8535) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8536) 		timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8537) 							1000) + jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8538) 		i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8539) 		/* Wait for command to complete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8540) 		while (((word0 & OWN_CHIP) == OWN_CHIP) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8541) 		       (!(ha_copy & HA_MBATT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8542) 			(phba->link_state > LPFC_WARM_START))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8543) 			if (time_after(jiffies, timeout)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8544) 				psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8545) 				spin_unlock_irqrestore(&phba->hbalock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8546) 						       drvr_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8547) 				goto out_not_finished;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8548) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8550) 			/* Check if we took a mbox interrupt while we were
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8551) 			   polling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8552) 			if (((word0 & OWN_CHIP) != OWN_CHIP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8553) 			    && (evtctr != psli->slistat.mbox_event))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8554) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8556) 			if (i++ > 10) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8557) 				spin_unlock_irqrestore(&phba->hbalock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8558) 						       drvr_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8559) 				msleep(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8560) 				spin_lock_irqsave(&phba->hbalock, drvr_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8561) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8563) 			if (psli->sli_flag & LPFC_SLI_ACTIVE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8564) 				/* First copy command data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8565) 				word0 = *((uint32_t *)phba->mbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8566) 				word0 = le32_to_cpu(word0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8567) 				if (mbx->mbxCommand == MBX_CONFIG_PORT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8568) 					MAILBOX_t *slimmb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8569) 					uint32_t slimword0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8570) 					/* Check real SLIM for any errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8571) 					slimword0 = readl(phba->MBslimaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8572) 					slimmb = (MAILBOX_t *) & slimword0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8573) 					if (((slimword0 & OWN_CHIP) != OWN_CHIP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8574) 					    && slimmb->mbxStatus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8575) 						psli->sli_flag &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8576) 						    ~LPFC_SLI_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8577) 						word0 = slimword0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8578) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8579) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8580) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8581) 				/* First copy command data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8582) 				word0 = readl(phba->MBslimaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8583) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8584) 			/* Read the HBA Host Attention Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8585) 			if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8586) 				spin_unlock_irqrestore(&phba->hbalock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8587) 						       drvr_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8588) 				goto out_not_finished;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8589) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8590) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8592) 		if (psli->sli_flag & LPFC_SLI_ACTIVE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8593) 			/* copy results back to user */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8594) 			lpfc_sli_pcimem_bcopy(phba->mbox, mbx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8595) 						MAILBOX_CMD_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8596) 			/* Copy the mailbox extension data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8597) 			if (pmbox->out_ext_byte_len && pmbox->ctx_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8598) 				lpfc_sli_pcimem_bcopy(phba->mbox_ext,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8599) 						      pmbox->ctx_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8600) 						      pmbox->out_ext_byte_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8601) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8602) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8603) 			/* First copy command data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8604) 			lpfc_memcpy_from_slim(mbx, phba->MBslimaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8605) 						MAILBOX_CMD_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8606) 			/* Copy the mailbox extension data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8607) 			if (pmbox->out_ext_byte_len && pmbox->ctx_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8608) 				lpfc_memcpy_from_slim(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8609) 					pmbox->ctx_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8610) 					phba->MBslimaddr +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8611) 					MAILBOX_HBA_EXT_OFFSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8612) 					pmbox->out_ext_byte_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8613) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8614) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8616) 		writel(HA_MBATT, phba->HAregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8617) 		readl(phba->HAregaddr); /* flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8619) 		psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8620) 		status = mbx->mbxStatus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8621) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8623) 	spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8624) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8626) out_not_finished:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8627) 	if (processing_queue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8628) 		pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8629) 		lpfc_mbox_cmpl_put(phba, pmbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8630) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8631) 	return MBX_NOT_FINISHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8634) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8635)  * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8636)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8637)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8638)  * The function blocks the posting of SLI4 asynchronous mailbox commands from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8639)  * the driver internal pending mailbox queue. It will then try to wait out the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8640)  * possible outstanding mailbox command before return.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8641)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8642)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8643)  * 	0 - the outstanding mailbox command completed; otherwise, the wait for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8644)  * 	the outstanding mailbox command timed out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8645)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8646) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8647) lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8648) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8649) 	struct lpfc_sli *psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8650) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8651) 	unsigned long timeout = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8653) 	/* Mark the asynchronous mailbox command posting as blocked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8654) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8655) 	psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8656) 	/* Determine how long we might wait for the active mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8657) 	 * command to be gracefully completed by firmware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8658) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8659) 	if (phba->sli.mbox_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8660) 		timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8661) 						phba->sli.mbox_active) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8662) 						1000) + jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8663) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8665) 	/* Make sure the mailbox is really active */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8666) 	if (timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8667) 		lpfc_sli4_process_missed_mbox_completions(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8669) 	/* Wait for the outstnading mailbox command to complete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8670) 	while (phba->sli.mbox_active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8671) 		/* Check active mailbox complete status every 2ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8672) 		msleep(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8673) 		if (time_after(jiffies, timeout)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8674) 			/* Timeout, marked the outstanding cmd not complete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8675) 			rc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8676) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8677) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8678) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8680) 	/* Can not cleanly block async mailbox command, fails it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8681) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8682) 		spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8683) 		psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8684) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8685) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8686) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8689) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8690)  * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8691)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8692)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8693)  * The function unblocks and resume posting of SLI4 asynchronous mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8694)  * commands from the driver internal pending mailbox queue. It makes sure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8695)  * that there is no outstanding mailbox command before resuming posting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8696)  * asynchronous mailbox commands. If, for any reason, there is outstanding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8697)  * mailbox command, it will try to wait it out before resuming asynchronous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8698)  * mailbox command posting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8699)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8700) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8701) lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8702) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8703) 	struct lpfc_sli *psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8705) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8706) 	if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8707) 		/* Asynchronous mailbox posting is not blocked, do nothing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8708) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8709) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8710) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8711) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8712) 	/* Outstanding synchronous mailbox command is guaranteed to be done,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8713) 	 * successful or timeout, after timing-out the outstanding mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8714) 	 * command shall always be removed, so just unblock posting async
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8715) 	 * mailbox command and resume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8716) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8717) 	psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8718) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8720) 	/* wake up worker thread to post asynchronous mailbox command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8721) 	lpfc_worker_wake_up(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8722) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8724) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8725)  * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8726)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8727)  * @mboxq: Pointer to mailbox object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8728)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8729)  * The function waits for the bootstrap mailbox register ready bit from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8730)  * port for twice the regular mailbox command timeout value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8731)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8732)  *      0 - no timeout on waiting for bootstrap mailbox register ready.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8733)  *      MBXERR_ERROR - wait for bootstrap mailbox register timed out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8734)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8735) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8736) lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8737) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8738) 	uint32_t db_ready;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8739) 	unsigned long timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8740) 	struct lpfc_register bmbx_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8742) 	timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8743) 				   * 1000) + jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8745) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8746) 		bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8747) 		db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8748) 		if (!db_ready)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8749) 			mdelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8751) 		if (time_after(jiffies, timeout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8752) 			return MBXERR_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8753) 	} while (!db_ready);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8755) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8756) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8758) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8759)  * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8760)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8761)  * @mboxq: Pointer to mailbox object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8762)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8763)  * The function posts a mailbox to the port.  The mailbox is expected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8764)  * to be comletely filled in and ready for the port to operate on it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8765)  * This routine executes a synchronous completion operation on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8766)  * mailbox by polling for its completion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8767)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8768)  * The caller must not be holding any locks when calling this routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8769)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8770)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8771)  *	MBX_SUCCESS - mailbox posted successfully
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8772)  *	Any of the MBX error values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8773)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8774) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8775) lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8776) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8777) 	int rc = MBX_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8778) 	unsigned long iflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8779) 	uint32_t mcqe_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8780) 	uint32_t mbx_cmnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8781) 	struct lpfc_sli *psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8782) 	struct lpfc_mqe *mb = &mboxq->u.mqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8783) 	struct lpfc_bmbx_create *mbox_rgn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8784) 	struct dma_address *dma_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8786) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8787) 	 * Only one mailbox can be active to the bootstrap mailbox region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8788) 	 * at a time and there is no queueing provided.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8789) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8790) 	spin_lock_irqsave(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8791) 	if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8792) 		spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8793) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8794) 				"(%d):2532 Mailbox command x%x (x%x/x%x) "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8795) 				"cannot issue Data: x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8796) 				mboxq->vport ? mboxq->vport->vpi : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8797) 				mboxq->u.mb.mbxCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8798) 				lpfc_sli_config_mbox_subsys_get(phba, mboxq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8799) 				lpfc_sli_config_mbox_opcode_get(phba, mboxq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8800) 				psli->sli_flag, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8801) 		return MBXERR_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8802) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8803) 	/* The server grabs the token and owns it until release */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8804) 	psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8805) 	phba->sli.mbox_active = mboxq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8806) 	spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8808) 	/* wait for bootstrap mbox register for readyness */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8809) 	rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8810) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8811) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8812) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8813) 	 * Initialize the bootstrap memory region to avoid stale data areas
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8814) 	 * in the mailbox post.  Then copy the caller's mailbox contents to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8815) 	 * the bmbx mailbox region.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8816) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8817) 	mbx_cmnd = bf_get(lpfc_mqe_command, mb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8818) 	memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8819) 	lpfc_sli4_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8820) 			       sizeof(struct lpfc_mqe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8822) 	/* Post the high mailbox dma address to the port and wait for ready. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8823) 	dma_address = &phba->sli4_hba.bmbx.dma_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8824) 	writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8826) 	/* wait for bootstrap mbox register for hi-address write done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8827) 	rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8828) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8829) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8831) 	/* Post the low mailbox dma address to the port. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8832) 	writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8834) 	/* wait for bootstrap mbox register for low address write done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8835) 	rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8836) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8837) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8839) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8840) 	 * Read the CQ to ensure the mailbox has completed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8841) 	 * If so, update the mailbox status so that the upper layers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8842) 	 * can complete the request normally.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8843) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8844) 	lpfc_sli4_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8845) 			       sizeof(struct lpfc_mqe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8846) 	mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8847) 	lpfc_sli4_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8848) 			       sizeof(struct lpfc_mcqe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8849) 	mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8850) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8851) 	 * When the CQE status indicates a failure and the mailbox status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8852) 	 * indicates success then copy the CQE status into the mailbox status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8853) 	 * (and prefix it with x4000).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8854) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8855) 	if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8856) 		if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8857) 			bf_set(lpfc_mqe_status, mb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8858) 			       (LPFC_MBX_ERROR_RANGE | mcqe_status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8859) 		rc = MBXERR_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8860) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8861) 		lpfc_sli4_swap_str(phba, mboxq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8862) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8863) 	lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8864) 			"(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8865) 			"Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8866) 			" x%x x%x CQ: x%x x%x x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8867) 			mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8868) 			lpfc_sli_config_mbox_subsys_get(phba, mboxq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8869) 			lpfc_sli_config_mbox_opcode_get(phba, mboxq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8870) 			bf_get(lpfc_mqe_status, mb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8871) 			mb->un.mb_words[0], mb->un.mb_words[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8872) 			mb->un.mb_words[2], mb->un.mb_words[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8873) 			mb->un.mb_words[4], mb->un.mb_words[5],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8874) 			mb->un.mb_words[6], mb->un.mb_words[7],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8875) 			mb->un.mb_words[8], mb->un.mb_words[9],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8876) 			mb->un.mb_words[10], mb->un.mb_words[11],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8877) 			mb->un.mb_words[12], mboxq->mcqe.word0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8878) 			mboxq->mcqe.mcqe_tag0, 	mboxq->mcqe.mcqe_tag1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8879) 			mboxq->mcqe.trailer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8880) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8881) 	/* We are holding the token, no needed for lock when release */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8882) 	spin_lock_irqsave(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8883) 	psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8884) 	phba->sli.mbox_active = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8885) 	spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8886) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8887) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8888) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8889) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8890)  * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8891)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8892)  * @mboxq: Pointer to mailbox object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8893)  * @flag: Flag indicating how the mailbox need to be processed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8894)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8895)  * This function is called by discovery code and HBA management code to submit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8896)  * a mailbox command to firmware with SLI-4 interface spec.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8897)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8898)  * Return codes the caller owns the mailbox command after the return of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8899)  * function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8900)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8901) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8902) lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8903) 		       uint32_t flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8904) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8905) 	struct lpfc_sli *psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8906) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8907) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8909) 	/* dump from issue mailbox command if setup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8910) 	lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8912) 	rc = lpfc_mbox_dev_check(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8913) 	if (unlikely(rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8914) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8915) 				"(%d):2544 Mailbox command x%x (x%x/x%x) "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8916) 				"cannot issue Data: x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8917) 				mboxq->vport ? mboxq->vport->vpi : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8918) 				mboxq->u.mb.mbxCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8919) 				lpfc_sli_config_mbox_subsys_get(phba, mboxq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8920) 				lpfc_sli_config_mbox_opcode_get(phba, mboxq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8921) 				psli->sli_flag, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8922) 		goto out_not_finished;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8923) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8925) 	/* Detect polling mode and jump to a handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8926) 	if (!phba->sli4_hba.intr_enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8927) 		if (flag == MBX_POLL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8928) 			rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8929) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8930) 			rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8931) 		if (rc != MBX_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8932) 			lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8933) 					"(%d):2541 Mailbox command x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8934) 					"(x%x/x%x) failure: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8935) 					"mqe_sta: x%x mcqe_sta: x%x/x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8936) 					"Data: x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8937) 					mboxq->vport ? mboxq->vport->vpi : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8938) 					mboxq->u.mb.mbxCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8939) 					lpfc_sli_config_mbox_subsys_get(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8940) 									mboxq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8941) 					lpfc_sli_config_mbox_opcode_get(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8942) 									mboxq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8943) 					bf_get(lpfc_mqe_status, &mboxq->u.mqe),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8944) 					bf_get(lpfc_mcqe_status, &mboxq->mcqe),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8945) 					bf_get(lpfc_mcqe_ext_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8946) 					       &mboxq->mcqe),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8947) 					psli->sli_flag, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8948) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8949) 	} else if (flag == MBX_POLL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8950) 		lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8951) 				"(%d):2542 Try to issue mailbox command "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8952) 				"x%x (x%x/x%x) synchronously ahead of async "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8953) 				"mailbox command queue: x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8954) 				mboxq->vport ? mboxq->vport->vpi : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8955) 				mboxq->u.mb.mbxCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8956) 				lpfc_sli_config_mbox_subsys_get(phba, mboxq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8957) 				lpfc_sli_config_mbox_opcode_get(phba, mboxq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8958) 				psli->sli_flag, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8959) 		/* Try to block the asynchronous mailbox posting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8960) 		rc = lpfc_sli4_async_mbox_block(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8961) 		if (!rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8962) 			/* Successfully blocked, now issue sync mbox cmd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8963) 			rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8964) 			if (rc != MBX_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8965) 				lpfc_printf_log(phba, KERN_WARNING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8966) 					LOG_MBOX | LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8967) 					"(%d):2597 Sync Mailbox command "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8968) 					"x%x (x%x/x%x) failure: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8969) 					"mqe_sta: x%x mcqe_sta: x%x/x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8970) 					"Data: x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8971) 					mboxq->vport ? mboxq->vport->vpi : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8972) 					mboxq->u.mb.mbxCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8973) 					lpfc_sli_config_mbox_subsys_get(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8974) 									mboxq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8975) 					lpfc_sli_config_mbox_opcode_get(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8976) 									mboxq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8977) 					bf_get(lpfc_mqe_status, &mboxq->u.mqe),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8978) 					bf_get(lpfc_mcqe_status, &mboxq->mcqe),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8979) 					bf_get(lpfc_mcqe_ext_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8980) 					       &mboxq->mcqe),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8981) 					psli->sli_flag, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8982) 			/* Unblock the async mailbox posting afterward */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8983) 			lpfc_sli4_async_mbox_unblock(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8984) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8985) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8986) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8988) 	/* Now, interrupt mode asynchronous mailbox command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8989) 	rc = lpfc_mbox_cmd_check(phba, mboxq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8990) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8991) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8992) 				"(%d):2543 Mailbox command x%x (x%x/x%x) "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8993) 				"cannot issue Data: x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8994) 				mboxq->vport ? mboxq->vport->vpi : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8995) 				mboxq->u.mb.mbxCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8996) 				lpfc_sli_config_mbox_subsys_get(phba, mboxq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8997) 				lpfc_sli_config_mbox_opcode_get(phba, mboxq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8998) 				psli->sli_flag, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8999) 		goto out_not_finished;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9000) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9002) 	/* Put the mailbox command to the driver internal FIFO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9003) 	psli->slistat.mbox_busy++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9004) 	spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9005) 	lpfc_mbox_put(phba, mboxq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9006) 	spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9007) 	lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9008) 			"(%d):0354 Mbox cmd issue - Enqueue Data: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9009) 			"x%x (x%x/x%x) x%x x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9010) 			mboxq->vport ? mboxq->vport->vpi : 0xffffff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9011) 			bf_get(lpfc_mqe_command, &mboxq->u.mqe),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9012) 			lpfc_sli_config_mbox_subsys_get(phba, mboxq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9013) 			lpfc_sli_config_mbox_opcode_get(phba, mboxq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9014) 			phba->pport->port_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9015) 			psli->sli_flag, MBX_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9016) 	/* Wake up worker thread to transport mailbox command from head */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9017) 	lpfc_worker_wake_up(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9018) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9019) 	return MBX_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9021) out_not_finished:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9022) 	return MBX_NOT_FINISHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9023) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9025) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9026)  * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9027)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9028)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9029)  * This function is called by worker thread to send a mailbox command to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9030)  * SLI4 HBA firmware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9031)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9032)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9033) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9034) lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9035) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9036) 	struct lpfc_sli *psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9037) 	LPFC_MBOXQ_t *mboxq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9038) 	int rc = MBX_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9039) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9040) 	struct lpfc_mqe *mqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9041) 	uint32_t mbx_cmnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9043) 	/* Check interrupt mode before post async mailbox command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9044) 	if (unlikely(!phba->sli4_hba.intr_enable))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9045) 		return MBX_NOT_FINISHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9046) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9047) 	/* Check for mailbox command service token */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9048) 	spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9049) 	if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9050) 		spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9051) 		return MBX_NOT_FINISHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9052) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9053) 	if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9054) 		spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9055) 		return MBX_NOT_FINISHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9056) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9057) 	if (unlikely(phba->sli.mbox_active)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9058) 		spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9059) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9060) 				"0384 There is pending active mailbox cmd\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9061) 		return MBX_NOT_FINISHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9062) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9063) 	/* Take the mailbox command service token */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9064) 	psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9066) 	/* Get the next mailbox command from head of queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9067) 	mboxq = lpfc_mbox_get(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9069) 	/* If no more mailbox command waiting for post, we're done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9070) 	if (!mboxq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9071) 		psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9072) 		spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9073) 		return MBX_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9074) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9075) 	phba->sli.mbox_active = mboxq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9076) 	spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9077) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9078) 	/* Check device readiness for posting mailbox command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9079) 	rc = lpfc_mbox_dev_check(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9080) 	if (unlikely(rc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9081) 		/* Driver clean routine will clean up pending mailbox */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9082) 		goto out_not_finished;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9083) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9084) 	/* Prepare the mbox command to be posted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9085) 	mqe = &mboxq->u.mqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9086) 	mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9088) 	/* Start timer for the mbox_tmo and log some mailbox post messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9089) 	mod_timer(&psli->mbox_tmo, (jiffies +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9090) 		  msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq))));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9091) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9092) 	lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9093) 			"(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9094) 			"x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9095) 			mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9096) 			lpfc_sli_config_mbox_subsys_get(phba, mboxq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9097) 			lpfc_sli_config_mbox_opcode_get(phba, mboxq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9098) 			phba->pport->port_state, psli->sli_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9099) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9100) 	if (mbx_cmnd != MBX_HEARTBEAT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9101) 		if (mboxq->vport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9102) 			lpfc_debugfs_disc_trc(mboxq->vport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9103) 				LPFC_DISC_TRC_MBOX_VPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9104) 				"MBOX Send vport: cmd:x%x mb:x%x x%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9105) 				mbx_cmnd, mqe->un.mb_words[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9106) 				mqe->un.mb_words[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9107) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9108) 			lpfc_debugfs_disc_trc(phba->pport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9109) 				LPFC_DISC_TRC_MBOX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9110) 				"MBOX Send: cmd:x%x mb:x%x x%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9111) 				mbx_cmnd, mqe->un.mb_words[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9112) 				mqe->un.mb_words[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9113) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9114) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9115) 	psli->slistat.mbox_cmd++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9117) 	/* Post the mailbox command to the port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9118) 	rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9119) 	if (rc != MBX_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9120) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9121) 				"(%d):2533 Mailbox command x%x (x%x/x%x) "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9122) 				"cannot issue Data: x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9123) 				mboxq->vport ? mboxq->vport->vpi : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9124) 				mboxq->u.mb.mbxCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9125) 				lpfc_sli_config_mbox_subsys_get(phba, mboxq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9126) 				lpfc_sli_config_mbox_opcode_get(phba, mboxq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9127) 				psli->sli_flag, MBX_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9128) 		goto out_not_finished;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9131) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9133) out_not_finished:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9134) 	spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9135) 	if (phba->sli.mbox_active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9136) 		mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9137) 		__lpfc_mbox_cmpl_put(phba, mboxq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9138) 		/* Release the token */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9139) 		psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9140) 		phba->sli.mbox_active = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9141) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9142) 	spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9144) 	return MBX_NOT_FINISHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9147) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9148)  * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9149)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9150)  * @pmbox: Pointer to mailbox object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9151)  * @flag: Flag indicating how the mailbox need to be processed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9152)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9153)  * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9154)  * the API jump table function pointer from the lpfc_hba struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9155)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9156)  * Return codes the caller owns the mailbox command after the return of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9157)  * function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9158)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9159) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9160) lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9162) 	return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9165) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9166)  * lpfc_mbox_api_table_setup - Set up mbox api function jump table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9167)  * @phba: The hba struct for which this call is being executed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9168)  * @dev_grp: The HBA PCI-Device group number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9169)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9170)  * This routine sets up the mbox interface API function jump table in @phba
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9171)  * struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9172)  * Returns: 0 - success, -ENODEV - failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9173)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9174) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9175) lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9178) 	switch (dev_grp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9179) 	case LPFC_PCI_DEV_LP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9180) 		phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9181) 		phba->lpfc_sli_handle_slow_ring_event =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9182) 				lpfc_sli_handle_slow_ring_event_s3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9183) 		phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9184) 		phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9185) 		phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9186) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9187) 	case LPFC_PCI_DEV_OC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9188) 		phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9189) 		phba->lpfc_sli_handle_slow_ring_event =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9190) 				lpfc_sli_handle_slow_ring_event_s4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9191) 		phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9192) 		phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9193) 		phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9194) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9195) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9196) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9197) 				"1420 Invalid HBA PCI-device group: 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9198) 				dev_grp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9199) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9200) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9201) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9202) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9205) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9206)  * __lpfc_sli_ringtx_put - Add an iocb to the txq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9207)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9208)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9209)  * @piocb: Pointer to address of newly added command iocb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9210)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9211)  * This function is called with hbalock held for SLI3 ports or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9212)  * the ring lock held for SLI4 ports to add a command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9213)  * iocb to the txq when SLI layer cannot submit the command iocb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9214)  * to the ring.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9215)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9216) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9217) __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9218) 		    struct lpfc_iocbq *piocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9220) 	if (phba->sli_rev == LPFC_SLI_REV4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9221) 		lockdep_assert_held(&pring->ring_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9222) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9223) 		lockdep_assert_held(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9224) 	/* Insert the caller's iocb in the txq tail for later processing. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9225) 	list_add_tail(&piocb->list, &pring->txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9228) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9229)  * lpfc_sli_next_iocb - Get the next iocb in the txq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9230)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9231)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9232)  * @piocb: Pointer to address of newly added command iocb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9233)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9234)  * This function is called with hbalock held before a new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9235)  * iocb is submitted to the firmware. This function checks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9236)  * txq to flush the iocbs in txq to Firmware before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9237)  * submitting new iocbs to the Firmware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9238)  * If there are iocbs in the txq which need to be submitted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9239)  * to firmware, lpfc_sli_next_iocb returns the first element
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9240)  * of the txq after dequeuing it from txq.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9241)  * If there is no iocb in the txq then the function will return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9242)  * *piocb and *piocb is set to NULL. Caller needs to check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9243)  * *piocb to find if there are more commands in the txq.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9244)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9245) static struct lpfc_iocbq *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9246) lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9247) 		   struct lpfc_iocbq **piocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9249) 	struct lpfc_iocbq * nextiocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9251) 	lockdep_assert_held(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9253) 	nextiocb = lpfc_sli_ringtx_get(phba, pring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9254) 	if (!nextiocb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9255) 		nextiocb = *piocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9256) 		*piocb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9257) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9259) 	return nextiocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9262) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9263)  * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9264)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9265)  * @ring_number: SLI ring number to issue iocb on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9266)  * @piocb: Pointer to command iocb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9267)  * @flag: Flag indicating if this command can be put into txq.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9268)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9269)  * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9270)  * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9271)  * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9272)  * flag is turned on, the function returns IOCB_ERROR. When the link is down,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9273)  * this function allows only iocbs for posting buffers. This function finds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9274)  * next available slot in the command ring and posts the command to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9275)  * available slot and writes the port attention register to request HBA start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9276)  * processing new iocb. If there is no slot available in the ring and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9277)  * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9278)  * the function returns IOCB_BUSY.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9279)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9280)  * This function is called with hbalock held. The function will return success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9281)  * after it successfully submit the iocb to firmware or after adding to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9282)  * txq.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9283)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9284) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9285) __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9286) 		    struct lpfc_iocbq *piocb, uint32_t flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9288) 	struct lpfc_iocbq *nextiocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9289) 	IOCB_t *iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9290) 	struct lpfc_sli_ring *pring = &phba->sli.sli3_ring[ring_number];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9292) 	lockdep_assert_held(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9294) 	if (piocb->iocb_cmpl && (!piocb->vport) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9295) 	   (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9296) 	   (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9297) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9298) 				"1807 IOCB x%x failed. No vport\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9299) 				piocb->iocb.ulpCommand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9300) 		dump_stack();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9301) 		return IOCB_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9302) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9305) 	/* If the PCI channel is in offline state, do not post iocbs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9306) 	if (unlikely(pci_channel_offline(phba->pcidev)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9307) 		return IOCB_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9309) 	/* If HBA has a deferred error attention, fail the iocb. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9310) 	if (unlikely(phba->hba_flag & DEFER_ERATT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9311) 		return IOCB_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9313) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9314) 	 * We should never get an IOCB if we are in a < LINK_DOWN state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9315) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9316) 	if (unlikely(phba->link_state < LPFC_LINK_DOWN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9317) 		return IOCB_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9319) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9320) 	 * Check to see if we are blocking IOCB processing because of a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9321) 	 * outstanding event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9322) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9323) 	if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9324) 		goto iocb_busy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9326) 	if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9327) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9328) 		 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9329) 		 * can be issued if the link is not up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9330) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9331) 		switch (piocb->iocb.ulpCommand) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9332) 		case CMD_GEN_REQUEST64_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9333) 		case CMD_GEN_REQUEST64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9334) 			if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9335) 				(piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9336) 					FC_RCTL_DD_UNSOL_CMD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9337) 				(piocb->iocb.un.genreq64.w5.hcsw.Type !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9338) 					MENLO_TRANSPORT_TYPE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9340) 				goto iocb_busy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9341) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9342) 		case CMD_QUE_RING_BUF_CN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9343) 		case CMD_QUE_RING_BUF64_CN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9344) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9345) 			 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9346) 			 * completion, iocb_cmpl MUST be 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9347) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9348) 			if (piocb->iocb_cmpl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9349) 				piocb->iocb_cmpl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9350) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9351) 		case CMD_CREATE_XRI_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9352) 		case CMD_CLOSE_XRI_CN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9353) 		case CMD_CLOSE_XRI_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9354) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9355) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9356) 			goto iocb_busy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9357) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9359) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9360) 	 * For FCP commands, we must be in a state where we can process link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9361) 	 * attention events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9362) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9363) 	} else if (unlikely(pring->ringno == LPFC_FCP_RING &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9364) 			    !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9365) 		goto iocb_busy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9366) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9368) 	while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9369) 	       (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9370) 		lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9372) 	if (iocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9373) 		lpfc_sli_update_ring(phba, pring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9374) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9375) 		lpfc_sli_update_full_ring(phba, pring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9377) 	if (!piocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9378) 		return IOCB_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9380) 	goto out_busy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9382)  iocb_busy:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9383) 	pring->stats.iocb_cmd_delay++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9385)  out_busy:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9387) 	if (!(flag & SLI_IOCB_RET_IOCB)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9388) 		__lpfc_sli_ringtx_put(phba, pring, piocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9389) 		return IOCB_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9390) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9392) 	return IOCB_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9395) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9396)  * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9397)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9398)  * @piocbq: Pointer to command iocb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9399)  * @sglq: Pointer to the scatter gather queue object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9400)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9401)  * This routine converts the bpl or bde that is in the IOCB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9402)  * to a sgl list for the sli4 hardware. The physical address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9403)  * of the bpl/bde is converted back to a virtual address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9404)  * If the IOCB contains a BPL then the list of BDE's is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9405)  * converted to sli4_sge's. If the IOCB contains a single
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9406)  * BDE then it is converted to a single sli_sge.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9407)  * The IOCB is still in cpu endianess so the contents of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9408)  * the bpl can be used without byte swapping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9409)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9410)  * Returns valid XRI = Success, NO_XRI = Failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9411) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9412) static uint16_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9413) lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9414) 		struct lpfc_sglq *sglq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9415) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9416) 	uint16_t xritag = NO_XRI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9417) 	struct ulp_bde64 *bpl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9418) 	struct ulp_bde64 bde;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9419) 	struct sli4_sge *sgl  = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9420) 	struct lpfc_dmabuf *dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9421) 	IOCB_t *icmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9422) 	int numBdes = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9423) 	int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9424) 	uint32_t offset = 0; /* accumulated offset in the sg request list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9425) 	int inbound = 0; /* number of sg reply entries inbound from firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9427) 	if (!piocbq || !sglq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9428) 		return xritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9430) 	sgl  = (struct sli4_sge *)sglq->sgl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9431) 	icmd = &piocbq->iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9432) 	if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9433) 		return sglq->sli4_xritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9434) 	if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9435) 		numBdes = icmd->un.genreq64.bdl.bdeSize /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9436) 				sizeof(struct ulp_bde64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9437) 		/* The addrHigh and addrLow fields within the IOCB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9438) 		 * have not been byteswapped yet so there is no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9439) 		 * need to swap them back.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9440) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9441) 		if (piocbq->context3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9442) 			dmabuf = (struct lpfc_dmabuf *)piocbq->context3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9443) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9444) 			return xritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9446) 		bpl  = (struct ulp_bde64 *)dmabuf->virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9447) 		if (!bpl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9448) 			return xritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9450) 		for (i = 0; i < numBdes; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9451) 			/* Should already be byte swapped. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9452) 			sgl->addr_hi = bpl->addrHigh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9453) 			sgl->addr_lo = bpl->addrLow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9455) 			sgl->word2 = le32_to_cpu(sgl->word2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9456) 			if ((i+1) == numBdes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9457) 				bf_set(lpfc_sli4_sge_last, sgl, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9458) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9459) 				bf_set(lpfc_sli4_sge_last, sgl, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9460) 			/* swap the size field back to the cpu so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9461) 			 * can assign it to the sgl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9462) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9463) 			bde.tus.w = le32_to_cpu(bpl->tus.w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9464) 			sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9465) 			/* The offsets in the sgl need to be accumulated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9466) 			 * separately for the request and reply lists.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9467) 			 * The request is always first, the reply follows.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9468) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9469) 			if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9470) 				/* add up the reply sg entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9471) 				if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9472) 					inbound++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9473) 				/* first inbound? reset the offset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9474) 				if (inbound == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9475) 					offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9476) 				bf_set(lpfc_sli4_sge_offset, sgl, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9477) 				bf_set(lpfc_sli4_sge_type, sgl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9478) 					LPFC_SGE_TYPE_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9479) 				offset += bde.tus.f.bdeSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9480) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9481) 			sgl->word2 = cpu_to_le32(sgl->word2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9482) 			bpl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9483) 			sgl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9484) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9485) 	} else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9486) 			/* The addrHigh and addrLow fields of the BDE have not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9487) 			 * been byteswapped yet so they need to be swapped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9488) 			 * before putting them in the sgl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9489) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9490) 			sgl->addr_hi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9491) 				cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9492) 			sgl->addr_lo =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9493) 				cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9494) 			sgl->word2 = le32_to_cpu(sgl->word2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9495) 			bf_set(lpfc_sli4_sge_last, sgl, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9496) 			sgl->word2 = cpu_to_le32(sgl->word2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9497) 			sgl->sge_len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9498) 				cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9499) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9500) 	return sglq->sli4_xritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9503) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9504)  * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9505)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9506)  * @iocbq: Pointer to command iocb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9507)  * @wqe: Pointer to the work queue entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9508)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9509)  * This routine converts the iocb command to its Work Queue Entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9510)  * equivalent. The wqe pointer should not have any fields set when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9511)  * this routine is called because it will memcpy over them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9512)  * This routine does not set the CQ_ID or the WQEC bits in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9513)  * wqe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9514)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9515)  * Returns: 0 = Success, IOCB_ERROR = Failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9516)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9517) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9518) lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9519) 		union lpfc_wqe128 *wqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9521) 	uint32_t xmit_len = 0, total_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9522) 	uint8_t ct = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9523) 	uint32_t fip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9524) 	uint32_t abort_tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9525) 	uint8_t command_type = ELS_COMMAND_NON_FIP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9526) 	uint8_t cmnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9527) 	uint16_t xritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9528) 	uint16_t abrt_iotag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9529) 	struct lpfc_iocbq *abrtiocbq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9530) 	struct ulp_bde64 *bpl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9531) 	uint32_t els_id = LPFC_ELS_ID_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9532) 	int numBdes, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9533) 	struct ulp_bde64 bde;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9534) 	struct lpfc_nodelist *ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9535) 	uint32_t *pcmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9536) 	uint32_t if_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9538) 	fip = phba->hba_flag & HBA_FIP_SUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9539) 	/* The fcp commands will set command type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9540) 	if (iocbq->iocb_flag &  LPFC_IO_FCP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9541) 		command_type = FCP_COMMAND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9542) 	else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9543) 		command_type = ELS_COMMAND_FIP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9544) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9545) 		command_type = ELS_COMMAND_NON_FIP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9547) 	if (phba->fcp_embed_io)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9548) 		memset(wqe, 0, sizeof(union lpfc_wqe128));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9549) 	/* Some of the fields are in the right position already */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9550) 	memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9551) 	/* The ct field has moved so reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9552) 	wqe->generic.wqe_com.word7 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9553) 	wqe->generic.wqe_com.word10 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9555) 	abort_tag = (uint32_t) iocbq->iotag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9556) 	xritag = iocbq->sli4_xritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9557) 	/* words0-2 bpl convert bde */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9558) 	if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9559) 		numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9560) 				sizeof(struct ulp_bde64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9561) 		bpl  = (struct ulp_bde64 *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9562) 			((struct lpfc_dmabuf *)iocbq->context3)->virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9563) 		if (!bpl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9564) 			return IOCB_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9566) 		/* Should already be byte swapped. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9567) 		wqe->generic.bde.addrHigh =  le32_to_cpu(bpl->addrHigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9568) 		wqe->generic.bde.addrLow =  le32_to_cpu(bpl->addrLow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9569) 		/* swap the size field back to the cpu so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9570) 		 * can assign it to the sgl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9571) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9572) 		wqe->generic.bde.tus.w  = le32_to_cpu(bpl->tus.w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9573) 		xmit_len = wqe->generic.bde.tus.f.bdeSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9574) 		total_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9575) 		for (i = 0; i < numBdes; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9576) 			bde.tus.w  = le32_to_cpu(bpl[i].tus.w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9577) 			total_len += bde.tus.f.bdeSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9578) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9579) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9580) 		xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9582) 	iocbq->iocb.ulpIoTag = iocbq->iotag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9583) 	cmnd = iocbq->iocb.ulpCommand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9585) 	switch (iocbq->iocb.ulpCommand) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9586) 	case CMD_ELS_REQUEST64_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9587) 		if (iocbq->iocb_flag & LPFC_IO_LIBDFC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9588) 			ndlp = iocbq->context_un.ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9589) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9590) 			ndlp = (struct lpfc_nodelist *)iocbq->context1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9591) 		if (!iocbq->iocb.ulpLe) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9592) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9593) 				"2007 Only Limited Edition cmd Format"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9594) 				" supported 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9595) 				iocbq->iocb.ulpCommand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9596) 			return IOCB_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9597) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9599) 		wqe->els_req.payload_len = xmit_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9600) 		/* Els_reguest64 has a TMO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9601) 		bf_set(wqe_tmo, &wqe->els_req.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9602) 			iocbq->iocb.ulpTimeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9603) 		/* Need a VF for word 4 set the vf bit*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9604) 		bf_set(els_req64_vf, &wqe->els_req, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9605) 		/* And a VFID for word 12 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9606) 		bf_set(els_req64_vfid, &wqe->els_req, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9607) 		ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9608) 		bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9609) 		       iocbq->iocb.ulpContext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9610) 		bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9611) 		bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9612) 		/* CCP CCPE PV PRI in word10 were set in the memcpy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9613) 		if (command_type == ELS_COMMAND_FIP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9614) 			els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9615) 					>> LPFC_FIP_ELS_ID_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9616) 		pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9617) 					iocbq->context2)->virt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9618) 		if_type = bf_get(lpfc_sli_intf_if_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9619) 					&phba->sli4_hba.sli_intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9620) 		if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9621) 			if (pcmd && (*pcmd == ELS_CMD_FLOGI ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9622) 				*pcmd == ELS_CMD_SCR ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9623) 				*pcmd == ELS_CMD_RDF ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9624) 				*pcmd == ELS_CMD_RSCN_XMT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9625) 				*pcmd == ELS_CMD_FDISC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9626) 				*pcmd == ELS_CMD_LOGO ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9627) 				*pcmd == ELS_CMD_PLOGI)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9628) 				bf_set(els_req64_sp, &wqe->els_req, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9629) 				bf_set(els_req64_sid, &wqe->els_req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9630) 					iocbq->vport->fc_myDID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9631) 				if ((*pcmd == ELS_CMD_FLOGI) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9632) 					!(phba->fc_topology ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9633) 						LPFC_TOPOLOGY_LOOP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9634) 					bf_set(els_req64_sid, &wqe->els_req, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9635) 				bf_set(wqe_ct, &wqe->els_req.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9636) 				bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9637) 					phba->vpi_ids[iocbq->vport->vpi]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9638) 			} else if (pcmd && iocbq->context1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9639) 				bf_set(wqe_ct, &wqe->els_req.wqe_com, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9640) 				bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9641) 					phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9642) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9643) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9644) 		bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9645) 		       phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9646) 		bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9647) 		bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9648) 		bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9649) 		bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9650) 		bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9651) 		bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9652) 		wqe->els_req.max_response_payload_len = total_len - xmit_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9653) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9654) 	case CMD_XMIT_SEQUENCE64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9655) 		bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9656) 		       iocbq->iocb.un.ulpWord[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9657) 		bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9658) 		       iocbq->iocb.unsli3.rcvsli3.ox_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9659) 		/* The entire sequence is transmitted for this IOCB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9660) 		xmit_len = total_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9661) 		cmnd = CMD_XMIT_SEQUENCE64_CR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9662) 		if (phba->link_flag & LS_LOOPBACK_MODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9663) 			bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9664) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9665) 	case CMD_XMIT_SEQUENCE64_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9666) 		/* word3 iocb=io_tag32 wqe=reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9667) 		wqe->xmit_sequence.rsvd3 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9668) 		/* word4 relative_offset memcpy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9669) 		/* word5 r_ctl/df_ctl memcpy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9670) 		bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9671) 		bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9672) 		bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9673) 		       LPFC_WQE_IOD_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9674) 		bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9675) 		       LPFC_WQE_LENLOC_WORD12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9676) 		bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9677) 		wqe->xmit_sequence.xmit_len = xmit_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9678) 		command_type = OTHER_COMMAND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9679) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9680) 	case CMD_XMIT_BCAST64_CN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9681) 		/* word3 iocb=iotag32 wqe=seq_payload_len */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9682) 		wqe->xmit_bcast64.seq_payload_len = xmit_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9683) 		/* word4 iocb=rsvd wqe=rsvd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9684) 		/* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9685) 		/* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9686) 		bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9687) 			((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9688) 		bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9689) 		bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9690) 		bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9691) 		       LPFC_WQE_LENLOC_WORD3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9692) 		bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9693) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9694) 	case CMD_FCP_IWRITE64_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9695) 		command_type = FCP_COMMAND_DATA_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9696) 		/* word3 iocb=iotag wqe=payload_offset_len */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9697) 		/* Add the FCP_CMD and FCP_RSP sizes to get the offset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9698) 		bf_set(payload_offset_len, &wqe->fcp_iwrite,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9699) 		       xmit_len + sizeof(struct fcp_rsp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9700) 		bf_set(cmd_buff_len, &wqe->fcp_iwrite,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9701) 		       0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9702) 		/* word4 iocb=parameter wqe=total_xfer_length memcpy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9703) 		/* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9704) 		bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9705) 		       iocbq->iocb.ulpFCP2Rcvy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9706) 		bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9707) 		/* Always open the exchange */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9708) 		bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9709) 		bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9710) 		       LPFC_WQE_LENLOC_WORD4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9711) 		bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9712) 		bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9713) 		if (iocbq->iocb_flag & LPFC_IO_OAS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9714) 			bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9715) 			bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9716) 			if (iocbq->priority) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9717) 				bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9718) 				       (iocbq->priority << 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9719) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9720) 				bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9721) 				       (phba->cfg_XLanePriority << 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9722) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9723) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9724) 		/* Note, word 10 is already initialized to 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9726) 		/* Don't set PBDE for Perf hints, just lpfc_enable_pbde */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9727) 		if (phba->cfg_enable_pbde)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9728) 			bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9729) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9730) 			bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9732) 		if (phba->fcp_embed_io) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9733) 			struct lpfc_io_buf *lpfc_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9734) 			struct sli4_sge *sgl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9735) 			struct fcp_cmnd *fcp_cmnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9736) 			uint32_t *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9738) 			/* 128 byte wqe support here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9740) 			lpfc_cmd = iocbq->context1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9741) 			sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9742) 			fcp_cmnd = lpfc_cmd->fcp_cmnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9744) 			/* Word 0-2 - FCP_CMND */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9745) 			wqe->generic.bde.tus.f.bdeFlags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9746) 				BUFF_TYPE_BDE_IMMED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9747) 			wqe->generic.bde.tus.f.bdeSize = sgl->sge_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9748) 			wqe->generic.bde.addrHigh = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9749) 			wqe->generic.bde.addrLow =  88;  /* Word 22 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9751) 			bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9752) 			bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9754) 			/* Word 22-29  FCP CMND Payload */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9755) 			ptr = &wqe->words[22];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9756) 			memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9757) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9758) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9759) 	case CMD_FCP_IREAD64_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9760) 		/* word3 iocb=iotag wqe=payload_offset_len */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9761) 		/* Add the FCP_CMD and FCP_RSP sizes to get the offset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9762) 		bf_set(payload_offset_len, &wqe->fcp_iread,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9763) 		       xmit_len + sizeof(struct fcp_rsp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9764) 		bf_set(cmd_buff_len, &wqe->fcp_iread,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9765) 		       0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9766) 		/* word4 iocb=parameter wqe=total_xfer_length memcpy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9767) 		/* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9768) 		bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9769) 		       iocbq->iocb.ulpFCP2Rcvy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9770) 		bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9771) 		/* Always open the exchange */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9772) 		bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9773) 		bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9774) 		       LPFC_WQE_LENLOC_WORD4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9775) 		bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9776) 		bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9777) 		if (iocbq->iocb_flag & LPFC_IO_OAS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9778) 			bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9779) 			bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9780) 			if (iocbq->priority) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9781) 				bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9782) 				       (iocbq->priority << 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9783) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9784) 				bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9785) 				       (phba->cfg_XLanePriority << 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9786) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9787) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9788) 		/* Note, word 10 is already initialized to 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9790) 		/* Don't set PBDE for Perf hints, just lpfc_enable_pbde */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9791) 		if (phba->cfg_enable_pbde)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9792) 			bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9793) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9794) 			bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9796) 		if (phba->fcp_embed_io) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9797) 			struct lpfc_io_buf *lpfc_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9798) 			struct sli4_sge *sgl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9799) 			struct fcp_cmnd *fcp_cmnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9800) 			uint32_t *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9802) 			/* 128 byte wqe support here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9804) 			lpfc_cmd = iocbq->context1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9805) 			sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9806) 			fcp_cmnd = lpfc_cmd->fcp_cmnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9808) 			/* Word 0-2 - FCP_CMND */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9809) 			wqe->generic.bde.tus.f.bdeFlags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9810) 				BUFF_TYPE_BDE_IMMED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9811) 			wqe->generic.bde.tus.f.bdeSize = sgl->sge_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9812) 			wqe->generic.bde.addrHigh = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9813) 			wqe->generic.bde.addrLow =  88;  /* Word 22 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9815) 			bf_set(wqe_wqes, &wqe->fcp_iread.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9816) 			bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9818) 			/* Word 22-29  FCP CMND Payload */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9819) 			ptr = &wqe->words[22];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9820) 			memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9821) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9822) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9823) 	case CMD_FCP_ICMND64_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9824) 		/* word3 iocb=iotag wqe=payload_offset_len */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9825) 		/* Add the FCP_CMD and FCP_RSP sizes to get the offset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9826) 		bf_set(payload_offset_len, &wqe->fcp_icmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9827) 		       xmit_len + sizeof(struct fcp_rsp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9828) 		bf_set(cmd_buff_len, &wqe->fcp_icmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9829) 		       0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9830) 		/* word3 iocb=IO_TAG wqe=reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9831) 		bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9832) 		/* Always open the exchange */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9833) 		bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9834) 		bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9835) 		bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9836) 		bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9837) 		       LPFC_WQE_LENLOC_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9838) 		bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9839) 		       iocbq->iocb.ulpFCP2Rcvy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9840) 		if (iocbq->iocb_flag & LPFC_IO_OAS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9841) 			bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9842) 			bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9843) 			if (iocbq->priority) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9844) 				bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9845) 				       (iocbq->priority << 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9846) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9847) 				bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9848) 				       (phba->cfg_XLanePriority << 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9849) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9850) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9851) 		/* Note, word 10 is already initialized to 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9853) 		if (phba->fcp_embed_io) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9854) 			struct lpfc_io_buf *lpfc_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9855) 			struct sli4_sge *sgl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9856) 			struct fcp_cmnd *fcp_cmnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9857) 			uint32_t *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9859) 			/* 128 byte wqe support here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9861) 			lpfc_cmd = iocbq->context1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9862) 			sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9863) 			fcp_cmnd = lpfc_cmd->fcp_cmnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9865) 			/* Word 0-2 - FCP_CMND */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9866) 			wqe->generic.bde.tus.f.bdeFlags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9867) 				BUFF_TYPE_BDE_IMMED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9868) 			wqe->generic.bde.tus.f.bdeSize = sgl->sge_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9869) 			wqe->generic.bde.addrHigh = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9870) 			wqe->generic.bde.addrLow =  88;  /* Word 22 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9872) 			bf_set(wqe_wqes, &wqe->fcp_icmd.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9873) 			bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9875) 			/* Word 22-29  FCP CMND Payload */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9876) 			ptr = &wqe->words[22];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9877) 			memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9878) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9879) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9880) 	case CMD_GEN_REQUEST64_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9881) 		/* For this command calculate the xmit length of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9882) 		 * request bde.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9883) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9884) 		xmit_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9885) 		numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9886) 			sizeof(struct ulp_bde64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9887) 		for (i = 0; i < numBdes; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9888) 			bde.tus.w = le32_to_cpu(bpl[i].tus.w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9889) 			if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9890) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9891) 			xmit_len += bde.tus.f.bdeSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9892) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9893) 		/* word3 iocb=IO_TAG wqe=request_payload_len */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9894) 		wqe->gen_req.request_payload_len = xmit_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9895) 		/* word4 iocb=parameter wqe=relative_offset memcpy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9896) 		/* word5 [rctl, type, df_ctl, la] copied in memcpy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9897) 		/* word6 context tag copied in memcpy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9898) 		if (iocbq->iocb.ulpCt_h  || iocbq->iocb.ulpCt_l) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9899) 			ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9900) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9901) 				"2015 Invalid CT %x command 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9902) 				ct, iocbq->iocb.ulpCommand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9903) 			return IOCB_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9904) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9905) 		bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9906) 		bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9907) 		bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9908) 		bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9909) 		bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9910) 		bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9911) 		bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9912) 		bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9913) 		wqe->gen_req.max_response_payload_len = total_len - xmit_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9914) 		command_type = OTHER_COMMAND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9915) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9916) 	case CMD_XMIT_ELS_RSP64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9917) 		ndlp = (struct lpfc_nodelist *)iocbq->context1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9918) 		/* words0-2 BDE memcpy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9919) 		/* word3 iocb=iotag32 wqe=response_payload_len */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9920) 		wqe->xmit_els_rsp.response_payload_len = xmit_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9921) 		/* word4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9922) 		wqe->xmit_els_rsp.word4 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9923) 		/* word5 iocb=rsvd wge=did */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9924) 		bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9925) 			 iocbq->iocb.un.xseq64.xmit_els_remoteID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9927) 		if_type = bf_get(lpfc_sli_intf_if_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9928) 					&phba->sli4_hba.sli_intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9929) 		if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9930) 			if (iocbq->vport->fc_flag & FC_PT2PT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9931) 				bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9932) 				bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9933) 					iocbq->vport->fc_myDID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9934) 				if (iocbq->vport->fc_myDID == Fabric_DID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9935) 					bf_set(wqe_els_did,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9936) 						&wqe->xmit_els_rsp.wqe_dest, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9937) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9938) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9939) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9940) 		bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9941) 		       ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9942) 		bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9943) 		bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9944) 		       iocbq->iocb.unsli3.rcvsli3.ox_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9945) 		if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9946) 			bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9947) 			       phba->vpi_ids[iocbq->vport->vpi]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9948) 		bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9949) 		bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9950) 		bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9951) 		bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9952) 		       LPFC_WQE_LENLOC_WORD3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9953) 		bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9954) 		bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9955) 		       phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9956) 		pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9957) 					iocbq->context2)->virt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9958) 		if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9959) 				bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9960) 				bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9961) 					iocbq->vport->fc_myDID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9962) 				bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9963) 				bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9964) 					phba->vpi_ids[phba->pport->vpi]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9965) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9966) 		command_type = OTHER_COMMAND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9967) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9968) 	case CMD_CLOSE_XRI_CN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9969) 	case CMD_ABORT_XRI_CN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9970) 	case CMD_ABORT_XRI_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9971) 		/* words 0-2 memcpy should be 0 rserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9972) 		/* port will send abts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9973) 		abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9974) 		if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9975) 			abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9976) 			fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9977) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9978) 			fip = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9979) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9980) 		if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9981) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9982) 			 * The link is down, or the command was ELS_FIP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9983) 			 * so the fw does not need to send abts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9984) 			 * on the wire.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9985) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9986) 			bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9987) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9988) 			bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9989) 		bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9990) 		/* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9991) 		wqe->abort_cmd.rsrvd5 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9992) 		bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9993) 			((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9994) 		abort_tag = iocbq->iocb.un.acxri.abortIoTag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9995) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9996) 		 * The abort handler will send us CMD_ABORT_XRI_CN or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9997) 		 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9998) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9999) 		bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10000) 		bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10001) 		bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10002) 		       LPFC_WQE_LENLOC_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10003) 		cmnd = CMD_ABORT_XRI_CX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10004) 		command_type = OTHER_COMMAND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10005) 		xritag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10006) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10007) 	case CMD_XMIT_BLS_RSP64_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10008) 		ndlp = (struct lpfc_nodelist *)iocbq->context1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10009) 		/* As BLS ABTS RSP WQE is very different from other WQEs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10010) 		 * we re-construct this WQE here based on information in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10011) 		 * iocbq from scratch.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10012) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10013) 		memset(wqe, 0, sizeof(*wqe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10014) 		/* OX_ID is invariable to who sent ABTS to CT exchange */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10015) 		bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10016) 		       bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10017) 		if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10018) 		    LPFC_ABTS_UNSOL_INT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10019) 			/* ABTS sent by initiator to CT exchange, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10020) 			 * RX_ID field will be filled with the newly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10021) 			 * allocated responder XRI.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10022) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10023) 			bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10024) 			       iocbq->sli4_xritag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10025) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10026) 			/* ABTS sent by responder to CT exchange, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10027) 			 * RX_ID field will be filled with the responder
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10028) 			 * RX_ID from ABTS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10029) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10030) 			bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10031) 			       bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10032) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10033) 		bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10034) 		bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10035) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10036) 		/* Use CT=VPI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10037) 		bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10038) 			ndlp->nlp_DID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10039) 		bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10040) 			iocbq->iocb.ulpContext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10041) 		bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10042) 		bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10043) 			phba->vpi_ids[phba->pport->vpi]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10044) 		bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10045) 		bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10046) 		       LPFC_WQE_LENLOC_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10047) 		/* Overwrite the pre-set comnd type with OTHER_COMMAND */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10048) 		command_type = OTHER_COMMAND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10049) 		if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10050) 			bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10051) 			       bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10052) 			bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10053) 			       bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10054) 			bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10055) 			       bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10056) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10058) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10059) 	case CMD_SEND_FRAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10060) 		bf_set(wqe_cmnd, &wqe->generic.wqe_com, CMD_SEND_FRAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10061) 		bf_set(wqe_sof, &wqe->generic.wqe_com, 0x2E); /* SOF byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10062) 		bf_set(wqe_eof, &wqe->generic.wqe_com, 0x41); /* EOF byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10063) 		bf_set(wqe_lenloc, &wqe->generic.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10064) 		bf_set(wqe_xbl, &wqe->generic.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10065) 		bf_set(wqe_dbde, &wqe->generic.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10066) 		bf_set(wqe_xc, &wqe->generic.wqe_com, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10067) 		bf_set(wqe_cmd_type, &wqe->generic.wqe_com, 0xA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10068) 		bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10069) 		bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10070) 		bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10071) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10072) 	case CMD_XRI_ABORTED_CX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10073) 	case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10074) 	case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10075) 	case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10076) 	case CMD_FCP_TRSP64_CX: /* Target mode rcv */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10077) 	case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10078) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10079) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10080) 				"2014 Invalid command 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10081) 				iocbq->iocb.ulpCommand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10082) 		return IOCB_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10083) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10084) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10086) 	if (iocbq->iocb_flag & LPFC_IO_DIF_PASS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10087) 		bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10088) 	else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10089) 		bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10090) 	else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10091) 		bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10092) 	iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10093) 			      LPFC_IO_DIF_INSERT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10094) 	bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10095) 	bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10096) 	wqe->generic.wqe_com.abort_tag = abort_tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10097) 	bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10098) 	bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10099) 	bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10100) 	bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10101) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10104) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10105)  * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10106)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10107)  * @ring_number: SLI ring number to issue iocb on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10108)  * @piocb: Pointer to command iocb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10109)  * @flag: Flag indicating if this command can be put into txq.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10110)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10111)  * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10112)  * an iocb command to an HBA with SLI-4 interface spec.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10113)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10114)  * This function is called with ringlock held. The function will return success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10115)  * after it successfully submit the iocb to firmware or after adding to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10116)  * txq.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10117)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10118) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10119) __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10120) 			 struct lpfc_iocbq *piocb, uint32_t flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10122) 	struct lpfc_sglq *sglq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10123) 	union lpfc_wqe128 wqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10124) 	struct lpfc_queue *wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10125) 	struct lpfc_sli_ring *pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10127) 	/* Get the WQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10128) 	if ((piocb->iocb_flag & LPFC_IO_FCP) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10129) 	    (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10130) 		wq = phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10131) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10132) 		wq = phba->sli4_hba.els_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10133) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10135) 	/* Get corresponding ring */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10136) 	pring = wq->pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10138) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10139) 	 * The WQE can be either 64 or 128 bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10140) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10142) 	lockdep_assert_held(&pring->ring_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10144) 	if (piocb->sli4_xritag == NO_XRI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10145) 		if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10146) 		    piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10147) 			sglq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10148) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10149) 			if (!list_empty(&pring->txq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10150) 				if (!(flag & SLI_IOCB_RET_IOCB)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10151) 					__lpfc_sli_ringtx_put(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10152) 						pring, piocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10153) 					return IOCB_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10154) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10155) 					return IOCB_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10156) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10157) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10158) 				sglq = __lpfc_sli_get_els_sglq(phba, piocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10159) 				if (!sglq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10160) 					if (!(flag & SLI_IOCB_RET_IOCB)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10161) 						__lpfc_sli_ringtx_put(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10162) 								pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10163) 								piocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10164) 						return IOCB_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10165) 					} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10166) 						return IOCB_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10167) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10168) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10169) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10170) 	} else if (piocb->iocb_flag &  LPFC_IO_FCP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10171) 		/* These IO's already have an XRI and a mapped sgl. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10172) 		sglq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10173) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10174) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10175) 		 * This is a continuation of a commandi,(CX) so this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10176) 		 * sglq is on the active list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10177) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10178) 		sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10179) 		if (!sglq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10180) 			return IOCB_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10181) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10183) 	if (sglq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10184) 		piocb->sli4_lxritag = sglq->sli4_lxritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10185) 		piocb->sli4_xritag = sglq->sli4_xritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10186) 		if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10187) 			return IOCB_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10188) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10190) 	if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10191) 		return IOCB_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10193) 	if (lpfc_sli4_wq_put(wq, &wqe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10194) 		return IOCB_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10195) 	lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10197) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10200) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10201)  * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10202)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10203)  * This routine wraps the actual lockless version for issusing IOCB function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10204)  * pointer from the lpfc_hba struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10205)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10206)  * Return codes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10207)  * IOCB_ERROR - Error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10208)  * IOCB_SUCCESS - Success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10209)  * IOCB_BUSY - Busy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10210)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10211) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10212) __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10213) 		struct lpfc_iocbq *piocb, uint32_t flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10215) 	return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10218) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10219)  * lpfc_sli_api_table_setup - Set up sli api function jump table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10220)  * @phba: The hba struct for which this call is being executed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10221)  * @dev_grp: The HBA PCI-Device group number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10222)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10223)  * This routine sets up the SLI interface API function jump table in @phba
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10224)  * struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10225)  * Returns: 0 - success, -ENODEV - failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10226)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10227) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10228) lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10231) 	switch (dev_grp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10232) 	case LPFC_PCI_DEV_LP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10233) 		phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10234) 		phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10235) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10236) 	case LPFC_PCI_DEV_OC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10237) 		phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10238) 		phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10239) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10240) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10241) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10242) 				"1419 Invalid HBA PCI-device group: 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10243) 				dev_grp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10244) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10245) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10246) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10247) 	phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10248) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10251) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10252)  * lpfc_sli4_calc_ring - Calculates which ring to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10253)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10254)  * @piocb: Pointer to command iocb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10255)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10256)  * For SLI4 only, FCP IO can deferred to one fo many WQs, based on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10257)  * hba_wqidx, thus we need to calculate the corresponding ring.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10258)  * Since ABORTS must go on the same WQ of the command they are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10259)  * aborting, we use command's hba_wqidx.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10260)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10261) struct lpfc_sli_ring *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10262) lpfc_sli4_calc_ring(struct lpfc_hba *phba, struct lpfc_iocbq *piocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10264) 	struct lpfc_io_buf *lpfc_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10266) 	if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10267) 		if (unlikely(!phba->sli4_hba.hdwq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10268) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10269) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10270) 		 * for abort iocb hba_wqidx should already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10271) 		 * be setup based on what work queue we used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10272) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10273) 		if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10274) 			lpfc_cmd = (struct lpfc_io_buf *)piocb->context1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10275) 			piocb->hba_wqidx = lpfc_cmd->hdwq_no;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10276) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10277) 		return phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq->pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10278) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10279) 		if (unlikely(!phba->sli4_hba.els_wq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10280) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10281) 		piocb->hba_wqidx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10282) 		return phba->sli4_hba.els_wq->pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10283) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10286) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10287)  * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10288)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10289)  * @ring_number: Ring number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10290)  * @piocb: Pointer to command iocb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10291)  * @flag: Flag indicating if this command can be put into txq.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10292)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10293)  * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10294)  * function. This function gets the hbalock and calls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10295)  * __lpfc_sli_issue_iocb function and will return the error returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10296)  * by __lpfc_sli_issue_iocb function. This wrapper is used by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10297)  * functions which do not hold hbalock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10298)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10299) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10300) lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10301) 		    struct lpfc_iocbq *piocb, uint32_t flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10303) 	struct lpfc_sli_ring *pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10304) 	struct lpfc_queue *eq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10305) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10306) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10308) 	if (phba->sli_rev == LPFC_SLI_REV4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10309) 		eq = phba->sli4_hba.hdwq[piocb->hba_wqidx].hba_eq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10311) 		pring = lpfc_sli4_calc_ring(phba, piocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10312) 		if (unlikely(pring == NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10313) 			return IOCB_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10315) 		spin_lock_irqsave(&pring->ring_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10316) 		rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10317) 		spin_unlock_irqrestore(&pring->ring_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10319) 		lpfc_sli4_poll_eq(eq, LPFC_POLL_FASTPATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10320) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10321) 		/* For now, SLI2/3 will still use hbalock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10322) 		spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10323) 		rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10324) 		spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10325) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10326) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10329) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10330)  * lpfc_extra_ring_setup - Extra ring setup function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10331)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10332)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10333)  * This function is called while driver attaches with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10334)  * HBA to setup the extra ring. The extra ring is used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10335)  * only when driver needs to support target mode functionality
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10336)  * or IP over FC functionalities.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10337)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10338)  * This function is called with no lock held. SLI3 only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10339)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10340) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10341) lpfc_extra_ring_setup( struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10343) 	struct lpfc_sli *psli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10344) 	struct lpfc_sli_ring *pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10346) 	psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10348) 	/* Adjust cmd/rsp ring iocb entries more evenly */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10350) 	/* Take some away from the FCP ring */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10351) 	pring = &psli->sli3_ring[LPFC_FCP_RING];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10352) 	pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10353) 	pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10354) 	pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10355) 	pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10357) 	/* and give them to the extra ring */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10358) 	pring = &psli->sli3_ring[LPFC_EXTRA_RING];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10360) 	pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10361) 	pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10362) 	pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10363) 	pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10365) 	/* Setup default profile for this ring */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10366) 	pring->iotag_max = 4096;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10367) 	pring->num_mask = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10368) 	pring->prt[0].profile = 0;      /* Mask 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10369) 	pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10370) 	pring->prt[0].type = phba->cfg_multi_ring_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10371) 	pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10372) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10375) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10376) lpfc_sli_post_recovery_event(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10377) 			     struct lpfc_nodelist *ndlp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10379) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10380) 	struct lpfc_work_evt  *evtp = &ndlp->recovery_evt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10382) 	spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10383) 	if (!list_empty(&evtp->evt_listp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10384) 		spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10385) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10386) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10388) 	/* Incrementing the reference count until the queued work is done. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10389) 	evtp->evt_arg1  = lpfc_nlp_get(ndlp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10390) 	if (!evtp->evt_arg1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10391) 		spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10392) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10393) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10394) 	evtp->evt = LPFC_EVT_RECOVER_PORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10395) 	list_add_tail(&evtp->evt_listp, &phba->work_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10396) 	spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10398) 	lpfc_worker_wake_up(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10401) /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10402)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10403)  * @iocbq: Pointer to iocb object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10404)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10405)  * The async_event handler calls this routine when it receives
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10406)  * an ASYNC_STATUS_CN event from the port.  The port generates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10407)  * this event when an Abort Sequence request to an rport fails
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10408)  * twice in succession.  The abort could be originated by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10409)  * driver or by the port.  The ABTS could have been for an ELS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10410)  * or FCP IO.  The port only generates this event when an ABTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10411)  * fails to complete after one retry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10412)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10413) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10414) lpfc_sli_abts_err_handler(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10415) 			  struct lpfc_iocbq *iocbq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10416) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10417) 	struct lpfc_nodelist *ndlp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10418) 	uint16_t rpi = 0, vpi = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10419) 	struct lpfc_vport *vport = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10421) 	/* The rpi in the ulpContext is vport-sensitive. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10422) 	vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10423) 	rpi = iocbq->iocb.ulpContext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10425) 	lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10426) 			"3092 Port generated ABTS async event "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10427) 			"on vpi %d rpi %d status 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10428) 			vpi, rpi, iocbq->iocb.ulpStatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10430) 	vport = lpfc_find_vport_by_vpid(phba, vpi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10431) 	if (!vport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10432) 		goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10433) 	ndlp = lpfc_findnode_rpi(vport, rpi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10434) 	if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10435) 		goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10437) 	if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10438) 		lpfc_sli_abts_recover_port(vport, ndlp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10439) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10441)  err_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10442) 	lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10443) 			"3095 Event Context not found, no "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10444) 			"action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10445) 			iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10446) 			vpi, rpi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10449) /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10450)  * @phba: pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10451)  * @ndlp: nodelist pointer for the impacted rport.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10452)  * @axri: pointer to the wcqe containing the failed exchange.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10453)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10454)  * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10455)  * port.  The port generates this event when an abort exchange request to an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10456)  * rport fails twice in succession with no reply.  The abort could be originated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10457)  * by the driver or by the port.  The ABTS could have been for an ELS or FCP IO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10458)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10459) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10460) lpfc_sli4_abts_err_handler(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10461) 			   struct lpfc_nodelist *ndlp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10462) 			   struct sli4_wcqe_xri_aborted *axri)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10463) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10464) 	uint32_t ext_status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10466) 	if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10467) 		lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10468) 				"3115 Node Context not found, driver "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10469) 				"ignoring abts err event\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10470) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10471) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10473) 	lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10474) 			"3116 Port generated FCP XRI ABORT event on "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10475) 			"vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10476) 			ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10477) 			bf_get(lpfc_wcqe_xa_xri, axri),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10478) 			bf_get(lpfc_wcqe_xa_status, axri),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10479) 			axri->parameter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10481) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10482) 	 * Catch the ABTS protocol failure case.  Older OCe FW releases returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10483) 	 * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10484) 	 * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10485) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10486) 	ext_status = axri->parameter & IOERR_PARAM_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10487) 	if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10488) 	    ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10489) 		lpfc_sli_post_recovery_event(phba, ndlp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10492) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10493)  * lpfc_sli_async_event_handler - ASYNC iocb handler function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10494)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10495)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10496)  * @iocbq: Pointer to iocb object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10497)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10498)  * This function is called by the slow ring event handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10499)  * function when there is an ASYNC event iocb in the ring.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10500)  * This function is called with no lock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10501)  * Currently this function handles only temperature related
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10502)  * ASYNC events. The function decodes the temperature sensor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10503)  * event message and posts events for the management applications.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10504)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10505) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10506) lpfc_sli_async_event_handler(struct lpfc_hba * phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10507) 	struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10508) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10509) 	IOCB_t *icmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10510) 	uint16_t evt_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10511) 	struct temp_event temp_event_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10512) 	struct Scsi_Host *shost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10513) 	uint32_t *iocb_w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10515) 	icmd = &iocbq->iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10516) 	evt_code = icmd->un.asyncstat.evt_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10518) 	switch (evt_code) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10519) 	case ASYNC_TEMP_WARN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10520) 	case ASYNC_TEMP_SAFE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10521) 		temp_event_data.data = (uint32_t) icmd->ulpContext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10522) 		temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10523) 		if (evt_code == ASYNC_TEMP_WARN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10524) 			temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10525) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10526) 				"0347 Adapter is very hot, please take "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10527) 				"corrective action. temperature : %d Celsius\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10528) 				(uint32_t) icmd->ulpContext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10529) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10530) 			temp_event_data.event_code = LPFC_NORMAL_TEMP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10531) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10532) 				"0340 Adapter temperature is OK now. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10533) 				"temperature : %d Celsius\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10534) 				(uint32_t) icmd->ulpContext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10535) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10537) 		/* Send temperature change event to applications */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10538) 		shost = lpfc_shost_from_vport(phba->pport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10539) 		fc_host_post_vendor_event(shost, fc_get_event_number(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10540) 			sizeof(temp_event_data), (char *) &temp_event_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10541) 			LPFC_NL_VENDOR_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10542) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10543) 	case ASYNC_STATUS_CN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10544) 		lpfc_sli_abts_err_handler(phba, iocbq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10545) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10546) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10547) 		iocb_w = (uint32_t *) icmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10548) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10549) 			"0346 Ring %d handler: unexpected ASYNC_STATUS"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10550) 			" evt_code 0x%x\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10551) 			"W0  0x%08x W1  0x%08x W2  0x%08x W3  0x%08x\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10552) 			"W4  0x%08x W5  0x%08x W6  0x%08x W7  0x%08x\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10553) 			"W8  0x%08x W9  0x%08x W10 0x%08x W11 0x%08x\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10554) 			"W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10555) 			pring->ringno, icmd->un.asyncstat.evt_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10556) 			iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10557) 			iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10558) 			iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10559) 			iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10561) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10562) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10566) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10567)  * lpfc_sli4_setup - SLI ring setup function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10568)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10569)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10570)  * lpfc_sli_setup sets up rings of the SLI interface with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10571)  * number of iocbs per ring and iotags. This function is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10572)  * called while driver attach to the HBA and before the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10573)  * interrupts are enabled. So there is no need for locking.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10574)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10575)  * This function always returns 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10576)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10577) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10578) lpfc_sli4_setup(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10579) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10580) 	struct lpfc_sli_ring *pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10582) 	pring = phba->sli4_hba.els_wq->pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10583) 	pring->num_mask = LPFC_MAX_RING_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10584) 	pring->prt[0].profile = 0;	/* Mask 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10585) 	pring->prt[0].rctl = FC_RCTL_ELS_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10586) 	pring->prt[0].type = FC_TYPE_ELS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10587) 	pring->prt[0].lpfc_sli_rcv_unsol_event =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10588) 	    lpfc_els_unsol_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10589) 	pring->prt[1].profile = 0;	/* Mask 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10590) 	pring->prt[1].rctl = FC_RCTL_ELS_REP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10591) 	pring->prt[1].type = FC_TYPE_ELS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10592) 	pring->prt[1].lpfc_sli_rcv_unsol_event =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10593) 	    lpfc_els_unsol_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10594) 	pring->prt[2].profile = 0;	/* Mask 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10595) 	/* NameServer Inquiry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10596) 	pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10597) 	/* NameServer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10598) 	pring->prt[2].type = FC_TYPE_CT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10599) 	pring->prt[2].lpfc_sli_rcv_unsol_event =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10600) 	    lpfc_ct_unsol_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10601) 	pring->prt[3].profile = 0;	/* Mask 3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10602) 	/* NameServer response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10603) 	pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10604) 	/* NameServer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10605) 	pring->prt[3].type = FC_TYPE_CT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10606) 	pring->prt[3].lpfc_sli_rcv_unsol_event =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10607) 	    lpfc_ct_unsol_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10608) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10611) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10612)  * lpfc_sli_setup - SLI ring setup function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10613)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10614)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10615)  * lpfc_sli_setup sets up rings of the SLI interface with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10616)  * number of iocbs per ring and iotags. This function is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10617)  * called while driver attach to the HBA and before the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10618)  * interrupts are enabled. So there is no need for locking.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10619)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10620)  * This function always returns 0. SLI3 only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10621)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10622) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10623) lpfc_sli_setup(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10624) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10625) 	int i, totiocbsize = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10626) 	struct lpfc_sli *psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10627) 	struct lpfc_sli_ring *pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10629) 	psli->num_rings = MAX_SLI3_CONFIGURED_RINGS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10630) 	psli->sli_flag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10632) 	psli->iocbq_lookup = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10633) 	psli->iocbq_lookup_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10634) 	psli->last_iotag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10636) 	for (i = 0; i < psli->num_rings; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10637) 		pring = &psli->sli3_ring[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10638) 		switch (i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10639) 		case LPFC_FCP_RING:	/* ring 0 - FCP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10640) 			/* numCiocb and numRiocb are used in config_port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10641) 			pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10642) 			pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10643) 			pring->sli.sli3.numCiocb +=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10644) 				SLI2_IOCB_CMD_R1XTRA_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10645) 			pring->sli.sli3.numRiocb +=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10646) 				SLI2_IOCB_RSP_R1XTRA_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10647) 			pring->sli.sli3.numCiocb +=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10648) 				SLI2_IOCB_CMD_R3XTRA_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10649) 			pring->sli.sli3.numRiocb +=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10650) 				SLI2_IOCB_RSP_R3XTRA_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10651) 			pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10652) 							SLI3_IOCB_CMD_SIZE :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10653) 							SLI2_IOCB_CMD_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10654) 			pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10655) 							SLI3_IOCB_RSP_SIZE :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10656) 							SLI2_IOCB_RSP_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10657) 			pring->iotag_ctr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10658) 			pring->iotag_max =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10659) 			    (phba->cfg_hba_queue_depth * 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10660) 			pring->fast_iotag = pring->iotag_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10661) 			pring->num_mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10662) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10663) 		case LPFC_EXTRA_RING:	/* ring 1 - EXTRA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10664) 			/* numCiocb and numRiocb are used in config_port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10665) 			pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10666) 			pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10667) 			pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10668) 							SLI3_IOCB_CMD_SIZE :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10669) 							SLI2_IOCB_CMD_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10670) 			pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10671) 							SLI3_IOCB_RSP_SIZE :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10672) 							SLI2_IOCB_RSP_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10673) 			pring->iotag_max = phba->cfg_hba_queue_depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10674) 			pring->num_mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10675) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10676) 		case LPFC_ELS_RING:	/* ring 2 - ELS / CT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10677) 			/* numCiocb and numRiocb are used in config_port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10678) 			pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10679) 			pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10680) 			pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10681) 							SLI3_IOCB_CMD_SIZE :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10682) 							SLI2_IOCB_CMD_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10683) 			pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10684) 							SLI3_IOCB_RSP_SIZE :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10685) 							SLI2_IOCB_RSP_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10686) 			pring->fast_iotag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10687) 			pring->iotag_ctr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10688) 			pring->iotag_max = 4096;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10689) 			pring->lpfc_sli_rcv_async_status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10690) 				lpfc_sli_async_event_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10691) 			pring->num_mask = LPFC_MAX_RING_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10692) 			pring->prt[0].profile = 0;	/* Mask 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10693) 			pring->prt[0].rctl = FC_RCTL_ELS_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10694) 			pring->prt[0].type = FC_TYPE_ELS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10695) 			pring->prt[0].lpfc_sli_rcv_unsol_event =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10696) 			    lpfc_els_unsol_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10697) 			pring->prt[1].profile = 0;	/* Mask 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10698) 			pring->prt[1].rctl = FC_RCTL_ELS_REP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10699) 			pring->prt[1].type = FC_TYPE_ELS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10700) 			pring->prt[1].lpfc_sli_rcv_unsol_event =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10701) 			    lpfc_els_unsol_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10702) 			pring->prt[2].profile = 0;	/* Mask 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10703) 			/* NameServer Inquiry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10704) 			pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10705) 			/* NameServer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10706) 			pring->prt[2].type = FC_TYPE_CT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10707) 			pring->prt[2].lpfc_sli_rcv_unsol_event =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10708) 			    lpfc_ct_unsol_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10709) 			pring->prt[3].profile = 0;	/* Mask 3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10710) 			/* NameServer response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10711) 			pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10712) 			/* NameServer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10713) 			pring->prt[3].type = FC_TYPE_CT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10714) 			pring->prt[3].lpfc_sli_rcv_unsol_event =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10715) 			    lpfc_ct_unsol_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10716) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10717) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10718) 		totiocbsize += (pring->sli.sli3.numCiocb *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10719) 			pring->sli.sli3.sizeCiocb) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10720) 			(pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10721) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10722) 	if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10723) 		/* Too many cmd / rsp ring entries in SLI2 SLIM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10724) 		printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10725) 		       "SLI2 SLIM Data: x%x x%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10726) 		       phba->brd_no, totiocbsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10727) 		       (unsigned long) MAX_SLIM_IOCB_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10728) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10729) 	if (phba->cfg_multi_ring_support == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10730) 		lpfc_extra_ring_setup(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10732) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10735) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10736)  * lpfc_sli4_queue_init - Queue initialization function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10737)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10738)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10739)  * lpfc_sli4_queue_init sets up mailbox queues and iocb queues for each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10740)  * ring. This function also initializes ring indices of each ring.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10741)  * This function is called during the initialization of the SLI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10742)  * interface of an HBA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10743)  * This function is called with no lock held and always returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10744)  * 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10745)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10746) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10747) lpfc_sli4_queue_init(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10748) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10749) 	struct lpfc_sli *psli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10750) 	struct lpfc_sli_ring *pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10751) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10753) 	psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10754) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10755) 	INIT_LIST_HEAD(&psli->mboxq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10756) 	INIT_LIST_HEAD(&psli->mboxq_cmpl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10757) 	/* Initialize list headers for txq and txcmplq as double linked lists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10758) 	for (i = 0; i < phba->cfg_hdw_queue; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10759) 		pring = phba->sli4_hba.hdwq[i].io_wq->pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10760) 		pring->flag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10761) 		pring->ringno = LPFC_FCP_RING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10762) 		pring->txcmplq_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10763) 		INIT_LIST_HEAD(&pring->txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10764) 		INIT_LIST_HEAD(&pring->txcmplq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10765) 		INIT_LIST_HEAD(&pring->iocb_continueq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10766) 		spin_lock_init(&pring->ring_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10767) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10768) 	pring = phba->sli4_hba.els_wq->pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10769) 	pring->flag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10770) 	pring->ringno = LPFC_ELS_RING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10771) 	pring->txcmplq_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10772) 	INIT_LIST_HEAD(&pring->txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10773) 	INIT_LIST_HEAD(&pring->txcmplq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10774) 	INIT_LIST_HEAD(&pring->iocb_continueq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10775) 	spin_lock_init(&pring->ring_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10777) 	if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10778) 		pring = phba->sli4_hba.nvmels_wq->pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10779) 		pring->flag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10780) 		pring->ringno = LPFC_ELS_RING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10781) 		pring->txcmplq_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10782) 		INIT_LIST_HEAD(&pring->txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10783) 		INIT_LIST_HEAD(&pring->txcmplq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10784) 		INIT_LIST_HEAD(&pring->iocb_continueq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10785) 		spin_lock_init(&pring->ring_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10786) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10788) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10789) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10791) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10792)  * lpfc_sli_queue_init - Queue initialization function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10793)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10794)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10795)  * lpfc_sli_queue_init sets up mailbox queues and iocb queues for each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10796)  * ring. This function also initializes ring indices of each ring.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10797)  * This function is called during the initialization of the SLI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10798)  * interface of an HBA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10799)  * This function is called with no lock held and always returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10800)  * 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10801)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10802) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10803) lpfc_sli_queue_init(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10804) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10805) 	struct lpfc_sli *psli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10806) 	struct lpfc_sli_ring *pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10807) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10809) 	psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10810) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10811) 	INIT_LIST_HEAD(&psli->mboxq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10812) 	INIT_LIST_HEAD(&psli->mboxq_cmpl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10813) 	/* Initialize list headers for txq and txcmplq as double linked lists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10814) 	for (i = 0; i < psli->num_rings; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10815) 		pring = &psli->sli3_ring[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10816) 		pring->ringno = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10817) 		pring->sli.sli3.next_cmdidx  = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10818) 		pring->sli.sli3.local_getidx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10819) 		pring->sli.sli3.cmdidx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10820) 		INIT_LIST_HEAD(&pring->iocb_continueq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10821) 		INIT_LIST_HEAD(&pring->iocb_continue_saveq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10822) 		INIT_LIST_HEAD(&pring->postbufq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10823) 		pring->flag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10824) 		INIT_LIST_HEAD(&pring->txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10825) 		INIT_LIST_HEAD(&pring->txcmplq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10826) 		spin_lock_init(&pring->ring_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10827) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10828) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10829) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10831) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10832)  * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10833)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10834)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10835)  * This routine flushes the mailbox command subsystem. It will unconditionally
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10836)  * flush all the mailbox commands in the three possible stages in the mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10837)  * command sub-system: pending mailbox command queue; the outstanding mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10838)  * command; and completed mailbox command queue. It is caller's responsibility
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10839)  * to make sure that the driver is in the proper state to flush the mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10840)  * command sub-system. Namely, the posting of mailbox commands into the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10841)  * pending mailbox command queue from the various clients must be stopped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10842)  * either the HBA is in a state that it will never works on the outstanding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10843)  * mailbox command (such as in EEH or ERATT conditions) or the outstanding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10844)  * mailbox command has been completed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10845)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10846) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10847) lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10848) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10849) 	LIST_HEAD(completions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10850) 	struct lpfc_sli *psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10851) 	LPFC_MBOXQ_t *pmb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10852) 	unsigned long iflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10854) 	/* Disable softirqs, including timers from obtaining phba->hbalock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10855) 	local_bh_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10857) 	/* Flush all the mailbox commands in the mbox system */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10858) 	spin_lock_irqsave(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10860) 	/* The pending mailbox command queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10861) 	list_splice_init(&phba->sli.mboxq, &completions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10862) 	/* The outstanding active mailbox command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10863) 	if (psli->mbox_active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10864) 		list_add_tail(&psli->mbox_active->list, &completions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10865) 		psli->mbox_active = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10866) 		psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10867) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10868) 	/* The completed mailbox command queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10869) 	list_splice_init(&phba->sli.mboxq_cmpl, &completions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10870) 	spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10872) 	/* Enable softirqs again, done with phba->hbalock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10873) 	local_bh_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10875) 	/* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10876) 	while (!list_empty(&completions)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10877) 		list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10878) 		pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10879) 		if (pmb->mbox_cmpl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10880) 			pmb->mbox_cmpl(phba, pmb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10881) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10882) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10883) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10884) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10885)  * lpfc_sli_host_down - Vport cleanup function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10886)  * @vport: Pointer to virtual port object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10887)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10888)  * lpfc_sli_host_down is called to clean up the resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10889)  * associated with a vport before destroying virtual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10890)  * port data structures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10891)  * This function does following operations:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10892)  * - Free discovery resources associated with this virtual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10893)  *   port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10894)  * - Free iocbs associated with this virtual port in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10895)  *   the txq.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10896)  * - Send abort for all iocb commands associated with this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10897)  *   vport in txcmplq.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10898)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10899)  * This function is called with no lock held and always returns 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10900)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10901) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10902) lpfc_sli_host_down(struct lpfc_vport *vport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10903) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10904) 	LIST_HEAD(completions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10905) 	struct lpfc_hba *phba = vport->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10906) 	struct lpfc_sli *psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10907) 	struct lpfc_queue *qp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10908) 	struct lpfc_sli_ring *pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10909) 	struct lpfc_iocbq *iocb, *next_iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10910) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10911) 	unsigned long flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10912) 	uint16_t prev_pring_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10914) 	lpfc_cleanup_discovery_resources(vport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10916) 	spin_lock_irqsave(&phba->hbalock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10918) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10919) 	 * Error everything on the txq since these iocbs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10920) 	 * have not been given to the FW yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10921) 	 * Also issue ABTS for everything on the txcmplq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10922) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10923) 	if (phba->sli_rev != LPFC_SLI_REV4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10924) 		for (i = 0; i < psli->num_rings; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10925) 			pring = &psli->sli3_ring[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10926) 			prev_pring_flag = pring->flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10927) 			/* Only slow rings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10928) 			if (pring->ringno == LPFC_ELS_RING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10929) 				pring->flag |= LPFC_DEFERRED_RING_EVENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10930) 				/* Set the lpfc data pending flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10931) 				set_bit(LPFC_DATA_READY, &phba->data_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10932) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10933) 			list_for_each_entry_safe(iocb, next_iocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10934) 						 &pring->txq, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10935) 				if (iocb->vport != vport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10936) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10937) 				list_move_tail(&iocb->list, &completions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10938) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10939) 			list_for_each_entry_safe(iocb, next_iocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10940) 						 &pring->txcmplq, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10941) 				if (iocb->vport != vport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10942) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10943) 				lpfc_sli_issue_abort_iotag(phba, pring, iocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10944) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10945) 			pring->flag = prev_pring_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10946) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10947) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10948) 		list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10949) 			pring = qp->pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10950) 			if (!pring)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10951) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10952) 			if (pring == phba->sli4_hba.els_wq->pring) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10953) 				pring->flag |= LPFC_DEFERRED_RING_EVENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10954) 				/* Set the lpfc data pending flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10955) 				set_bit(LPFC_DATA_READY, &phba->data_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10956) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10957) 			prev_pring_flag = pring->flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10958) 			spin_lock(&pring->ring_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10959) 			list_for_each_entry_safe(iocb, next_iocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10960) 						 &pring->txq, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10961) 				if (iocb->vport != vport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10962) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10963) 				list_move_tail(&iocb->list, &completions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10964) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10965) 			spin_unlock(&pring->ring_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10966) 			list_for_each_entry_safe(iocb, next_iocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10967) 						 &pring->txcmplq, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10968) 				if (iocb->vport != vport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10969) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10970) 				lpfc_sli_issue_abort_iotag(phba, pring, iocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10971) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10972) 			pring->flag = prev_pring_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10973) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10974) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10975) 	spin_unlock_irqrestore(&phba->hbalock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10977) 	/* Cancel all the IOCBs from the completions list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10978) 	lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10979) 			      IOERR_SLI_DOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10980) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10981) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10982) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10983) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10984)  * lpfc_sli_hba_down - Resource cleanup function for the HBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10985)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10986)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10987)  * This function cleans up all iocb, buffers, mailbox commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10988)  * while shutting down the HBA. This function is called with no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10989)  * lock held and always returns 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10990)  * This function does the following to cleanup driver resources:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10991)  * - Free discovery resources for each virtual port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10992)  * - Cleanup any pending fabric iocbs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10993)  * - Iterate through the iocb txq and free each entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10994)  *   in the list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10995)  * - Free up any buffer posted to the HBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10996)  * - Free mailbox commands in the mailbox queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10997)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10998) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10999) lpfc_sli_hba_down(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11001) 	LIST_HEAD(completions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11002) 	struct lpfc_sli *psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11003) 	struct lpfc_queue *qp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11004) 	struct lpfc_sli_ring *pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11005) 	struct lpfc_dmabuf *buf_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11006) 	unsigned long flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11007) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11008) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11009) 	/* Shutdown the mailbox command sub-system */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11010) 	lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11011) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11012) 	lpfc_hba_down_prep(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11014) 	/* Disable softirqs, including timers from obtaining phba->hbalock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11015) 	local_bh_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11016) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11017) 	lpfc_fabric_abort_hba(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11018) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11019) 	spin_lock_irqsave(&phba->hbalock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11021) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11022) 	 * Error everything on the txq since these iocbs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11023) 	 * have not been given to the FW yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11024) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11025) 	if (phba->sli_rev != LPFC_SLI_REV4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11026) 		for (i = 0; i < psli->num_rings; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11027) 			pring = &psli->sli3_ring[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11028) 			/* Only slow rings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11029) 			if (pring->ringno == LPFC_ELS_RING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11030) 				pring->flag |= LPFC_DEFERRED_RING_EVENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11031) 				/* Set the lpfc data pending flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11032) 				set_bit(LPFC_DATA_READY, &phba->data_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11033) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11034) 			list_splice_init(&pring->txq, &completions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11035) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11036) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11037) 		list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11038) 			pring = qp->pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11039) 			if (!pring)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11040) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11041) 			spin_lock(&pring->ring_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11042) 			list_splice_init(&pring->txq, &completions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11043) 			spin_unlock(&pring->ring_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11044) 			if (pring == phba->sli4_hba.els_wq->pring) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11045) 				pring->flag |= LPFC_DEFERRED_RING_EVENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11046) 				/* Set the lpfc data pending flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11047) 				set_bit(LPFC_DATA_READY, &phba->data_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11048) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11049) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11050) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11051) 	spin_unlock_irqrestore(&phba->hbalock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11052) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11053) 	/* Cancel all the IOCBs from the completions list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11054) 	lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11055) 			      IOERR_SLI_DOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11057) 	spin_lock_irqsave(&phba->hbalock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11058) 	list_splice_init(&phba->elsbuf, &completions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11059) 	phba->elsbuf_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11060) 	phba->elsbuf_prev_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11061) 	spin_unlock_irqrestore(&phba->hbalock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11063) 	while (!list_empty(&completions)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11064) 		list_remove_head(&completions, buf_ptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11065) 			struct lpfc_dmabuf, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11066) 		lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11067) 		kfree(buf_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11068) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11070) 	/* Enable softirqs again, done with phba->hbalock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11071) 	local_bh_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11072) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11073) 	/* Return any active mbox cmds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11074) 	del_timer_sync(&psli->mbox_tmo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11075) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11076) 	spin_lock_irqsave(&phba->pport->work_port_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11077) 	phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11078) 	spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11079) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11080) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11081) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11082) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11083) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11084)  * lpfc_sli_pcimem_bcopy - SLI memory copy function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11085)  * @srcp: Source memory pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11086)  * @destp: Destination memory pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11087)  * @cnt: Number of words required to be copied.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11088)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11089)  * This function is used for copying data between driver memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11090)  * and the SLI memory. This function also changes the endianness
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11091)  * of each word if native endianness is different from SLI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11092)  * endianness. This function can be called with or without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11093)  * lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11094)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11095) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11096) lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11097) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11098) 	uint32_t *src = srcp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11099) 	uint32_t *dest = destp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11100) 	uint32_t ldata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11101) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11103) 	for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11104) 		ldata = *src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11105) 		ldata = le32_to_cpu(ldata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11106) 		*dest = ldata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11107) 		src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11108) 		dest++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11109) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11113) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11114)  * lpfc_sli_bemem_bcopy - SLI memory copy function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11115)  * @srcp: Source memory pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11116)  * @destp: Destination memory pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11117)  * @cnt: Number of words required to be copied.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11118)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11119)  * This function is used for copying data between a data structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11120)  * with big endian representation to local endianness.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11121)  * This function can be called with or without lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11122)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11123) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11124) lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11126) 	uint32_t *src = srcp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11127) 	uint32_t *dest = destp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11128) 	uint32_t ldata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11129) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11131) 	for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11132) 		ldata = *src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11133) 		ldata = be32_to_cpu(ldata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11134) 		*dest = ldata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11135) 		src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11136) 		dest++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11137) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11140) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11141)  * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11142)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11143)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11144)  * @mp: Pointer to driver buffer object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11145)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11146)  * This function is called with no lock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11147)  * It always return zero after adding the buffer to the postbufq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11148)  * buffer list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11149)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11150) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11151) lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11152) 			 struct lpfc_dmabuf *mp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11154) 	/* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11155) 	   later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11156) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11157) 	list_add_tail(&mp->list, &pring->postbufq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11158) 	pring->postbufq_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11159) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11160) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11163) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11164)  * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11165)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11166)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11167)  * When HBQ is enabled, buffers are searched based on tags. This function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11168)  * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11169)  * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11170)  * does not conflict with tags of buffer posted for unsolicited events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11171)  * The function returns the allocated tag. The function is called with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11172)  * no locks held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11173)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11174) uint32_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11175) lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11177) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11178) 	phba->buffer_tag_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11179) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11180) 	 * Always set the QUE_BUFTAG_BIT to distiguish between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11181) 	 * a tag assigned by HBQ.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11182) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11183) 	phba->buffer_tag_count |= QUE_BUFTAG_BIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11184) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11185) 	return phba->buffer_tag_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11188) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11189)  * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11190)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11191)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11192)  * @tag: Buffer tag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11193)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11194)  * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11195)  * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11196)  * iocb is posted to the response ring with the tag of the buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11197)  * This function searches the pring->postbufq list using the tag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11198)  * to find buffer associated with CMD_IOCB_RET_XRI64_CX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11199)  * iocb. If the buffer is found then lpfc_dmabuf object of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11200)  * buffer is returned to the caller else NULL is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11201)  * This function is called with no lock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11202)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11203) struct lpfc_dmabuf *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11204) lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11205) 			uint32_t tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11207) 	struct lpfc_dmabuf *mp, *next_mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11208) 	struct list_head *slp = &pring->postbufq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11210) 	/* Search postbufq, from the beginning, looking for a match on tag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11211) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11212) 	list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11213) 		if (mp->buffer_tag == tag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11214) 			list_del_init(&mp->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11215) 			pring->postbufq_cnt--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11216) 			spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11217) 			return mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11218) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11219) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11221) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11222) 	lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11223) 			"0402 Cannot find virtual addr for buffer tag on "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11224) 			"ring %d Data x%lx x%px x%px x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11225) 			pring->ringno, (unsigned long) tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11226) 			slp->next, slp->prev, pring->postbufq_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11228) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11231) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11232)  * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11233)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11234)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11235)  * @phys: DMA address of the buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11236)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11237)  * This function searches the buffer list using the dma_address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11238)  * of unsolicited event to find the driver's lpfc_dmabuf object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11239)  * corresponding to the dma_address. The function returns the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11240)  * lpfc_dmabuf object if a buffer is found else it returns NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11241)  * This function is called by the ct and els unsolicited event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11242)  * handlers to get the buffer associated with the unsolicited
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11243)  * event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11244)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11245)  * This function is called with no lock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11246)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11247) struct lpfc_dmabuf *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11248) lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11249) 			 dma_addr_t phys)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11251) 	struct lpfc_dmabuf *mp, *next_mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11252) 	struct list_head *slp = &pring->postbufq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11254) 	/* Search postbufq, from the beginning, looking for a match on phys */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11255) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11256) 	list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11257) 		if (mp->phys == phys) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11258) 			list_del_init(&mp->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11259) 			pring->postbufq_cnt--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11260) 			spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11261) 			return mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11262) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11263) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11265) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11266) 	lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11267) 			"0410 Cannot find virtual addr for mapped buf on "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11268) 			"ring %d Data x%llx x%px x%px x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11269) 			pring->ringno, (unsigned long long)phys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11270) 			slp->next, slp->prev, pring->postbufq_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11271) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11274) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11275)  * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11276)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11277)  * @cmdiocb: Pointer to driver command iocb object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11278)  * @rspiocb: Pointer to driver response iocb object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11279)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11280)  * This function is the completion handler for the abort iocbs for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11281)  * ELS commands. This function is called from the ELS ring event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11282)  * handler with no lock held. This function frees memory resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11283)  * associated with the abort iocb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11284)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11285) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11286) lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11287) 			struct lpfc_iocbq *rspiocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11289) 	IOCB_t *irsp = &rspiocb->iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11290) 	uint16_t abort_iotag, abort_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11291) 	struct lpfc_iocbq *abort_iocb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11293) 	if (irsp->ulpStatus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11295) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11296) 		 * Assume that the port already completed and returned, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11297) 		 * will return the iocb. Just Log the message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11298) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11299) 		abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11300) 		abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11302) 		spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11303) 		if (phba->sli_rev < LPFC_SLI_REV4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11304) 			if (irsp->ulpCommand == CMD_ABORT_XRI_CX &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11305) 			    irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11306) 			    irsp->un.ulpWord[4] == IOERR_ABORT_REQUESTED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11307) 				spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11308) 				goto release_iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11309) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11310) 			if (abort_iotag != 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11311) 				abort_iotag <= phba->sli.last_iotag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11312) 				abort_iocb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11313) 					phba->sli.iocbq_lookup[abort_iotag];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11314) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11315) 			/* For sli4 the abort_tag is the XRI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11316) 			 * so the abort routine puts the iotag  of the iocb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11317) 			 * being aborted in the context field of the abort
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11318) 			 * IOCB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11319) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11320) 			abort_iocb = phba->sli.iocbq_lookup[abort_context];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11322) 		lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11323) 				"0327 Cannot abort els iocb x%px "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11324) 				"with tag %x context %x, abort status %x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11325) 				"abort code %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11326) 				abort_iocb, abort_iotag, abort_context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11327) 				irsp->ulpStatus, irsp->un.ulpWord[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11329) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11330) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11331) release_iocb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11332) 	lpfc_sli_release_iocbq(phba, cmdiocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11333) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11336) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11337)  * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11338)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11339)  * @cmdiocb: Pointer to driver command iocb object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11340)  * @rspiocb: Pointer to driver response iocb object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11341)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11342)  * The function is called from SLI ring event handler with no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11343)  * lock held. This function is the completion handler for ELS commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11344)  * which are aborted. The function frees memory resources used for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11345)  * the aborted ELS commands.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11346)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11347) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11348) lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11349) 		     struct lpfc_iocbq *rspiocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11351) 	IOCB_t *irsp = &rspiocb->iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11353) 	/* ELS cmd tag <ulpIoTag> completes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11354) 	lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11355) 			"0139 Ignoring ELS cmd tag x%x completion Data: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11356) 			"x%x x%x x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11357) 			irsp->ulpIoTag, irsp->ulpStatus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11358) 			irsp->un.ulpWord[4], irsp->ulpTimeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11359) 	if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11360) 		lpfc_ct_free_iocb(phba, cmdiocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11361) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11362) 		lpfc_els_free_iocb(phba, cmdiocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11363) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11366) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11367)  * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11368)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11369)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11370)  * @cmdiocb: Pointer to driver command iocb object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11371)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11372)  * This function issues an abort iocb for the provided command iocb down to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11373)  * the port. Other than the case the outstanding command iocb is an abort
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11374)  * request, this function issues abort out unconditionally. This function is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11375)  * called with hbalock held. The function returns 0 when it fails due to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11376)  * memory allocation failure or when the command iocb is an abort request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11377)  * The hbalock is asserted held in the code path calling this routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11378)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11379) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11380) lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11381) 			   struct lpfc_iocbq *cmdiocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11382) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11383) 	struct lpfc_vport *vport = cmdiocb->vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11384) 	struct lpfc_iocbq *abtsiocbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11385) 	IOCB_t *icmd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11386) 	IOCB_t *iabt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11387) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11388) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11389) 	struct lpfc_nodelist *ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11391) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11392) 	 * There are certain command types we don't want to abort.  And we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11393) 	 * don't want to abort commands that are already in the process of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11394) 	 * being aborted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11395) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11396) 	icmd = &cmdiocb->iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11397) 	if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11398) 	    icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11399) 	    (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11400) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11402) 	/* issue ABTS for this IOCB based on iotag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11403) 	abtsiocbp = __lpfc_sli_get_iocbq(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11404) 	if (abtsiocbp == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11405) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11407) 	/* This signals the response to set the correct status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11408) 	 * before calling the completion handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11409) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11410) 	cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11412) 	iabt = &abtsiocbp->iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11413) 	iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11414) 	iabt->un.acxri.abortContextTag = icmd->ulpContext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11415) 	if (phba->sli_rev == LPFC_SLI_REV4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11416) 		iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11417) 		iabt->un.acxri.abortContextTag = cmdiocb->iotag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11418) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11419) 		iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11420) 		if (pring->ringno == LPFC_ELS_RING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11421) 			ndlp = (struct lpfc_nodelist *)(cmdiocb->context1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11422) 			iabt->un.acxri.abortContextTag = ndlp->nlp_rpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11423) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11424) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11425) 	iabt->ulpLe = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11426) 	iabt->ulpClass = icmd->ulpClass;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11428) 	/* ABTS WQE must go to the same WQ as the WQE to be aborted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11429) 	abtsiocbp->hba_wqidx = cmdiocb->hba_wqidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11430) 	if (cmdiocb->iocb_flag & LPFC_IO_FCP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11431) 		abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11432) 	if (cmdiocb->iocb_flag & LPFC_IO_FOF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11433) 		abtsiocbp->iocb_flag |= LPFC_IO_FOF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11435) 	if (phba->link_state >= LPFC_LINK_UP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11436) 		iabt->ulpCommand = CMD_ABORT_XRI_CN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11437) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11438) 		iabt->ulpCommand = CMD_CLOSE_XRI_CN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11440) 	abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11441) 	abtsiocbp->vport = vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11443) 	lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11444) 			 "0339 Abort xri x%x, original iotag x%x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11445) 			 "abort cmd iotag x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11446) 			 iabt->un.acxri.abortIoTag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11447) 			 iabt->un.acxri.abortContextTag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11448) 			 abtsiocbp->iotag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11450) 	if (phba->sli_rev == LPFC_SLI_REV4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11451) 		pring = lpfc_sli4_calc_ring(phba, abtsiocbp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11452) 		if (unlikely(pring == NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11453) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11454) 		/* Note: both hbalock and ring_lock need to be set here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11455) 		spin_lock_irqsave(&pring->ring_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11456) 		retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11457) 			abtsiocbp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11458) 		spin_unlock_irqrestore(&pring->ring_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11459) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11460) 		retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11461) 			abtsiocbp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11462) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11464) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11465) 		__lpfc_sli_release_iocbq(phba, abtsiocbp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11467) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11468) 	 * Caller to this routine should check for IOCB_ERROR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11469) 	 * and handle it properly.  This routine no longer removes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11470) 	 * iocb off txcmplq and call compl in case of IOCB_ERROR.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11471) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11472) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11475) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11476)  * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11477)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11478)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11479)  * @cmdiocb: Pointer to driver command iocb object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11480)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11481)  * This function issues an abort iocb for the provided command iocb. In case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11482)  * of unloading, the abort iocb will not be issued to commands on the ELS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11483)  * ring. Instead, the callback function shall be changed to those commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11484)  * so that nothing happens when them finishes. This function is called with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11485)  * hbalock held. The function returns 0 when the command iocb is an abort
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11486)  * request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11487)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11488) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11489) lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11490) 			   struct lpfc_iocbq *cmdiocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11491) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11492) 	struct lpfc_vport *vport = cmdiocb->vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11493) 	int retval = IOCB_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11494) 	IOCB_t *icmd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11496) 	lockdep_assert_held(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11498) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11499) 	 * There are certain command types we don't want to abort.  And we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11500) 	 * don't want to abort commands that are already in the process of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11501) 	 * being aborted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11502) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11503) 	icmd = &cmdiocb->iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11504) 	if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11505) 	    icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11506) 	    (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11507) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11509) 	if (!pring) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11510) 		if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11511) 			cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11512) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11513) 			cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11514) 		goto abort_iotag_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11515) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11517) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11518) 	 * If we're unloading, don't abort iocb on the ELS ring, but change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11519) 	 * the callback so that nothing happens when it finishes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11520) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11521) 	if ((vport->load_flag & FC_UNLOADING) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11522) 	    (pring->ringno == LPFC_ELS_RING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11523) 		if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11524) 			cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11525) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11526) 			cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11527) 		goto abort_iotag_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11528) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11530) 	/* Now, we try to issue the abort to the cmdiocb out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11531) 	retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11533) abort_iotag_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11534) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11535) 	 * Caller to this routine should check for IOCB_ERROR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11536) 	 * and handle it properly.  This routine no longer removes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11537) 	 * iocb off txcmplq and call compl in case of IOCB_ERROR.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11538) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11539) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11542) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11543)  * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11544)  * @phba: pointer to lpfc HBA data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11545)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11546)  * This routine will abort all pending and outstanding iocbs to an HBA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11547)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11548) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11549) lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11550) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11551) 	struct lpfc_sli *psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11552) 	struct lpfc_sli_ring *pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11553) 	struct lpfc_queue *qp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11554) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11556) 	if (phba->sli_rev != LPFC_SLI_REV4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11557) 		for (i = 0; i < psli->num_rings; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11558) 			pring = &psli->sli3_ring[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11559) 			lpfc_sli_abort_iocb_ring(phba, pring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11560) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11561) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11562) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11563) 	list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11564) 		pring = qp->pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11565) 		if (!pring)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11566) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11567) 		lpfc_sli_abort_iocb_ring(phba, pring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11568) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11569) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11571) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11572)  * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11573)  * @iocbq: Pointer to driver iocb object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11574)  * @vport: Pointer to driver virtual port object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11575)  * @tgt_id: SCSI ID of the target.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11576)  * @lun_id: LUN ID of the scsi device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11577)  * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11578)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11579)  * This function acts as an iocb filter for functions which abort or count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11580)  * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11581)  * 0 if the filtering criteria is met for the given iocb and will return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11582)  * 1 if the filtering criteria is not met.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11583)  * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11584)  * given iocb is for the SCSI device specified by vport, tgt_id and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11585)  * lun_id parameter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11586)  * If ctx_cmd == LPFC_CTX_TGT,  the function returns 0 only if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11587)  * given iocb is for the SCSI target specified by vport and tgt_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11588)  * parameters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11589)  * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11590)  * given iocb is for the SCSI host associated with the given vport.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11591)  * This function is called with no locks held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11592)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11593) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11594) lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11595) 			   uint16_t tgt_id, uint64_t lun_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11596) 			   lpfc_ctx_cmd ctx_cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11597) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11598) 	struct lpfc_io_buf *lpfc_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11599) 	IOCB_t *icmd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11600) 	int rc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11602) 	if (iocbq->vport != vport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11603) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11605) 	if (!(iocbq->iocb_flag & LPFC_IO_FCP) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11606) 	    !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11607) 	      iocbq->iocb_flag & LPFC_DRIVER_ABORTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11608) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11610) 	icmd = &iocbq->iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11611) 	if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11612) 	    icmd->ulpCommand == CMD_CLOSE_XRI_CN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11613) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11615) 	lpfc_cmd = container_of(iocbq, struct lpfc_io_buf, cur_iocbq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11617) 	if (lpfc_cmd->pCmd == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11618) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11620) 	switch (ctx_cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11621) 	case LPFC_CTX_LUN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11622) 		if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11623) 		    (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11624) 		    (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11625) 			rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11626) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11627) 	case LPFC_CTX_TGT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11628) 		if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11629) 		    (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11630) 			rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11631) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11632) 	case LPFC_CTX_HOST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11633) 		rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11634) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11635) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11636) 		printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11637) 			__func__, ctx_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11638) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11639) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11641) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11644) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11645)  * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11646)  * @vport: Pointer to virtual port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11647)  * @tgt_id: SCSI ID of the target.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11648)  * @lun_id: LUN ID of the scsi device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11649)  * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11650)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11651)  * This function returns number of FCP commands pending for the vport.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11652)  * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11653)  * commands pending on the vport associated with SCSI device specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11654)  * by tgt_id and lun_id parameters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11655)  * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11656)  * commands pending on the vport associated with SCSI target specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11657)  * by tgt_id parameter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11658)  * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11659)  * commands pending on the vport.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11660)  * This function returns the number of iocbs which satisfy the filter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11661)  * This function is called without any lock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11662)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11663) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11664) lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11665) 		  lpfc_ctx_cmd ctx_cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11666) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11667) 	struct lpfc_hba *phba = vport->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11668) 	struct lpfc_iocbq *iocbq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11669) 	int sum, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11671) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11672) 	for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11673) 		iocbq = phba->sli.iocbq_lookup[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11675) 		if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11676) 						ctx_cmd) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11677) 			sum++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11678) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11679) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11681) 	return sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11682) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11684) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11685)  * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11686)  * @phba: Pointer to HBA context object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11687)  * @cmdiocb: Pointer to command iocb object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11688)  * @rspiocb: Pointer to response iocb object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11689)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11690)  * This function is called when an aborted FCP iocb completes. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11691)  * function is called by the ring event handler with no lock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11692)  * This function frees the iocb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11693)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11694) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11695) lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11696) 			struct lpfc_iocbq *rspiocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11697) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11698) 	lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11699) 			"3096 ABORT_XRI_CN completing on rpi x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11700) 			"original iotag x%x, abort cmd iotag x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11701) 			"status 0x%x, reason 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11702) 			cmdiocb->iocb.un.acxri.abortContextTag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11703) 			cmdiocb->iocb.un.acxri.abortIoTag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11704) 			cmdiocb->iotag, rspiocb->iocb.ulpStatus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11705) 			rspiocb->iocb.un.ulpWord[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11706) 	lpfc_sli_release_iocbq(phba, cmdiocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11707) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11708) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11710) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11711)  * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11712)  * @vport: Pointer to virtual port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11713)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11714)  * @tgt_id: SCSI ID of the target.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11715)  * @lun_id: LUN ID of the scsi device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11716)  * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11717)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11718)  * This function sends an abort command for every SCSI command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11719)  * associated with the given virtual port pending on the ring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11720)  * filtered by lpfc_sli_validate_fcp_iocb function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11721)  * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11722)  * FCP iocbs associated with lun specified by tgt_id and lun_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11723)  * parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11724)  * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11725)  * FCP iocbs associated with SCSI target specified by tgt_id parameter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11726)  * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11727)  * FCP iocbs associated with virtual port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11728)  * This function returns number of iocbs it failed to abort.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11729)  * This function is called with no locks held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11730)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11731) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11732) lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11733) 		    uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11734) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11735) 	struct lpfc_hba *phba = vport->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11736) 	struct lpfc_iocbq *iocbq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11737) 	struct lpfc_iocbq *abtsiocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11738) 	struct lpfc_sli_ring *pring_s4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11739) 	IOCB_t *cmd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11740) 	int errcnt = 0, ret_val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11741) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11743) 	/* all I/Os are in process of being flushed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11744) 	if (phba->hba_flag & HBA_IOQ_FLUSH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11745) 		return errcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11747) 	for (i = 1; i <= phba->sli.last_iotag; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11748) 		iocbq = phba->sli.iocbq_lookup[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11750) 		if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11751) 					       abort_cmd) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11752) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11754) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11755) 		 * If the iocbq is already being aborted, don't take a second
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11756) 		 * action, but do count it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11757) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11758) 		if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11759) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11761) 		/* issue ABTS for this IOCB based on iotag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11762) 		abtsiocb = lpfc_sli_get_iocbq(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11763) 		if (abtsiocb == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11764) 			errcnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11765) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11766) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11768) 		/* indicate the IO is being aborted by the driver. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11769) 		iocbq->iocb_flag |= LPFC_DRIVER_ABORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11771) 		cmd = &iocbq->iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11772) 		abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11773) 		abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11774) 		if (phba->sli_rev == LPFC_SLI_REV4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11775) 			abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11776) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11777) 			abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11778) 		abtsiocb->iocb.ulpLe = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11779) 		abtsiocb->iocb.ulpClass = cmd->ulpClass;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11780) 		abtsiocb->vport = vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11782) 		/* ABTS WQE must go to the same WQ as the WQE to be aborted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11783) 		abtsiocb->hba_wqidx = iocbq->hba_wqidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11784) 		if (iocbq->iocb_flag & LPFC_IO_FCP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11785) 			abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11786) 		if (iocbq->iocb_flag & LPFC_IO_FOF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11787) 			abtsiocb->iocb_flag |= LPFC_IO_FOF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11789) 		if (lpfc_is_link_up(phba))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11790) 			abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11791) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11792) 			abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11794) 		/* Setup callback routine and issue the command. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11795) 		abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11796) 		if (phba->sli_rev == LPFC_SLI_REV4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11797) 			pring_s4 = lpfc_sli4_calc_ring(phba, iocbq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11798) 			if (!pring_s4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11799) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11800) 			ret_val = lpfc_sli_issue_iocb(phba, pring_s4->ringno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11801) 						      abtsiocb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11802) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11803) 			ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11804) 						      abtsiocb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11805) 		if (ret_val == IOCB_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11806) 			lpfc_sli_release_iocbq(phba, abtsiocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11807) 			errcnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11808) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11809) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11810) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11812) 	return errcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11813) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11815) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11816)  * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11817)  * @vport: Pointer to virtual port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11818)  * @pring: Pointer to driver SLI ring object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11819)  * @tgt_id: SCSI ID of the target.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11820)  * @lun_id: LUN ID of the scsi device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11821)  * @cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11822)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11823)  * This function sends an abort command for every SCSI command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11824)  * associated with the given virtual port pending on the ring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11825)  * filtered by lpfc_sli_validate_fcp_iocb function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11826)  * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11827)  * FCP iocbs associated with lun specified by tgt_id and lun_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11828)  * parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11829)  * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11830)  * FCP iocbs associated with SCSI target specified by tgt_id parameter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11831)  * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11832)  * FCP iocbs associated with virtual port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11833)  * This function returns number of iocbs it aborted .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11834)  * This function is called with no locks held right after a taskmgmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11835)  * command is sent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11836)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11837) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11838) lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11839) 			uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11840) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11841) 	struct lpfc_hba *phba = vport->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11842) 	struct lpfc_io_buf *lpfc_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11843) 	struct lpfc_iocbq *abtsiocbq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11844) 	struct lpfc_nodelist *ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11845) 	struct lpfc_iocbq *iocbq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11846) 	IOCB_t *icmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11847) 	int sum, i, ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11848) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11849) 	struct lpfc_sli_ring *pring_s4 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11851) 	spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11853) 	/* all I/Os are in process of being flushed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11854) 	if (phba->hba_flag & HBA_IOQ_FLUSH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11855) 		spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11856) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11857) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11858) 	sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11860) 	for (i = 1; i <= phba->sli.last_iotag; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11861) 		iocbq = phba->sli.iocbq_lookup[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11862) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11863) 		if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11864) 					       cmd) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11865) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11867) 		/* Guard against IO completion being called at same time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11868) 		lpfc_cmd = container_of(iocbq, struct lpfc_io_buf, cur_iocbq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11869) 		spin_lock(&lpfc_cmd->buf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11871) 		if (!lpfc_cmd->pCmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11872) 			spin_unlock(&lpfc_cmd->buf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11873) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11874) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11876) 		if (phba->sli_rev == LPFC_SLI_REV4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11877) 			pring_s4 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11878) 			    phba->sli4_hba.hdwq[iocbq->hba_wqidx].io_wq->pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11879) 			if (!pring_s4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11880) 				spin_unlock(&lpfc_cmd->buf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11881) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11882) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11883) 			/* Note: both hbalock and ring_lock must be set here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11884) 			spin_lock(&pring_s4->ring_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11885) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11887) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11888) 		 * If the iocbq is already being aborted, don't take a second
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11889) 		 * action, but do count it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11890) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11891) 		if ((iocbq->iocb_flag & LPFC_DRIVER_ABORTED) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11892) 		    !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11893) 			if (phba->sli_rev == LPFC_SLI_REV4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11894) 				spin_unlock(&pring_s4->ring_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11895) 			spin_unlock(&lpfc_cmd->buf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11896) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11897) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11898) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11899) 		/* issue ABTS for this IOCB based on iotag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11900) 		abtsiocbq = __lpfc_sli_get_iocbq(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11901) 		if (!abtsiocbq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11902) 			if (phba->sli_rev == LPFC_SLI_REV4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11903) 				spin_unlock(&pring_s4->ring_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11904) 			spin_unlock(&lpfc_cmd->buf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11905) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11906) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11908) 		icmd = &iocbq->iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11909) 		abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11910) 		abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11911) 		if (phba->sli_rev == LPFC_SLI_REV4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11912) 			abtsiocbq->iocb.un.acxri.abortIoTag =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11913) 							 iocbq->sli4_xritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11914) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11915) 			abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11916) 		abtsiocbq->iocb.ulpLe = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11917) 		abtsiocbq->iocb.ulpClass = icmd->ulpClass;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11918) 		abtsiocbq->vport = vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11920) 		/* ABTS WQE must go to the same WQ as the WQE to be aborted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11921) 		abtsiocbq->hba_wqidx = iocbq->hba_wqidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11922) 		if (iocbq->iocb_flag & LPFC_IO_FCP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11923) 			abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11924) 		if (iocbq->iocb_flag & LPFC_IO_FOF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11925) 			abtsiocbq->iocb_flag |= LPFC_IO_FOF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11927) 		ndlp = lpfc_cmd->rdata->pnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11928) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11929) 		if (lpfc_is_link_up(phba) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11930) 		    (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11931) 			abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11932) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11933) 			abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11935) 		/* Setup callback routine and issue the command. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11936) 		abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11937) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11938) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11939) 		 * Indicate the IO is being aborted by the driver and set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11940) 		 * the caller's flag into the aborted IO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11941) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11942) 		iocbq->iocb_flag |= LPFC_DRIVER_ABORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11944) 		if (phba->sli_rev == LPFC_SLI_REV4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11945) 			ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11946) 							abtsiocbq, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11947) 			spin_unlock(&pring_s4->ring_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11948) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11949) 			ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11950) 							abtsiocbq, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11951) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11952) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11953) 		spin_unlock(&lpfc_cmd->buf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11955) 		if (ret_val == IOCB_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11956) 			__lpfc_sli_release_iocbq(phba, abtsiocbq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11957) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11958) 			sum++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11959) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11960) 	spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11961) 	return sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11962) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11964) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11965)  * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11966)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11967)  * @cmdiocbq: Pointer to command iocb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11968)  * @rspiocbq: Pointer to response iocb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11969)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11970)  * This function is the completion handler for iocbs issued using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11971)  * lpfc_sli_issue_iocb_wait function. This function is called by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11972)  * ring event handler function without any lock held. This function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11973)  * can be called from both worker thread context and interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11974)  * context. This function also can be called from other thread which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11975)  * cleans up the SLI layer objects.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11976)  * This function copy the contents of the response iocb to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11977)  * response iocb memory object provided by the caller of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11978)  * lpfc_sli_issue_iocb_wait and then wakes up the thread which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11979)  * sleeps for the iocb completion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11980)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11981) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11982) lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11983) 			struct lpfc_iocbq *cmdiocbq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11984) 			struct lpfc_iocbq *rspiocbq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11985) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11986) 	wait_queue_head_t *pdone_q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11987) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11988) 	struct lpfc_io_buf *lpfc_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11989) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11990) 	spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11991) 	if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11992) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11993) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11994) 		 * A time out has occurred for the iocb.  If a time out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11995) 		 * completion handler has been supplied, call it.  Otherwise,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11996) 		 * just free the iocbq.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11997) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11999) 		spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12000) 		cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12001) 		cmdiocbq->wait_iocb_cmpl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12002) 		if (cmdiocbq->iocb_cmpl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12003) 			(cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12004) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12005) 			lpfc_sli_release_iocbq(phba, cmdiocbq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12006) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12007) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12008) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12009) 	cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12010) 	if (cmdiocbq->context2 && rspiocbq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12011) 		memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12012) 		       &rspiocbq->iocb, sizeof(IOCB_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12014) 	/* Set the exchange busy flag for task management commands */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12015) 	if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12016) 		!(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12017) 		lpfc_cmd = container_of(cmdiocbq, struct lpfc_io_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12018) 			cur_iocbq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12019) 		if (rspiocbq && (rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12020) 			lpfc_cmd->flags |= LPFC_SBUF_XBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12021) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12022) 			lpfc_cmd->flags &= ~LPFC_SBUF_XBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12023) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12025) 	pdone_q = cmdiocbq->context_un.wait_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12026) 	if (pdone_q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12027) 		wake_up(pdone_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12028) 	spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12029) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12030) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12031) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12032) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12033)  * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12034)  * @phba: Pointer to HBA context object..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12035)  * @piocbq: Pointer to command iocb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12036)  * @flag: Flag to test.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12037)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12038)  * This routine grabs the hbalock and then test the iocb_flag to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12039)  * see if the passed in flag is set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12040)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12041)  * 1 if flag is set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12042)  * 0 if flag is not set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12043)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12044) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12045) lpfc_chk_iocb_flg(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12046) 		 struct lpfc_iocbq *piocbq, uint32_t flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12047) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12048) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12049) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12051) 	spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12052) 	ret = piocbq->iocb_flag & flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12053) 	spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12054) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12056) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12058) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12059)  * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12060)  * @phba: Pointer to HBA context object..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12061)  * @ring_number: Ring number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12062)  * @piocb: Pointer to command iocb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12063)  * @prspiocbq: Pointer to response iocb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12064)  * @timeout: Timeout in number of seconds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12065)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12066)  * This function issues the iocb to firmware and waits for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12067)  * iocb to complete. The iocb_cmpl field of the shall be used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12068)  * to handle iocbs which time out. If the field is NULL, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12069)  * function shall free the iocbq structure.  If more clean up is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12070)  * needed, the caller is expected to provide a completion function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12071)  * that will provide the needed clean up.  If the iocb command is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12072)  * not completed within timeout seconds, the function will either
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12073)  * free the iocbq structure (if iocb_cmpl == NULL) or execute the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12074)  * completion function set in the iocb_cmpl field and then return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12075)  * a status of IOCB_TIMEDOUT.  The caller should not free the iocb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12076)  * resources if this function returns IOCB_TIMEDOUT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12077)  * The function waits for the iocb completion using an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12078)  * non-interruptible wait.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12079)  * This function will sleep while waiting for iocb completion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12080)  * So, this function should not be called from any context which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12081)  * does not allow sleeping. Due to the same reason, this function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12082)  * cannot be called with interrupt disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12083)  * This function assumes that the iocb completions occur while
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12084)  * this function sleep. So, this function cannot be called from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12085)  * the thread which process iocb completion for this ring.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12086)  * This function clears the iocb_flag of the iocb object before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12087)  * issuing the iocb and the iocb completion handler sets this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12088)  * flag and wakes this thread when the iocb completes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12089)  * The contents of the response iocb will be copied to prspiocbq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12090)  * by the completion handler when the command completes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12091)  * This function returns IOCB_SUCCESS when success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12092)  * This function is called with no lock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12093)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12094) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12095) lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12096) 			 uint32_t ring_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12097) 			 struct lpfc_iocbq *piocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12098) 			 struct lpfc_iocbq *prspiocbq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12099) 			 uint32_t timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12101) 	DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12102) 	long timeleft, timeout_req = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12103) 	int retval = IOCB_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12104) 	uint32_t creg_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12105) 	struct lpfc_iocbq *iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12106) 	int txq_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12107) 	int txcmplq_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12108) 	struct lpfc_sli_ring *pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12109) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12110) 	bool iocb_completed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12112) 	if (phba->sli_rev >= LPFC_SLI_REV4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12113) 		pring = lpfc_sli4_calc_ring(phba, piocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12114) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12115) 		pring = &phba->sli.sli3_ring[ring_number];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12116) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12117) 	 * If the caller has provided a response iocbq buffer, then context2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12118) 	 * is NULL or its an error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12119) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12120) 	if (prspiocbq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12121) 		if (piocb->context2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12122) 			return IOCB_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12123) 		piocb->context2 = prspiocbq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12124) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12126) 	piocb->wait_iocb_cmpl = piocb->iocb_cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12127) 	piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12128) 	piocb->context_un.wait_queue = &done_q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12129) 	piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12131) 	if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12132) 		if (lpfc_readl(phba->HCregaddr, &creg_val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12133) 			return IOCB_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12134) 		creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12135) 		writel(creg_val, phba->HCregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12136) 		readl(phba->HCregaddr); /* flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12137) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12139) 	retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12140) 				     SLI_IOCB_RET_IOCB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12141) 	if (retval == IOCB_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12142) 		timeout_req = msecs_to_jiffies(timeout * 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12143) 		timeleft = wait_event_timeout(done_q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12144) 				lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12145) 				timeout_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12146) 		spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12147) 		if (!(piocb->iocb_flag & LPFC_IO_WAKE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12149) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12150) 			 * IOCB timed out.  Inform the wake iocb wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12151) 			 * completion function and set local status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12152) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12154) 			iocb_completed = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12155) 			piocb->iocb_flag |= LPFC_IO_WAKE_TMO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12156) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12157) 		spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12158) 		if (iocb_completed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12159) 			lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12160) 					"0331 IOCB wake signaled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12161) 			/* Note: we are not indicating if the IOCB has a success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12162) 			 * status or not - that's for the caller to check.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12163) 			 * IOCB_SUCCESS means just that the command was sent and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12164) 			 * completed. Not that it completed successfully.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12165) 			 * */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12166) 		} else if (timeleft == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12167) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12168) 					"0338 IOCB wait timeout error - no "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12169) 					"wake response Data x%x\n", timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12170) 			retval = IOCB_TIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12171) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12172) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12173) 					"0330 IOCB wake NOT set, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12174) 					"Data x%x x%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12175) 					timeout, (timeleft / jiffies));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12176) 			retval = IOCB_TIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12177) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12178) 	} else if (retval == IOCB_BUSY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12179) 		if (phba->cfg_log_verbose & LOG_SLI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12180) 			list_for_each_entry(iocb, &pring->txq, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12181) 				txq_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12182) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12183) 			list_for_each_entry(iocb, &pring->txcmplq, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12184) 				txcmplq_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12185) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12186) 			lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12187) 				"2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12188) 				phba->iocb_cnt, txq_cnt, txcmplq_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12189) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12190) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12191) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12192) 		lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12193) 				"0332 IOCB wait issue failed, Data x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12194) 				retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12195) 		retval = IOCB_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12196) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12198) 	if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12199) 		if (lpfc_readl(phba->HCregaddr, &creg_val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12200) 			return IOCB_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12201) 		creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12202) 		writel(creg_val, phba->HCregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12203) 		readl(phba->HCregaddr); /* flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12204) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12206) 	if (prspiocbq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12207) 		piocb->context2 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12209) 	piocb->context_un.wait_queue = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12210) 	piocb->iocb_cmpl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12211) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12214) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12215)  * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12216)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12217)  * @pmboxq: Pointer to driver mailbox object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12218)  * @timeout: Timeout in number of seconds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12219)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12220)  * This function issues the mailbox to firmware and waits for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12221)  * mailbox command to complete. If the mailbox command is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12222)  * completed within timeout seconds, it returns MBX_TIMEOUT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12223)  * The function waits for the mailbox completion using an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12224)  * interruptible wait. If the thread is woken up due to a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12225)  * signal, MBX_TIMEOUT error is returned to the caller. Caller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12226)  * should not free the mailbox resources, if this function returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12227)  * MBX_TIMEOUT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12228)  * This function will sleep while waiting for mailbox completion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12229)  * So, this function should not be called from any context which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12230)  * does not allow sleeping. Due to the same reason, this function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12231)  * cannot be called with interrupt disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12232)  * This function assumes that the mailbox completion occurs while
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12233)  * this function sleep. So, this function cannot be called from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12234)  * the worker thread which processes mailbox completion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12235)  * This function is called in the context of HBA management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12236)  * applications.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12237)  * This function returns MBX_SUCCESS when successful.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12238)  * This function is called with no lock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12239)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12240) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12241) lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12242) 			 uint32_t timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12244) 	struct completion mbox_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12245) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12246) 	unsigned long flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12248) 	pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12249) 	/* setup wake call as IOCB callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12250) 	pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12252) 	/* setup context3 field to pass wait_queue pointer to wake function  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12253) 	init_completion(&mbox_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12254) 	pmboxq->context3 = &mbox_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12255) 	/* now issue the command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12256) 	retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12257) 	if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12258) 		wait_for_completion_timeout(&mbox_done,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12259) 					    msecs_to_jiffies(timeout * 1000));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12261) 		spin_lock_irqsave(&phba->hbalock, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12262) 		pmboxq->context3 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12263) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12264) 		 * if LPFC_MBX_WAKE flag is set the mailbox is completed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12265) 		 * else do not free the resources.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12266) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12267) 		if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12268) 			retval = MBX_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12269) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12270) 			retval = MBX_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12271) 			pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12272) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12273) 		spin_unlock_irqrestore(&phba->hbalock, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12274) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12275) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12278) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12279)  * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12280)  * @phba: Pointer to HBA context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12281)  * @mbx_action: Mailbox shutdown options.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12282)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12283)  * This function is called to shutdown the driver's mailbox sub-system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12284)  * It first marks the mailbox sub-system is in a block state to prevent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12285)  * the asynchronous mailbox command from issued off the pending mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12286)  * command queue. If the mailbox command sub-system shutdown is due to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12287)  * HBA error conditions such as EEH or ERATT, this routine shall invoke
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12288)  * the mailbox sub-system flush routine to forcefully bring down the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12289)  * mailbox sub-system. Otherwise, if it is due to normal condition (such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12290)  * as with offline or HBA function reset), this routine will wait for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12291)  * outstanding mailbox command to complete before invoking the mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12292)  * sub-system flush routine to gracefully bring down mailbox sub-system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12293)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12294) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12295) lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12297) 	struct lpfc_sli *psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12298) 	unsigned long timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12300) 	if (mbx_action == LPFC_MBX_NO_WAIT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12301) 		/* delay 100ms for port state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12302) 		msleep(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12303) 		lpfc_sli_mbox_sys_flush(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12304) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12305) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12306) 	timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12308) 	/* Disable softirqs, including timers from obtaining phba->hbalock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12309) 	local_bh_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12311) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12312) 	psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12314) 	if (psli->sli_flag & LPFC_SLI_ACTIVE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12315) 		/* Determine how long we might wait for the active mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12316) 		 * command to be gracefully completed by firmware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12317) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12318) 		if (phba->sli.mbox_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12319) 			timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12320) 						phba->sli.mbox_active) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12321) 						1000) + jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12322) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12324) 		/* Enable softirqs again, done with phba->hbalock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12325) 		local_bh_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12327) 		while (phba->sli.mbox_active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12328) 			/* Check active mailbox complete status every 2ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12329) 			msleep(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12330) 			if (time_after(jiffies, timeout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12331) 				/* Timeout, let the mailbox flush routine to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12332) 				 * forcefully release active mailbox command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12333) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12334) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12335) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12336) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12337) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12339) 		/* Enable softirqs again, done with phba->hbalock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12340) 		local_bh_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12341) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12343) 	lpfc_sli_mbox_sys_flush(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12346) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12347)  * lpfc_sli_eratt_read - read sli-3 error attention events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12348)  * @phba: Pointer to HBA context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12349)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12350)  * This function is called to read the SLI3 device error attention registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12351)  * for possible error attention events. The caller must hold the hostlock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12352)  * with spin_lock_irq().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12353)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12354)  * This function returns 1 when there is Error Attention in the Host Attention
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12355)  * Register and returns 0 otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12356)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12357) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12358) lpfc_sli_eratt_read(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12359) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12360) 	uint32_t ha_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12362) 	/* Read chip Host Attention (HA) register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12363) 	if (lpfc_readl(phba->HAregaddr, &ha_copy))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12364) 		goto unplug_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12366) 	if (ha_copy & HA_ERATT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12367) 		/* Read host status register to retrieve error event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12368) 		if (lpfc_sli_read_hs(phba))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12369) 			goto unplug_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12371) 		/* Check if there is a deferred error condition is active */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12372) 		if ((HS_FFER1 & phba->work_hs) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12373) 		    ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12374) 		      HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12375) 			phba->hba_flag |= DEFER_ERATT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12376) 			/* Clear all interrupt enable conditions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12377) 			writel(0, phba->HCregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12378) 			readl(phba->HCregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12379) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12381) 		/* Set the driver HA work bitmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12382) 		phba->work_ha |= HA_ERATT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12383) 		/* Indicate polling handles this ERATT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12384) 		phba->hba_flag |= HBA_ERATT_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12385) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12386) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12387) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12389) unplug_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12390) 	/* Set the driver HS work bitmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12391) 	phba->work_hs |= UNPLUG_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12392) 	/* Set the driver HA work bitmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12393) 	phba->work_ha |= HA_ERATT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12394) 	/* Indicate polling handles this ERATT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12395) 	phba->hba_flag |= HBA_ERATT_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12396) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12399) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12400)  * lpfc_sli4_eratt_read - read sli-4 error attention events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12401)  * @phba: Pointer to HBA context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12402)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12403)  * This function is called to read the SLI4 device error attention registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12404)  * for possible error attention events. The caller must hold the hostlock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12405)  * with spin_lock_irq().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12406)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12407)  * This function returns 1 when there is Error Attention in the Host Attention
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12408)  * Register and returns 0 otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12409)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12410) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12411) lpfc_sli4_eratt_read(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12412) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12413) 	uint32_t uerr_sta_hi, uerr_sta_lo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12414) 	uint32_t if_type, portsmphr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12415) 	struct lpfc_register portstat_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12416) 	u32 logmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12418) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12419) 	 * For now, use the SLI4 device internal unrecoverable error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12420) 	 * registers for error attention. This can be changed later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12421) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12422) 	if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12423) 	switch (if_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12424) 	case LPFC_SLI_INTF_IF_TYPE_0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12425) 		if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12426) 			&uerr_sta_lo) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12427) 			lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12428) 			&uerr_sta_hi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12429) 			phba->work_hs |= UNPLUG_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12430) 			phba->work_ha |= HA_ERATT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12431) 			phba->hba_flag |= HBA_ERATT_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12432) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12433) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12434) 		if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12435) 		    (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12436) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12437) 					"1423 HBA Unrecoverable error: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12438) 					"uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12439) 					"ue_mask_lo_reg=0x%x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12440) 					"ue_mask_hi_reg=0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12441) 					uerr_sta_lo, uerr_sta_hi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12442) 					phba->sli4_hba.ue_mask_lo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12443) 					phba->sli4_hba.ue_mask_hi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12444) 			phba->work_status[0] = uerr_sta_lo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12445) 			phba->work_status[1] = uerr_sta_hi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12446) 			phba->work_ha |= HA_ERATT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12447) 			phba->hba_flag |= HBA_ERATT_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12448) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12449) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12450) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12451) 	case LPFC_SLI_INTF_IF_TYPE_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12452) 	case LPFC_SLI_INTF_IF_TYPE_6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12453) 		if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12454) 			&portstat_reg.word0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12455) 			lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12456) 			&portsmphr)){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12457) 			phba->work_hs |= UNPLUG_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12458) 			phba->work_ha |= HA_ERATT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12459) 			phba->hba_flag |= HBA_ERATT_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12460) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12461) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12462) 		if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12463) 			phba->work_status[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12464) 				readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12465) 			phba->work_status[1] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12466) 				readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12467) 			logmask = LOG_TRACE_EVENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12468) 			if (phba->work_status[0] ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12469) 				SLIPORT_ERR1_REG_ERR_CODE_2 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12470) 			    phba->work_status[1] == SLIPORT_ERR2_REG_FW_RESTART)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12471) 				logmask = LOG_SLI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12472) 			lpfc_printf_log(phba, KERN_ERR, logmask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12473) 					"2885 Port Status Event: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12474) 					"port status reg 0x%x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12475) 					"port smphr reg 0x%x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12476) 					"error 1=0x%x, error 2=0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12477) 					portstat_reg.word0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12478) 					portsmphr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12479) 					phba->work_status[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12480) 					phba->work_status[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12481) 			phba->work_ha |= HA_ERATT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12482) 			phba->hba_flag |= HBA_ERATT_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12483) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12484) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12485) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12486) 	case LPFC_SLI_INTF_IF_TYPE_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12487) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12488) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12489) 				"2886 HBA Error Attention on unsupported "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12490) 				"if type %d.", if_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12491) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12492) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12494) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12497) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12498)  * lpfc_sli_check_eratt - check error attention events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12499)  * @phba: Pointer to HBA context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12500)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12501)  * This function is called from timer soft interrupt context to check HBA's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12502)  * error attention register bit for error attention events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12503)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12504)  * This function returns 1 when there is Error Attention in the Host Attention
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12505)  * Register and returns 0 otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12506)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12507) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12508) lpfc_sli_check_eratt(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12510) 	uint32_t ha_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12512) 	/* If somebody is waiting to handle an eratt, don't process it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12513) 	 * here. The brdkill function will do this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12514) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12515) 	if (phba->link_flag & LS_IGNORE_ERATT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12516) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12518) 	/* Check if interrupt handler handles this ERATT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12519) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12520) 	if (phba->hba_flag & HBA_ERATT_HANDLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12521) 		/* Interrupt handler has handled ERATT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12522) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12523) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12524) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12526) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12527) 	 * If there is deferred error attention, do not check for error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12528) 	 * attention
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12529) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12530) 	if (unlikely(phba->hba_flag & DEFER_ERATT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12531) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12532) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12533) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12535) 	/* If PCI channel is offline, don't process it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12536) 	if (unlikely(pci_channel_offline(phba->pcidev))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12537) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12538) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12539) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12541) 	switch (phba->sli_rev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12542) 	case LPFC_SLI_REV2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12543) 	case LPFC_SLI_REV3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12544) 		/* Read chip Host Attention (HA) register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12545) 		ha_copy = lpfc_sli_eratt_read(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12546) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12547) 	case LPFC_SLI_REV4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12548) 		/* Read device Uncoverable Error (UERR) registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12549) 		ha_copy = lpfc_sli4_eratt_read(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12550) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12551) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12552) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12553) 				"0299 Invalid SLI revision (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12554) 				phba->sli_rev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12555) 		ha_copy = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12556) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12557) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12558) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12560) 	return ha_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12561) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12563) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12564)  * lpfc_intr_state_check - Check device state for interrupt handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12565)  * @phba: Pointer to HBA context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12566)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12567)  * This inline routine checks whether a device or its PCI slot is in a state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12568)  * that the interrupt should be handled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12569)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12570)  * This function returns 0 if the device or the PCI slot is in a state that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12571)  * interrupt should be handled, otherwise -EIO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12572)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12573) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12574) lpfc_intr_state_check(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12575) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12576) 	/* If the pci channel is offline, ignore all the interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12577) 	if (unlikely(pci_channel_offline(phba->pcidev)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12578) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12580) 	/* Update device level interrupt statistics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12581) 	phba->sli.slistat.sli_intr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12583) 	/* Ignore all interrupts during initialization. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12584) 	if (unlikely(phba->link_state < LPFC_LINK_DOWN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12585) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12587) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12588) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12590) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12591)  * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12592)  * @irq: Interrupt number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12593)  * @dev_id: The device context pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12594)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12595)  * This function is directly called from the PCI layer as an interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12596)  * service routine when device with SLI-3 interface spec is enabled with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12597)  * MSI-X multi-message interrupt mode and there are slow-path events in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12598)  * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12599)  * interrupt mode, this function is called as part of the device-level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12600)  * interrupt handler. When the PCI slot is in error recovery or the HBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12601)  * is undergoing initialization, the interrupt handler will not process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12602)  * the interrupt. The link attention and ELS ring attention events are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12603)  * handled by the worker thread. The interrupt handler signals the worker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12604)  * thread and returns for these events. This function is called without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12605)  * any lock held. It gets the hbalock to access and update SLI data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12606)  * structures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12607)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12608)  * This function returns IRQ_HANDLED when interrupt is handled else it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12609)  * returns IRQ_NONE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12610)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12611) irqreturn_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12612) lpfc_sli_sp_intr_handler(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12613) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12614) 	struct lpfc_hba  *phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12615) 	uint32_t ha_copy, hc_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12616) 	uint32_t work_ha_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12617) 	unsigned long status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12618) 	unsigned long iflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12619) 	uint32_t control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12621) 	MAILBOX_t *mbox, *pmbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12622) 	struct lpfc_vport *vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12623) 	struct lpfc_nodelist *ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12624) 	struct lpfc_dmabuf *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12625) 	LPFC_MBOXQ_t *pmb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12626) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12628) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12629) 	 * Get the driver's phba structure from the dev_id and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12630) 	 * assume the HBA is not interrupting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12631) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12632) 	phba = (struct lpfc_hba *)dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12634) 	if (unlikely(!phba))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12635) 		return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12637) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12638) 	 * Stuff needs to be attented to when this function is invoked as an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12639) 	 * individual interrupt handler in MSI-X multi-message interrupt mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12640) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12641) 	if (phba->intr_type == MSIX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12642) 		/* Check device state for handling interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12643) 		if (lpfc_intr_state_check(phba))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12644) 			return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12645) 		/* Need to read HA REG for slow-path events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12646) 		spin_lock_irqsave(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12647) 		if (lpfc_readl(phba->HAregaddr, &ha_copy))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12648) 			goto unplug_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12649) 		/* If somebody is waiting to handle an eratt don't process it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12650) 		 * here. The brdkill function will do this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12651) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12652) 		if (phba->link_flag & LS_IGNORE_ERATT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12653) 			ha_copy &= ~HA_ERATT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12654) 		/* Check the need for handling ERATT in interrupt handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12655) 		if (ha_copy & HA_ERATT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12656) 			if (phba->hba_flag & HBA_ERATT_HANDLED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12657) 				/* ERATT polling has handled ERATT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12658) 				ha_copy &= ~HA_ERATT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12659) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12660) 				/* Indicate interrupt handler handles ERATT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12661) 				phba->hba_flag |= HBA_ERATT_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12662) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12664) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12665) 		 * If there is deferred error attention, do not check for any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12666) 		 * interrupt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12667) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12668) 		if (unlikely(phba->hba_flag & DEFER_ERATT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12669) 			spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12670) 			return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12671) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12673) 		/* Clear up only attention source related to slow-path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12674) 		if (lpfc_readl(phba->HCregaddr, &hc_copy))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12675) 			goto unplug_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12677) 		writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12678) 			HC_LAINT_ENA | HC_ERINT_ENA),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12679) 			phba->HCregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12680) 		writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12681) 			phba->HAregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12682) 		writel(hc_copy, phba->HCregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12683) 		readl(phba->HAregaddr); /* flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12684) 		spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12685) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12686) 		ha_copy = phba->ha_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12688) 	work_ha_copy = ha_copy & phba->work_ha_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12690) 	if (work_ha_copy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12691) 		if (work_ha_copy & HA_LATT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12692) 			if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12693) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12694) 				 * Turn off Link Attention interrupts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12695) 				 * until CLEAR_LA done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12696) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12697) 				spin_lock_irqsave(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12698) 				phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12699) 				if (lpfc_readl(phba->HCregaddr, &control))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12700) 					goto unplug_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12701) 				control &= ~HC_LAINT_ENA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12702) 				writel(control, phba->HCregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12703) 				readl(phba->HCregaddr); /* flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12704) 				spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12705) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12706) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12707) 				work_ha_copy &= ~HA_LATT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12708) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12710) 		if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12711) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12712) 			 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12713) 			 * the only slow ring.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12714) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12715) 			status = (work_ha_copy &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12716) 				(HA_RXMASK  << (4*LPFC_ELS_RING)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12717) 			status >>= (4*LPFC_ELS_RING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12718) 			if (status & HA_RXMASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12719) 				spin_lock_irqsave(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12720) 				if (lpfc_readl(phba->HCregaddr, &control))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12721) 					goto unplug_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12723) 				lpfc_debugfs_slow_ring_trc(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12724) 				"ISR slow ring:   ctl:x%x stat:x%x isrcnt:x%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12725) 				control, status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12726) 				(uint32_t)phba->sli.slistat.sli_intr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12728) 				if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12729) 					lpfc_debugfs_slow_ring_trc(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12730) 						"ISR Disable ring:"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12731) 						"pwork:x%x hawork:x%x wait:x%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12732) 						phba->work_ha, work_ha_copy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12733) 						(uint32_t)((unsigned long)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12734) 						&phba->work_waitq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12736) 					control &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12737) 					    ~(HC_R0INT_ENA << LPFC_ELS_RING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12738) 					writel(control, phba->HCregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12739) 					readl(phba->HCregaddr); /* flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12740) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12741) 				else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12742) 					lpfc_debugfs_slow_ring_trc(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12743) 						"ISR slow ring:   pwork:"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12744) 						"x%x hawork:x%x wait:x%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12745) 						phba->work_ha, work_ha_copy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12746) 						(uint32_t)((unsigned long)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12747) 						&phba->work_waitq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12748) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12749) 				spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12750) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12751) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12752) 		spin_lock_irqsave(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12753) 		if (work_ha_copy & HA_ERATT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12754) 			if (lpfc_sli_read_hs(phba))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12755) 				goto unplug_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12756) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12757) 			 * Check if there is a deferred error condition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12758) 			 * is active
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12759) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12760) 			if ((HS_FFER1 & phba->work_hs) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12761) 				((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12762) 				  HS_FFER6 | HS_FFER7 | HS_FFER8) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12763) 				  phba->work_hs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12764) 				phba->hba_flag |= DEFER_ERATT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12765) 				/* Clear all interrupt enable conditions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12766) 				writel(0, phba->HCregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12767) 				readl(phba->HCregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12768) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12769) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12771) 		if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12772) 			pmb = phba->sli.mbox_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12773) 			pmbox = &pmb->u.mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12774) 			mbox = phba->mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12775) 			vport = pmb->vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12777) 			/* First check out the status word */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12778) 			lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12779) 			if (pmbox->mbxOwner != OWN_HOST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12780) 				spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12781) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12782) 				 * Stray Mailbox Interrupt, mbxCommand <cmd>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12783) 				 * mbxStatus <status>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12784) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12785) 				lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12786) 						"(%d):0304 Stray Mailbox "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12787) 						"Interrupt mbxCommand x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12788) 						"mbxStatus x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12789) 						(vport ? vport->vpi : 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12790) 						pmbox->mbxCommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12791) 						pmbox->mbxStatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12792) 				/* clear mailbox attention bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12793) 				work_ha_copy &= ~HA_MBATT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12794) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12795) 				phba->sli.mbox_active = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12796) 				spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12797) 				phba->last_completion_time = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12798) 				del_timer(&phba->sli.mbox_tmo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12799) 				if (pmb->mbox_cmpl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12800) 					lpfc_sli_pcimem_bcopy(mbox, pmbox,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12801) 							MAILBOX_CMD_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12802) 					if (pmb->out_ext_byte_len &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12803) 						pmb->ctx_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12804) 						lpfc_sli_pcimem_bcopy(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12805) 						phba->mbox_ext,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12806) 						pmb->ctx_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12807) 						pmb->out_ext_byte_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12808) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12809) 				if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12810) 					pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12812) 					lpfc_debugfs_disc_trc(vport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12813) 						LPFC_DISC_TRC_MBOX_VPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12814) 						"MBOX dflt rpi: : "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12815) 						"status:x%x rpi:x%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12816) 						(uint32_t)pmbox->mbxStatus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12817) 						pmbox->un.varWords[0], 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12819) 					if (!pmbox->mbxStatus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12820) 						mp = (struct lpfc_dmabuf *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12821) 							(pmb->ctx_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12822) 						ndlp = (struct lpfc_nodelist *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12823) 							pmb->ctx_ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12825) 						/* Reg_LOGIN of dflt RPI was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12826) 						 * successful. new lets get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12827) 						 * rid of the RPI using the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12828) 						 * same mbox buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12829) 						 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12830) 						lpfc_unreg_login(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12831) 							vport->vpi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12832) 							pmbox->un.varWords[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12833) 							pmb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12834) 						pmb->mbox_cmpl =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12835) 							lpfc_mbx_cmpl_dflt_rpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12836) 						pmb->ctx_buf = mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12837) 						pmb->ctx_ndlp = ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12838) 						pmb->vport = vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12839) 						rc = lpfc_sli_issue_mbox(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12840) 								pmb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12841) 								MBX_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12842) 						if (rc != MBX_BUSY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12843) 							lpfc_printf_log(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12844) 							KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12845) 							LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12846) 							"0350 rc should have"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12847) 							"been MBX_BUSY\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12848) 						if (rc != MBX_NOT_FINISHED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12849) 							goto send_current_mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12850) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12851) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12852) 				spin_lock_irqsave(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12853) 						&phba->pport->work_port_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12854) 						iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12855) 				phba->pport->work_port_events &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12856) 					~WORKER_MBOX_TMO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12857) 				spin_unlock_irqrestore(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12858) 						&phba->pport->work_port_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12859) 						iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12860) 				lpfc_mbox_cmpl_put(phba, pmb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12861) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12862) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12863) 			spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12865) 		if ((work_ha_copy & HA_MBATT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12866) 		    (phba->sli.mbox_active == NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12867) send_current_mbox:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12868) 			/* Process next mailbox command if there is one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12869) 			do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12870) 				rc = lpfc_sli_issue_mbox(phba, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12871) 							 MBX_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12872) 			} while (rc == MBX_NOT_FINISHED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12873) 			if (rc != MBX_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12874) 				lpfc_printf_log(phba, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12875) 						LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12876) 						"0349 rc should be "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12877) 						"MBX_SUCCESS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12878) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12880) 		spin_lock_irqsave(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12881) 		phba->work_ha |= work_ha_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12882) 		spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12883) 		lpfc_worker_wake_up(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12884) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12885) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12886) unplug_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12887) 	spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12888) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12890) } /* lpfc_sli_sp_intr_handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12892) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12893)  * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12894)  * @irq: Interrupt number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12895)  * @dev_id: The device context pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12896)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12897)  * This function is directly called from the PCI layer as an interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12898)  * service routine when device with SLI-3 interface spec is enabled with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12899)  * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12900)  * ring event in the HBA. However, when the device is enabled with either
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12901)  * MSI or Pin-IRQ interrupt mode, this function is called as part of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12902)  * device-level interrupt handler. When the PCI slot is in error recovery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12903)  * or the HBA is undergoing initialization, the interrupt handler will not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12904)  * process the interrupt. The SCSI FCP fast-path ring event are handled in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12905)  * the intrrupt context. This function is called without any lock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12906)  * It gets the hbalock to access and update SLI data structures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12907)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12908)  * This function returns IRQ_HANDLED when interrupt is handled else it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12909)  * returns IRQ_NONE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12910)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12911) irqreturn_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12912) lpfc_sli_fp_intr_handler(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12913) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12914) 	struct lpfc_hba  *phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12915) 	uint32_t ha_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12916) 	unsigned long status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12917) 	unsigned long iflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12918) 	struct lpfc_sli_ring *pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12920) 	/* Get the driver's phba structure from the dev_id and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12921) 	 * assume the HBA is not interrupting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12922) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12923) 	phba = (struct lpfc_hba *) dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12925) 	if (unlikely(!phba))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12926) 		return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12928) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12929) 	 * Stuff needs to be attented to when this function is invoked as an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12930) 	 * individual interrupt handler in MSI-X multi-message interrupt mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12931) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12932) 	if (phba->intr_type == MSIX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12933) 		/* Check device state for handling interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12934) 		if (lpfc_intr_state_check(phba))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12935) 			return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12936) 		/* Need to read HA REG for FCP ring and other ring events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12937) 		if (lpfc_readl(phba->HAregaddr, &ha_copy))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12938) 			return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12939) 		/* Clear up only attention source related to fast-path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12940) 		spin_lock_irqsave(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12941) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12942) 		 * If there is deferred error attention, do not check for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12943) 		 * any interrupt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12944) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12945) 		if (unlikely(phba->hba_flag & DEFER_ERATT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12946) 			spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12947) 			return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12948) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12949) 		writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12950) 			phba->HAregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12951) 		readl(phba->HAregaddr); /* flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12952) 		spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12953) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12954) 		ha_copy = phba->ha_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12955) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12956) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12957) 	 * Process all events on FCP ring. Take the optimized path for FCP IO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12958) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12959) 	ha_copy &= ~(phba->work_ha_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12961) 	status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12962) 	status >>= (4*LPFC_FCP_RING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12963) 	pring = &phba->sli.sli3_ring[LPFC_FCP_RING];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12964) 	if (status & HA_RXMASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12965) 		lpfc_sli_handle_fast_ring_event(phba, pring, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12967) 	if (phba->cfg_multi_ring_support == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12968) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12969) 		 * Process all events on extra ring. Take the optimized path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12970) 		 * for extra ring IO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12971) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12972) 		status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12973) 		status >>= (4*LPFC_EXTRA_RING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12974) 		if (status & HA_RXMASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12975) 			lpfc_sli_handle_fast_ring_event(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12976) 					&phba->sli.sli3_ring[LPFC_EXTRA_RING],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12977) 					status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12978) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12979) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12980) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12981) }  /* lpfc_sli_fp_intr_handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12982) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12983) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12984)  * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12985)  * @irq: Interrupt number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12986)  * @dev_id: The device context pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12987)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12988)  * This function is the HBA device-level interrupt handler to device with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12989)  * SLI-3 interface spec, called from the PCI layer when either MSI or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12990)  * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12991)  * requires driver attention. This function invokes the slow-path interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12992)  * attention handling function and fast-path interrupt attention handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12993)  * function in turn to process the relevant HBA attention events. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12994)  * function is called without any lock held. It gets the hbalock to access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12995)  * and update SLI data structures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12996)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12997)  * This function returns IRQ_HANDLED when interrupt is handled, else it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12998)  * returns IRQ_NONE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12999)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13000) irqreturn_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13001) lpfc_sli_intr_handler(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13002) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13003) 	struct lpfc_hba  *phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13004) 	irqreturn_t sp_irq_rc, fp_irq_rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13005) 	unsigned long status1, status2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13006) 	uint32_t hc_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13008) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13009) 	 * Get the driver's phba structure from the dev_id and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13010) 	 * assume the HBA is not interrupting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13011) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13012) 	phba = (struct lpfc_hba *) dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13014) 	if (unlikely(!phba))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13015) 		return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13016) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13017) 	/* Check device state for handling interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13018) 	if (lpfc_intr_state_check(phba))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13019) 		return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13021) 	spin_lock(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13022) 	if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13023) 		spin_unlock(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13024) 		return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13025) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13026) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13027) 	if (unlikely(!phba->ha_copy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13028) 		spin_unlock(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13029) 		return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13030) 	} else if (phba->ha_copy & HA_ERATT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13031) 		if (phba->hba_flag & HBA_ERATT_HANDLED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13032) 			/* ERATT polling has handled ERATT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13033) 			phba->ha_copy &= ~HA_ERATT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13034) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13035) 			/* Indicate interrupt handler handles ERATT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13036) 			phba->hba_flag |= HBA_ERATT_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13037) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13038) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13039) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13040) 	 * If there is deferred error attention, do not check for any interrupt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13041) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13042) 	if (unlikely(phba->hba_flag & DEFER_ERATT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13043) 		spin_unlock(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13044) 		return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13045) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13046) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13047) 	/* Clear attention sources except link and error attentions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13048) 	if (lpfc_readl(phba->HCregaddr, &hc_copy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13049) 		spin_unlock(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13050) 		return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13051) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13052) 	writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13053) 		| HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13054) 		phba->HCregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13055) 	writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13056) 	writel(hc_copy, phba->HCregaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13057) 	readl(phba->HAregaddr); /* flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13058) 	spin_unlock(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13060) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13061) 	 * Invokes slow-path host attention interrupt handling as appropriate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13062) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13063) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13064) 	/* status of events with mailbox and link attention */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13065) 	status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13066) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13067) 	/* status of events with ELS ring */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13068) 	status2 = (phba->ha_copy & (HA_RXMASK  << (4*LPFC_ELS_RING)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13069) 	status2 >>= (4*LPFC_ELS_RING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13070) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13071) 	if (status1 || (status2 & HA_RXMASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13072) 		sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13073) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13074) 		sp_irq_rc = IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13075) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13076) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13077) 	 * Invoke fast-path host attention interrupt handling as appropriate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13078) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13079) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13080) 	/* status of events with FCP ring */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13081) 	status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13082) 	status1 >>= (4*LPFC_FCP_RING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13083) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13084) 	/* status of events with extra ring */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13085) 	if (phba->cfg_multi_ring_support == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13086) 		status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13087) 		status2 >>= (4*LPFC_EXTRA_RING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13088) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13089) 		status2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13090) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13091) 	if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13092) 		fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13093) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13094) 		fp_irq_rc = IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13095) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13096) 	/* Return device-level interrupt handling status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13097) 	return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13098) }  /* lpfc_sli_intr_handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13099) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13100) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13101)  * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13102)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13103)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13104)  * This routine is invoked by the worker thread to process all the pending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13105)  * SLI4 els abort xri events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13106)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13107) void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13109) 	struct lpfc_cq_event *cq_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13110) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13112) 	/* First, declare the els xri abort event has been handled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13113) 	spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13114) 	phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13115) 	spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13117) 	/* Now, handle all the els xri abort events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13118) 	spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13119) 	while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13120) 		/* Get the first event from the head of the event queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13121) 		list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13122) 				 cq_event, struct lpfc_cq_event, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13123) 		spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13124) 				       iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13125) 		/* Notify aborted XRI for ELS work queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13126) 		lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13128) 		/* Free the event processed back to the free pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13129) 		lpfc_sli4_cq_event_release(phba, cq_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13130) 		spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13131) 				  iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13132) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13133) 	spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13136) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13137)  * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13138)  * @phba: pointer to lpfc hba data structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13139)  * @pIocbIn: pointer to the rspiocbq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13140)  * @pIocbOut: pointer to the cmdiocbq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13141)  * @wcqe: pointer to the complete wcqe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13142)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13143)  * This routine transfers the fields of a command iocbq to a response iocbq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13144)  * by copying all the IOCB fields from command iocbq and transferring the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13145)  * completion status information from the complete wcqe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13146)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13147) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13148) lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13149) 			      struct lpfc_iocbq *pIocbIn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13150) 			      struct lpfc_iocbq *pIocbOut,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13151) 			      struct lpfc_wcqe_complete *wcqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13153) 	int numBdes, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13154) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13155) 	uint32_t status, max_response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13156) 	struct lpfc_dmabuf *dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13157) 	struct ulp_bde64 *bpl, bde;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13158) 	size_t offset = offsetof(struct lpfc_iocbq, iocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13160) 	memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13161) 	       sizeof(struct lpfc_iocbq) - offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13162) 	/* Map WCQE parameters into irspiocb parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13163) 	status = bf_get(lpfc_wcqe_c_status, wcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13164) 	pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13165) 	if (pIocbOut->iocb_flag & LPFC_IO_FCP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13166) 		if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13167) 			pIocbIn->iocb.un.fcpi.fcpi_parm =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13168) 					pIocbOut->iocb.un.fcpi.fcpi_parm -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13169) 					wcqe->total_data_placed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13170) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13171) 			pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13172) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13173) 		pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13174) 		switch (pIocbOut->iocb.ulpCommand) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13175) 		case CMD_ELS_REQUEST64_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13176) 			dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13177) 			bpl  = (struct ulp_bde64 *)dmabuf->virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13178) 			bde.tus.w = le32_to_cpu(bpl[1].tus.w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13179) 			max_response = bde.tus.f.bdeSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13180) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13181) 		case CMD_GEN_REQUEST64_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13182) 			max_response = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13183) 			if (!pIocbOut->context3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13184) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13185) 			numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13186) 					sizeof(struct ulp_bde64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13187) 			dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13188) 			bpl = (struct ulp_bde64 *)dmabuf->virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13189) 			for (i = 0; i < numBdes; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13190) 				bde.tus.w = le32_to_cpu(bpl[i].tus.w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13191) 				if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13192) 					max_response += bde.tus.f.bdeSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13193) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13194) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13195) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13196) 			max_response = wcqe->total_data_placed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13197) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13198) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13199) 		if (max_response < wcqe->total_data_placed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13200) 			pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13201) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13202) 			pIocbIn->iocb.un.genreq64.bdl.bdeSize =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13203) 				wcqe->total_data_placed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13204) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13206) 	/* Convert BG errors for completion status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13207) 	if (status == CQE_STATUS_DI_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13208) 		pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13210) 		if (bf_get(lpfc_wcqe_c_bg_edir, wcqe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13211) 			pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13212) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13213) 			pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13215) 		pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13216) 		if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13217) 			pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13218) 				BGS_GUARD_ERR_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13219) 		if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13220) 			pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13221) 				BGS_APPTAG_ERR_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13222) 		if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13223) 			pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13224) 				BGS_REFTAG_ERR_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13226) 		/* Check to see if there was any good data before the error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13227) 		if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13228) 			pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13229) 				BGS_HI_WATER_MARK_PRESENT_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13230) 			pIocbIn->iocb.unsli3.sli3_bg.bghm =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13231) 				wcqe->total_data_placed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13232) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13234) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13235) 		* Set ALL the error bits to indicate we don't know what
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13236) 		* type of error it is.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13237) 		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13238) 		if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13239) 			pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13240) 				(BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13241) 				BGS_GUARD_ERR_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13242) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13244) 	/* Pick up HBA exchange busy condition */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13245) 	if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13246) 		spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13247) 		pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13248) 		spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13249) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13252) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13253)  * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13254)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13255)  * @irspiocbq: Pointer to work-queue completion queue entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13256)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13257)  * This routine handles an ELS work-queue completion event and construct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13258)  * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13259)  * discovery engine to handle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13260)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13261)  * Return: Pointer to the receive IOCBQ, NULL otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13262)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13263) static struct lpfc_iocbq *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13264) lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13265) 			       struct lpfc_iocbq *irspiocbq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13267) 	struct lpfc_sli_ring *pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13268) 	struct lpfc_iocbq *cmdiocbq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13269) 	struct lpfc_wcqe_complete *wcqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13270) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13272) 	pring = lpfc_phba_elsring(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13273) 	if (unlikely(!pring))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13274) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13276) 	wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13277) 	pring->stats.iocb_event++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13278) 	/* Look up the ELS command IOCB and create pseudo response IOCB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13279) 	cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13280) 				bf_get(lpfc_wcqe_c_request_tag, wcqe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13281) 	if (unlikely(!cmdiocbq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13282) 		lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13283) 				"0386 ELS complete with no corresponding "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13284) 				"cmdiocb: 0x%x 0x%x 0x%x 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13285) 				wcqe->word0, wcqe->total_data_placed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13286) 				wcqe->parameter, wcqe->word3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13287) 		lpfc_sli_release_iocbq(phba, irspiocbq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13288) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13289) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13291) 	spin_lock_irqsave(&pring->ring_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13292) 	/* Put the iocb back on the txcmplq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13293) 	lpfc_sli_ringtxcmpl_put(phba, pring, cmdiocbq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13294) 	spin_unlock_irqrestore(&pring->ring_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13296) 	/* Fake the irspiocbq and copy necessary response information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13297) 	lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13299) 	return irspiocbq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13302) inline struct lpfc_cq_event *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13303) lpfc_cq_event_setup(struct lpfc_hba *phba, void *entry, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13304) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13305) 	struct lpfc_cq_event *cq_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13307) 	/* Allocate a new internal CQ_EVENT entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13308) 	cq_event = lpfc_sli4_cq_event_alloc(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13309) 	if (!cq_event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13310) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13311) 				"0602 Failed to alloc CQ_EVENT entry\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13312) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13313) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13315) 	/* Move the CQE into the event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13316) 	memcpy(&cq_event->cqe, entry, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13317) 	return cq_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13320) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13321)  * lpfc_sli4_sp_handle_async_event - Handle an asynchronous event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13322)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13323)  * @mcqe: Pointer to mailbox completion queue entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13324)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13325)  * This routine process a mailbox completion queue entry with asynchronous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13326)  * event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13327)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13328)  * Return: true if work posted to worker thread, otherwise false.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13329)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13330) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13331) lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13333) 	struct lpfc_cq_event *cq_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13334) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13336) 	lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13337) 			"0392 Async Event: word0:x%x, word1:x%x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13338) 			"word2:x%x, word3:x%x\n", mcqe->word0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13339) 			mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13341) 	cq_event = lpfc_cq_event_setup(phba, mcqe, sizeof(struct lpfc_mcqe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13342) 	if (!cq_event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13343) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13345) 	spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13346) 	list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13347) 	spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13349) 	/* Set the async event flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13350) 	spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13351) 	phba->hba_flag |= ASYNC_EVENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13352) 	spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13354) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13357) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13358)  * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13359)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13360)  * @mcqe: Pointer to mailbox completion queue entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13361)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13362)  * This routine process a mailbox completion queue entry with mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13363)  * completion event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13364)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13365)  * Return: true if work posted to worker thread, otherwise false.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13366)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13367) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13368) lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13370) 	uint32_t mcqe_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13371) 	MAILBOX_t *mbox, *pmbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13372) 	struct lpfc_mqe *mqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13373) 	struct lpfc_vport *vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13374) 	struct lpfc_nodelist *ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13375) 	struct lpfc_dmabuf *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13376) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13377) 	LPFC_MBOXQ_t *pmb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13378) 	bool workposted = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13379) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13381) 	/* If not a mailbox complete MCQE, out by checking mailbox consume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13382) 	if (!bf_get(lpfc_trailer_completed, mcqe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13383) 		goto out_no_mqe_complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13385) 	/* Get the reference to the active mbox command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13386) 	spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13387) 	pmb = phba->sli.mbox_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13388) 	if (unlikely(!pmb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13389) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13390) 				"1832 No pending MBOX command to handle\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13391) 		spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13392) 		goto out_no_mqe_complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13393) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13394) 	spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13395) 	mqe = &pmb->u.mqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13396) 	pmbox = (MAILBOX_t *)&pmb->u.mqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13397) 	mbox = phba->mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13398) 	vport = pmb->vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13400) 	/* Reset heartbeat timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13401) 	phba->last_completion_time = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13402) 	del_timer(&phba->sli.mbox_tmo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13404) 	/* Move mbox data to caller's mailbox region, do endian swapping */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13405) 	if (pmb->mbox_cmpl && mbox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13406) 		lpfc_sli4_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13408) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13409) 	 * For mcqe errors, conditionally move a modified error code to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13410) 	 * the mbox so that the error will not be missed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13411) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13412) 	mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13413) 	if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13414) 		if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13415) 			bf_set(lpfc_mqe_status, mqe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13416) 			       (LPFC_MBX_ERROR_RANGE | mcqe_status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13417) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13418) 	if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13419) 		pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13420) 		lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13421) 				      "MBOX dflt rpi: status:x%x rpi:x%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13422) 				      mcqe_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13423) 				      pmbox->un.varWords[0], 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13424) 		if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13425) 			mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13426) 			ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13427) 			/* Reg_LOGIN of dflt RPI was successful. Now lets get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13428) 			 * RID of the PPI using the same mbox buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13429) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13430) 			lpfc_unreg_login(phba, vport->vpi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13431) 					 pmbox->un.varWords[0], pmb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13432) 			pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13433) 			pmb->ctx_buf = mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13434) 			pmb->ctx_ndlp = ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13435) 			pmb->vport = vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13436) 			rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13437) 			if (rc != MBX_BUSY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13438) 				lpfc_printf_log(phba, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13439) 						LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13440) 						"0385 rc should "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13441) 						"have been MBX_BUSY\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13442) 			if (rc != MBX_NOT_FINISHED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13443) 				goto send_current_mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13444) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13445) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13446) 	spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13447) 	phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13448) 	spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13450) 	/* There is mailbox completion work to do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13451) 	spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13452) 	__lpfc_mbox_cmpl_put(phba, pmb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13453) 	phba->work_ha |= HA_MBATT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13454) 	spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13455) 	workposted = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13457) send_current_mbox:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13458) 	spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13459) 	/* Release the mailbox command posting token */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13460) 	phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13461) 	/* Setting active mailbox pointer need to be in sync to flag clear */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13462) 	phba->sli.mbox_active = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13463) 	if (bf_get(lpfc_trailer_consumed, mcqe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13464) 		lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13465) 	spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13466) 	/* Wake up worker thread to post the next pending mailbox command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13467) 	lpfc_worker_wake_up(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13468) 	return workposted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13470) out_no_mqe_complete:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13471) 	spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13472) 	if (bf_get(lpfc_trailer_consumed, mcqe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13473) 		lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13474) 	spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13475) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13478) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13479)  * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13480)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13481)  * @cq: Pointer to associated CQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13482)  * @cqe: Pointer to mailbox completion queue entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13483)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13484)  * This routine process a mailbox completion queue entry, it invokes the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13485)  * proper mailbox complete handling or asynchronous event handling routine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13486)  * according to the MCQE's async bit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13487)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13488)  * Return: true if work posted to worker thread, otherwise false.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13489)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13490) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13491) lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13492) 			 struct lpfc_cqe *cqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13493) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13494) 	struct lpfc_mcqe mcqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13495) 	bool workposted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13497) 	cq->CQ_mbox++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13499) 	/* Copy the mailbox MCQE and convert endian order as needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13500) 	lpfc_sli4_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13502) 	/* Invoke the proper event handling routine */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13503) 	if (!bf_get(lpfc_trailer_async, &mcqe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13504) 		workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13505) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13506) 		workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13507) 	return workposted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13510) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13511)  * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13512)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13513)  * @cq: Pointer to associated CQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13514)  * @wcqe: Pointer to work-queue completion queue entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13515)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13516)  * This routine handles an ELS work-queue completion event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13517)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13518)  * Return: true if work posted to worker thread, otherwise false.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13519)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13520) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13521) lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13522) 			     struct lpfc_wcqe_complete *wcqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13523) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13524) 	struct lpfc_iocbq *irspiocbq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13525) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13526) 	struct lpfc_sli_ring *pring = cq->pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13527) 	int txq_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13528) 	int txcmplq_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13530) 	/* Check for response status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13531) 	if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13532) 		/* Log the error status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13533) 		lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13534) 				"0357 ELS CQE error: status=x%x: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13535) 				"CQE: %08x %08x %08x %08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13536) 				bf_get(lpfc_wcqe_c_status, wcqe),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13537) 				wcqe->word0, wcqe->total_data_placed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13538) 				wcqe->parameter, wcqe->word3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13539) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13541) 	/* Get an irspiocbq for later ELS response processing use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13542) 	irspiocbq = lpfc_sli_get_iocbq(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13543) 	if (!irspiocbq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13544) 		if (!list_empty(&pring->txq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13545) 			txq_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13546) 		if (!list_empty(&pring->txcmplq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13547) 			txcmplq_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13548) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13549) 			"0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13550) 			"els_txcmplq_cnt=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13551) 			txq_cnt, phba->iocb_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13552) 			txcmplq_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13553) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13554) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13556) 	/* Save off the slow-path queue event for work thread to process */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13557) 	memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13558) 	spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13559) 	list_add_tail(&irspiocbq->cq_event.list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13560) 		      &phba->sli4_hba.sp_queue_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13561) 	phba->hba_flag |= HBA_SP_QUEUE_EVT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13562) 	spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13564) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13565) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13567) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13568)  * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13569)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13570)  * @wcqe: Pointer to work-queue completion queue entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13571)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13572)  * This routine handles slow-path WQ entry consumed event by invoking the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13573)  * proper WQ release routine to the slow-path WQ.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13574)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13575) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13576) lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13577) 			     struct lpfc_wcqe_release *wcqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13578) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13579) 	/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13580) 	if (unlikely(!phba->sli4_hba.els_wq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13581) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13582) 	/* Check for the slow-path ELS work queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13583) 	if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13584) 		lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13585) 				     bf_get(lpfc_wcqe_r_wqe_index, wcqe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13586) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13587) 		lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13588) 				"2579 Slow-path wqe consume event carries "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13589) 				"miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13590) 				bf_get(lpfc_wcqe_r_wqe_index, wcqe),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13591) 				phba->sli4_hba.els_wq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13594) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13595)  * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13596)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13597)  * @cq: Pointer to a WQ completion queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13598)  * @wcqe: Pointer to work-queue completion queue entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13599)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13600)  * This routine handles an XRI abort event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13601)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13602)  * Return: true if work posted to worker thread, otherwise false.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13603)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13604) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13605) lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13606) 				   struct lpfc_queue *cq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13607) 				   struct sli4_wcqe_xri_aborted *wcqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13608) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13609) 	bool workposted = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13610) 	struct lpfc_cq_event *cq_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13611) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13613) 	switch (cq->subtype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13614) 	case LPFC_IO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13615) 		lpfc_sli4_io_xri_aborted(phba, wcqe, cq->hdwq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13616) 		if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13617) 			/* Notify aborted XRI for NVME work queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13618) 			if (phba->nvmet_support)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13619) 				lpfc_sli4_nvmet_xri_aborted(phba, wcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13620) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13621) 		workposted = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13622) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13623) 	case LPFC_NVME_LS: /* NVME LS uses ELS resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13624) 	case LPFC_ELS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13625) 		cq_event = lpfc_cq_event_setup(phba, wcqe, sizeof(*wcqe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13626) 		if (!cq_event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13627) 			workposted = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13628) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13629) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13630) 		cq_event->hdwq = cq->hdwq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13631) 		spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13632) 				  iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13633) 		list_add_tail(&cq_event->list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13634) 			      &phba->sli4_hba.sp_els_xri_aborted_work_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13635) 		/* Set the els xri abort event flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13636) 		phba->hba_flag |= ELS_XRI_ABORT_EVENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13637) 		spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13638) 				       iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13639) 		workposted = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13640) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13641) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13642) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13643) 				"0603 Invalid CQ subtype %d: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13644) 				"%08x %08x %08x %08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13645) 				cq->subtype, wcqe->word0, wcqe->parameter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13646) 				wcqe->word2, wcqe->word3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13647) 		workposted = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13648) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13649) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13650) 	return workposted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13653) #define FC_RCTL_MDS_DIAGS	0xF4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13655) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13656)  * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13657)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13658)  * @rcqe: Pointer to receive-queue completion queue entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13659)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13660)  * This routine process a receive-queue completion queue entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13661)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13662)  * Return: true if work posted to worker thread, otherwise false.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13663)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13664) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13665) lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13666) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13667) 	bool workposted = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13668) 	struct fc_frame_header *fc_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13669) 	struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13670) 	struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13671) 	struct lpfc_nvmet_tgtport *tgtp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13672) 	struct hbq_dmabuf *dma_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13673) 	uint32_t status, rq_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13674) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13676) 	/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13677) 	if (unlikely(!hrq) || unlikely(!drq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13678) 		return workposted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13680) 	if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13681) 		rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13682) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13683) 		rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13684) 	if (rq_id != hrq->queue_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13685) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13687) 	status = bf_get(lpfc_rcqe_status, rcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13688) 	switch (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13689) 	case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13690) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13691) 				"2537 Receive Frame Truncated!!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13692) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13693) 	case FC_STATUS_RQ_SUCCESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13694) 		spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13695) 		lpfc_sli4_rq_release(hrq, drq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13696) 		dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13697) 		if (!dma_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13698) 			hrq->RQ_no_buf_found++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13699) 			spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13700) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13701) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13702) 		hrq->RQ_rcv_buf++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13703) 		hrq->RQ_buf_posted--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13704) 		memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13706) 		fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13708) 		if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13709) 		    fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13710) 			spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13711) 			/* Handle MDS Loopback frames */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13712) 			if  (!(phba->pport->load_flag & FC_UNLOADING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13713) 				lpfc_sli4_handle_mds_loopback(phba->pport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13714) 							      dma_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13715) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13716) 				lpfc_in_buf_free(phba, &dma_buf->dbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13717) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13718) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13720) 		/* save off the frame for the work thread to process */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13721) 		list_add_tail(&dma_buf->cq_event.list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13722) 			      &phba->sli4_hba.sp_queue_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13723) 		/* Frame received */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13724) 		phba->hba_flag |= HBA_SP_QUEUE_EVT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13725) 		spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13726) 		workposted = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13727) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13728) 	case FC_STATUS_INSUFF_BUF_FRM_DISC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13729) 		if (phba->nvmet_support) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13730) 			tgtp = phba->targetport->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13731) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13732) 					"6402 RQE Error x%x, posted %d err_cnt "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13733) 					"%d: %x %x %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13734) 					status, hrq->RQ_buf_posted,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13735) 					hrq->RQ_no_posted_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13736) 					atomic_read(&tgtp->rcv_fcp_cmd_in),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13737) 					atomic_read(&tgtp->rcv_fcp_cmd_out),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13738) 					atomic_read(&tgtp->xmt_fcp_release));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13739) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13740) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13742) 	case FC_STATUS_INSUFF_BUF_NEED_BUF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13743) 		hrq->RQ_no_posted_buf++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13744) 		/* Post more buffers if possible */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13745) 		spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13746) 		phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13747) 		spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13748) 		workposted = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13749) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13750) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13751) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13752) 	return workposted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13753) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13755) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13756)  * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13757)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13758)  * @cq: Pointer to the completion queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13759)  * @cqe: Pointer to a completion queue entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13760)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13761)  * This routine process a slow-path work-queue or receive queue completion queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13762)  * entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13763)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13764)  * Return: true if work posted to worker thread, otherwise false.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13765)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13766) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13767) lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13768) 			 struct lpfc_cqe *cqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13769) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13770) 	struct lpfc_cqe cqevt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13771) 	bool workposted = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13773) 	/* Copy the work queue CQE and convert endian order if needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13774) 	lpfc_sli4_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13776) 	/* Check and process for different type of WCQE and dispatch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13777) 	switch (bf_get(lpfc_cqe_code, &cqevt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13778) 	case CQE_CODE_COMPL_WQE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13779) 		/* Process the WQ/RQ complete event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13780) 		phba->last_completion_time = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13781) 		workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13782) 				(struct lpfc_wcqe_complete *)&cqevt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13783) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13784) 	case CQE_CODE_RELEASE_WQE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13785) 		/* Process the WQ release event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13786) 		lpfc_sli4_sp_handle_rel_wcqe(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13787) 				(struct lpfc_wcqe_release *)&cqevt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13788) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13789) 	case CQE_CODE_XRI_ABORTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13790) 		/* Process the WQ XRI abort event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13791) 		phba->last_completion_time = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13792) 		workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13793) 				(struct sli4_wcqe_xri_aborted *)&cqevt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13794) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13795) 	case CQE_CODE_RECEIVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13796) 	case CQE_CODE_RECEIVE_V1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13797) 		/* Process the RQ event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13798) 		phba->last_completion_time = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13799) 		workposted = lpfc_sli4_sp_handle_rcqe(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13800) 				(struct lpfc_rcqe *)&cqevt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13801) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13802) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13803) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13804) 				"0388 Not a valid WCQE code: x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13805) 				bf_get(lpfc_cqe_code, &cqevt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13806) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13807) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13808) 	return workposted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13809) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13811) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13812)  * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13813)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13814)  * @eqe: Pointer to fast-path event queue entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13815)  * @speq: Pointer to slow-path event queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13816)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13817)  * This routine process a event queue entry from the slow-path event queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13818)  * It will check the MajorCode and MinorCode to determine this is for a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13819)  * completion event on a completion queue, if not, an error shall be logged
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13820)  * and just return. Otherwise, it will get to the corresponding completion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13821)  * queue and process all the entries on that completion queue, rearm the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13822)  * completion queue, and then return.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13823)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13824)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13825) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13826) lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13827) 	struct lpfc_queue *speq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13828) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13829) 	struct lpfc_queue *cq = NULL, *childq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13830) 	uint16_t cqid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13831) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13833) 	/* Get the reference to the corresponding CQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13834) 	cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13836) 	list_for_each_entry(childq, &speq->child_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13837) 		if (childq->queue_id == cqid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13838) 			cq = childq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13839) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13840) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13841) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13842) 	if (unlikely(!cq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13843) 		if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13844) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13845) 					"0365 Slow-path CQ identifier "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13846) 					"(%d) does not exist\n", cqid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13847) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13848) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13850) 	/* Save EQ associated with this CQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13851) 	cq->assoc_qp = speq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13853) 	if (is_kdump_kernel())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13854) 		ret = queue_work(phba->wq, &cq->spwork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13855) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13856) 		ret = queue_work_on(cq->chann, phba->wq, &cq->spwork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13858) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13859) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13860) 				"0390 Cannot schedule queue work "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13861) 				"for CQ eqcqid=%d, cqid=%d on CPU %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13862) 				cqid, cq->queue_id, raw_smp_processor_id());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13863) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13865) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13866)  * __lpfc_sli4_process_cq - Process elements of a CQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13867)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13868)  * @cq: Pointer to CQ to be processed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13869)  * @handler: Routine to process each cqe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13870)  * @delay: Pointer to usdelay to set in case of rescheduling of the handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13871)  * @poll_mode: Polling mode we were called from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13872)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13873)  * This routine processes completion queue entries in a CQ. While a valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13874)  * queue element is found, the handler is called. During processing checks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13875)  * are made for periodic doorbell writes to let the hardware know of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13876)  * element consumption.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13877)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13878)  * If the max limit on cqes to process is hit, or there are no more valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13879)  * entries, the loop stops. If we processed a sufficient number of elements,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13880)  * meaning there is sufficient load, rather than rearming and generating
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13881)  * another interrupt, a cq rescheduling delay will be set. A delay of 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13882)  * indicates no rescheduling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13883)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13884)  * Returns True if work scheduled, False otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13885)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13886) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13887) __lpfc_sli4_process_cq(struct lpfc_hba *phba, struct lpfc_queue *cq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13888) 	bool (*handler)(struct lpfc_hba *, struct lpfc_queue *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13889) 			struct lpfc_cqe *), unsigned long *delay,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13890) 			enum lpfc_poll_mode poll_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13891) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13892) 	struct lpfc_cqe *cqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13893) 	bool workposted = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13894) 	int count = 0, consumed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13895) 	bool arm = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13897) 	/* default - no reschedule */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13898) 	*delay = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13899) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13900) 	if (cmpxchg(&cq->queue_claimed, 0, 1) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13901) 		goto rearm_and_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13903) 	/* Process all the entries to the CQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13904) 	cq->q_flag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13905) 	cqe = lpfc_sli4_cq_get(cq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13906) 	while (cqe) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13907) 		workposted |= handler(phba, cq, cqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13908) 		__lpfc_sli4_consume_cqe(phba, cq, cqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13910) 		consumed++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13911) 		if (!(++count % cq->max_proc_limit))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13912) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13914) 		if (!(count % cq->notify_interval)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13915) 			phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13916) 						LPFC_QUEUE_NOARM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13917) 			consumed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13918) 			cq->assoc_qp->q_flag |= HBA_EQ_DELAY_CHK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13919) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13921) 		if (count == LPFC_NVMET_CQ_NOTIFY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13922) 			cq->q_flag |= HBA_NVMET_CQ_NOTIFY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13924) 		cqe = lpfc_sli4_cq_get(cq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13925) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13926) 	if (count >= phba->cfg_cq_poll_threshold) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13927) 		*delay = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13928) 		arm = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13929) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13931) 	/* Note: complete the irq_poll softirq before rearming CQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13932) 	if (poll_mode == LPFC_IRQ_POLL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13933) 		irq_poll_complete(&cq->iop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13935) 	/* Track the max number of CQEs processed in 1 EQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13936) 	if (count > cq->CQ_max_cqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13937) 		cq->CQ_max_cqe = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13938) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13939) 	cq->assoc_qp->EQ_cqe_cnt += count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13941) 	/* Catch the no cq entry condition */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13942) 	if (unlikely(count == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13943) 		lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13944) 				"0369 No entry from completion queue "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13945) 				"qid=%d\n", cq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13947) 	xchg(&cq->queue_claimed, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13949) rearm_and_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13950) 	phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13951) 			arm ?  LPFC_QUEUE_REARM : LPFC_QUEUE_NOARM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13952) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13953) 	return workposted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13954) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13955) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13956) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13957)  * lpfc_sli4_sp_process_cq - Process a slow-path event queue entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13958)  * @cq: pointer to CQ to process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13959)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13960)  * This routine calls the cq processing routine with a handler specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13961)  * to the type of queue bound to it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13962)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13963)  * The CQ routine returns two values: the first is the calling status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13964)  * which indicates whether work was queued to the  background discovery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13965)  * thread. If true, the routine should wakeup the discovery thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13966)  * the second is the delay parameter. If non-zero, rather than rearming
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13967)  * the CQ and yet another interrupt, the CQ handler should be queued so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13968)  * that it is processed in a subsequent polling action. The value of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13969)  * the delay indicates when to reschedule it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13970)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13971) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13972) __lpfc_sli4_sp_process_cq(struct lpfc_queue *cq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13973) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13974) 	struct lpfc_hba *phba = cq->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13975) 	unsigned long delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13976) 	bool workposted = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13977) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13979) 	/* Process and rearm the CQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13980) 	switch (cq->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13981) 	case LPFC_MCQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13982) 		workposted |= __lpfc_sli4_process_cq(phba, cq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13983) 						lpfc_sli4_sp_handle_mcqe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13984) 						&delay, LPFC_QUEUE_WORK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13985) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13986) 	case LPFC_WCQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13987) 		if (cq->subtype == LPFC_IO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13988) 			workposted |= __lpfc_sli4_process_cq(phba, cq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13989) 						lpfc_sli4_fp_handle_cqe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13990) 						&delay, LPFC_QUEUE_WORK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13991) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13992) 			workposted |= __lpfc_sli4_process_cq(phba, cq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13993) 						lpfc_sli4_sp_handle_cqe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13994) 						&delay, LPFC_QUEUE_WORK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13995) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13996) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13997) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13998) 				"0370 Invalid completion queue type (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13999) 				cq->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14000) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14001) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14003) 	if (delay) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14004) 		if (is_kdump_kernel())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14005) 			ret = queue_delayed_work(phba->wq, &cq->sched_spwork,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14006) 						delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14007) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14008) 			ret = queue_delayed_work_on(cq->chann, phba->wq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14009) 						&cq->sched_spwork, delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14010) 		if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14011) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14012) 				"0394 Cannot schedule queue work "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14013) 				"for cqid=%d on CPU %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14014) 				cq->queue_id, cq->chann);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14015) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14016) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14017) 	/* wake up worker thread if there are works to be done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14018) 	if (workposted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14019) 		lpfc_worker_wake_up(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14020) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14022) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14023)  * lpfc_sli4_sp_process_cq - slow-path work handler when started by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14024)  *   interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14025)  * @work: pointer to work element
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14026)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14027)  * translates from the work handler and calls the slow-path handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14028)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14029) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14030) lpfc_sli4_sp_process_cq(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14031) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14032) 	struct lpfc_queue *cq = container_of(work, struct lpfc_queue, spwork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14033) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14034) 	__lpfc_sli4_sp_process_cq(cq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14035) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14037) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14038)  * lpfc_sli4_dly_sp_process_cq - slow-path work handler when started by timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14039)  * @work: pointer to work element
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14040)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14041)  * translates from the work handler and calls the slow-path handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14042)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14043) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14044) lpfc_sli4_dly_sp_process_cq(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14045) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14046) 	struct lpfc_queue *cq = container_of(to_delayed_work(work),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14047) 					struct lpfc_queue, sched_spwork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14048) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14049) 	__lpfc_sli4_sp_process_cq(cq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14050) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14051) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14052) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14053)  * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14054)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14055)  * @cq: Pointer to associated CQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14056)  * @wcqe: Pointer to work-queue completion queue entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14057)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14058)  * This routine process a fast-path work queue completion entry from fast-path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14059)  * event queue for FCP command response completion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14060)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14061) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14062) lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14063) 			     struct lpfc_wcqe_complete *wcqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14064) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14065) 	struct lpfc_sli_ring *pring = cq->pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14066) 	struct lpfc_iocbq *cmdiocbq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14067) 	struct lpfc_iocbq irspiocbq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14068) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14070) 	/* Check for response status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14071) 	if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14072) 		/* If resource errors reported from HBA, reduce queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14073) 		 * depth of the SCSI device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14074) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14075) 		if (((bf_get(lpfc_wcqe_c_status, wcqe) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14076) 		     IOSTAT_LOCAL_REJECT)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14077) 		    ((wcqe->parameter & IOERR_PARAM_MASK) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14078) 		     IOERR_NO_RESOURCES))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14079) 			phba->lpfc_rampdown_queue_depth(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14080) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14081) 		/* Log the cmpl status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14082) 		lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14083) 				"0373 FCP CQE cmpl: status=x%x: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14084) 				"CQE: %08x %08x %08x %08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14085) 				bf_get(lpfc_wcqe_c_status, wcqe),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14086) 				wcqe->word0, wcqe->total_data_placed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14087) 				wcqe->parameter, wcqe->word3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14088) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14089) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14090) 	/* Look up the FCP command IOCB and create pseudo response IOCB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14091) 	spin_lock_irqsave(&pring->ring_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14092) 	pring->stats.iocb_event++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14093) 	spin_unlock_irqrestore(&pring->ring_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14094) 	cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14095) 				bf_get(lpfc_wcqe_c_request_tag, wcqe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14096) 	if (unlikely(!cmdiocbq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14097) 		lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14098) 				"0374 FCP complete with no corresponding "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14099) 				"cmdiocb: iotag (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14100) 				bf_get(lpfc_wcqe_c_request_tag, wcqe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14101) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14103) #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14104) 	cmdiocbq->isr_timestamp = cq->isr_timestamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14105) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14106) 	if (cmdiocbq->iocb_cmpl == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14107) 		if (cmdiocbq->wqe_cmpl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14108) 			if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14109) 				spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14110) 				cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14111) 				spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14112) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14114) 			/* Pass the cmd_iocb and the wcqe to the upper layer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14115) 			(cmdiocbq->wqe_cmpl)(phba, cmdiocbq, wcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14116) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14117) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14118) 		lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14119) 				"0375 FCP cmdiocb not callback function "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14120) 				"iotag: (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14121) 				bf_get(lpfc_wcqe_c_request_tag, wcqe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14122) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14123) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14125) 	/* Fake the irspiocb and copy necessary response information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14126) 	lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14128) 	if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14129) 		spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14130) 		cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14131) 		spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14132) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14134) 	/* Pass the cmd_iocb and the rsp state to the upper layer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14135) 	(cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14138) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14139)  * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14140)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14141)  * @cq: Pointer to completion queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14142)  * @wcqe: Pointer to work-queue completion queue entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14143)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14144)  * This routine handles an fast-path WQ entry consumed event by invoking the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14145)  * proper WQ release routine to the slow-path WQ.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14146)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14147) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14148) lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14149) 			     struct lpfc_wcqe_release *wcqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14151) 	struct lpfc_queue *childwq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14152) 	bool wqid_matched = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14153) 	uint16_t hba_wqid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14155) 	/* Check for fast-path FCP work queue release */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14156) 	hba_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14157) 	list_for_each_entry(childwq, &cq->child_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14158) 		if (childwq->queue_id == hba_wqid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14159) 			lpfc_sli4_wq_release(childwq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14160) 					bf_get(lpfc_wcqe_r_wqe_index, wcqe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14161) 			if (childwq->q_flag & HBA_NVMET_WQFULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14162) 				lpfc_nvmet_wqfull_process(phba, childwq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14163) 			wqid_matched = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14164) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14165) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14166) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14167) 	/* Report warning log message if no match found */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14168) 	if (wqid_matched != true)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14169) 		lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14170) 				"2580 Fast-path wqe consume event carries "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14171) 				"miss-matched qid: wcqe-qid=x%x\n", hba_wqid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14174) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14175)  * lpfc_sli4_nvmet_handle_rcqe - Process a receive-queue completion queue entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14176)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14177)  * @cq: Pointer to completion queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14178)  * @rcqe: Pointer to receive-queue completion queue entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14179)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14180)  * This routine process a receive-queue completion queue entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14181)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14182)  * Return: true if work posted to worker thread, otherwise false.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14183)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14184) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14185) lpfc_sli4_nvmet_handle_rcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14186) 			    struct lpfc_rcqe *rcqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14188) 	bool workposted = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14189) 	struct lpfc_queue *hrq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14190) 	struct lpfc_queue *drq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14191) 	struct rqb_dmabuf *dma_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14192) 	struct fc_frame_header *fc_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14193) 	struct lpfc_nvmet_tgtport *tgtp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14194) 	uint32_t status, rq_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14195) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14196) 	uint32_t fctl, idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14198) 	if ((phba->nvmet_support == 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14199) 	    (phba->sli4_hba.nvmet_cqset == NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14200) 		return workposted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14202) 	idx = cq->queue_id - phba->sli4_hba.nvmet_cqset[0]->queue_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14203) 	hrq = phba->sli4_hba.nvmet_mrq_hdr[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14204) 	drq = phba->sli4_hba.nvmet_mrq_data[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14206) 	/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14207) 	if (unlikely(!hrq) || unlikely(!drq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14208) 		return workposted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14210) 	if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14211) 		rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14212) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14213) 		rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14215) 	if ((phba->nvmet_support == 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14216) 	    (rq_id != hrq->queue_id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14217) 		return workposted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14219) 	status = bf_get(lpfc_rcqe_status, rcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14220) 	switch (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14221) 	case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14222) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14223) 				"6126 Receive Frame Truncated!!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14224) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14225) 	case FC_STATUS_RQ_SUCCESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14226) 		spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14227) 		lpfc_sli4_rq_release(hrq, drq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14228) 		dma_buf = lpfc_sli_rqbuf_get(phba, hrq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14229) 		if (!dma_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14230) 			hrq->RQ_no_buf_found++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14231) 			spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14232) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14233) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14234) 		spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14235) 		hrq->RQ_rcv_buf++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14236) 		hrq->RQ_buf_posted--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14237) 		fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14239) 		/* Just some basic sanity checks on FCP Command frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14240) 		fctl = (fc_hdr->fh_f_ctl[0] << 16 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14241) 			fc_hdr->fh_f_ctl[1] << 8 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14242) 			fc_hdr->fh_f_ctl[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14243) 		if (((fctl &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14244) 		    (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14245) 		    (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14246) 		    (fc_hdr->fh_seq_cnt != 0)) /* 0 byte swapped is still 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14247) 			goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14249) 		if (fc_hdr->fh_type == FC_TYPE_FCP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14250) 			dma_buf->bytes_recv = bf_get(lpfc_rcqe_length, rcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14251) 			lpfc_nvmet_unsol_fcp_event(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14252) 				phba, idx, dma_buf, cq->isr_timestamp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14253) 				cq->q_flag & HBA_NVMET_CQ_NOTIFY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14254) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14255) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14256) drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14257) 		lpfc_rq_buf_free(phba, &dma_buf->hbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14258) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14259) 	case FC_STATUS_INSUFF_BUF_FRM_DISC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14260) 		if (phba->nvmet_support) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14261) 			tgtp = phba->targetport->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14262) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14263) 					"6401 RQE Error x%x, posted %d err_cnt "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14264) 					"%d: %x %x %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14265) 					status, hrq->RQ_buf_posted,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14266) 					hrq->RQ_no_posted_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14267) 					atomic_read(&tgtp->rcv_fcp_cmd_in),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14268) 					atomic_read(&tgtp->rcv_fcp_cmd_out),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14269) 					atomic_read(&tgtp->xmt_fcp_release));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14270) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14271) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14273) 	case FC_STATUS_INSUFF_BUF_NEED_BUF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14274) 		hrq->RQ_no_posted_buf++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14275) 		/* Post more buffers if possible */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14276) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14277) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14278) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14279) 	return workposted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14282) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14283)  * lpfc_sli4_fp_handle_cqe - Process fast-path work queue completion entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14284)  * @phba: adapter with cq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14285)  * @cq: Pointer to the completion queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14286)  * @cqe: Pointer to fast-path completion queue entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14287)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14288)  * This routine process a fast-path work queue completion entry from fast-path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14289)  * event queue for FCP command response completion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14290)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14291)  * Return: true if work posted to worker thread, otherwise false.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14292)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14293) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14294) lpfc_sli4_fp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14295) 			 struct lpfc_cqe *cqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14297) 	struct lpfc_wcqe_release wcqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14298) 	bool workposted = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14300) 	/* Copy the work queue CQE and convert endian order if needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14301) 	lpfc_sli4_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14303) 	/* Check and process for different type of WCQE and dispatch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14304) 	switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14305) 	case CQE_CODE_COMPL_WQE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14306) 	case CQE_CODE_NVME_ERSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14307) 		cq->CQ_wq++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14308) 		/* Process the WQ complete event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14309) 		phba->last_completion_time = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14310) 		if (cq->subtype == LPFC_IO || cq->subtype == LPFC_NVME_LS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14311) 			lpfc_sli4_fp_handle_fcp_wcqe(phba, cq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14312) 				(struct lpfc_wcqe_complete *)&wcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14313) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14314) 	case CQE_CODE_RELEASE_WQE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14315) 		cq->CQ_release_wqe++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14316) 		/* Process the WQ release event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14317) 		lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14318) 				(struct lpfc_wcqe_release *)&wcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14319) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14320) 	case CQE_CODE_XRI_ABORTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14321) 		cq->CQ_xri_aborted++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14322) 		/* Process the WQ XRI abort event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14323) 		phba->last_completion_time = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14324) 		workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14325) 				(struct sli4_wcqe_xri_aborted *)&wcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14326) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14327) 	case CQE_CODE_RECEIVE_V1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14328) 	case CQE_CODE_RECEIVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14329) 		phba->last_completion_time = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14330) 		if (cq->subtype == LPFC_NVMET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14331) 			workposted = lpfc_sli4_nvmet_handle_rcqe(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14332) 				phba, cq, (struct lpfc_rcqe *)&wcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14333) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14334) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14335) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14336) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14337) 				"0144 Not a valid CQE code: x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14338) 				bf_get(lpfc_wcqe_c_code, &wcqe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14339) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14340) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14341) 	return workposted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14344) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14345)  * lpfc_sli4_sched_cq_work - Schedules cq work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14346)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14347)  * @cq: Pointer to CQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14348)  * @cqid: CQ ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14349)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14350)  * This routine checks the poll mode of the CQ corresponding to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14351)  * cq->chann, then either schedules a softirq or queue_work to complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14352)  * cq work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14353)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14354)  * queue_work path is taken if in NVMET mode, or if poll_mode is in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14355)  * LPFC_QUEUE_WORK mode.  Otherwise, softirq path is taken.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14356)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14357)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14358) static void lpfc_sli4_sched_cq_work(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14359) 				    struct lpfc_queue *cq, uint16_t cqid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14360) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14361) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14363) 	switch (cq->poll_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14364) 	case LPFC_IRQ_POLL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14365) 		irq_poll_sched(&cq->iop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14366) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14367) 	case LPFC_QUEUE_WORK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14368) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14369) 		if (is_kdump_kernel())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14370) 			ret = queue_work(phba->wq, &cq->irqwork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14371) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14372) 			ret = queue_work_on(cq->chann, phba->wq, &cq->irqwork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14373) 		if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14374) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14375) 					"0383 Cannot schedule queue work "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14376) 					"for CQ eqcqid=%d, cqid=%d on CPU %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14377) 					cqid, cq->queue_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14378) 					raw_smp_processor_id());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14379) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14382) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14383)  * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14384)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14385)  * @eq: Pointer to the queue structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14386)  * @eqe: Pointer to fast-path event queue entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14387)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14388)  * This routine process a event queue entry from the fast-path event queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14389)  * It will check the MajorCode and MinorCode to determine this is for a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14390)  * completion event on a completion queue, if not, an error shall be logged
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14391)  * and just return. Otherwise, it will get to the corresponding completion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14392)  * queue and process all the entries on the completion queue, rearm the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14393)  * completion queue, and then return.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14394)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14395) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14396) lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_queue *eq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14397) 			 struct lpfc_eqe *eqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14399) 	struct lpfc_queue *cq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14400) 	uint32_t qidx = eq->hdwq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14401) 	uint16_t cqid, id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14403) 	if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14404) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14405) 				"0366 Not a valid completion "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14406) 				"event: majorcode=x%x, minorcode=x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14407) 				bf_get_le32(lpfc_eqe_major_code, eqe),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14408) 				bf_get_le32(lpfc_eqe_minor_code, eqe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14409) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14410) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14412) 	/* Get the reference to the corresponding CQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14413) 	cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14415) 	/* Use the fast lookup method first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14416) 	if (cqid <= phba->sli4_hba.cq_max) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14417) 		cq = phba->sli4_hba.cq_lookup[cqid];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14418) 		if (cq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14419) 			goto  work_cq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14420) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14422) 	/* Next check for NVMET completion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14423) 	if (phba->cfg_nvmet_mrq && phba->sli4_hba.nvmet_cqset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14424) 		id = phba->sli4_hba.nvmet_cqset[0]->queue_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14425) 		if ((cqid >= id) && (cqid < (id + phba->cfg_nvmet_mrq))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14426) 			/* Process NVMET unsol rcv */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14427) 			cq = phba->sli4_hba.nvmet_cqset[cqid - id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14428) 			goto  process_cq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14429) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14430) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14432) 	if (phba->sli4_hba.nvmels_cq &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14433) 	    (cqid == phba->sli4_hba.nvmels_cq->queue_id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14434) 		/* Process NVME unsol rcv */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14435) 		cq = phba->sli4_hba.nvmels_cq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14436) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14438) 	/* Otherwise this is a Slow path event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14439) 	if (cq == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14440) 		lpfc_sli4_sp_handle_eqe(phba, eqe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14441) 					phba->sli4_hba.hdwq[qidx].hba_eq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14442) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14443) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14445) process_cq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14446) 	if (unlikely(cqid != cq->queue_id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14447) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14448) 				"0368 Miss-matched fast-path completion "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14449) 				"queue identifier: eqcqid=%d, fcpcqid=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14450) 				cqid, cq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14451) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14452) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14454) work_cq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14455) #if defined(CONFIG_SCSI_LPFC_DEBUG_FS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14456) 	if (phba->ktime_on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14457) 		cq->isr_timestamp = ktime_get_ns();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14458) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14459) 		cq->isr_timestamp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14460) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14461) 	lpfc_sli4_sched_cq_work(phba, cq, cqid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14464) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14465)  * __lpfc_sli4_hba_process_cq - Process a fast-path event queue entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14466)  * @cq: Pointer to CQ to be processed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14467)  * @poll_mode: Enum lpfc_poll_state to determine poll mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14468)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14469)  * This routine calls the cq processing routine with the handler for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14470)  * fast path CQEs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14471)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14472)  * The CQ routine returns two values: the first is the calling status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14473)  * which indicates whether work was queued to the  background discovery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14474)  * thread. If true, the routine should wakeup the discovery thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14475)  * the second is the delay parameter. If non-zero, rather than rearming
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14476)  * the CQ and yet another interrupt, the CQ handler should be queued so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14477)  * that it is processed in a subsequent polling action. The value of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14478)  * the delay indicates when to reschedule it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14479)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14480) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14481) __lpfc_sli4_hba_process_cq(struct lpfc_queue *cq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14482) 			   enum lpfc_poll_mode poll_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14483) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14484) 	struct lpfc_hba *phba = cq->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14485) 	unsigned long delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14486) 	bool workposted = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14487) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14489) 	/* process and rearm the CQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14490) 	workposted |= __lpfc_sli4_process_cq(phba, cq, lpfc_sli4_fp_handle_cqe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14491) 					     &delay, poll_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14493) 	if (delay) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14494) 		if (is_kdump_kernel())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14495) 			ret = queue_delayed_work(phba->wq, &cq->sched_irqwork,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14496) 						delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14497) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14498) 			ret = queue_delayed_work_on(cq->chann, phba->wq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14499) 						&cq->sched_irqwork, delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14500) 		if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14501) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14502) 					"0367 Cannot schedule queue work "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14503) 					"for cqid=%d on CPU %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14504) 					cq->queue_id, cq->chann);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14505) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14507) 	/* wake up worker thread if there are works to be done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14508) 	if (workposted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14509) 		lpfc_worker_wake_up(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14512) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14513)  * lpfc_sli4_hba_process_cq - fast-path work handler when started by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14514)  *   interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14515)  * @work: pointer to work element
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14516)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14517)  * translates from the work handler and calls the fast-path handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14518)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14519) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14520) lpfc_sli4_hba_process_cq(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14521) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14522) 	struct lpfc_queue *cq = container_of(work, struct lpfc_queue, irqwork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14524) 	__lpfc_sli4_hba_process_cq(cq, LPFC_QUEUE_WORK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14527) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14528)  * lpfc_sli4_hba_process_cq - fast-path work handler when started by timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14529)  * @work: pointer to work element
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14530)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14531)  * translates from the work handler and calls the fast-path handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14532)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14533) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14534) lpfc_sli4_dly_hba_process_cq(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14535) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14536) 	struct lpfc_queue *cq = container_of(to_delayed_work(work),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14537) 					struct lpfc_queue, sched_irqwork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14539) 	__lpfc_sli4_hba_process_cq(cq, LPFC_QUEUE_WORK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14542) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14543)  * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14544)  * @irq: Interrupt number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14545)  * @dev_id: The device context pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14546)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14547)  * This function is directly called from the PCI layer as an interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14548)  * service routine when device with SLI-4 interface spec is enabled with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14549)  * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14550)  * ring event in the HBA. However, when the device is enabled with either
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14551)  * MSI or Pin-IRQ interrupt mode, this function is called as part of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14552)  * device-level interrupt handler. When the PCI slot is in error recovery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14553)  * or the HBA is undergoing initialization, the interrupt handler will not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14554)  * process the interrupt. The SCSI FCP fast-path ring event are handled in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14555)  * the intrrupt context. This function is called without any lock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14556)  * It gets the hbalock to access and update SLI data structures. Note that,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14557)  * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14558)  * equal to that of FCP CQ index.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14559)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14560)  * The link attention and ELS ring attention events are handled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14561)  * by the worker thread. The interrupt handler signals the worker thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14562)  * and returns for these events. This function is called without any lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14563)  * held. It gets the hbalock to access and update SLI data structures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14564)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14565)  * This function returns IRQ_HANDLED when interrupt is handled else it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14566)  * returns IRQ_NONE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14567)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14568) irqreturn_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14569) lpfc_sli4_hba_intr_handler(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14570) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14571) 	struct lpfc_hba *phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14572) 	struct lpfc_hba_eq_hdl *hba_eq_hdl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14573) 	struct lpfc_queue *fpeq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14574) 	unsigned long iflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14575) 	int ecount = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14576) 	int hba_eqidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14577) 	struct lpfc_eq_intr_info *eqi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14579) 	/* Get the driver's phba structure from the dev_id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14580) 	hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14581) 	phba = hba_eq_hdl->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14582) 	hba_eqidx = hba_eq_hdl->idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14584) 	if (unlikely(!phba))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14585) 		return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14586) 	if (unlikely(!phba->sli4_hba.hdwq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14587) 		return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14589) 	/* Get to the EQ struct associated with this vector */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14590) 	fpeq = phba->sli4_hba.hba_eq_hdl[hba_eqidx].eq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14591) 	if (unlikely(!fpeq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14592) 		return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14594) 	/* Check device state for handling interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14595) 	if (unlikely(lpfc_intr_state_check(phba))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14596) 		/* Check again for link_state with lock held */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14597) 		spin_lock_irqsave(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14598) 		if (phba->link_state < LPFC_LINK_DOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14599) 			/* Flush, clear interrupt, and rearm the EQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14600) 			lpfc_sli4_eqcq_flush(phba, fpeq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14601) 		spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14602) 		return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14603) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14605) 	eqi = this_cpu_ptr(phba->sli4_hba.eq_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14606) 	eqi->icnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14608) 	fpeq->last_cpu = raw_smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14610) 	if (eqi->icnt > LPFC_EQD_ISR_TRIGGER &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14611) 	    fpeq->q_flag & HBA_EQ_DELAY_CHK &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14612) 	    phba->cfg_auto_imax &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14613) 	    fpeq->q_mode != LPFC_MAX_AUTO_EQ_DELAY &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14614) 	    phba->sli.sli_flag & LPFC_SLI_USE_EQDR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14615) 		lpfc_sli4_mod_hba_eq_delay(phba, fpeq, LPFC_MAX_AUTO_EQ_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14617) 	/* process and rearm the EQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14618) 	ecount = lpfc_sli4_process_eq(phba, fpeq, LPFC_QUEUE_REARM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14620) 	if (unlikely(ecount == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14621) 		fpeq->EQ_no_entry++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14622) 		if (phba->intr_type == MSIX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14623) 			/* MSI-X treated interrupt served as no EQ share INT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14624) 			lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14625) 					"0358 MSI-X interrupt with no EQE\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14626) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14627) 			/* Non MSI-X treated on interrupt as EQ share INT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14628) 			return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14629) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14631) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14632) } /* lpfc_sli4_fp_intr_handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14634) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14635)  * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14636)  * @irq: Interrupt number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14637)  * @dev_id: The device context pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14638)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14639)  * This function is the device-level interrupt handler to device with SLI-4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14640)  * interface spec, called from the PCI layer when either MSI or Pin-IRQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14641)  * interrupt mode is enabled and there is an event in the HBA which requires
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14642)  * driver attention. This function invokes the slow-path interrupt attention
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14643)  * handling function and fast-path interrupt attention handling function in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14644)  * turn to process the relevant HBA attention events. This function is called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14645)  * without any lock held. It gets the hbalock to access and update SLI data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14646)  * structures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14647)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14648)  * This function returns IRQ_HANDLED when interrupt is handled, else it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14649)  * returns IRQ_NONE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14650)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14651) irqreturn_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14652) lpfc_sli4_intr_handler(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14653) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14654) 	struct lpfc_hba  *phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14655) 	irqreturn_t hba_irq_rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14656) 	bool hba_handled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14657) 	int qidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14659) 	/* Get the driver's phba structure from the dev_id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14660) 	phba = (struct lpfc_hba *)dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14662) 	if (unlikely(!phba))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14663) 		return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14665) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14666) 	 * Invoke fast-path host attention interrupt handling as appropriate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14667) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14668) 	for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14669) 		hba_irq_rc = lpfc_sli4_hba_intr_handler(irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14670) 					&phba->sli4_hba.hba_eq_hdl[qidx]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14671) 		if (hba_irq_rc == IRQ_HANDLED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14672) 			hba_handled |= true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14673) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14675) 	return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14676) } /* lpfc_sli4_intr_handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14678) void lpfc_sli4_poll_hbtimer(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14679) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14680) 	struct lpfc_hba *phba = from_timer(phba, t, cpuhp_poll_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14681) 	struct lpfc_queue *eq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14682) 	int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14684) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14686) 	list_for_each_entry_rcu(eq, &phba->poll_list, _poll_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14687) 		i += lpfc_sli4_poll_eq(eq, LPFC_POLL_SLOWPATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14688) 	if (!list_empty(&phba->poll_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14689) 		mod_timer(&phba->cpuhp_poll_timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14690) 			  jiffies + msecs_to_jiffies(LPFC_POLL_HB));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14692) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14693) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14695) inline int lpfc_sli4_poll_eq(struct lpfc_queue *eq, uint8_t path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14696) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14697) 	struct lpfc_hba *phba = eq->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14698) 	int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14700) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14701) 	 * Unlocking an irq is one of the entry point to check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14702) 	 * for re-schedule, but we are good for io submission
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14703) 	 * path as midlayer does a get_cpu to glue us in. Flush
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14704) 	 * out the invalidate queue so we can see the updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14705) 	 * value for flag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14706) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14707) 	smp_rmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14709) 	if (READ_ONCE(eq->mode) == LPFC_EQ_POLL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14710) 		/* We will not likely get the completion for the caller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14711) 		 * during this iteration but i guess that's fine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14712) 		 * Future io's coming on this eq should be able to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14713) 		 * pick it up.  As for the case of single io's, they
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14714) 		 * will be handled through a sched from polling timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14715) 		 * function which is currently triggered every 1msec.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14716) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14717) 		i = lpfc_sli4_process_eq(phba, eq, LPFC_QUEUE_NOARM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14719) 	return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14720) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14721) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14722) static inline void lpfc_sli4_add_to_poll_list(struct lpfc_queue *eq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14723) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14724) 	struct lpfc_hba *phba = eq->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14726) 	/* kickstart slowpath processing if needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14727) 	if (list_empty(&phba->poll_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14728) 		mod_timer(&phba->cpuhp_poll_timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14729) 			  jiffies + msecs_to_jiffies(LPFC_POLL_HB));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14731) 	list_add_rcu(&eq->_poll_list, &phba->poll_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14732) 	synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14735) static inline void lpfc_sli4_remove_from_poll_list(struct lpfc_queue *eq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14736) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14737) 	struct lpfc_hba *phba = eq->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14739) 	/* Disable slowpath processing for this eq.  Kick start the eq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14740) 	 * by RE-ARMING the eq's ASAP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14741) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14742) 	list_del_rcu(&eq->_poll_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14743) 	synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14745) 	if (list_empty(&phba->poll_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14746) 		del_timer_sync(&phba->cpuhp_poll_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14747) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14749) void lpfc_sli4_cleanup_poll_list(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14750) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14751) 	struct lpfc_queue *eq, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14753) 	list_for_each_entry_safe(eq, next, &phba->poll_list, _poll_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14754) 		list_del(&eq->_poll_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14756) 	INIT_LIST_HEAD(&phba->poll_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14757) 	synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14758) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14760) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14761) __lpfc_sli4_switch_eqmode(struct lpfc_queue *eq, uint8_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14762) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14763) 	if (mode == eq->mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14764) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14765) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14766) 	 * currently this function is only called during a hotplug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14767) 	 * event and the cpu on which this function is executing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14768) 	 * is going offline.  By now the hotplug has instructed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14769) 	 * the scheduler to remove this cpu from cpu active mask.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14770) 	 * So we don't need to work about being put aside by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14771) 	 * scheduler for a high priority process.  Yes, the inte-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14772) 	 * rrupts could come but they are known to retire ASAP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14773) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14775) 	/* Disable polling in the fastpath */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14776) 	WRITE_ONCE(eq->mode, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14777) 	/* flush out the store buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14778) 	smp_wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14780) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14781) 	 * Add this eq to the polling list and start polling. For
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14782) 	 * a grace period both interrupt handler and poller will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14783) 	 * try to process the eq _but_ that's fine.  We have a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14784) 	 * synchronization mechanism in place (queue_claimed) to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14785) 	 * deal with it.  This is just a draining phase for int-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14786) 	 * errupt handler (not eq's) as we have guranteed through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14787) 	 * barrier that all the CPUs have seen the new CQ_POLLED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14788) 	 * state. which will effectively disable the REARMING of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14789) 	 * the EQ.  The whole idea is eq's die off eventually as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14790) 	 * we are not rearming EQ's anymore.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14791) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14792) 	mode ? lpfc_sli4_add_to_poll_list(eq) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14793) 	       lpfc_sli4_remove_from_poll_list(eq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14796) void lpfc_sli4_start_polling(struct lpfc_queue *eq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14797) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14798) 	__lpfc_sli4_switch_eqmode(eq, LPFC_EQ_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14799) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14801) void lpfc_sli4_stop_polling(struct lpfc_queue *eq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14802) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14803) 	struct lpfc_hba *phba = eq->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14805) 	__lpfc_sli4_switch_eqmode(eq, LPFC_EQ_INTERRUPT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14807) 	/* Kick start for the pending io's in h/w.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14808) 	 * Once we switch back to interrupt processing on a eq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14809) 	 * the io path completion will only arm eq's when it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14810) 	 * receives a completion.  But since eq's are in disa-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14811) 	 * rmed state it doesn't receive a completion.  This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14812) 	 * creates a deadlock scenaro.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14813) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14814) 	phba->sli4_hba.sli4_write_eq_db(phba, eq, 0, LPFC_QUEUE_REARM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14815) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14817) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14818)  * lpfc_sli4_queue_free - free a queue structure and associated memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14819)  * @queue: The queue structure to free.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14820)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14821)  * This function frees a queue structure and the DMAable memory used for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14822)  * the host resident queue. This function must be called after destroying the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14823)  * queue on the HBA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14824)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14825) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14826) lpfc_sli4_queue_free(struct lpfc_queue *queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14827) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14828) 	struct lpfc_dmabuf *dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14830) 	if (!queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14831) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14833) 	if (!list_empty(&queue->wq_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14834) 		list_del(&queue->wq_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14836) 	while (!list_empty(&queue->page_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14837) 		list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14838) 				 list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14839) 		dma_free_coherent(&queue->phba->pcidev->dev, queue->page_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14840) 				  dmabuf->virt, dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14841) 		kfree(dmabuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14842) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14843) 	if (queue->rqbp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14844) 		lpfc_free_rq_buffer(queue->phba, queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14845) 		kfree(queue->rqbp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14846) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14848) 	if (!list_empty(&queue->cpu_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14849) 		list_del(&queue->cpu_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14851) 	kfree(queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14852) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14853) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14854) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14855) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14856)  * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14857)  * @phba: The HBA that this queue is being created on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14858)  * @page_size: The size of a queue page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14859)  * @entry_size: The size of each queue entry for this queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14860)  * @entry_count: The number of entries that this queue will handle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14861)  * @cpu: The cpu that will primarily utilize this queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14862)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14863)  * This function allocates a queue structure and the DMAable memory used for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14864)  * the host resident queue. This function must be called before creating the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14865)  * queue on the HBA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14866)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14867) struct lpfc_queue *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14868) lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t page_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14869) 		      uint32_t entry_size, uint32_t entry_count, int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14870) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14871) 	struct lpfc_queue *queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14872) 	struct lpfc_dmabuf *dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14873) 	uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14874) 	uint16_t x, pgcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14876) 	if (!phba->sli4_hba.pc_sli4_params.supported)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14877) 		hw_page_size = page_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14879) 	pgcnt = ALIGN(entry_size * entry_count, hw_page_size) / hw_page_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14881) 	/* If needed, Adjust page count to match the max the adapter supports */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14882) 	if (pgcnt > phba->sli4_hba.pc_sli4_params.wqpcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14883) 		pgcnt = phba->sli4_hba.pc_sli4_params.wqpcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14885) 	queue = kzalloc_node(sizeof(*queue) + (sizeof(void *) * pgcnt),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14886) 			     GFP_KERNEL, cpu_to_node(cpu));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14887) 	if (!queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14888) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14890) 	INIT_LIST_HEAD(&queue->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14891) 	INIT_LIST_HEAD(&queue->_poll_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14892) 	INIT_LIST_HEAD(&queue->wq_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14893) 	INIT_LIST_HEAD(&queue->wqfull_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14894) 	INIT_LIST_HEAD(&queue->page_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14895) 	INIT_LIST_HEAD(&queue->child_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14896) 	INIT_LIST_HEAD(&queue->cpu_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14898) 	/* Set queue parameters now.  If the system cannot provide memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14899) 	 * resources, the free routine needs to know what was allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14900) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14901) 	queue->page_count = pgcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14902) 	queue->q_pgs = (void **)&queue[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14903) 	queue->entry_cnt_per_pg = hw_page_size / entry_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14904) 	queue->entry_size = entry_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14905) 	queue->entry_count = entry_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14906) 	queue->page_size = hw_page_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14907) 	queue->phba = phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14909) 	for (x = 0; x < queue->page_count; x++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14910) 		dmabuf = kzalloc_node(sizeof(*dmabuf), GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14911) 				      dev_to_node(&phba->pcidev->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14912) 		if (!dmabuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14913) 			goto out_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14914) 		dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14915) 						  hw_page_size, &dmabuf->phys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14916) 						  GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14917) 		if (!dmabuf->virt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14918) 			kfree(dmabuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14919) 			goto out_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14920) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14921) 		dmabuf->buffer_tag = x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14922) 		list_add_tail(&dmabuf->list, &queue->page_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14923) 		/* use lpfc_sli4_qe to index a paritcular entry in this page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14924) 		queue->q_pgs[x] = dmabuf->virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14925) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14926) 	INIT_WORK(&queue->irqwork, lpfc_sli4_hba_process_cq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14927) 	INIT_WORK(&queue->spwork, lpfc_sli4_sp_process_cq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14928) 	INIT_DELAYED_WORK(&queue->sched_irqwork, lpfc_sli4_dly_hba_process_cq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14929) 	INIT_DELAYED_WORK(&queue->sched_spwork, lpfc_sli4_dly_sp_process_cq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14931) 	/* notify_interval will be set during q creation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14933) 	return queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14934) out_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14935) 	lpfc_sli4_queue_free(queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14936) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14937) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14938) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14939) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14940)  * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14941)  * @phba: HBA structure that indicates port to create a queue on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14942)  * @pci_barset: PCI BAR set flag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14943)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14944)  * This function shall perform iomap of the specified PCI BAR address to host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14945)  * memory address if not already done so and return it. The returned host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14946)  * memory address can be NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14947)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14948) static void __iomem *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14949) lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14950) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14951) 	if (!phba->pcidev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14952) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14953) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14954) 	switch (pci_barset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14955) 	case WQ_PCI_BAR_0_AND_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14956) 		return phba->pci_bar0_memmap_p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14957) 	case WQ_PCI_BAR_2_AND_3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14958) 		return phba->pci_bar2_memmap_p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14959) 	case WQ_PCI_BAR_4_AND_5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14960) 		return phba->pci_bar4_memmap_p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14961) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14962) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14963) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14964) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14965) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14967) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14968)  * lpfc_modify_hba_eq_delay - Modify Delay Multiplier on EQs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14969)  * @phba: HBA structure that EQs are on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14970)  * @startq: The starting EQ index to modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14971)  * @numq: The number of EQs (consecutive indexes) to modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14972)  * @usdelay: amount of delay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14973)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14974)  * This function revises the EQ delay on 1 or more EQs. The EQ delay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14975)  * is set either by writing to a register (if supported by the SLI Port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14976)  * or by mailbox command. The mailbox command allows several EQs to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14977)  * updated at once.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14978)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14979)  * The @phba struct is used to send a mailbox command to HBA. The @startq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14980)  * is used to get the starting EQ index to change. The @numq value is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14981)  * used to specify how many consecutive EQ indexes, starting at EQ index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14982)  * are to be changed. This function is asynchronous and will wait for any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14983)  * mailbox commands to finish before returning.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14984)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14985)  * On success this function will return a zero. If unable to allocate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14986)  * enough memory this function will return -ENOMEM. If a mailbox command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14987)  * fails this function will return -ENXIO. Note: on ENXIO, some EQs may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14988)  * have had their delay multipler changed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14989)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14990) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14991) lpfc_modify_hba_eq_delay(struct lpfc_hba *phba, uint32_t startq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14992) 			 uint32_t numq, uint32_t usdelay)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14993) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14994) 	struct lpfc_mbx_modify_eq_delay *eq_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14995) 	LPFC_MBOXQ_t *mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14996) 	struct lpfc_queue *eq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14997) 	int cnt = 0, rc, length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14998) 	uint32_t shdr_status, shdr_add_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14999) 	uint32_t dmult;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15000) 	int qidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15001) 	union lpfc_sli4_cfg_shdr *shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15003) 	if (startq >= phba->cfg_irq_chann)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15004) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15005) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15006) 	if (usdelay > 0xFFFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15007) 		lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP | LOG_NVME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15008) 				"6429 usdelay %d too large. Scaled down to "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15009) 				"0xFFFF.\n", usdelay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15010) 		usdelay = 0xFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15011) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15013) 	/* set values by EQ_DELAY register if supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15014) 	if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15015) 		for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15016) 			eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15017) 			if (!eq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15018) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15019) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15020) 			lpfc_sli4_mod_hba_eq_delay(phba, eq, usdelay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15022) 			if (++cnt >= numq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15023) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15024) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15025) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15026) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15028) 	/* Otherwise, set values by mailbox cmd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15030) 	mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15031) 	if (!mbox) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15032) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15033) 				"6428 Failed allocating mailbox cmd buffer."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15034) 				" EQ delay was not set.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15035) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15036) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15037) 	length = (sizeof(struct lpfc_mbx_modify_eq_delay) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15038) 		  sizeof(struct lpfc_sli4_cfg_mhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15039) 	lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15040) 			 LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15041) 			 length, LPFC_SLI4_MBX_EMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15042) 	eq_delay = &mbox->u.mqe.un.eq_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15044) 	/* Calculate delay multiper from maximum interrupt per second */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15045) 	dmult = (usdelay * LPFC_DMULT_CONST) / LPFC_SEC_TO_USEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15046) 	if (dmult)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15047) 		dmult--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15048) 	if (dmult > LPFC_DMULT_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15049) 		dmult = LPFC_DMULT_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15051) 	for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15052) 		eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15053) 		if (!eq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15054) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15055) 		eq->q_mode = usdelay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15056) 		eq_delay->u.request.eq[cnt].eq_id = eq->queue_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15057) 		eq_delay->u.request.eq[cnt].phase = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15058) 		eq_delay->u.request.eq[cnt].delay_multi = dmult;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15060) 		if (++cnt >= numq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15061) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15062) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15063) 	eq_delay->u.request.num_eq = cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15064) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15065) 	mbox->vport = phba->pport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15066) 	mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15067) 	mbox->ctx_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15068) 	mbox->ctx_ndlp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15069) 	rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15070) 	shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15071) 	shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15072) 	shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15073) 	if (shdr_status || shdr_add_status || rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15074) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15075) 				"2512 MODIFY_EQ_DELAY mailbox failed with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15076) 				"status x%x add_status x%x, mbx status x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15077) 				shdr_status, shdr_add_status, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15078) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15079) 	mempool_free(mbox, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15080) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15081) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15082) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15083) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15084)  * lpfc_eq_create - Create an Event Queue on the HBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15085)  * @phba: HBA structure that indicates port to create a queue on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15086)  * @eq: The queue structure to use to create the event queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15087)  * @imax: The maximum interrupt per second limit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15088)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15089)  * This function creates an event queue, as detailed in @eq, on a port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15090)  * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15091)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15092)  * The @phba struct is used to send mailbox command to HBA. The @eq struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15093)  * is used to get the entry count and entry size that are necessary to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15094)  * determine the number of pages to allocate and use for this queue. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15095)  * function will send the EQ_CREATE mailbox command to the HBA to setup the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15096)  * event queue. This function is asynchronous and will wait for the mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15097)  * command to finish before continuing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15098)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15099)  * On success this function will return a zero. If unable to allocate enough
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15100)  * memory this function will return -ENOMEM. If the queue create mailbox command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15101)  * fails this function will return -ENXIO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15102)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15103) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15104) lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint32_t imax)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15106) 	struct lpfc_mbx_eq_create *eq_create;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15107) 	LPFC_MBOXQ_t *mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15108) 	int rc, length, status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15109) 	struct lpfc_dmabuf *dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15110) 	uint32_t shdr_status, shdr_add_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15111) 	union lpfc_sli4_cfg_shdr *shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15112) 	uint16_t dmult;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15113) 	uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15115) 	/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15116) 	if (!eq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15117) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15118) 	if (!phba->sli4_hba.pc_sli4_params.supported)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15119) 		hw_page_size = SLI4_PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15121) 	mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15122) 	if (!mbox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15123) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15124) 	length = (sizeof(struct lpfc_mbx_eq_create) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15125) 		  sizeof(struct lpfc_sli4_cfg_mhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15126) 	lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15127) 			 LPFC_MBOX_OPCODE_EQ_CREATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15128) 			 length, LPFC_SLI4_MBX_EMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15129) 	eq_create = &mbox->u.mqe.un.eq_create;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15130) 	shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15131) 	bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15132) 	       eq->page_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15133) 	bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15134) 	       LPFC_EQE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15135) 	bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15137) 	/* Use version 2 of CREATE_EQ if eqav is set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15138) 	if (phba->sli4_hba.pc_sli4_params.eqav) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15139) 		bf_set(lpfc_mbox_hdr_version, &shdr->request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15140) 		       LPFC_Q_CREATE_VERSION_2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15141) 		bf_set(lpfc_eq_context_autovalid, &eq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15142) 		       phba->sli4_hba.pc_sli4_params.eqav);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15143) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15145) 	/* don't setup delay multiplier using EQ_CREATE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15146) 	dmult = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15147) 	bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15148) 	       dmult);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15149) 	switch (eq->entry_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15150) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15151) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15152) 				"0360 Unsupported EQ count. (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15153) 				eq->entry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15154) 		if (eq->entry_count < 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15155) 			status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15156) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15157) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15158) 		fallthrough;	/* otherwise default to smallest count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15159) 	case 256:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15160) 		bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15161) 		       LPFC_EQ_CNT_256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15162) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15163) 	case 512:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15164) 		bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15165) 		       LPFC_EQ_CNT_512);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15166) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15167) 	case 1024:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15168) 		bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15169) 		       LPFC_EQ_CNT_1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15170) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15171) 	case 2048:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15172) 		bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15173) 		       LPFC_EQ_CNT_2048);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15174) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15175) 	case 4096:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15176) 		bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15177) 		       LPFC_EQ_CNT_4096);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15178) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15179) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15180) 	list_for_each_entry(dmabuf, &eq->page_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15181) 		memset(dmabuf->virt, 0, hw_page_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15182) 		eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15183) 					putPaddrLow(dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15184) 		eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15185) 					putPaddrHigh(dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15186) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15187) 	mbox->vport = phba->pport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15188) 	mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15189) 	mbox->ctx_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15190) 	mbox->ctx_ndlp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15191) 	rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15192) 	shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15193) 	shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15194) 	if (shdr_status || shdr_add_status || rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15195) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15196) 				"2500 EQ_CREATE mailbox failed with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15197) 				"status x%x add_status x%x, mbx status x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15198) 				shdr_status, shdr_add_status, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15199) 		status = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15200) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15201) 	eq->type = LPFC_EQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15202) 	eq->subtype = LPFC_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15203) 	eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15204) 	if (eq->queue_id == 0xFFFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15205) 		status = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15206) 	eq->host_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15207) 	eq->notify_interval = LPFC_EQ_NOTIFY_INTRVL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15208) 	eq->max_proc_limit = LPFC_EQ_MAX_PROC_LIMIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15209) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15210) 	mempool_free(mbox, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15211) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15214) static int lpfc_cq_poll_hdler(struct irq_poll *iop, int budget)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15216) 	struct lpfc_queue *cq = container_of(iop, struct lpfc_queue, iop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15218) 	__lpfc_sli4_hba_process_cq(cq, LPFC_IRQ_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15220) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15223) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15224)  * lpfc_cq_create - Create a Completion Queue on the HBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15225)  * @phba: HBA structure that indicates port to create a queue on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15226)  * @cq: The queue structure to use to create the completion queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15227)  * @eq: The event queue to bind this completion queue to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15228)  * @type: Type of queue (EQ, GCQ, MCQ, WCQ, etc).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15229)  * @subtype: Functional purpose of the queue (MBOX, IO, ELS, NVMET, etc).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15230)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15231)  * This function creates a completion queue, as detailed in @wq, on a port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15232)  * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15233)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15234)  * The @phba struct is used to send mailbox command to HBA. The @cq struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15235)  * is used to get the entry count and entry size that are necessary to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15236)  * determine the number of pages to allocate and use for this queue. The @eq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15237)  * is used to indicate which event queue to bind this completion queue to. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15238)  * function will send the CQ_CREATE mailbox command to the HBA to setup the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15239)  * completion queue. This function is asynchronous and will wait for the mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15240)  * command to finish before continuing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15241)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15242)  * On success this function will return a zero. If unable to allocate enough
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15243)  * memory this function will return -ENOMEM. If the queue create mailbox command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15244)  * fails this function will return -ENXIO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15245)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15246) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15247) lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15248) 	       struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15250) 	struct lpfc_mbx_cq_create *cq_create;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15251) 	struct lpfc_dmabuf *dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15252) 	LPFC_MBOXQ_t *mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15253) 	int rc, length, status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15254) 	uint32_t shdr_status, shdr_add_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15255) 	union lpfc_sli4_cfg_shdr *shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15257) 	/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15258) 	if (!cq || !eq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15259) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15261) 	mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15262) 	if (!mbox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15263) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15264) 	length = (sizeof(struct lpfc_mbx_cq_create) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15265) 		  sizeof(struct lpfc_sli4_cfg_mhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15266) 	lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15267) 			 LPFC_MBOX_OPCODE_CQ_CREATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15268) 			 length, LPFC_SLI4_MBX_EMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15269) 	cq_create = &mbox->u.mqe.un.cq_create;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15270) 	shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15271) 	bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15272) 		    cq->page_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15273) 	bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15274) 	bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15275) 	bf_set(lpfc_mbox_hdr_version, &shdr->request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15276) 	       phba->sli4_hba.pc_sli4_params.cqv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15277) 	if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15278) 		bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15279) 		       (cq->page_size / SLI4_PAGE_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15280) 		bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15281) 		       eq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15282) 		bf_set(lpfc_cq_context_autovalid, &cq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15283) 		       phba->sli4_hba.pc_sli4_params.cqav);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15284) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15285) 		bf_set(lpfc_cq_eq_id, &cq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15286) 		       eq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15287) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15288) 	switch (cq->entry_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15289) 	case 2048:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15290) 	case 4096:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15291) 		if (phba->sli4_hba.pc_sli4_params.cqv ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15292) 		    LPFC_Q_CREATE_VERSION_2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15293) 			cq_create->u.request.context.lpfc_cq_context_count =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15294) 				cq->entry_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15295) 			bf_set(lpfc_cq_context_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15296) 			       &cq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15297) 			       LPFC_CQ_CNT_WORD7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15298) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15299) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15300) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15301) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15302) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15303) 				"0361 Unsupported CQ count: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15304) 				"entry cnt %d sz %d pg cnt %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15305) 				cq->entry_count, cq->entry_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15306) 				cq->page_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15307) 		if (cq->entry_count < 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15308) 			status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15309) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15310) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15311) 		fallthrough;	/* otherwise default to smallest count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15312) 	case 256:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15313) 		bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15314) 		       LPFC_CQ_CNT_256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15315) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15316) 	case 512:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15317) 		bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15318) 		       LPFC_CQ_CNT_512);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15319) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15320) 	case 1024:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15321) 		bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15322) 		       LPFC_CQ_CNT_1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15323) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15324) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15325) 	list_for_each_entry(dmabuf, &cq->page_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15326) 		memset(dmabuf->virt, 0, cq->page_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15327) 		cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15328) 					putPaddrLow(dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15329) 		cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15330) 					putPaddrHigh(dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15331) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15332) 	rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15334) 	/* The IOCTL status is embedded in the mailbox subheader. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15335) 	shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15336) 	shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15337) 	if (shdr_status || shdr_add_status || rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15338) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15339) 				"2501 CQ_CREATE mailbox failed with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15340) 				"status x%x add_status x%x, mbx status x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15341) 				shdr_status, shdr_add_status, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15342) 		status = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15343) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15344) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15345) 	cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15346) 	if (cq->queue_id == 0xFFFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15347) 		status = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15348) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15349) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15350) 	/* link the cq onto the parent eq child list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15351) 	list_add_tail(&cq->list, &eq->child_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15352) 	/* Set up completion queue's type and subtype */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15353) 	cq->type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15354) 	cq->subtype = subtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15355) 	cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15356) 	cq->assoc_qid = eq->queue_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15357) 	cq->assoc_qp = eq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15358) 	cq->host_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15359) 	cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15360) 	cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit, cq->entry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15362) 	if (cq->queue_id > phba->sli4_hba.cq_max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15363) 		phba->sli4_hba.cq_max = cq->queue_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15365) 	irq_poll_init(&cq->iop, LPFC_IRQ_POLL_WEIGHT, lpfc_cq_poll_hdler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15366) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15367) 	mempool_free(mbox, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15368) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15371) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15372)  * lpfc_cq_create_set - Create a set of Completion Queues on the HBA for MRQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15373)  * @phba: HBA structure that indicates port to create a queue on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15374)  * @cqp: The queue structure array to use to create the completion queues.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15375)  * @hdwq: The hardware queue array  with the EQ to bind completion queues to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15376)  * @type: Type of queue (EQ, GCQ, MCQ, WCQ, etc).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15377)  * @subtype: Functional purpose of the queue (MBOX, IO, ELS, NVMET, etc).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15378)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15379)  * This function creates a set of  completion queue, s to support MRQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15380)  * as detailed in @cqp, on a port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15381)  * described by @phba by sending a CREATE_CQ_SET mailbox command to the HBA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15382)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15383)  * The @phba struct is used to send mailbox command to HBA. The @cq struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15384)  * is used to get the entry count and entry size that are necessary to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15385)  * determine the number of pages to allocate and use for this queue. The @eq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15386)  * is used to indicate which event queue to bind this completion queue to. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15387)  * function will send the CREATE_CQ_SET mailbox command to the HBA to setup the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15388)  * completion queue. This function is asynchronous and will wait for the mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15389)  * command to finish before continuing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15390)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15391)  * On success this function will return a zero. If unable to allocate enough
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15392)  * memory this function will return -ENOMEM. If the queue create mailbox command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15393)  * fails this function will return -ENXIO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15394)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15395) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15396) lpfc_cq_create_set(struct lpfc_hba *phba, struct lpfc_queue **cqp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15397) 		   struct lpfc_sli4_hdw_queue *hdwq, uint32_t type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15398) 		   uint32_t subtype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15400) 	struct lpfc_queue *cq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15401) 	struct lpfc_queue *eq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15402) 	struct lpfc_mbx_cq_create_set *cq_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15403) 	struct lpfc_dmabuf *dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15404) 	LPFC_MBOXQ_t *mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15405) 	int rc, length, alloclen, status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15406) 	int cnt, idx, numcq, page_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15407) 	uint32_t shdr_status, shdr_add_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15408) 	union lpfc_sli4_cfg_shdr *shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15409) 	uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15411) 	/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15412) 	numcq = phba->cfg_nvmet_mrq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15413) 	if (!cqp || !hdwq || !numcq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15414) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15416) 	mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15417) 	if (!mbox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15418) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15420) 	length = sizeof(struct lpfc_mbx_cq_create_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15421) 	length += ((numcq * cqp[0]->page_count) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15422) 		   sizeof(struct dma_address));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15423) 	alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15424) 			LPFC_MBOX_OPCODE_FCOE_CQ_CREATE_SET, length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15425) 			LPFC_SLI4_MBX_NEMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15426) 	if (alloclen < length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15427) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15428) 				"3098 Allocated DMA memory size (%d) is "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15429) 				"less than the requested DMA memory size "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15430) 				"(%d)\n", alloclen, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15431) 		status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15432) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15433) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15434) 	cq_set = mbox->sge_array->addr[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15435) 	shdr = (union lpfc_sli4_cfg_shdr *)&cq_set->cfg_shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15436) 	bf_set(lpfc_mbox_hdr_version, &shdr->request, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15438) 	for (idx = 0; idx < numcq; idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15439) 		cq = cqp[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15440) 		eq = hdwq[idx].hba_eq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15441) 		if (!cq || !eq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15442) 			status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15443) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15444) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15445) 		if (!phba->sli4_hba.pc_sli4_params.supported)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15446) 			hw_page_size = cq->page_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15448) 		switch (idx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15449) 		case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15450) 			bf_set(lpfc_mbx_cq_create_set_page_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15451) 			       &cq_set->u.request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15452) 			       (hw_page_size / SLI4_PAGE_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15453) 			bf_set(lpfc_mbx_cq_create_set_num_pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15454) 			       &cq_set->u.request, cq->page_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15455) 			bf_set(lpfc_mbx_cq_create_set_evt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15456) 			       &cq_set->u.request, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15457) 			bf_set(lpfc_mbx_cq_create_set_valid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15458) 			       &cq_set->u.request, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15459) 			bf_set(lpfc_mbx_cq_create_set_cqe_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15460) 			       &cq_set->u.request, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15461) 			bf_set(lpfc_mbx_cq_create_set_num_cq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15462) 			       &cq_set->u.request, numcq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15463) 			bf_set(lpfc_mbx_cq_create_set_autovalid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15464) 			       &cq_set->u.request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15465) 			       phba->sli4_hba.pc_sli4_params.cqav);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15466) 			switch (cq->entry_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15467) 			case 2048:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15468) 			case 4096:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15469) 				if (phba->sli4_hba.pc_sli4_params.cqv ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15470) 				    LPFC_Q_CREATE_VERSION_2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15471) 					bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15472) 					       &cq_set->u.request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15473) 						cq->entry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15474) 					bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15475) 					       &cq_set->u.request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15476) 					       LPFC_CQ_CNT_WORD7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15477) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15478) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15479) 				fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15480) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15481) 				lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15482) 						"3118 Bad CQ count. (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15483) 						cq->entry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15484) 				if (cq->entry_count < 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15485) 					status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15486) 					goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15487) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15488) 				fallthrough;	/* otherwise default to smallest */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15489) 			case 256:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15490) 				bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15491) 				       &cq_set->u.request, LPFC_CQ_CNT_256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15492) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15493) 			case 512:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15494) 				bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15495) 				       &cq_set->u.request, LPFC_CQ_CNT_512);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15496) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15497) 			case 1024:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15498) 				bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15499) 				       &cq_set->u.request, LPFC_CQ_CNT_1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15500) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15501) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15502) 			bf_set(lpfc_mbx_cq_create_set_eq_id0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15503) 			       &cq_set->u.request, eq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15504) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15505) 		case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15506) 			bf_set(lpfc_mbx_cq_create_set_eq_id1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15507) 			       &cq_set->u.request, eq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15508) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15509) 		case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15510) 			bf_set(lpfc_mbx_cq_create_set_eq_id2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15511) 			       &cq_set->u.request, eq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15512) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15513) 		case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15514) 			bf_set(lpfc_mbx_cq_create_set_eq_id3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15515) 			       &cq_set->u.request, eq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15516) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15517) 		case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15518) 			bf_set(lpfc_mbx_cq_create_set_eq_id4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15519) 			       &cq_set->u.request, eq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15520) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15521) 		case 5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15522) 			bf_set(lpfc_mbx_cq_create_set_eq_id5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15523) 			       &cq_set->u.request, eq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15524) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15525) 		case 6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15526) 			bf_set(lpfc_mbx_cq_create_set_eq_id6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15527) 			       &cq_set->u.request, eq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15528) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15529) 		case 7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15530) 			bf_set(lpfc_mbx_cq_create_set_eq_id7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15531) 			       &cq_set->u.request, eq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15532) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15533) 		case 8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15534) 			bf_set(lpfc_mbx_cq_create_set_eq_id8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15535) 			       &cq_set->u.request, eq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15536) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15537) 		case 9:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15538) 			bf_set(lpfc_mbx_cq_create_set_eq_id9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15539) 			       &cq_set->u.request, eq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15540) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15541) 		case 10:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15542) 			bf_set(lpfc_mbx_cq_create_set_eq_id10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15543) 			       &cq_set->u.request, eq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15544) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15545) 		case 11:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15546) 			bf_set(lpfc_mbx_cq_create_set_eq_id11,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15547) 			       &cq_set->u.request, eq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15548) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15549) 		case 12:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15550) 			bf_set(lpfc_mbx_cq_create_set_eq_id12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15551) 			       &cq_set->u.request, eq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15552) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15553) 		case 13:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15554) 			bf_set(lpfc_mbx_cq_create_set_eq_id13,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15555) 			       &cq_set->u.request, eq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15556) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15557) 		case 14:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15558) 			bf_set(lpfc_mbx_cq_create_set_eq_id14,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15559) 			       &cq_set->u.request, eq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15560) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15561) 		case 15:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15562) 			bf_set(lpfc_mbx_cq_create_set_eq_id15,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15563) 			       &cq_set->u.request, eq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15564) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15565) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15567) 		/* link the cq onto the parent eq child list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15568) 		list_add_tail(&cq->list, &eq->child_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15569) 		/* Set up completion queue's type and subtype */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15570) 		cq->type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15571) 		cq->subtype = subtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15572) 		cq->assoc_qid = eq->queue_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15573) 		cq->assoc_qp = eq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15574) 		cq->host_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15575) 		cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15576) 		cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15577) 					 cq->entry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15578) 		cq->chann = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15580) 		rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15581) 		list_for_each_entry(dmabuf, &cq->page_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15582) 			memset(dmabuf->virt, 0, hw_page_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15583) 			cnt = page_idx + dmabuf->buffer_tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15584) 			cq_set->u.request.page[cnt].addr_lo =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15585) 					putPaddrLow(dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15586) 			cq_set->u.request.page[cnt].addr_hi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15587) 					putPaddrHigh(dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15588) 			rc++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15589) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15590) 		page_idx += rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15591) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15593) 	rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15595) 	/* The IOCTL status is embedded in the mailbox subheader. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15596) 	shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15597) 	shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15598) 	if (shdr_status || shdr_add_status || rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15599) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15600) 				"3119 CQ_CREATE_SET mailbox failed with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15601) 				"status x%x add_status x%x, mbx status x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15602) 				shdr_status, shdr_add_status, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15603) 		status = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15604) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15605) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15606) 	rc = bf_get(lpfc_mbx_cq_create_set_base_id, &cq_set->u.response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15607) 	if (rc == 0xFFFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15608) 		status = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15609) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15610) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15612) 	for (idx = 0; idx < numcq; idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15613) 		cq = cqp[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15614) 		cq->queue_id = rc + idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15615) 		if (cq->queue_id > phba->sli4_hba.cq_max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15616) 			phba->sli4_hba.cq_max = cq->queue_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15617) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15619) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15620) 	lpfc_sli4_mbox_cmd_free(phba, mbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15621) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15624) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15625)  * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15626)  * @phba: HBA structure that indicates port to create a queue on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15627)  * @mq: The queue structure to use to create the mailbox queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15628)  * @mbox: An allocated pointer to type LPFC_MBOXQ_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15629)  * @cq: The completion queue to associate with this cq.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15630)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15631)  * This function provides failback (fb) functionality when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15632)  * mq_create_ext fails on older FW generations.  It's purpose is identical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15633)  * to mq_create_ext otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15634)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15635)  * This routine cannot fail as all attributes were previously accessed and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15636)  * initialized in mq_create_ext.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15637)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15638) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15639) lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15640) 		       LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15641) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15642) 	struct lpfc_mbx_mq_create *mq_create;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15643) 	struct lpfc_dmabuf *dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15644) 	int length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15646) 	length = (sizeof(struct lpfc_mbx_mq_create) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15647) 		  sizeof(struct lpfc_sli4_cfg_mhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15648) 	lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15649) 			 LPFC_MBOX_OPCODE_MQ_CREATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15650) 			 length, LPFC_SLI4_MBX_EMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15651) 	mq_create = &mbox->u.mqe.un.mq_create;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15652) 	bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15653) 	       mq->page_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15654) 	bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15655) 	       cq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15656) 	bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15657) 	switch (mq->entry_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15658) 	case 16:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15659) 		bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15660) 		       LPFC_MQ_RING_SIZE_16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15661) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15662) 	case 32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15663) 		bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15664) 		       LPFC_MQ_RING_SIZE_32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15665) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15666) 	case 64:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15667) 		bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15668) 		       LPFC_MQ_RING_SIZE_64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15669) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15670) 	case 128:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15671) 		bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15672) 		       LPFC_MQ_RING_SIZE_128);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15673) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15674) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15675) 	list_for_each_entry(dmabuf, &mq->page_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15676) 		mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15677) 			putPaddrLow(dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15678) 		mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15679) 			putPaddrHigh(dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15680) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15681) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15683) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15684)  * lpfc_mq_create - Create a mailbox Queue on the HBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15685)  * @phba: HBA structure that indicates port to create a queue on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15686)  * @mq: The queue structure to use to create the mailbox queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15687)  * @cq: The completion queue to associate with this cq.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15688)  * @subtype: The queue's subtype.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15689)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15690)  * This function creates a mailbox queue, as detailed in @mq, on a port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15691)  * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15692)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15693)  * The @phba struct is used to send mailbox command to HBA. The @cq struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15694)  * is used to get the entry count and entry size that are necessary to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15695)  * determine the number of pages to allocate and use for this queue. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15696)  * function will send the MQ_CREATE mailbox command to the HBA to setup the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15697)  * mailbox queue. This function is asynchronous and will wait for the mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15698)  * command to finish before continuing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15699)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15700)  * On success this function will return a zero. If unable to allocate enough
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15701)  * memory this function will return -ENOMEM. If the queue create mailbox command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15702)  * fails this function will return -ENXIO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15703)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15704) int32_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15705) lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15706) 	       struct lpfc_queue *cq, uint32_t subtype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15707) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15708) 	struct lpfc_mbx_mq_create *mq_create;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15709) 	struct lpfc_mbx_mq_create_ext *mq_create_ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15710) 	struct lpfc_dmabuf *dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15711) 	LPFC_MBOXQ_t *mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15712) 	int rc, length, status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15713) 	uint32_t shdr_status, shdr_add_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15714) 	union lpfc_sli4_cfg_shdr *shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15715) 	uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15717) 	/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15718) 	if (!mq || !cq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15719) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15720) 	if (!phba->sli4_hba.pc_sli4_params.supported)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15721) 		hw_page_size = SLI4_PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15723) 	mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15724) 	if (!mbox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15725) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15726) 	length = (sizeof(struct lpfc_mbx_mq_create_ext) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15727) 		  sizeof(struct lpfc_sli4_cfg_mhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15728) 	lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15729) 			 LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15730) 			 length, LPFC_SLI4_MBX_EMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15732) 	mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15733) 	shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15734) 	bf_set(lpfc_mbx_mq_create_ext_num_pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15735) 	       &mq_create_ext->u.request, mq->page_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15736) 	bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15737) 	       &mq_create_ext->u.request, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15738) 	bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15739) 	       &mq_create_ext->u.request, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15740) 	bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15741) 	       &mq_create_ext->u.request, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15742) 	bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15743) 	       &mq_create_ext->u.request, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15744) 	bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15745) 	       &mq_create_ext->u.request, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15746) 	bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15747) 	bf_set(lpfc_mbox_hdr_version, &shdr->request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15748) 	       phba->sli4_hba.pc_sli4_params.mqv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15749) 	if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15750) 		bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15751) 		       cq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15752) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15753) 		bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15754) 		       cq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15755) 	switch (mq->entry_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15756) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15757) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15758) 				"0362 Unsupported MQ count. (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15759) 				mq->entry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15760) 		if (mq->entry_count < 16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15761) 			status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15762) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15763) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15764) 		fallthrough;	/* otherwise default to smallest count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15765) 	case 16:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15766) 		bf_set(lpfc_mq_context_ring_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15767) 		       &mq_create_ext->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15768) 		       LPFC_MQ_RING_SIZE_16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15769) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15770) 	case 32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15771) 		bf_set(lpfc_mq_context_ring_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15772) 		       &mq_create_ext->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15773) 		       LPFC_MQ_RING_SIZE_32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15774) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15775) 	case 64:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15776) 		bf_set(lpfc_mq_context_ring_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15777) 		       &mq_create_ext->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15778) 		       LPFC_MQ_RING_SIZE_64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15779) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15780) 	case 128:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15781) 		bf_set(lpfc_mq_context_ring_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15782) 		       &mq_create_ext->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15783) 		       LPFC_MQ_RING_SIZE_128);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15784) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15785) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15786) 	list_for_each_entry(dmabuf, &mq->page_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15787) 		memset(dmabuf->virt, 0, hw_page_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15788) 		mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15789) 					putPaddrLow(dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15790) 		mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15791) 					putPaddrHigh(dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15792) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15793) 	rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15794) 	mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15795) 			      &mq_create_ext->u.response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15796) 	if (rc != MBX_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15797) 		lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15798) 				"2795 MQ_CREATE_EXT failed with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15799) 				"status x%x. Failback to MQ_CREATE.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15800) 				rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15801) 		lpfc_mq_create_fb_init(phba, mq, mbox, cq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15802) 		mq_create = &mbox->u.mqe.un.mq_create;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15803) 		rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15804) 		shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15805) 		mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15806) 				      &mq_create->u.response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15807) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15809) 	/* The IOCTL status is embedded in the mailbox subheader. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15810) 	shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15811) 	shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15812) 	if (shdr_status || shdr_add_status || rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15813) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15814) 				"2502 MQ_CREATE mailbox failed with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15815) 				"status x%x add_status x%x, mbx status x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15816) 				shdr_status, shdr_add_status, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15817) 		status = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15818) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15819) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15820) 	if (mq->queue_id == 0xFFFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15821) 		status = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15822) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15823) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15824) 	mq->type = LPFC_MQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15825) 	mq->assoc_qid = cq->queue_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15826) 	mq->subtype = subtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15827) 	mq->host_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15828) 	mq->hba_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15830) 	/* link the mq onto the parent cq child list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15831) 	list_add_tail(&mq->list, &cq->child_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15832) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15833) 	mempool_free(mbox, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15834) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15835) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15837) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15838)  * lpfc_wq_create - Create a Work Queue on the HBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15839)  * @phba: HBA structure that indicates port to create a queue on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15840)  * @wq: The queue structure to use to create the work queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15841)  * @cq: The completion queue to bind this work queue to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15842)  * @subtype: The subtype of the work queue indicating its functionality.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15843)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15844)  * This function creates a work queue, as detailed in @wq, on a port, described
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15845)  * by @phba by sending a WQ_CREATE mailbox command to the HBA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15846)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15847)  * The @phba struct is used to send mailbox command to HBA. The @wq struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15848)  * is used to get the entry count and entry size that are necessary to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15849)  * determine the number of pages to allocate and use for this queue. The @cq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15850)  * is used to indicate which completion queue to bind this work queue to. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15851)  * function will send the WQ_CREATE mailbox command to the HBA to setup the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15852)  * work queue. This function is asynchronous and will wait for the mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15853)  * command to finish before continuing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15854)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15855)  * On success this function will return a zero. If unable to allocate enough
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15856)  * memory this function will return -ENOMEM. If the queue create mailbox command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15857)  * fails this function will return -ENXIO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15858)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15859) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15860) lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15861) 	       struct lpfc_queue *cq, uint32_t subtype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15862) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15863) 	struct lpfc_mbx_wq_create *wq_create;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15864) 	struct lpfc_dmabuf *dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15865) 	LPFC_MBOXQ_t *mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15866) 	int rc, length, status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15867) 	uint32_t shdr_status, shdr_add_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15868) 	union lpfc_sli4_cfg_shdr *shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15869) 	uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15870) 	struct dma_address *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15871) 	void __iomem *bar_memmap_p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15872) 	uint32_t db_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15873) 	uint16_t pci_barset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15874) 	uint8_t dpp_barset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15875) 	uint32_t dpp_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15876) 	uint8_t wq_create_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15877) #ifdef CONFIG_X86
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15878) 	unsigned long pg_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15879) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15881) 	/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15882) 	if (!wq || !cq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15883) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15884) 	if (!phba->sli4_hba.pc_sli4_params.supported)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15885) 		hw_page_size = wq->page_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15887) 	mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15888) 	if (!mbox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15889) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15890) 	length = (sizeof(struct lpfc_mbx_wq_create) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15891) 		  sizeof(struct lpfc_sli4_cfg_mhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15892) 	lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15893) 			 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15894) 			 length, LPFC_SLI4_MBX_EMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15895) 	wq_create = &mbox->u.mqe.un.wq_create;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15896) 	shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15897) 	bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15898) 		    wq->page_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15899) 	bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15900) 		    cq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15902) 	/* wqv is the earliest version supported, NOT the latest */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15903) 	bf_set(lpfc_mbox_hdr_version, &shdr->request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15904) 	       phba->sli4_hba.pc_sli4_params.wqv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15906) 	if ((phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15907) 	    (wq->page_size > SLI4_PAGE_SIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15908) 		wq_create_version = LPFC_Q_CREATE_VERSION_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15909) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15910) 		wq_create_version = LPFC_Q_CREATE_VERSION_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15912) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15913) 	if (phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15914) 		wq_create_version = LPFC_Q_CREATE_VERSION_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15915) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15916) 		wq_create_version = LPFC_Q_CREATE_VERSION_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15918) 	switch (wq_create_version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15919) 	case LPFC_Q_CREATE_VERSION_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15920) 		bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15921) 		       wq->entry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15922) 		bf_set(lpfc_mbox_hdr_version, &shdr->request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15923) 		       LPFC_Q_CREATE_VERSION_1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15925) 		switch (wq->entry_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15926) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15927) 		case 64:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15928) 			bf_set(lpfc_mbx_wq_create_wqe_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15929) 			       &wq_create->u.request_1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15930) 			       LPFC_WQ_WQE_SIZE_64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15931) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15932) 		case 128:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15933) 			bf_set(lpfc_mbx_wq_create_wqe_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15934) 			       &wq_create->u.request_1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15935) 			       LPFC_WQ_WQE_SIZE_128);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15936) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15937) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15938) 		/* Request DPP by default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15939) 		bf_set(lpfc_mbx_wq_create_dpp_req, &wq_create->u.request_1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15940) 		bf_set(lpfc_mbx_wq_create_page_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15941) 		       &wq_create->u.request_1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15942) 		       (wq->page_size / SLI4_PAGE_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15943) 		page = wq_create->u.request_1.page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15944) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15945) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15946) 		page = wq_create->u.request.page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15947) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15948) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15949) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15950) 	list_for_each_entry(dmabuf, &wq->page_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15951) 		memset(dmabuf->virt, 0, hw_page_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15952) 		page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15953) 		page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15954) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15955) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15956) 	if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15957) 		bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15959) 	rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15960) 	/* The IOCTL status is embedded in the mailbox subheader. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15961) 	shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15962) 	shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15963) 	if (shdr_status || shdr_add_status || rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15964) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15965) 				"2503 WQ_CREATE mailbox failed with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15966) 				"status x%x add_status x%x, mbx status x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15967) 				shdr_status, shdr_add_status, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15968) 		status = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15969) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15970) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15972) 	if (wq_create_version == LPFC_Q_CREATE_VERSION_0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15973) 		wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15974) 					&wq_create->u.response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15975) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15976) 		wq->queue_id = bf_get(lpfc_mbx_wq_create_v1_q_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15977) 					&wq_create->u.response_1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15979) 	if (wq->queue_id == 0xFFFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15980) 		status = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15981) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15982) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15984) 	wq->db_format = LPFC_DB_LIST_FORMAT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15985) 	if (wq_create_version == LPFC_Q_CREATE_VERSION_0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15986) 		if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15987) 			wq->db_format = bf_get(lpfc_mbx_wq_create_db_format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15988) 					       &wq_create->u.response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15989) 			if ((wq->db_format != LPFC_DB_LIST_FORMAT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15990) 			    (wq->db_format != LPFC_DB_RING_FORMAT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15991) 				lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15992) 						"3265 WQ[%d] doorbell format "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15993) 						"not supported: x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15994) 						wq->queue_id, wq->db_format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15995) 				status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15996) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15997) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15998) 			pci_barset = bf_get(lpfc_mbx_wq_create_bar_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15999) 					    &wq_create->u.response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16000) 			bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16001) 								   pci_barset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16002) 			if (!bar_memmap_p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16003) 				lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16004) 						"3263 WQ[%d] failed to memmap "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16005) 						"pci barset:x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16006) 						wq->queue_id, pci_barset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16007) 				status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16008) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16009) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16010) 			db_offset = wq_create->u.response.doorbell_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16011) 			if ((db_offset != LPFC_ULP0_WQ_DOORBELL) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16012) 			    (db_offset != LPFC_ULP1_WQ_DOORBELL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16013) 				lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16014) 						"3252 WQ[%d] doorbell offset "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16015) 						"not supported: x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16016) 						wq->queue_id, db_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16017) 				status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16018) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16019) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16020) 			wq->db_regaddr = bar_memmap_p + db_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16021) 			lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16022) 					"3264 WQ[%d]: barset:x%x, offset:x%x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16023) 					"format:x%x\n", wq->queue_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16024) 					pci_barset, db_offset, wq->db_format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16025) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16026) 			wq->db_regaddr = phba->sli4_hba.WQDBregaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16027) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16028) 		/* Check if DPP was honored by the firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16029) 		wq->dpp_enable = bf_get(lpfc_mbx_wq_create_dpp_rsp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16030) 				    &wq_create->u.response_1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16031) 		if (wq->dpp_enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16032) 			pci_barset = bf_get(lpfc_mbx_wq_create_v1_bar_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16033) 					    &wq_create->u.response_1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16034) 			bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16035) 								   pci_barset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16036) 			if (!bar_memmap_p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16037) 				lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16038) 						"3267 WQ[%d] failed to memmap "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16039) 						"pci barset:x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16040) 						wq->queue_id, pci_barset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16041) 				status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16042) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16043) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16044) 			db_offset = wq_create->u.response_1.doorbell_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16045) 			wq->db_regaddr = bar_memmap_p + db_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16046) 			wq->dpp_id = bf_get(lpfc_mbx_wq_create_dpp_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16047) 					    &wq_create->u.response_1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16048) 			dpp_barset = bf_get(lpfc_mbx_wq_create_dpp_bar,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16049) 					    &wq_create->u.response_1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16050) 			bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16051) 								   dpp_barset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16052) 			if (!bar_memmap_p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16053) 				lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16054) 						"3268 WQ[%d] failed to memmap "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16055) 						"pci barset:x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16056) 						wq->queue_id, dpp_barset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16057) 				status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16058) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16059) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16060) 			dpp_offset = wq_create->u.response_1.dpp_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16061) 			wq->dpp_regaddr = bar_memmap_p + dpp_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16062) 			lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16063) 					"3271 WQ[%d]: barset:x%x, offset:x%x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16064) 					"dpp_id:x%x dpp_barset:x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16065) 					"dpp_offset:x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16066) 					wq->queue_id, pci_barset, db_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16067) 					wq->dpp_id, dpp_barset, dpp_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16069) #ifdef CONFIG_X86
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16070) 			/* Enable combined writes for DPP aperture */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16071) 			pg_addr = (unsigned long)(wq->dpp_regaddr) & PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16072) 			rc = set_memory_wc(pg_addr, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16073) 			if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16074) 				lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16075) 					"3272 Cannot setup Combined "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16076) 					"Write on WQ[%d] - disable DPP\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16077) 					wq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16078) 				phba->cfg_enable_dpp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16079) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16080) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16081) 			phba->cfg_enable_dpp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16082) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16083) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16084) 			wq->db_regaddr = phba->sli4_hba.WQDBregaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16085) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16086) 	wq->pring = kzalloc(sizeof(struct lpfc_sli_ring), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16087) 	if (wq->pring == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16088) 		status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16089) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16090) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16091) 	wq->type = LPFC_WQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16092) 	wq->assoc_qid = cq->queue_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16093) 	wq->subtype = subtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16094) 	wq->host_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16095) 	wq->hba_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16096) 	wq->notify_interval = LPFC_WQ_NOTIFY_INTRVL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16097) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16098) 	/* link the wq onto the parent cq child list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16099) 	list_add_tail(&wq->list, &cq->child_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16100) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16101) 	mempool_free(mbox, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16102) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16105) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16106)  * lpfc_rq_create - Create a Receive Queue on the HBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16107)  * @phba: HBA structure that indicates port to create a queue on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16108)  * @hrq: The queue structure to use to create the header receive queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16109)  * @drq: The queue structure to use to create the data receive queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16110)  * @cq: The completion queue to bind this work queue to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16111)  * @subtype: The subtype of the work queue indicating its functionality.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16112)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16113)  * This function creates a receive buffer queue pair , as detailed in @hrq and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16114)  * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16115)  * to the HBA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16116)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16117)  * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16118)  * struct is used to get the entry count that is necessary to determine the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16119)  * number of pages to use for this queue. The @cq is used to indicate which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16120)  * completion queue to bind received buffers that are posted to these queues to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16121)  * This function will send the RQ_CREATE mailbox command to the HBA to setup the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16122)  * receive queue pair. This function is asynchronous and will wait for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16123)  * mailbox command to finish before continuing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16124)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16125)  * On success this function will return a zero. If unable to allocate enough
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16126)  * memory this function will return -ENOMEM. If the queue create mailbox command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16127)  * fails this function will return -ENXIO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16128)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16129) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16130) lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16131) 	       struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16133) 	struct lpfc_mbx_rq_create *rq_create;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16134) 	struct lpfc_dmabuf *dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16135) 	LPFC_MBOXQ_t *mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16136) 	int rc, length, status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16137) 	uint32_t shdr_status, shdr_add_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16138) 	union lpfc_sli4_cfg_shdr *shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16139) 	uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16140) 	void __iomem *bar_memmap_p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16141) 	uint32_t db_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16142) 	uint16_t pci_barset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16144) 	/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16145) 	if (!hrq || !drq || !cq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16146) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16147) 	if (!phba->sli4_hba.pc_sli4_params.supported)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16148) 		hw_page_size = SLI4_PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16150) 	if (hrq->entry_count != drq->entry_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16151) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16152) 	mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16153) 	if (!mbox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16154) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16155) 	length = (sizeof(struct lpfc_mbx_rq_create) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16156) 		  sizeof(struct lpfc_sli4_cfg_mhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16157) 	lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16158) 			 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16159) 			 length, LPFC_SLI4_MBX_EMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16160) 	rq_create = &mbox->u.mqe.un.rq_create;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16161) 	shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16162) 	bf_set(lpfc_mbox_hdr_version, &shdr->request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16163) 	       phba->sli4_hba.pc_sli4_params.rqv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16164) 	if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16165) 		bf_set(lpfc_rq_context_rqe_count_1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16166) 		       &rq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16167) 		       hrq->entry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16168) 		rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16169) 		bf_set(lpfc_rq_context_rqe_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16170) 		       &rq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16171) 		       LPFC_RQE_SIZE_8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16172) 		bf_set(lpfc_rq_context_page_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16173) 		       &rq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16174) 		       LPFC_RQ_PAGE_SIZE_4096);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16175) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16176) 		switch (hrq->entry_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16177) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16178) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16179) 					"2535 Unsupported RQ count. (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16180) 					hrq->entry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16181) 			if (hrq->entry_count < 512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16182) 				status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16183) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16184) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16185) 			fallthrough;	/* otherwise default to smallest count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16186) 		case 512:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16187) 			bf_set(lpfc_rq_context_rqe_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16188) 			       &rq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16189) 			       LPFC_RQ_RING_SIZE_512);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16190) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16191) 		case 1024:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16192) 			bf_set(lpfc_rq_context_rqe_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16193) 			       &rq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16194) 			       LPFC_RQ_RING_SIZE_1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16195) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16196) 		case 2048:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16197) 			bf_set(lpfc_rq_context_rqe_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16198) 			       &rq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16199) 			       LPFC_RQ_RING_SIZE_2048);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16200) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16201) 		case 4096:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16202) 			bf_set(lpfc_rq_context_rqe_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16203) 			       &rq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16204) 			       LPFC_RQ_RING_SIZE_4096);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16205) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16206) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16207) 		bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16208) 		       LPFC_HDR_BUF_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16209) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16210) 	bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16211) 	       cq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16212) 	bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16213) 	       hrq->page_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16214) 	list_for_each_entry(dmabuf, &hrq->page_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16215) 		memset(dmabuf->virt, 0, hw_page_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16216) 		rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16217) 					putPaddrLow(dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16218) 		rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16219) 					putPaddrHigh(dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16220) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16221) 	if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16222) 		bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16224) 	rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16225) 	/* The IOCTL status is embedded in the mailbox subheader. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16226) 	shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16227) 	shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16228) 	if (shdr_status || shdr_add_status || rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16229) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16230) 				"2504 RQ_CREATE mailbox failed with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16231) 				"status x%x add_status x%x, mbx status x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16232) 				shdr_status, shdr_add_status, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16233) 		status = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16234) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16235) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16236) 	hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16237) 	if (hrq->queue_id == 0xFFFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16238) 		status = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16239) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16240) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16242) 	if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16243) 		hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16244) 					&rq_create->u.response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16245) 		if ((hrq->db_format != LPFC_DB_LIST_FORMAT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16246) 		    (hrq->db_format != LPFC_DB_RING_FORMAT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16247) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16248) 					"3262 RQ [%d] doorbell format not "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16249) 					"supported: x%x\n", hrq->queue_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16250) 					hrq->db_format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16251) 			status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16252) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16253) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16255) 		pci_barset = bf_get(lpfc_mbx_rq_create_bar_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16256) 				    &rq_create->u.response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16257) 		bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16258) 		if (!bar_memmap_p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16259) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16260) 					"3269 RQ[%d] failed to memmap pci "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16261) 					"barset:x%x\n", hrq->queue_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16262) 					pci_barset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16263) 			status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16264) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16265) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16267) 		db_offset = rq_create->u.response.doorbell_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16268) 		if ((db_offset != LPFC_ULP0_RQ_DOORBELL) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16269) 		    (db_offset != LPFC_ULP1_RQ_DOORBELL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16270) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16271) 					"3270 RQ[%d] doorbell offset not "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16272) 					"supported: x%x\n", hrq->queue_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16273) 					db_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16274) 			status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16275) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16276) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16277) 		hrq->db_regaddr = bar_memmap_p + db_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16278) 		lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16279) 				"3266 RQ[qid:%d]: barset:x%x, offset:x%x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16280) 				"format:x%x\n", hrq->queue_id, pci_barset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16281) 				db_offset, hrq->db_format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16282) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16283) 		hrq->db_format = LPFC_DB_RING_FORMAT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16284) 		hrq->db_regaddr = phba->sli4_hba.RQDBregaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16285) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16286) 	hrq->type = LPFC_HRQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16287) 	hrq->assoc_qid = cq->queue_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16288) 	hrq->subtype = subtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16289) 	hrq->host_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16290) 	hrq->hba_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16291) 	hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16293) 	/* now create the data queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16294) 	lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16295) 			 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16296) 			 length, LPFC_SLI4_MBX_EMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16297) 	bf_set(lpfc_mbox_hdr_version, &shdr->request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16298) 	       phba->sli4_hba.pc_sli4_params.rqv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16299) 	if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16300) 		bf_set(lpfc_rq_context_rqe_count_1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16301) 		       &rq_create->u.request.context, hrq->entry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16302) 		if (subtype == LPFC_NVMET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16303) 			rq_create->u.request.context.buffer_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16304) 				LPFC_NVMET_DATA_BUF_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16305) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16306) 			rq_create->u.request.context.buffer_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16307) 				LPFC_DATA_BUF_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16308) 		bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16309) 		       LPFC_RQE_SIZE_8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16310) 		bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16311) 		       (PAGE_SIZE/SLI4_PAGE_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16312) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16313) 		switch (drq->entry_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16314) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16315) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16316) 					"2536 Unsupported RQ count. (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16317) 					drq->entry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16318) 			if (drq->entry_count < 512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16319) 				status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16320) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16321) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16322) 			fallthrough;	/* otherwise default to smallest count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16323) 		case 512:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16324) 			bf_set(lpfc_rq_context_rqe_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16325) 			       &rq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16326) 			       LPFC_RQ_RING_SIZE_512);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16327) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16328) 		case 1024:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16329) 			bf_set(lpfc_rq_context_rqe_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16330) 			       &rq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16331) 			       LPFC_RQ_RING_SIZE_1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16332) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16333) 		case 2048:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16334) 			bf_set(lpfc_rq_context_rqe_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16335) 			       &rq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16336) 			       LPFC_RQ_RING_SIZE_2048);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16337) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16338) 		case 4096:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16339) 			bf_set(lpfc_rq_context_rqe_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16340) 			       &rq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16341) 			       LPFC_RQ_RING_SIZE_4096);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16342) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16343) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16344) 		if (subtype == LPFC_NVMET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16345) 			bf_set(lpfc_rq_context_buf_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16346) 			       &rq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16347) 			       LPFC_NVMET_DATA_BUF_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16348) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16349) 			bf_set(lpfc_rq_context_buf_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16350) 			       &rq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16351) 			       LPFC_DATA_BUF_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16352) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16353) 	bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16354) 	       cq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16355) 	bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16356) 	       drq->page_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16357) 	list_for_each_entry(dmabuf, &drq->page_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16358) 		rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16359) 					putPaddrLow(dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16360) 		rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16361) 					putPaddrHigh(dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16362) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16363) 	if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16364) 		bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16365) 	rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16366) 	/* The IOCTL status is embedded in the mailbox subheader. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16367) 	shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16368) 	shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16369) 	shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16370) 	if (shdr_status || shdr_add_status || rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16371) 		status = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16372) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16373) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16374) 	drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16375) 	if (drq->queue_id == 0xFFFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16376) 		status = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16377) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16378) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16379) 	drq->type = LPFC_DRQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16380) 	drq->assoc_qid = cq->queue_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16381) 	drq->subtype = subtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16382) 	drq->host_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16383) 	drq->hba_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16384) 	drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16386) 	/* link the header and data RQs onto the parent cq child list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16387) 	list_add_tail(&hrq->list, &cq->child_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16388) 	list_add_tail(&drq->list, &cq->child_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16390) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16391) 	mempool_free(mbox, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16392) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16395) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16396)  * lpfc_mrq_create - Create MRQ Receive Queues on the HBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16397)  * @phba: HBA structure that indicates port to create a queue on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16398)  * @hrqp: The queue structure array to use to create the header receive queues.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16399)  * @drqp: The queue structure array to use to create the data receive queues.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16400)  * @cqp: The completion queue array to bind these receive queues to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16401)  * @subtype: Functional purpose of the queue (MBOX, IO, ELS, NVMET, etc).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16402)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16403)  * This function creates a receive buffer queue pair , as detailed in @hrq and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16404)  * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16405)  * to the HBA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16406)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16407)  * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16408)  * struct is used to get the entry count that is necessary to determine the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16409)  * number of pages to use for this queue. The @cq is used to indicate which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16410)  * completion queue to bind received buffers that are posted to these queues to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16411)  * This function will send the RQ_CREATE mailbox command to the HBA to setup the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16412)  * receive queue pair. This function is asynchronous and will wait for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16413)  * mailbox command to finish before continuing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16414)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16415)  * On success this function will return a zero. If unable to allocate enough
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16416)  * memory this function will return -ENOMEM. If the queue create mailbox command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16417)  * fails this function will return -ENXIO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16418)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16419) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16420) lpfc_mrq_create(struct lpfc_hba *phba, struct lpfc_queue **hrqp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16421) 		struct lpfc_queue **drqp, struct lpfc_queue **cqp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16422) 		uint32_t subtype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16424) 	struct lpfc_queue *hrq, *drq, *cq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16425) 	struct lpfc_mbx_rq_create_v2 *rq_create;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16426) 	struct lpfc_dmabuf *dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16427) 	LPFC_MBOXQ_t *mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16428) 	int rc, length, alloclen, status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16429) 	int cnt, idx, numrq, page_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16430) 	uint32_t shdr_status, shdr_add_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16431) 	union lpfc_sli4_cfg_shdr *shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16432) 	uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16434) 	numrq = phba->cfg_nvmet_mrq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16435) 	/* sanity check on array memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16436) 	if (!hrqp || !drqp || !cqp || !numrq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16437) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16438) 	if (!phba->sli4_hba.pc_sli4_params.supported)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16439) 		hw_page_size = SLI4_PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16441) 	mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16442) 	if (!mbox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16443) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16445) 	length = sizeof(struct lpfc_mbx_rq_create_v2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16446) 	length += ((2 * numrq * hrqp[0]->page_count) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16447) 		   sizeof(struct dma_address));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16449) 	alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16450) 				    LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16451) 				    LPFC_SLI4_MBX_NEMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16452) 	if (alloclen < length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16453) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16454) 				"3099 Allocated DMA memory size (%d) is "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16455) 				"less than the requested DMA memory size "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16456) 				"(%d)\n", alloclen, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16457) 		status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16458) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16459) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16463) 	rq_create = mbox->sge_array->addr[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16464) 	shdr = (union lpfc_sli4_cfg_shdr *)&rq_create->cfg_shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16466) 	bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_Q_CREATE_VERSION_2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16467) 	cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16469) 	for (idx = 0; idx < numrq; idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16470) 		hrq = hrqp[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16471) 		drq = drqp[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16472) 		cq  = cqp[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16474) 		/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16475) 		if (!hrq || !drq || !cq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16476) 			status = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16477) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16478) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16480) 		if (hrq->entry_count != drq->entry_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16481) 			status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16482) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16483) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16485) 		if (idx == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16486) 			bf_set(lpfc_mbx_rq_create_num_pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16487) 			       &rq_create->u.request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16488) 			       hrq->page_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16489) 			bf_set(lpfc_mbx_rq_create_rq_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16490) 			       &rq_create->u.request, (numrq * 2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16491) 			bf_set(lpfc_mbx_rq_create_dnb, &rq_create->u.request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16492) 			       1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16493) 			bf_set(lpfc_rq_context_base_cq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16494) 			       &rq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16495) 			       cq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16496) 			bf_set(lpfc_rq_context_data_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16497) 			       &rq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16498) 			       LPFC_NVMET_DATA_BUF_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16499) 			bf_set(lpfc_rq_context_hdr_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16500) 			       &rq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16501) 			       LPFC_HDR_BUF_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16502) 			bf_set(lpfc_rq_context_rqe_count_1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16503) 			       &rq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16504) 			       hrq->entry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16505) 			bf_set(lpfc_rq_context_rqe_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16506) 			       &rq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16507) 			       LPFC_RQE_SIZE_8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16508) 			bf_set(lpfc_rq_context_page_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16509) 			       &rq_create->u.request.context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16510) 			       (PAGE_SIZE/SLI4_PAGE_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16511) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16512) 		rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16513) 		list_for_each_entry(dmabuf, &hrq->page_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16514) 			memset(dmabuf->virt, 0, hw_page_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16515) 			cnt = page_idx + dmabuf->buffer_tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16516) 			rq_create->u.request.page[cnt].addr_lo =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16517) 					putPaddrLow(dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16518) 			rq_create->u.request.page[cnt].addr_hi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16519) 					putPaddrHigh(dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16520) 			rc++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16521) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16522) 		page_idx += rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16524) 		rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16525) 		list_for_each_entry(dmabuf, &drq->page_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16526) 			memset(dmabuf->virt, 0, hw_page_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16527) 			cnt = page_idx + dmabuf->buffer_tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16528) 			rq_create->u.request.page[cnt].addr_lo =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16529) 					putPaddrLow(dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16530) 			rq_create->u.request.page[cnt].addr_hi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16531) 					putPaddrHigh(dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16532) 			rc++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16533) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16534) 		page_idx += rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16536) 		hrq->db_format = LPFC_DB_RING_FORMAT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16537) 		hrq->db_regaddr = phba->sli4_hba.RQDBregaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16538) 		hrq->type = LPFC_HRQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16539) 		hrq->assoc_qid = cq->queue_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16540) 		hrq->subtype = subtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16541) 		hrq->host_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16542) 		hrq->hba_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16543) 		hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16545) 		drq->db_format = LPFC_DB_RING_FORMAT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16546) 		drq->db_regaddr = phba->sli4_hba.RQDBregaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16547) 		drq->type = LPFC_DRQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16548) 		drq->assoc_qid = cq->queue_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16549) 		drq->subtype = subtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16550) 		drq->host_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16551) 		drq->hba_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16552) 		drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16554) 		list_add_tail(&hrq->list, &cq->child_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16555) 		list_add_tail(&drq->list, &cq->child_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16556) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16558) 	rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16559) 	/* The IOCTL status is embedded in the mailbox subheader. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16560) 	shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16561) 	shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16562) 	if (shdr_status || shdr_add_status || rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16563) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16564) 				"3120 RQ_CREATE mailbox failed with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16565) 				"status x%x add_status x%x, mbx status x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16566) 				shdr_status, shdr_add_status, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16567) 		status = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16568) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16569) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16570) 	rc = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16571) 	if (rc == 0xFFFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16572) 		status = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16573) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16574) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16576) 	/* Initialize all RQs with associated queue id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16577) 	for (idx = 0; idx < numrq; idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16578) 		hrq = hrqp[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16579) 		hrq->queue_id = rc + (2 * idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16580) 		drq = drqp[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16581) 		drq->queue_id = rc + (2 * idx) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16582) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16584) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16585) 	lpfc_sli4_mbox_cmd_free(phba, mbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16586) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16589) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16590)  * lpfc_eq_destroy - Destroy an event Queue on the HBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16591)  * @phba: HBA structure that indicates port to destroy a queue on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16592)  * @eq: The queue structure associated with the queue to destroy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16593)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16594)  * This function destroys a queue, as detailed in @eq by sending an mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16595)  * command, specific to the type of queue, to the HBA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16596)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16597)  * The @eq struct is used to get the queue ID of the queue to destroy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16598)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16599)  * On success this function will return a zero. If the queue destroy mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16600)  * command fails this function will return -ENXIO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16601)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16602) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16603) lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16604) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16605) 	LPFC_MBOXQ_t *mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16606) 	int rc, length, status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16607) 	uint32_t shdr_status, shdr_add_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16608) 	union lpfc_sli4_cfg_shdr *shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16610) 	/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16611) 	if (!eq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16612) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16614) 	mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16615) 	if (!mbox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16616) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16617) 	length = (sizeof(struct lpfc_mbx_eq_destroy) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16618) 		  sizeof(struct lpfc_sli4_cfg_mhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16619) 	lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16620) 			 LPFC_MBOX_OPCODE_EQ_DESTROY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16621) 			 length, LPFC_SLI4_MBX_EMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16622) 	bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16623) 	       eq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16624) 	mbox->vport = eq->phba->pport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16625) 	mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16627) 	rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16628) 	/* The IOCTL status is embedded in the mailbox subheader. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16629) 	shdr = (union lpfc_sli4_cfg_shdr *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16630) 		&mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16631) 	shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16632) 	shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16633) 	if (shdr_status || shdr_add_status || rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16634) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16635) 				"2505 EQ_DESTROY mailbox failed with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16636) 				"status x%x add_status x%x, mbx status x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16637) 				shdr_status, shdr_add_status, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16638) 		status = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16639) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16641) 	/* Remove eq from any list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16642) 	list_del_init(&eq->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16643) 	mempool_free(mbox, eq->phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16644) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16645) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16647) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16648)  * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16649)  * @phba: HBA structure that indicates port to destroy a queue on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16650)  * @cq: The queue structure associated with the queue to destroy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16651)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16652)  * This function destroys a queue, as detailed in @cq by sending an mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16653)  * command, specific to the type of queue, to the HBA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16654)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16655)  * The @cq struct is used to get the queue ID of the queue to destroy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16656)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16657)  * On success this function will return a zero. If the queue destroy mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16658)  * command fails this function will return -ENXIO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16659)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16660) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16661) lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16662) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16663) 	LPFC_MBOXQ_t *mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16664) 	int rc, length, status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16665) 	uint32_t shdr_status, shdr_add_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16666) 	union lpfc_sli4_cfg_shdr *shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16668) 	/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16669) 	if (!cq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16670) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16671) 	mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16672) 	if (!mbox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16673) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16674) 	length = (sizeof(struct lpfc_mbx_cq_destroy) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16675) 		  sizeof(struct lpfc_sli4_cfg_mhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16676) 	lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16677) 			 LPFC_MBOX_OPCODE_CQ_DESTROY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16678) 			 length, LPFC_SLI4_MBX_EMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16679) 	bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16680) 	       cq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16681) 	mbox->vport = cq->phba->pport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16682) 	mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16683) 	rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16684) 	/* The IOCTL status is embedded in the mailbox subheader. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16685) 	shdr = (union lpfc_sli4_cfg_shdr *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16686) 		&mbox->u.mqe.un.wq_create.header.cfg_shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16687) 	shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16688) 	shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16689) 	if (shdr_status || shdr_add_status || rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16690) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16691) 				"2506 CQ_DESTROY mailbox failed with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16692) 				"status x%x add_status x%x, mbx status x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16693) 				shdr_status, shdr_add_status, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16694) 		status = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16695) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16696) 	/* Remove cq from any list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16697) 	list_del_init(&cq->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16698) 	mempool_free(mbox, cq->phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16699) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16700) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16702) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16703)  * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16704)  * @phba: HBA structure that indicates port to destroy a queue on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16705)  * @mq: The queue structure associated with the queue to destroy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16706)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16707)  * This function destroys a queue, as detailed in @mq by sending an mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16708)  * command, specific to the type of queue, to the HBA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16709)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16710)  * The @mq struct is used to get the queue ID of the queue to destroy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16711)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16712)  * On success this function will return a zero. If the queue destroy mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16713)  * command fails this function will return -ENXIO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16714)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16715) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16716) lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16717) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16718) 	LPFC_MBOXQ_t *mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16719) 	int rc, length, status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16720) 	uint32_t shdr_status, shdr_add_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16721) 	union lpfc_sli4_cfg_shdr *shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16723) 	/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16724) 	if (!mq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16725) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16726) 	mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16727) 	if (!mbox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16728) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16729) 	length = (sizeof(struct lpfc_mbx_mq_destroy) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16730) 		  sizeof(struct lpfc_sli4_cfg_mhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16731) 	lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16732) 			 LPFC_MBOX_OPCODE_MQ_DESTROY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16733) 			 length, LPFC_SLI4_MBX_EMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16734) 	bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16735) 	       mq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16736) 	mbox->vport = mq->phba->pport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16737) 	mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16738) 	rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16739) 	/* The IOCTL status is embedded in the mailbox subheader. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16740) 	shdr = (union lpfc_sli4_cfg_shdr *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16741) 		&mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16742) 	shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16743) 	shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16744) 	if (shdr_status || shdr_add_status || rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16745) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16746) 				"2507 MQ_DESTROY mailbox failed with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16747) 				"status x%x add_status x%x, mbx status x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16748) 				shdr_status, shdr_add_status, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16749) 		status = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16750) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16751) 	/* Remove mq from any list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16752) 	list_del_init(&mq->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16753) 	mempool_free(mbox, mq->phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16754) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16755) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16757) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16758)  * lpfc_wq_destroy - Destroy a Work Queue on the HBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16759)  * @phba: HBA structure that indicates port to destroy a queue on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16760)  * @wq: The queue structure associated with the queue to destroy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16761)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16762)  * This function destroys a queue, as detailed in @wq by sending an mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16763)  * command, specific to the type of queue, to the HBA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16764)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16765)  * The @wq struct is used to get the queue ID of the queue to destroy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16766)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16767)  * On success this function will return a zero. If the queue destroy mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16768)  * command fails this function will return -ENXIO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16769)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16770) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16771) lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16772) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16773) 	LPFC_MBOXQ_t *mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16774) 	int rc, length, status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16775) 	uint32_t shdr_status, shdr_add_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16776) 	union lpfc_sli4_cfg_shdr *shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16778) 	/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16779) 	if (!wq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16780) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16781) 	mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16782) 	if (!mbox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16783) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16784) 	length = (sizeof(struct lpfc_mbx_wq_destroy) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16785) 		  sizeof(struct lpfc_sli4_cfg_mhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16786) 	lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16787) 			 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16788) 			 length, LPFC_SLI4_MBX_EMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16789) 	bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16790) 	       wq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16791) 	mbox->vport = wq->phba->pport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16792) 	mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16793) 	rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16794) 	shdr = (union lpfc_sli4_cfg_shdr *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16795) 		&mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16796) 	shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16797) 	shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16798) 	if (shdr_status || shdr_add_status || rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16799) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16800) 				"2508 WQ_DESTROY mailbox failed with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16801) 				"status x%x add_status x%x, mbx status x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16802) 				shdr_status, shdr_add_status, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16803) 		status = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16804) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16805) 	/* Remove wq from any list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16806) 	list_del_init(&wq->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16807) 	kfree(wq->pring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16808) 	wq->pring = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16809) 	mempool_free(mbox, wq->phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16810) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16811) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16813) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16814)  * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16815)  * @phba: HBA structure that indicates port to destroy a queue on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16816)  * @hrq: The queue structure associated with the queue to destroy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16817)  * @drq: The queue structure associated with the queue to destroy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16818)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16819)  * This function destroys a queue, as detailed in @rq by sending an mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16820)  * command, specific to the type of queue, to the HBA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16821)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16822)  * The @rq struct is used to get the queue ID of the queue to destroy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16823)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16824)  * On success this function will return a zero. If the queue destroy mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16825)  * command fails this function will return -ENXIO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16826)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16827) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16828) lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16829) 		struct lpfc_queue *drq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16830) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16831) 	LPFC_MBOXQ_t *mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16832) 	int rc, length, status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16833) 	uint32_t shdr_status, shdr_add_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16834) 	union lpfc_sli4_cfg_shdr *shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16836) 	/* sanity check on queue memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16837) 	if (!hrq || !drq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16838) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16839) 	mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16840) 	if (!mbox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16841) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16842) 	length = (sizeof(struct lpfc_mbx_rq_destroy) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16843) 		  sizeof(struct lpfc_sli4_cfg_mhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16844) 	lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16845) 			 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16846) 			 length, LPFC_SLI4_MBX_EMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16847) 	bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16848) 	       hrq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16849) 	mbox->vport = hrq->phba->pport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16850) 	mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16851) 	rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16852) 	/* The IOCTL status is embedded in the mailbox subheader. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16853) 	shdr = (union lpfc_sli4_cfg_shdr *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16854) 		&mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16855) 	shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16856) 	shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16857) 	if (shdr_status || shdr_add_status || rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16858) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16859) 				"2509 RQ_DESTROY mailbox failed with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16860) 				"status x%x add_status x%x, mbx status x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16861) 				shdr_status, shdr_add_status, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16862) 		mempool_free(mbox, hrq->phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16863) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16864) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16865) 	bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16866) 	       drq->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16867) 	rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16868) 	shdr = (union lpfc_sli4_cfg_shdr *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16869) 		&mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16870) 	shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16871) 	shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16872) 	if (shdr_status || shdr_add_status || rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16873) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16874) 				"2510 RQ_DESTROY mailbox failed with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16875) 				"status x%x add_status x%x, mbx status x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16876) 				shdr_status, shdr_add_status, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16877) 		status = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16878) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16879) 	list_del_init(&hrq->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16880) 	list_del_init(&drq->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16881) 	mempool_free(mbox, hrq->phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16882) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16883) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16885) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16886)  * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16887)  * @phba: The virtual port for which this call being executed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16888)  * @pdma_phys_addr0: Physical address of the 1st SGL page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16889)  * @pdma_phys_addr1: Physical address of the 2nd SGL page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16890)  * @xritag: the xritag that ties this io to the SGL pages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16891)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16892)  * This routine will post the sgl pages for the IO that has the xritag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16893)  * that is in the iocbq structure. The xritag is assigned during iocbq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16894)  * creation and persists for as long as the driver is loaded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16895)  * if the caller has fewer than 256 scatter gather segments to map then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16896)  * pdma_phys_addr1 should be 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16897)  * If the caller needs to map more than 256 scatter gather segment then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16898)  * pdma_phys_addr1 should be a valid physical address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16899)  * physical address for SGLs must be 64 byte aligned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16900)  * If you are going to map 2 SGL's then the first one must have 256 entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16901)  * the second sgl can have between 1 and 256 entries.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16902)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16903)  * Return codes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16904)  * 	0 - Success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16905)  * 	-ENXIO, -ENOMEM - Failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16906)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16907) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16908) lpfc_sli4_post_sgl(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16909) 		dma_addr_t pdma_phys_addr0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16910) 		dma_addr_t pdma_phys_addr1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16911) 		uint16_t xritag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16912) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16913) 	struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16914) 	LPFC_MBOXQ_t *mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16915) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16916) 	uint32_t shdr_status, shdr_add_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16917) 	uint32_t mbox_tmo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16918) 	union lpfc_sli4_cfg_shdr *shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16920) 	if (xritag == NO_XRI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16921) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16922) 				"0364 Invalid param:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16923) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16924) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16926) 	mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16927) 	if (!mbox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16928) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16930) 	lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16931) 			LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16932) 			sizeof(struct lpfc_mbx_post_sgl_pages) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16933) 			sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16935) 	post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16936) 				&mbox->u.mqe.un.post_sgl_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16937) 	bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16938) 	bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16940) 	post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo	=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16941) 				cpu_to_le32(putPaddrLow(pdma_phys_addr0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16942) 	post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16943) 				cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16944) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16945) 	post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo	=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16946) 				cpu_to_le32(putPaddrLow(pdma_phys_addr1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16947) 	post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16948) 				cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16949) 	if (!phba->sli4_hba.intr_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16950) 		rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16951) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16952) 		mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16953) 		rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16954) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16955) 	/* The IOCTL status is embedded in the mailbox subheader. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16956) 	shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16957) 	shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16958) 	shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16959) 	if (!phba->sli4_hba.intr_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16960) 		mempool_free(mbox, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16961) 	else if (rc != MBX_TIMEOUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16962) 		mempool_free(mbox, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16963) 	if (shdr_status || shdr_add_status || rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16964) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16965) 				"2511 POST_SGL mailbox failed with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16966) 				"status x%x add_status x%x, mbx status x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16967) 				shdr_status, shdr_add_status, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16968) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16969) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16970) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16972) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16973)  * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16974)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16975)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16976)  * This routine is invoked to post rpi header templates to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16977)  * HBA consistent with the SLI-4 interface spec.  This routine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16978)  * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16979)  * SLI4_PAGE_SIZE modulo 64 rpi context headers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16980)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16981)  * Returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16982)  *	A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16983)  *	LPFC_RPI_ALLOC_ERROR if no rpis are available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16984)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16985) static uint16_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16986) lpfc_sli4_alloc_xri(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16987) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16988) 	unsigned long xri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16989) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16990) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16991) 	 * Fetch the next logical xri.  Because this index is logical,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16992) 	 * the driver starts at 0 each time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16993) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16994) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16995) 	xri = find_next_zero_bit(phba->sli4_hba.xri_bmask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16996) 				 phba->sli4_hba.max_cfg_param.max_xri, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16997) 	if (xri >= phba->sli4_hba.max_cfg_param.max_xri) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16998) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16999) 		return NO_XRI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17000) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17001) 		set_bit(xri, phba->sli4_hba.xri_bmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17002) 		phba->sli4_hba.max_cfg_param.xri_used++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17003) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17004) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17005) 	return xri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17006) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17008) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17009)  * lpfc_sli4_free_xri - Release an xri for reuse.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17010)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17011)  * @xri: xri to release.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17012)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17013)  * This routine is invoked to release an xri to the pool of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17014)  * available rpis maintained by the driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17015)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17016) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17017) __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17018) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17019) 	if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17020) 		phba->sli4_hba.max_cfg_param.xri_used--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17021) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17022) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17024) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17025)  * lpfc_sli4_free_xri - Release an xri for reuse.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17026)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17027)  * @xri: xri to release.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17028)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17029)  * This routine is invoked to release an xri to the pool of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17030)  * available rpis maintained by the driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17031)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17032) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17033) lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17034) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17035) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17036) 	__lpfc_sli4_free_xri(phba, xri);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17037) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17038) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17039) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17040) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17041)  * lpfc_sli4_next_xritag - Get an xritag for the io
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17042)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17043)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17044)  * This function gets an xritag for the iocb. If there is no unused xritag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17045)  * it will return 0xffff.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17046)  * The function returns the allocated xritag if successful, else returns zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17047)  * Zero is not a valid xritag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17048)  * The caller is not required to hold any lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17049)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17050) uint16_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17051) lpfc_sli4_next_xritag(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17052) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17053) 	uint16_t xri_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17055) 	xri_index = lpfc_sli4_alloc_xri(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17056) 	if (xri_index == NO_XRI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17057) 		lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17058) 				"2004 Failed to allocate XRI.last XRITAG is %d"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17059) 				" Max XRI is %d, Used XRI is %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17060) 				xri_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17061) 				phba->sli4_hba.max_cfg_param.max_xri,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17062) 				phba->sli4_hba.max_cfg_param.xri_used);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17063) 	return xri_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17064) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17066) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17067)  * lpfc_sli4_post_sgl_list - post a block of ELS sgls to the port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17068)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17069)  * @post_sgl_list: pointer to els sgl entry list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17070)  * @post_cnt: number of els sgl entries on the list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17071)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17072)  * This routine is invoked to post a block of driver's sgl pages to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17073)  * HBA using non-embedded mailbox command. No Lock is held. This routine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17074)  * is only called when the driver is loading and after all IO has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17075)  * stopped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17076)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17077) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17078) lpfc_sli4_post_sgl_list(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17079) 			    struct list_head *post_sgl_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17080) 			    int post_cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17081) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17082) 	struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17083) 	struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17084) 	struct sgl_page_pairs *sgl_pg_pairs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17085) 	void *viraddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17086) 	LPFC_MBOXQ_t *mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17087) 	uint32_t reqlen, alloclen, pg_pairs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17088) 	uint32_t mbox_tmo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17089) 	uint16_t xritag_start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17090) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17091) 	uint32_t shdr_status, shdr_add_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17092) 	union lpfc_sli4_cfg_shdr *shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17093) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17094) 	reqlen = post_cnt * sizeof(struct sgl_page_pairs) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17095) 		 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17096) 	if (reqlen > SLI4_PAGE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17097) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17098) 				"2559 Block sgl registration required DMA "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17099) 				"size (%d) great than a page\n", reqlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17100) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17101) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17103) 	mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17104) 	if (!mbox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17105) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17107) 	/* Allocate DMA memory and set up the non-embedded mailbox command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17108) 	alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17109) 			 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17110) 			 LPFC_SLI4_MBX_NEMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17112) 	if (alloclen < reqlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17113) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17114) 				"0285 Allocated DMA memory size (%d) is "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17115) 				"less than the requested DMA memory "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17116) 				"size (%d)\n", alloclen, reqlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17117) 		lpfc_sli4_mbox_cmd_free(phba, mbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17118) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17119) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17120) 	/* Set up the SGL pages in the non-embedded DMA pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17121) 	viraddr = mbox->sge_array->addr[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17122) 	sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17123) 	sgl_pg_pairs = &sgl->sgl_pg_pairs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17125) 	pg_pairs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17126) 	list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17127) 		/* Set up the sge entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17128) 		sgl_pg_pairs->sgl_pg0_addr_lo =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17129) 				cpu_to_le32(putPaddrLow(sglq_entry->phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17130) 		sgl_pg_pairs->sgl_pg0_addr_hi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17131) 				cpu_to_le32(putPaddrHigh(sglq_entry->phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17132) 		sgl_pg_pairs->sgl_pg1_addr_lo =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17133) 				cpu_to_le32(putPaddrLow(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17134) 		sgl_pg_pairs->sgl_pg1_addr_hi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17135) 				cpu_to_le32(putPaddrHigh(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17137) 		/* Keep the first xritag on the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17138) 		if (pg_pairs == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17139) 			xritag_start = sglq_entry->sli4_xritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17140) 		sgl_pg_pairs++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17141) 		pg_pairs++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17142) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17144) 	/* Complete initialization and perform endian conversion. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17145) 	bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17146) 	bf_set(lpfc_post_sgl_pages_xricnt, sgl, post_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17147) 	sgl->word0 = cpu_to_le32(sgl->word0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17149) 	if (!phba->sli4_hba.intr_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17150) 		rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17151) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17152) 		mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17153) 		rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17154) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17155) 	shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17156) 	shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17157) 	shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17158) 	if (!phba->sli4_hba.intr_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17159) 		lpfc_sli4_mbox_cmd_free(phba, mbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17160) 	else if (rc != MBX_TIMEOUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17161) 		lpfc_sli4_mbox_cmd_free(phba, mbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17162) 	if (shdr_status || shdr_add_status || rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17163) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17164) 				"2513 POST_SGL_BLOCK mailbox command failed "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17165) 				"status x%x add_status x%x mbx status x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17166) 				shdr_status, shdr_add_status, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17167) 		rc = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17168) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17169) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17172) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17173)  * lpfc_sli4_post_io_sgl_block - post a block of nvme sgl list to firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17174)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17175)  * @nblist: pointer to nvme buffer list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17176)  * @count: number of scsi buffers on the list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17177)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17178)  * This routine is invoked to post a block of @count scsi sgl pages from a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17179)  * SCSI buffer list @nblist to the HBA using non-embedded mailbox command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17180)  * No Lock is held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17181)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17182)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17183) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17184) lpfc_sli4_post_io_sgl_block(struct lpfc_hba *phba, struct list_head *nblist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17185) 			    int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17187) 	struct lpfc_io_buf *lpfc_ncmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17188) 	struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17189) 	struct sgl_page_pairs *sgl_pg_pairs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17190) 	void *viraddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17191) 	LPFC_MBOXQ_t *mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17192) 	uint32_t reqlen, alloclen, pg_pairs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17193) 	uint32_t mbox_tmo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17194) 	uint16_t xritag_start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17195) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17196) 	uint32_t shdr_status, shdr_add_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17197) 	dma_addr_t pdma_phys_bpl1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17198) 	union lpfc_sli4_cfg_shdr *shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17200) 	/* Calculate the requested length of the dma memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17201) 	reqlen = count * sizeof(struct sgl_page_pairs) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17202) 		 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17203) 	if (reqlen > SLI4_PAGE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17204) 		lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17205) 				"6118 Block sgl registration required DMA "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17206) 				"size (%d) great than a page\n", reqlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17207) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17208) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17209) 	mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17210) 	if (!mbox) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17211) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17212) 				"6119 Failed to allocate mbox cmd memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17213) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17214) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17216) 	/* Allocate DMA memory and set up the non-embedded mailbox command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17217) 	alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17218) 				    LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17219) 				    reqlen, LPFC_SLI4_MBX_NEMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17221) 	if (alloclen < reqlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17222) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17223) 				"6120 Allocated DMA memory size (%d) is "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17224) 				"less than the requested DMA memory "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17225) 				"size (%d)\n", alloclen, reqlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17226) 		lpfc_sli4_mbox_cmd_free(phba, mbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17227) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17228) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17230) 	/* Get the first SGE entry from the non-embedded DMA memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17231) 	viraddr = mbox->sge_array->addr[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17233) 	/* Set up the SGL pages in the non-embedded DMA pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17234) 	sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17235) 	sgl_pg_pairs = &sgl->sgl_pg_pairs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17237) 	pg_pairs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17238) 	list_for_each_entry(lpfc_ncmd, nblist, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17239) 		/* Set up the sge entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17240) 		sgl_pg_pairs->sgl_pg0_addr_lo =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17241) 			cpu_to_le32(putPaddrLow(lpfc_ncmd->dma_phys_sgl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17242) 		sgl_pg_pairs->sgl_pg0_addr_hi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17243) 			cpu_to_le32(putPaddrHigh(lpfc_ncmd->dma_phys_sgl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17244) 		if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17245) 			pdma_phys_bpl1 = lpfc_ncmd->dma_phys_sgl +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17246) 						SGL_PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17247) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17248) 			pdma_phys_bpl1 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17249) 		sgl_pg_pairs->sgl_pg1_addr_lo =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17250) 			cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17251) 		sgl_pg_pairs->sgl_pg1_addr_hi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17252) 			cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17253) 		/* Keep the first xritag on the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17254) 		if (pg_pairs == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17255) 			xritag_start = lpfc_ncmd->cur_iocbq.sli4_xritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17256) 		sgl_pg_pairs++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17257) 		pg_pairs++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17258) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17259) 	bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17260) 	bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17261) 	/* Perform endian conversion if necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17262) 	sgl->word0 = cpu_to_le32(sgl->word0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17264) 	if (!phba->sli4_hba.intr_enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17265) 		rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17266) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17267) 		mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17268) 		rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17269) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17270) 	shdr = (union lpfc_sli4_cfg_shdr *)&sgl->cfg_shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17271) 	shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17272) 	shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17273) 	if (!phba->sli4_hba.intr_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17274) 		lpfc_sli4_mbox_cmd_free(phba, mbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17275) 	else if (rc != MBX_TIMEOUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17276) 		lpfc_sli4_mbox_cmd_free(phba, mbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17277) 	if (shdr_status || shdr_add_status || rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17278) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17279) 				"6125 POST_SGL_BLOCK mailbox command failed "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17280) 				"status x%x add_status x%x mbx status x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17281) 				shdr_status, shdr_add_status, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17282) 		rc = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17283) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17284) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17287) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17288)  * lpfc_sli4_post_io_sgl_list - Post blocks of nvme buffer sgls from a list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17289)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17290)  * @post_nblist: pointer to the nvme buffer list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17291)  * @sb_count: number of nvme buffers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17292)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17293)  * This routine walks a list of nvme buffers that was passed in. It attempts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17294)  * to construct blocks of nvme buffer sgls which contains contiguous xris and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17295)  * uses the non-embedded SGL block post mailbox commands to post to the port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17296)  * For single NVME buffer sgl with non-contiguous xri, if any, it shall use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17297)  * embedded SGL post mailbox command for posting. The @post_nblist passed in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17298)  * must be local list, thus no lock is needed when manipulate the list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17299)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17300)  * Returns: 0 = failure, non-zero number of successfully posted buffers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17301)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17302) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17303) lpfc_sli4_post_io_sgl_list(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17304) 			   struct list_head *post_nblist, int sb_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17306) 	struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17307) 	int status, sgl_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17308) 	int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17309) 	dma_addr_t pdma_phys_sgl1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17310) 	int last_xritag = NO_XRI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17311) 	int cur_xritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17312) 	LIST_HEAD(prep_nblist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17313) 	LIST_HEAD(blck_nblist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17314) 	LIST_HEAD(nvme_nblist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17316) 	/* sanity check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17317) 	if (sb_count <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17318) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17320) 	sgl_size = phba->cfg_sg_dma_buf_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17321) 	list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, post_nblist, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17322) 		list_del_init(&lpfc_ncmd->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17323) 		block_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17324) 		if ((last_xritag != NO_XRI) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17325) 		    (lpfc_ncmd->cur_iocbq.sli4_xritag != last_xritag + 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17326) 			/* a hole in xri block, form a sgl posting block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17327) 			list_splice_init(&prep_nblist, &blck_nblist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17328) 			post_cnt = block_cnt - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17329) 			/* prepare list for next posting block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17330) 			list_add_tail(&lpfc_ncmd->list, &prep_nblist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17331) 			block_cnt = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17332) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17333) 			/* prepare list for next posting block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17334) 			list_add_tail(&lpfc_ncmd->list, &prep_nblist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17335) 			/* enough sgls for non-embed sgl mbox command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17336) 			if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17337) 				list_splice_init(&prep_nblist, &blck_nblist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17338) 				post_cnt = block_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17339) 				block_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17340) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17341) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17342) 		num_posting++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17343) 		last_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17345) 		/* end of repost sgl list condition for NVME buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17346) 		if (num_posting == sb_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17347) 			if (post_cnt == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17348) 				/* last sgl posting block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17349) 				list_splice_init(&prep_nblist, &blck_nblist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17350) 				post_cnt = block_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17351) 			} else if (block_cnt == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17352) 				/* last single sgl with non-contiguous xri */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17353) 				if (sgl_size > SGL_PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17354) 					pdma_phys_sgl1 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17355) 						lpfc_ncmd->dma_phys_sgl +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17356) 						SGL_PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17357) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17358) 					pdma_phys_sgl1 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17359) 				cur_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17360) 				status = lpfc_sli4_post_sgl(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17361) 						phba, lpfc_ncmd->dma_phys_sgl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17362) 						pdma_phys_sgl1, cur_xritag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17363) 				if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17364) 					/* Post error.  Buffer unavailable. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17365) 					lpfc_ncmd->flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17366) 						LPFC_SBUF_NOT_POSTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17367) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17368) 					/* Post success. Bffer available. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17369) 					lpfc_ncmd->flags &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17370) 						~LPFC_SBUF_NOT_POSTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17371) 					lpfc_ncmd->status = IOSTAT_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17372) 					num_posted++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17373) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17374) 				/* success, put on NVME buffer sgl list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17375) 				list_add_tail(&lpfc_ncmd->list, &nvme_nblist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17376) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17377) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17379) 		/* continue until a nembed page worth of sgls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17380) 		if (post_cnt == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17381) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17383) 		/* post block of NVME buffer list sgls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17384) 		status = lpfc_sli4_post_io_sgl_block(phba, &blck_nblist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17385) 						     post_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17387) 		/* don't reset xirtag due to hole in xri block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17388) 		if (block_cnt == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17389) 			last_xritag = NO_XRI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17391) 		/* reset NVME buffer post count for next round of posting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17392) 		post_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17394) 		/* put posted NVME buffer-sgl posted on NVME buffer sgl list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17395) 		while (!list_empty(&blck_nblist)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17396) 			list_remove_head(&blck_nblist, lpfc_ncmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17397) 					 struct lpfc_io_buf, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17398) 			if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17399) 				/* Post error.  Mark buffer unavailable. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17400) 				lpfc_ncmd->flags |= LPFC_SBUF_NOT_POSTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17401) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17402) 				/* Post success, Mark buffer available. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17403) 				lpfc_ncmd->flags &= ~LPFC_SBUF_NOT_POSTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17404) 				lpfc_ncmd->status = IOSTAT_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17405) 				num_posted++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17406) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17407) 			list_add_tail(&lpfc_ncmd->list, &nvme_nblist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17408) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17409) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17410) 	/* Push NVME buffers with sgl posted to the available list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17411) 	lpfc_io_buf_replenish(phba, &nvme_nblist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17413) 	return num_posted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17416) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17417)  * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17418)  * @phba: pointer to lpfc_hba struct that the frame was received on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17419)  * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17420)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17421)  * This function checks the fields in the @fc_hdr to see if the FC frame is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17422)  * valid type of frame that the LPFC driver will handle. This function will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17423)  * return a zero if the frame is a valid frame or a non zero value when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17424)  * frame does not pass the check.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17425)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17426) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17427) lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17429) 	/*  make rctl_names static to save stack space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17430) 	struct fc_vft_header *fc_vft_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17431) 	uint32_t *header = (uint32_t *) fc_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17433) #define FC_RCTL_MDS_DIAGS	0xF4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17435) 	switch (fc_hdr->fh_r_ctl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17436) 	case FC_RCTL_DD_UNCAT:		/* uncategorized information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17437) 	case FC_RCTL_DD_SOL_DATA:	/* solicited data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17438) 	case FC_RCTL_DD_UNSOL_CTL:	/* unsolicited control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17439) 	case FC_RCTL_DD_SOL_CTL:	/* solicited control or reply */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17440) 	case FC_RCTL_DD_UNSOL_DATA:	/* unsolicited data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17441) 	case FC_RCTL_DD_DATA_DESC:	/* data descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17442) 	case FC_RCTL_DD_UNSOL_CMD:	/* unsolicited command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17443) 	case FC_RCTL_DD_CMD_STATUS:	/* command status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17444) 	case FC_RCTL_ELS_REQ:	/* extended link services request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17445) 	case FC_RCTL_ELS_REP:	/* extended link services reply */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17446) 	case FC_RCTL_ELS4_REQ:	/* FC-4 ELS request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17447) 	case FC_RCTL_ELS4_REP:	/* FC-4 ELS reply */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17448) 	case FC_RCTL_BA_NOP:  	/* basic link service NOP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17449) 	case FC_RCTL_BA_ABTS: 	/* basic link service abort */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17450) 	case FC_RCTL_BA_RMC: 	/* remove connection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17451) 	case FC_RCTL_BA_ACC:	/* basic accept */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17452) 	case FC_RCTL_BA_RJT:	/* basic reject */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17453) 	case FC_RCTL_BA_PRMT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17454) 	case FC_RCTL_ACK_1:	/* acknowledge_1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17455) 	case FC_RCTL_ACK_0:	/* acknowledge_0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17456) 	case FC_RCTL_P_RJT:	/* port reject */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17457) 	case FC_RCTL_F_RJT:	/* fabric reject */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17458) 	case FC_RCTL_P_BSY:	/* port busy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17459) 	case FC_RCTL_F_BSY:	/* fabric busy to data frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17460) 	case FC_RCTL_F_BSYL:	/* fabric busy to link control frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17461) 	case FC_RCTL_LCR:	/* link credit reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17462) 	case FC_RCTL_MDS_DIAGS: /* MDS Diagnostics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17463) 	case FC_RCTL_END:	/* end */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17464) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17465) 	case FC_RCTL_VFTH:	/* Virtual Fabric tagging Header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17466) 		fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17467) 		fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17468) 		return lpfc_fc_frame_check(phba, fc_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17469) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17470) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17471) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17473) 	switch (fc_hdr->fh_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17474) 	case FC_TYPE_BLS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17475) 	case FC_TYPE_ELS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17476) 	case FC_TYPE_FCP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17477) 	case FC_TYPE_CT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17478) 	case FC_TYPE_NVME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17479) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17480) 	case FC_TYPE_IP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17481) 	case FC_TYPE_ILS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17482) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17483) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17484) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17486) 	lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17487) 			"2538 Received frame rctl:x%x, type:x%x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17488) 			"frame Data:%08x %08x %08x %08x %08x %08x %08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17489) 			fc_hdr->fh_r_ctl, fc_hdr->fh_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17490) 			be32_to_cpu(header[0]), be32_to_cpu(header[1]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17491) 			be32_to_cpu(header[2]), be32_to_cpu(header[3]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17492) 			be32_to_cpu(header[4]), be32_to_cpu(header[5]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17493) 			be32_to_cpu(header[6]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17494) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17495) drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17496) 	lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17497) 			"2539 Dropped frame rctl:x%x type:x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17498) 			fc_hdr->fh_r_ctl, fc_hdr->fh_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17499) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17502) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17503)  * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17504)  * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17505)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17506)  * This function processes the FC header to retrieve the VFI from the VF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17507)  * header, if one exists. This function will return the VFI if one exists
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17508)  * or 0 if no VSAN Header exists.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17509)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17510) static uint32_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17511) lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17513) 	struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17515) 	if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17516) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17517) 	return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17520) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17521)  * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17522)  * @phba: Pointer to the HBA structure to search for the vport on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17523)  * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17524)  * @fcfi: The FC Fabric ID that the frame came from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17525)  * @did: Destination ID to match against
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17526)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17527)  * This function searches the @phba for a vport that matches the content of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17528)  * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17529)  * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17530)  * returns the matching vport pointer or NULL if unable to match frame to a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17531)  * vport.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17532)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17533) static struct lpfc_vport *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17534) lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17535) 		       uint16_t fcfi, uint32_t did)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17536) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17537) 	struct lpfc_vport **vports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17538) 	struct lpfc_vport *vport = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17539) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17541) 	if (did == Fabric_DID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17542) 		return phba->pport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17543) 	if ((phba->pport->fc_flag & FC_PT2PT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17544) 		!(phba->link_state == LPFC_HBA_READY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17545) 		return phba->pport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17547) 	vports = lpfc_create_vport_work_array(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17548) 	if (vports != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17549) 		for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17550) 			if (phba->fcf.fcfi == fcfi &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17551) 			    vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17552) 			    vports[i]->fc_myDID == did) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17553) 				vport = vports[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17554) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17555) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17556) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17557) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17558) 	lpfc_destroy_vport_work_array(phba, vports);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17559) 	return vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17562) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17563)  * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17564)  * @vport: The vport to work on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17565)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17566)  * This function updates the receive sequence time stamp for this vport. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17567)  * receive sequence time stamp indicates the time that the last frame of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17568)  * the sequence that has been idle for the longest amount of time was received.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17569)  * the driver uses this time stamp to indicate if any received sequences have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17570)  * timed out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17571)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17572) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17573) lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17574) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17575) 	struct lpfc_dmabuf *h_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17576) 	struct hbq_dmabuf *dmabuf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17578) 	/* get the oldest sequence on the rcv list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17579) 	h_buf = list_get_first(&vport->rcv_buffer_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17580) 			       struct lpfc_dmabuf, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17581) 	if (!h_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17582) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17583) 	dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17584) 	vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17587) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17588)  * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17589)  * @vport: The vport that the received sequences were sent to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17590)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17591)  * This function cleans up all outstanding received sequences. This is called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17592)  * by the driver when a link event or user action invalidates all the received
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17593)  * sequences.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17594)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17595) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17596) lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17597) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17598) 	struct lpfc_dmabuf *h_buf, *hnext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17599) 	struct lpfc_dmabuf *d_buf, *dnext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17600) 	struct hbq_dmabuf *dmabuf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17602) 	/* start with the oldest sequence on the rcv list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17603) 	list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17604) 		dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17605) 		list_del_init(&dmabuf->hbuf.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17606) 		list_for_each_entry_safe(d_buf, dnext,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17607) 					 &dmabuf->dbuf.list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17608) 			list_del_init(&d_buf->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17609) 			lpfc_in_buf_free(vport->phba, d_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17610) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17611) 		lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17612) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17615) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17616)  * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17617)  * @vport: The vport that the received sequences were sent to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17618)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17619)  * This function determines whether any received sequences have timed out by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17620)  * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17621)  * indicates that there is at least one timed out sequence this routine will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17622)  * go through the received sequences one at a time from most inactive to most
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17623)  * active to determine which ones need to be cleaned up. Once it has determined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17624)  * that a sequence needs to be cleaned up it will simply free up the resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17625)  * without sending an abort.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17626)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17627) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17628) lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17629) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17630) 	struct lpfc_dmabuf *h_buf, *hnext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17631) 	struct lpfc_dmabuf *d_buf, *dnext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17632) 	struct hbq_dmabuf *dmabuf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17633) 	unsigned long timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17634) 	int abort_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17636) 	timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17637) 		   vport->rcv_buffer_time_stamp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17638) 	if (list_empty(&vport->rcv_buffer_list) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17639) 	    time_before(jiffies, timeout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17640) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17641) 	/* start with the oldest sequence on the rcv list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17642) 	list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17643) 		dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17644) 		timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17645) 			   dmabuf->time_stamp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17646) 		if (time_before(jiffies, timeout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17647) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17648) 		abort_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17649) 		list_del_init(&dmabuf->hbuf.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17650) 		list_for_each_entry_safe(d_buf, dnext,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17651) 					 &dmabuf->dbuf.list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17652) 			list_del_init(&d_buf->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17653) 			lpfc_in_buf_free(vport->phba, d_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17654) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17655) 		lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17656) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17657) 	if (abort_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17658) 		lpfc_update_rcv_time_stamp(vport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17659) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17661) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17662)  * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17663)  * @vport: pointer to a vitural port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17664)  * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17665)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17666)  * This function searches through the existing incomplete sequences that have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17667)  * been sent to this @vport. If the frame matches one of the incomplete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17668)  * sequences then the dbuf in the @dmabuf is added to the list of frames that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17669)  * make up that sequence. If no sequence is found that matches this frame then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17670)  * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17671)  * This function returns a pointer to the first dmabuf in the sequence list that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17672)  * the frame was linked to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17673)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17674) static struct hbq_dmabuf *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17675) lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17676) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17677) 	struct fc_frame_header *new_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17678) 	struct fc_frame_header *temp_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17679) 	struct lpfc_dmabuf *d_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17680) 	struct lpfc_dmabuf *h_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17681) 	struct hbq_dmabuf *seq_dmabuf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17682) 	struct hbq_dmabuf *temp_dmabuf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17683) 	uint8_t	found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17685) 	INIT_LIST_HEAD(&dmabuf->dbuf.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17686) 	dmabuf->time_stamp = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17687) 	new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17689) 	/* Use the hdr_buf to find the sequence that this frame belongs to */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17690) 	list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17691) 		temp_hdr = (struct fc_frame_header *)h_buf->virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17692) 		if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17693) 		    (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17694) 		    (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17695) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17696) 		/* found a pending sequence that matches this frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17697) 		seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17698) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17699) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17700) 	if (!seq_dmabuf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17701) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17702) 		 * This indicates first frame received for this sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17703) 		 * Queue the buffer on the vport's rcv_buffer_list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17704) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17705) 		list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17706) 		lpfc_update_rcv_time_stamp(vport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17707) 		return dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17708) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17709) 	temp_hdr = seq_dmabuf->hbuf.virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17710) 	if (be16_to_cpu(new_hdr->fh_seq_cnt) <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17711) 		be16_to_cpu(temp_hdr->fh_seq_cnt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17712) 		list_del_init(&seq_dmabuf->hbuf.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17713) 		list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17714) 		list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17715) 		lpfc_update_rcv_time_stamp(vport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17716) 		return dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17717) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17718) 	/* move this sequence to the tail to indicate a young sequence */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17719) 	list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17720) 	seq_dmabuf->time_stamp = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17721) 	lpfc_update_rcv_time_stamp(vport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17722) 	if (list_empty(&seq_dmabuf->dbuf.list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17723) 		temp_hdr = dmabuf->hbuf.virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17724) 		list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17725) 		return seq_dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17726) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17727) 	/* find the correct place in the sequence to insert this frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17728) 	d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17729) 	while (!found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17730) 		temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17731) 		temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17732) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17733) 		 * If the frame's sequence count is greater than the frame on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17734) 		 * the list then insert the frame right after this frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17735) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17736) 		if (be16_to_cpu(new_hdr->fh_seq_cnt) >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17737) 			be16_to_cpu(temp_hdr->fh_seq_cnt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17738) 			list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17739) 			found = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17740) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17741) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17743) 		if (&d_buf->list == &seq_dmabuf->dbuf.list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17744) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17745) 		d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17746) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17748) 	if (found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17749) 		return seq_dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17750) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17751) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17753) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17754)  * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17755)  * @vport: pointer to a vitural port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17756)  * @dmabuf: pointer to a dmabuf that describes the FC sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17757)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17758)  * This function tries to abort from the partially assembed sequence, described
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17759)  * by the information from basic abbort @dmabuf. It checks to see whether such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17760)  * partially assembled sequence held by the driver. If so, it shall free up all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17761)  * the frames from the partially assembled sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17762)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17763)  * Return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17764)  * true  -- if there is matching partially assembled sequence present and all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17765)  *          the frames freed with the sequence;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17766)  * false -- if there is no matching partially assembled sequence present so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17767)  *          nothing got aborted in the lower layer driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17768)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17769) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17770) lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17771) 			    struct hbq_dmabuf *dmabuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17772) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17773) 	struct fc_frame_header *new_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17774) 	struct fc_frame_header *temp_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17775) 	struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17776) 	struct hbq_dmabuf *seq_dmabuf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17778) 	/* Use the hdr_buf to find the sequence that matches this frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17779) 	INIT_LIST_HEAD(&dmabuf->dbuf.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17780) 	INIT_LIST_HEAD(&dmabuf->hbuf.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17781) 	new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17782) 	list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17783) 		temp_hdr = (struct fc_frame_header *)h_buf->virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17784) 		if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17785) 		    (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17786) 		    (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17787) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17788) 		/* found a pending sequence that matches this frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17789) 		seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17790) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17791) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17793) 	/* Free up all the frames from the partially assembled sequence */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17794) 	if (seq_dmabuf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17795) 		list_for_each_entry_safe(d_buf, n_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17796) 					 &seq_dmabuf->dbuf.list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17797) 			list_del_init(&d_buf->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17798) 			lpfc_in_buf_free(vport->phba, d_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17799) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17800) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17801) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17802) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17803) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17805) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17806)  * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17807)  * @vport: pointer to a vitural port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17808)  * @dmabuf: pointer to a dmabuf that describes the FC sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17809)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17810)  * This function tries to abort from the assembed sequence from upper level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17811)  * protocol, described by the information from basic abbort @dmabuf. It
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17812)  * checks to see whether such pending context exists at upper level protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17813)  * If so, it shall clean up the pending context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17814)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17815)  * Return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17816)  * true  -- if there is matching pending context of the sequence cleaned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17817)  *          at ulp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17818)  * false -- if there is no matching pending context of the sequence present
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17819)  *          at ulp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17820)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17821) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17822) lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17823) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17824) 	struct lpfc_hba *phba = vport->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17825) 	int handled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17827) 	/* Accepting abort at ulp with SLI4 only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17828) 	if (phba->sli_rev < LPFC_SLI_REV4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17829) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17831) 	/* Register all caring upper level protocols to attend abort */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17832) 	handled = lpfc_ct_handle_unsol_abort(phba, dmabuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17833) 	if (handled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17834) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17836) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17837) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17839) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17840)  * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17841)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17842)  * @cmd_iocbq: pointer to the command iocbq structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17843)  * @rsp_iocbq: pointer to the response iocbq structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17844)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17845)  * This function handles the sequence abort response iocb command complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17846)  * event. It properly releases the memory allocated to the sequence abort
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17847)  * accept iocb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17848)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17849) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17850) lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17851) 			     struct lpfc_iocbq *cmd_iocbq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17852) 			     struct lpfc_iocbq *rsp_iocbq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17853) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17854) 	struct lpfc_nodelist *ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17856) 	if (cmd_iocbq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17857) 		ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17858) 		lpfc_nlp_put(ndlp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17859) 		lpfc_sli_release_iocbq(phba, cmd_iocbq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17860) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17862) 	/* Failure means BLS ABORT RSP did not get delivered to remote node*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17863) 	if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17864) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17865) 			"3154 BLS ABORT RSP failed, data:  x%x/x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17866) 			rsp_iocbq->iocb.ulpStatus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17867) 			rsp_iocbq->iocb.un.ulpWord[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17870) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17871)  * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17872)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17873)  * @xri: xri id in transaction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17874)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17875)  * This function validates the xri maps to the known range of XRIs allocated an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17876)  * used by the driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17877)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17878) uint16_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17879) lpfc_sli4_xri_inrange(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17880) 		      uint16_t xri)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17881) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17882) 	uint16_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17883) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17884) 	for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17885) 		if (xri == phba->sli4_hba.xri_ids[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17886) 			return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17887) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17888) 	return NO_XRI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17889) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17891) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17892)  * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17893)  * @vport: pointer to a vitural port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17894)  * @fc_hdr: pointer to a FC frame header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17895)  * @aborted: was the partially assembled receive sequence successfully aborted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17896)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17897)  * This function sends a basic response to a previous unsol sequence abort
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17898)  * event after aborting the sequence handling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17899)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17900) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17901) lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17902) 			struct fc_frame_header *fc_hdr, bool aborted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17903) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17904) 	struct lpfc_hba *phba = vport->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17905) 	struct lpfc_iocbq *ctiocb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17906) 	struct lpfc_nodelist *ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17907) 	uint16_t oxid, rxid, xri, lxri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17908) 	uint32_t sid, fctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17909) 	IOCB_t *icmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17910) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17912) 	if (!lpfc_is_link_up(phba))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17913) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17915) 	sid = sli4_sid_from_fc_hdr(fc_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17916) 	oxid = be16_to_cpu(fc_hdr->fh_ox_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17917) 	rxid = be16_to_cpu(fc_hdr->fh_rx_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17918) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17919) 	ndlp = lpfc_findnode_did(vport, sid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17920) 	if (!ndlp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17921) 		ndlp = lpfc_nlp_init(vport, sid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17922) 		if (!ndlp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17923) 			lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17924) 					 "1268 Failed to allocate ndlp for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17925) 					 "oxid:x%x SID:x%x\n", oxid, sid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17926) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17927) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17928) 		/* Put ndlp onto pport node list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17929) 		lpfc_enqueue_node(vport, ndlp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17930) 	} else if (!NLP_CHK_NODE_ACT(ndlp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17931) 		/* re-setup ndlp without removing from node list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17932) 		ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17933) 		if (!ndlp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17934) 			lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17935) 					 "3275 Failed to active ndlp found "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17936) 					 "for oxid:x%x SID:x%x\n", oxid, sid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17937) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17938) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17939) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17941) 	/* Allocate buffer for rsp iocb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17942) 	ctiocb = lpfc_sli_get_iocbq(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17943) 	if (!ctiocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17944) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17946) 	/* Extract the F_CTL field from FC_HDR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17947) 	fctl = sli4_fctl_from_fc_hdr(fc_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17949) 	icmd = &ctiocb->iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17950) 	icmd->un.xseq64.bdl.bdeSize = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17951) 	icmd->un.xseq64.bdl.ulpIoTag32 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17952) 	icmd->un.xseq64.w5.hcsw.Dfctl = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17953) 	icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17954) 	icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17955) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17956) 	/* Fill in the rest of iocb fields */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17957) 	icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17958) 	icmd->ulpBdeCount = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17959) 	icmd->ulpLe = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17960) 	icmd->ulpClass = CLASS3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17961) 	icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17962) 	ctiocb->context1 = lpfc_nlp_get(ndlp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17964) 	ctiocb->vport = phba->pport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17965) 	ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17966) 	ctiocb->sli4_lxritag = NO_XRI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17967) 	ctiocb->sli4_xritag = NO_XRI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17969) 	if (fctl & FC_FC_EX_CTX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17970) 		/* Exchange responder sent the abort so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17971) 		 * own the oxid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17972) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17973) 		xri = oxid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17974) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17975) 		xri = rxid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17976) 	lxri = lpfc_sli4_xri_inrange(phba, xri);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17977) 	if (lxri != NO_XRI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17978) 		lpfc_set_rrq_active(phba, ndlp, lxri,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17979) 			(xri == oxid) ? rxid : oxid, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17980) 	/* For BA_ABTS from exchange responder, if the logical xri with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17981) 	 * the oxid maps to the FCP XRI range, the port no longer has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17982) 	 * that exchange context, send a BLS_RJT. Override the IOCB for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17983) 	 * a BA_RJT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17984) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17985) 	if ((fctl & FC_FC_EX_CTX) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17986) 	    (lxri > lpfc_sli4_get_iocb_cnt(phba))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17987) 		icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17988) 		bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17989) 		bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17990) 		bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17991) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17992) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17993) 	/* If BA_ABTS failed to abort a partially assembled receive sequence,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17994) 	 * the driver no longer has that exchange, send a BLS_RJT. Override
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17995) 	 * the IOCB for a BA_RJT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17996) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17997) 	if (aborted == false) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17998) 		icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17999) 		bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18000) 		bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18001) 		bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18002) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18004) 	if (fctl & FC_FC_EX_CTX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18005) 		/* ABTS sent by responder to CT exchange, construction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18006) 		 * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18007) 		 * field and RX_ID from ABTS for RX_ID field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18008) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18009) 		bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18010) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18011) 		/* ABTS sent by initiator to CT exchange, construction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18012) 		 * of BA_ACC will need to allocate a new XRI as for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18013) 		 * XRI_TAG field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18014) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18015) 		bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18016) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18017) 	bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18018) 	bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18019) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18020) 	/* Xmit CT abts response on exchange <xid> */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18021) 	lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18022) 			 "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18023) 			 icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18025) 	rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18026) 	if (rc == IOCB_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18027) 		lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18028) 				 "2925 Failed to issue CT ABTS RSP x%x on "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18029) 				 "xri x%x, Data x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18030) 				 icmd->un.xseq64.w5.hcsw.Rctl, oxid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18031) 				 phba->link_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18032) 		lpfc_nlp_put(ndlp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18033) 		ctiocb->context1 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18034) 		lpfc_sli_release_iocbq(phba, ctiocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18035) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18036) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18037) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18038) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18039)  * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18040)  * @vport: Pointer to the vport on which this sequence was received
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18041)  * @dmabuf: pointer to a dmabuf that describes the FC sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18042)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18043)  * This function handles an SLI-4 unsolicited abort event. If the unsolicited
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18044)  * receive sequence is only partially assembed by the driver, it shall abort
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18045)  * the partially assembled frames for the sequence. Otherwise, if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18046)  * unsolicited receive sequence has been completely assembled and passed to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18047)  * the Upper Layer Protocol (ULP), it then mark the per oxid status for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18048)  * unsolicited sequence has been aborted. After that, it will issue a basic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18049)  * accept to accept the abort.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18050)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18051) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18052) lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18053) 			     struct hbq_dmabuf *dmabuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18054) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18055) 	struct lpfc_hba *phba = vport->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18056) 	struct fc_frame_header fc_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18057) 	uint32_t fctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18058) 	bool aborted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18060) 	/* Make a copy of fc_hdr before the dmabuf being released */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18061) 	memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18062) 	fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18063) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18064) 	if (fctl & FC_FC_EX_CTX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18065) 		/* ABTS by responder to exchange, no cleanup needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18066) 		aborted = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18067) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18068) 		/* ABTS by initiator to exchange, need to do cleanup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18069) 		aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18070) 		if (aborted == false)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18071) 			aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18072) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18073) 	lpfc_in_buf_free(phba, &dmabuf->dbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18074) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18075) 	if (phba->nvmet_support) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18076) 		lpfc_nvmet_rcv_unsol_abort(vport, &fc_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18077) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18078) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18079) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18080) 	/* Respond with BA_ACC or BA_RJT accordingly */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18081) 	lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18082) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18083) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18084) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18085)  * lpfc_seq_complete - Indicates if a sequence is complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18086)  * @dmabuf: pointer to a dmabuf that describes the FC sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18087)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18088)  * This function checks the sequence, starting with the frame described by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18089)  * @dmabuf, to see if all the frames associated with this sequence are present.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18090)  * the frames associated with this sequence are linked to the @dmabuf using the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18091)  * dbuf list. This function looks for two major things. 1) That the first frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18092)  * has a sequence count of zero. 2) There is a frame with last frame of sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18093)  * set. 3) That there are no holes in the sequence count. The function will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18094)  * return 1 when the sequence is complete, otherwise it will return 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18095)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18096) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18097) lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18098) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18099) 	struct fc_frame_header *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18100) 	struct lpfc_dmabuf *d_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18101) 	struct hbq_dmabuf *seq_dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18102) 	uint32_t fctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18103) 	int seq_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18105) 	hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18106) 	/* make sure first fame of sequence has a sequence count of zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18107) 	if (hdr->fh_seq_cnt != seq_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18108) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18109) 	fctl = (hdr->fh_f_ctl[0] << 16 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18110) 		hdr->fh_f_ctl[1] << 8 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18111) 		hdr->fh_f_ctl[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18112) 	/* If last frame of sequence we can return success. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18113) 	if (fctl & FC_FC_END_SEQ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18114) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18115) 	list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18116) 		seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18117) 		hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18118) 		/* If there is a hole in the sequence count then fail. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18119) 		if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18120) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18121) 		fctl = (hdr->fh_f_ctl[0] << 16 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18122) 			hdr->fh_f_ctl[1] << 8 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18123) 			hdr->fh_f_ctl[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18124) 		/* If last frame of sequence we can return success. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18125) 		if (fctl & FC_FC_END_SEQ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18126) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18127) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18128) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18131) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18132)  * lpfc_prep_seq - Prep sequence for ULP processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18133)  * @vport: Pointer to the vport on which this sequence was received
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18134)  * @seq_dmabuf: pointer to a dmabuf that describes the FC sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18135)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18136)  * This function takes a sequence, described by a list of frames, and creates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18137)  * a list of iocbq structures to describe the sequence. This iocbq list will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18138)  * used to issue to the generic unsolicited sequence handler. This routine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18139)  * returns a pointer to the first iocbq in the list. If the function is unable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18140)  * to allocate an iocbq then it throw out the received frames that were not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18141)  * able to be described and return a pointer to the first iocbq. If unable to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18142)  * allocate any iocbqs (including the first) this function will return NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18143)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18144) static struct lpfc_iocbq *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18145) lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18147) 	struct hbq_dmabuf *hbq_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18148) 	struct lpfc_dmabuf *d_buf, *n_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18149) 	struct lpfc_iocbq *first_iocbq, *iocbq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18150) 	struct fc_frame_header *fc_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18151) 	uint32_t sid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18152) 	uint32_t len, tot_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18153) 	struct ulp_bde64 *pbde;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18155) 	fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18156) 	/* remove from receive buffer list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18157) 	list_del_init(&seq_dmabuf->hbuf.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18158) 	lpfc_update_rcv_time_stamp(vport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18159) 	/* get the Remote Port's SID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18160) 	sid = sli4_sid_from_fc_hdr(fc_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18161) 	tot_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18162) 	/* Get an iocbq struct to fill in. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18163) 	first_iocbq = lpfc_sli_get_iocbq(vport->phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18164) 	if (first_iocbq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18165) 		/* Initialize the first IOCB. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18166) 		first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18167) 		first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18168) 		first_iocbq->vport = vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18170) 		/* Check FC Header to see what TYPE of frame we are rcv'ing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18171) 		if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18172) 			first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18173) 			first_iocbq->iocb.un.rcvels.parmRo =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18174) 				sli4_did_from_fc_hdr(fc_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18175) 			first_iocbq->iocb.ulpPU = PARM_NPIV_DID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18176) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18177) 			first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18178) 		first_iocbq->iocb.ulpContext = NO_XRI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18179) 		first_iocbq->iocb.unsli3.rcvsli3.ox_id =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18180) 			be16_to_cpu(fc_hdr->fh_ox_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18181) 		/* iocbq is prepped for internal consumption.  Physical vpi. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18182) 		first_iocbq->iocb.unsli3.rcvsli3.vpi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18183) 			vport->phba->vpi_ids[vport->vpi];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18184) 		/* put the first buffer into the first IOCBq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18185) 		tot_len = bf_get(lpfc_rcqe_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18186) 				       &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18188) 		first_iocbq->context2 = &seq_dmabuf->dbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18189) 		first_iocbq->context3 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18190) 		first_iocbq->iocb.ulpBdeCount = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18191) 		if (tot_len > LPFC_DATA_BUF_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18192) 			first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18193) 							LPFC_DATA_BUF_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18194) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18195) 			first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18197) 		first_iocbq->iocb.un.rcvels.remoteID = sid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18199) 		first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18200) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18201) 	iocbq = first_iocbq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18202) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18203) 	 * Each IOCBq can have two Buffers assigned, so go through the list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18204) 	 * of buffers for this sequence and save two buffers in each IOCBq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18205) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18206) 	list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18207) 		if (!iocbq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18208) 			lpfc_in_buf_free(vport->phba, d_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18209) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18210) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18211) 		if (!iocbq->context3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18212) 			iocbq->context3 = d_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18213) 			iocbq->iocb.ulpBdeCount++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18214) 			/* We need to get the size out of the right CQE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18215) 			hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18216) 			len = bf_get(lpfc_rcqe_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18217) 				       &hbq_buf->cq_event.cqe.rcqe_cmpl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18218) 			pbde = (struct ulp_bde64 *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18219) 					&iocbq->iocb.unsli3.sli3Words[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18220) 			if (len > LPFC_DATA_BUF_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18221) 				pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18222) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18223) 				pbde->tus.f.bdeSize = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18225) 			iocbq->iocb.unsli3.rcvsli3.acc_len += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18226) 			tot_len += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18227) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18228) 			iocbq = lpfc_sli_get_iocbq(vport->phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18229) 			if (!iocbq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18230) 				if (first_iocbq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18231) 					first_iocbq->iocb.ulpStatus =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18232) 							IOSTAT_FCP_RSP_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18233) 					first_iocbq->iocb.un.ulpWord[4] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18234) 							IOERR_NO_RESOURCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18235) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18236) 				lpfc_in_buf_free(vport->phba, d_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18237) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18238) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18239) 			/* We need to get the size out of the right CQE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18240) 			hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18241) 			len = bf_get(lpfc_rcqe_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18242) 				       &hbq_buf->cq_event.cqe.rcqe_cmpl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18243) 			iocbq->context2 = d_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18244) 			iocbq->context3 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18245) 			iocbq->iocb.ulpBdeCount = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18246) 			if (len > LPFC_DATA_BUF_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18247) 				iocbq->iocb.un.cont64[0].tus.f.bdeSize =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18248) 							LPFC_DATA_BUF_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18249) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18250) 				iocbq->iocb.un.cont64[0].tus.f.bdeSize = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18252) 			tot_len += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18253) 			iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18255) 			iocbq->iocb.un.rcvels.remoteID = sid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18256) 			list_add_tail(&iocbq->list, &first_iocbq->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18257) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18258) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18259) 	/* Free the sequence's header buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18260) 	if (!first_iocbq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18261) 		lpfc_in_buf_free(vport->phba, &seq_dmabuf->dbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18263) 	return first_iocbq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18266) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18267) lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18268) 			  struct hbq_dmabuf *seq_dmabuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18270) 	struct fc_frame_header *fc_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18271) 	struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18272) 	struct lpfc_hba *phba = vport->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18274) 	fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18275) 	iocbq = lpfc_prep_seq(vport, seq_dmabuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18276) 	if (!iocbq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18277) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18278) 				"2707 Ring %d handler: Failed to allocate "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18279) 				"iocb Rctl x%x Type x%x received\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18280) 				LPFC_ELS_RING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18281) 				fc_hdr->fh_r_ctl, fc_hdr->fh_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18282) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18283) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18284) 	if (!lpfc_complete_unsol_iocb(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18285) 				      phba->sli4_hba.els_wq->pring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18286) 				      iocbq, fc_hdr->fh_r_ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18287) 				      fc_hdr->fh_type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18288) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18289) 				"2540 Ring %d handler: unexpected Rctl "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18290) 				"x%x Type x%x received\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18291) 				LPFC_ELS_RING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18292) 				fc_hdr->fh_r_ctl, fc_hdr->fh_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18294) 	/* Free iocb created in lpfc_prep_seq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18295) 	list_for_each_entry_safe(curr_iocb, next_iocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18296) 		&iocbq->list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18297) 		list_del_init(&curr_iocb->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18298) 		lpfc_sli_release_iocbq(phba, curr_iocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18299) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18300) 	lpfc_sli_release_iocbq(phba, iocbq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18303) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18304) lpfc_sli4_mds_loopback_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18305) 			    struct lpfc_iocbq *rspiocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18307) 	struct lpfc_dmabuf *pcmd = cmdiocb->context2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18309) 	if (pcmd && pcmd->virt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18310) 		dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18311) 	kfree(pcmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18312) 	lpfc_sli_release_iocbq(phba, cmdiocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18313) 	lpfc_drain_txq(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18316) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18317) lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18318) 			      struct hbq_dmabuf *dmabuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18320) 	struct fc_frame_header *fc_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18321) 	struct lpfc_hba *phba = vport->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18322) 	struct lpfc_iocbq *iocbq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18323) 	union  lpfc_wqe *wqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18324) 	struct lpfc_dmabuf *pcmd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18325) 	uint32_t frame_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18326) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18327) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18329) 	fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18330) 	frame_len = bf_get(lpfc_rcqe_length, &dmabuf->cq_event.cqe.rcqe_cmpl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18332) 	/* Send the received frame back */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18333) 	iocbq = lpfc_sli_get_iocbq(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18334) 	if (!iocbq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18335) 		/* Queue cq event and wakeup worker thread to process it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18336) 		spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18337) 		list_add_tail(&dmabuf->cq_event.list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18338) 			      &phba->sli4_hba.sp_queue_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18339) 		phba->hba_flag |= HBA_SP_QUEUE_EVT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18340) 		spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18341) 		lpfc_worker_wake_up(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18342) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18343) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18345) 	/* Allocate buffer for command payload */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18346) 	pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18347) 	if (pcmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18348) 		pcmd->virt = dma_pool_alloc(phba->lpfc_drb_pool, GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18349) 					    &pcmd->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18350) 	if (!pcmd || !pcmd->virt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18351) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18353) 	INIT_LIST_HEAD(&pcmd->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18355) 	/* copyin the payload */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18356) 	memcpy(pcmd->virt, dmabuf->dbuf.virt, frame_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18358) 	/* fill in BDE's for command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18359) 	iocbq->iocb.un.xseq64.bdl.addrHigh = putPaddrHigh(pcmd->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18360) 	iocbq->iocb.un.xseq64.bdl.addrLow = putPaddrLow(pcmd->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18361) 	iocbq->iocb.un.xseq64.bdl.bdeFlags = BUFF_TYPE_BDE_64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18362) 	iocbq->iocb.un.xseq64.bdl.bdeSize = frame_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18364) 	iocbq->context2 = pcmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18365) 	iocbq->vport = vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18366) 	iocbq->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18367) 	iocbq->iocb_flag |= LPFC_USE_FCPWQIDX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18369) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18370) 	 * Setup rest of the iocb as though it were a WQE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18371) 	 * Build the SEND_FRAME WQE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18372) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18373) 	wqe = (union lpfc_wqe *)&iocbq->iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18375) 	wqe->send_frame.frame_len = frame_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18376) 	wqe->send_frame.fc_hdr_wd0 = be32_to_cpu(*((uint32_t *)fc_hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18377) 	wqe->send_frame.fc_hdr_wd1 = be32_to_cpu(*((uint32_t *)fc_hdr + 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18378) 	wqe->send_frame.fc_hdr_wd2 = be32_to_cpu(*((uint32_t *)fc_hdr + 2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18379) 	wqe->send_frame.fc_hdr_wd3 = be32_to_cpu(*((uint32_t *)fc_hdr + 3));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18380) 	wqe->send_frame.fc_hdr_wd4 = be32_to_cpu(*((uint32_t *)fc_hdr + 4));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18381) 	wqe->send_frame.fc_hdr_wd5 = be32_to_cpu(*((uint32_t *)fc_hdr + 5));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18383) 	iocbq->iocb.ulpCommand = CMD_SEND_FRAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18384) 	iocbq->iocb.ulpLe = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18385) 	iocbq->iocb_cmpl = lpfc_sli4_mds_loopback_cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18386) 	rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocbq, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18387) 	if (rc == IOCB_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18388) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18390) 	lpfc_in_buf_free(phba, &dmabuf->dbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18391) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18393) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18394) 	lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18395) 			"2023 Unable to process MDS loopback frame\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18396) 	if (pcmd && pcmd->virt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18397) 		dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18398) 	kfree(pcmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18399) 	if (iocbq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18400) 		lpfc_sli_release_iocbq(phba, iocbq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18401) 	lpfc_in_buf_free(phba, &dmabuf->dbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18404) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18405)  * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18406)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18407)  * @dmabuf: Pointer to a dmabuf that describes the FC sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18408)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18409)  * This function is called with no lock held. This function processes all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18410)  * the received buffers and gives it to upper layers when a received buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18411)  * indicates that it is the final frame in the sequence. The interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18412)  * service routine processes received buffers at interrupt contexts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18413)  * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18414)  * appropriate receive function when the final frame in a sequence is received.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18415)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18416) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18417) lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18418) 				 struct hbq_dmabuf *dmabuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18419) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18420) 	struct hbq_dmabuf *seq_dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18421) 	struct fc_frame_header *fc_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18422) 	struct lpfc_vport *vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18423) 	uint32_t fcfi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18424) 	uint32_t did;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18426) 	/* Process each received buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18427) 	fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18429) 	if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18430) 	    fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18431) 		vport = phba->pport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18432) 		/* Handle MDS Loopback frames */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18433) 		if  (!(phba->pport->load_flag & FC_UNLOADING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18434) 			lpfc_sli4_handle_mds_loopback(vport, dmabuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18435) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18436) 			lpfc_in_buf_free(phba, &dmabuf->dbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18437) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18438) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18440) 	/* check to see if this a valid type of frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18441) 	if (lpfc_fc_frame_check(phba, fc_hdr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18442) 		lpfc_in_buf_free(phba, &dmabuf->dbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18443) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18444) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18446) 	if ((bf_get(lpfc_cqe_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18447) 		    &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18448) 		fcfi = bf_get(lpfc_rcqe_fcf_id_v1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18449) 			      &dmabuf->cq_event.cqe.rcqe_cmpl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18450) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18451) 		fcfi = bf_get(lpfc_rcqe_fcf_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18452) 			      &dmabuf->cq_event.cqe.rcqe_cmpl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18454) 	if (fc_hdr->fh_r_ctl == 0xF4 && fc_hdr->fh_type == 0xFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18455) 		vport = phba->pport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18456) 		lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18457) 				"2023 MDS Loopback %d bytes\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18458) 				bf_get(lpfc_rcqe_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18459) 				       &dmabuf->cq_event.cqe.rcqe_cmpl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18460) 		/* Handle MDS Loopback frames */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18461) 		lpfc_sli4_handle_mds_loopback(vport, dmabuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18462) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18463) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18465) 	/* d_id this frame is directed to */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18466) 	did = sli4_did_from_fc_hdr(fc_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18468) 	vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi, did);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18469) 	if (!vport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18470) 		/* throw out the frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18471) 		lpfc_in_buf_free(phba, &dmabuf->dbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18472) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18473) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18475) 	/* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18476) 	if (!(vport->vpi_state & LPFC_VPI_REGISTERED) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18477) 		(did != Fabric_DID)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18478) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18479) 		 * Throw out the frame if we are not pt2pt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18480) 		 * The pt2pt protocol allows for discovery frames
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18481) 		 * to be received without a registered VPI.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18482) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18483) 		if (!(vport->fc_flag & FC_PT2PT) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18484) 			(phba->link_state == LPFC_HBA_READY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18485) 			lpfc_in_buf_free(phba, &dmabuf->dbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18486) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18487) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18488) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18490) 	/* Handle the basic abort sequence (BA_ABTS) event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18491) 	if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18492) 		lpfc_sli4_handle_unsol_abort(vport, dmabuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18493) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18494) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18496) 	/* Link this frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18497) 	seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18498) 	if (!seq_dmabuf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18499) 		/* unable to add frame to vport - throw it out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18500) 		lpfc_in_buf_free(phba, &dmabuf->dbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18501) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18502) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18503) 	/* If not last frame in sequence continue processing frames. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18504) 	if (!lpfc_seq_complete(seq_dmabuf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18505) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18507) 	/* Send the complete sequence to the upper layer protocol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18508) 	lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18511) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18512)  * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18513)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18514)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18515)  * This routine is invoked to post rpi header templates to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18516)  * HBA consistent with the SLI-4 interface spec.  This routine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18517)  * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18518)  * SLI4_PAGE_SIZE modulo 64 rpi context headers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18519)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18520)  * This routine does not require any locks.  It's usage is expected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18521)  * to be driver load or reset recovery when the driver is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18522)  * sequential.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18523)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18524)  * Return codes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18525)  * 	0 - successful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18526)  *      -EIO - The mailbox failed to complete successfully.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18527)  * 	When this error occurs, the driver is not guaranteed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18528)  *	to have any rpi regions posted to the device and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18529)  *	must either attempt to repost the regions or take a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18530)  *	fatal error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18531)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18532) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18533) lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18534) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18535) 	struct lpfc_rpi_hdr *rpi_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18536) 	uint32_t rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18537) 	uint16_t lrpi = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18539) 	/* SLI4 ports that support extents do not require RPI headers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18540) 	if (!phba->sli4_hba.rpi_hdrs_in_use)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18541) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18542) 	if (phba->sli4_hba.extents_in_use)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18543) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18545) 	list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18546) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18547) 		 * Assign the rpi headers a physical rpi only if the driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18548) 		 * has not initialized those resources.  A port reset only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18549) 		 * needs the headers posted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18550) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18551) 		if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18552) 		    LPFC_RPI_RSRC_RDY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18553) 			rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18555) 		rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18556) 		if (rc != MBX_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18557) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18558) 					"2008 Error %d posting all rpi "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18559) 					"headers\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18560) 			rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18561) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18562) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18563) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18565)  exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18566) 	bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18567) 	       LPFC_RPI_RSRC_RDY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18568) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18569) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18571) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18572)  * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18573)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18574)  * @rpi_page:  pointer to the rpi memory region.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18575)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18576)  * This routine is invoked to post a single rpi header to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18577)  * HBA consistent with the SLI-4 interface spec.  This memory region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18578)  * maps up to 64 rpi context regions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18579)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18580)  * Return codes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18581)  * 	0 - successful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18582)  * 	-ENOMEM - No available memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18583)  *      -EIO - The mailbox failed to complete successfully.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18584)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18585) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18586) lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18587) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18588) 	LPFC_MBOXQ_t *mboxq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18589) 	struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18590) 	uint32_t rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18591) 	uint32_t shdr_status, shdr_add_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18592) 	union lpfc_sli4_cfg_shdr *shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18594) 	/* SLI4 ports that support extents do not require RPI headers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18595) 	if (!phba->sli4_hba.rpi_hdrs_in_use)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18596) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18597) 	if (phba->sli4_hba.extents_in_use)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18598) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18600) 	/* The port is notified of the header region via a mailbox command. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18601) 	mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18602) 	if (!mboxq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18603) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18604) 				"2001 Unable to allocate memory for issuing "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18605) 				"SLI_CONFIG_SPECIAL mailbox command\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18606) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18607) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18609) 	/* Post all rpi memory regions to the port. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18610) 	hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18611) 	lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18612) 			 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18613) 			 sizeof(struct lpfc_mbx_post_hdr_tmpl) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18614) 			 sizeof(struct lpfc_sli4_cfg_mhdr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18615) 			 LPFC_SLI4_MBX_EMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18618) 	/* Post the physical rpi to the port for this rpi header. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18619) 	bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18620) 	       rpi_page->start_rpi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18621) 	bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18622) 	       hdr_tmpl, rpi_page->page_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18624) 	hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18625) 	hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18626) 	rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18627) 	shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18628) 	shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18629) 	shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18630) 	mempool_free(mboxq, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18631) 	if (shdr_status || shdr_add_status || rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18632) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18633) 				"2514 POST_RPI_HDR mailbox failed with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18634) 				"status x%x add_status x%x, mbx status x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18635) 				shdr_status, shdr_add_status, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18636) 		rc = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18637) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18638) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18639) 		 * The next_rpi stores the next logical module-64 rpi value used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18640) 		 * to post physical rpis in subsequent rpi postings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18641) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18642) 		spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18643) 		phba->sli4_hba.next_rpi = rpi_page->next_rpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18644) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18645) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18646) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18649) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18650)  * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18651)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18652)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18653)  * This routine is invoked to post rpi header templates to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18654)  * HBA consistent with the SLI-4 interface spec.  This routine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18655)  * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18656)  * SLI4_PAGE_SIZE modulo 64 rpi context headers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18657)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18658)  * Returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18659)  * 	A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18660)  * 	LPFC_RPI_ALLOC_ERROR if no rpis are available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18661)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18662) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18663) lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18664) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18665) 	unsigned long rpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18666) 	uint16_t max_rpi, rpi_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18667) 	uint16_t rpi_remaining, lrpi = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18668) 	struct lpfc_rpi_hdr *rpi_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18669) 	unsigned long iflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18671) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18672) 	 * Fetch the next logical rpi.  Because this index is logical,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18673) 	 * the  driver starts at 0 each time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18674) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18675) 	spin_lock_irqsave(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18676) 	max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18677) 	rpi_limit = phba->sli4_hba.next_rpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18679) 	rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18680) 	if (rpi >= rpi_limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18681) 		rpi = LPFC_RPI_ALLOC_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18682) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18683) 		set_bit(rpi, phba->sli4_hba.rpi_bmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18684) 		phba->sli4_hba.max_cfg_param.rpi_used++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18685) 		phba->sli4_hba.rpi_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18686) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18687) 	lpfc_printf_log(phba, KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18688) 			LOG_NODE | LOG_DISCOVERY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18689) 			"0001 Allocated rpi:x%x max:x%x lim:x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18690) 			(int) rpi, max_rpi, rpi_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18692) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18693) 	 * Don't try to allocate more rpi header regions if the device limit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18694) 	 * has been exhausted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18695) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18696) 	if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18697) 	    (phba->sli4_hba.rpi_count >= max_rpi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18698) 		spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18699) 		return rpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18700) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18702) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18703) 	 * RPI header postings are not required for SLI4 ports capable of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18704) 	 * extents.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18705) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18706) 	if (!phba->sli4_hba.rpi_hdrs_in_use) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18707) 		spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18708) 		return rpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18709) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18711) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18712) 	 * If the driver is running low on rpi resources, allocate another
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18713) 	 * page now.  Note that the next_rpi value is used because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18714) 	 * it represents how many are actually in use whereas max_rpi notes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18715) 	 * how many are supported max by the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18716) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18717) 	rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18718) 	spin_unlock_irqrestore(&phba->hbalock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18719) 	if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18720) 		rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18721) 		if (!rpi_hdr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18722) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18723) 					"2002 Error Could not grow rpi "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18724) 					"count\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18725) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18726) 			lrpi = rpi_hdr->start_rpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18727) 			rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18728) 			lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18729) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18730) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18732) 	return rpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18735) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18736)  * lpfc_sli4_free_rpi - Release an rpi for reuse.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18737)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18738)  * @rpi: rpi to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18739)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18740)  * This routine is invoked to release an rpi to the pool of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18741)  * available rpis maintained by the driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18742)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18743) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18744) __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18745) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18746) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18747) 	 * if the rpi value indicates a prior unreg has already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18748) 	 * been done, skip the unreg.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18749) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18750) 	if (rpi == LPFC_RPI_ALLOC_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18751) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18753) 	if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18754) 		phba->sli4_hba.rpi_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18755) 		phba->sli4_hba.max_cfg_param.rpi_used--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18756) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18757) 		lpfc_printf_log(phba, KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18758) 				LOG_NODE | LOG_DISCOVERY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18759) 				"2016 rpi %x not inuse\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18760) 				rpi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18761) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18762) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18764) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18765)  * lpfc_sli4_free_rpi - Release an rpi for reuse.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18766)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18767)  * @rpi: rpi to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18768)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18769)  * This routine is invoked to release an rpi to the pool of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18770)  * available rpis maintained by the driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18771)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18772) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18773) lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18774) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18775) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18776) 	__lpfc_sli4_free_rpi(phba, rpi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18777) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18778) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18780) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18781)  * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18782)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18783)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18784)  * This routine is invoked to remove the memory region that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18785)  * provided rpi via a bitmask.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18786)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18787) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18788) lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18789) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18790) 	kfree(phba->sli4_hba.rpi_bmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18791) 	kfree(phba->sli4_hba.rpi_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18792) 	bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18795) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18796)  * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18797)  * @ndlp: pointer to lpfc nodelist data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18798)  * @cmpl: completion call-back.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18799)  * @arg: data to load as MBox 'caller buffer information'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18800)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18801)  * This routine is invoked to remove the memory region that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18802)  * provided rpi via a bitmask.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18803)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18804) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18805) lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18806) 	void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18807) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18808) 	LPFC_MBOXQ_t *mboxq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18809) 	struct lpfc_hba *phba = ndlp->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18810) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18812) 	/* The port is notified of the header region via a mailbox command. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18813) 	mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18814) 	if (!mboxq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18815) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18817) 	/* Post all rpi memory regions to the port. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18818) 	lpfc_resume_rpi(mboxq, ndlp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18819) 	if (cmpl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18820) 		mboxq->mbox_cmpl = cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18821) 		mboxq->ctx_buf = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18822) 		mboxq->ctx_ndlp = ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18823) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18824) 		mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18825) 	mboxq->vport = ndlp->vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18826) 	rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18827) 	if (rc == MBX_NOT_FINISHED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18828) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18829) 				"2010 Resume RPI Mailbox failed "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18830) 				"status %d, mbxStatus x%x\n", rc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18831) 				bf_get(lpfc_mqe_status, &mboxq->u.mqe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18832) 		mempool_free(mboxq, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18833) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18834) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18835) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18836) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18838) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18839)  * lpfc_sli4_init_vpi - Initialize a vpi with the port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18840)  * @vport: Pointer to the vport for which the vpi is being initialized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18841)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18842)  * This routine is invoked to activate a vpi with the port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18843)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18844)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18845)  *    0 success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18846)  *    -Evalue otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18847)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18848) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18849) lpfc_sli4_init_vpi(struct lpfc_vport *vport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18850) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18851) 	LPFC_MBOXQ_t *mboxq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18852) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18853) 	int retval = MBX_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18854) 	uint32_t mbox_tmo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18855) 	struct lpfc_hba *phba = vport->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18856) 	mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18857) 	if (!mboxq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18858) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18859) 	lpfc_init_vpi(phba, mboxq, vport->vpi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18860) 	mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18861) 	rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18862) 	if (rc != MBX_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18863) 		lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18864) 				"2022 INIT VPI Mailbox failed "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18865) 				"status %d, mbxStatus x%x\n", rc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18866) 				bf_get(lpfc_mqe_status, &mboxq->u.mqe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18867) 		retval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18868) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18869) 	if (rc != MBX_TIMEOUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18870) 		mempool_free(mboxq, vport->phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18872) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18873) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18875) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18876)  * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18877)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18878)  * @mboxq: Pointer to mailbox object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18879)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18880)  * This routine is invoked to manually add a single FCF record. The caller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18881)  * must pass a completely initialized FCF_Record.  This routine takes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18882)  * care of the nonembedded mailbox operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18883)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18884) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18885) lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18886) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18887) 	void *virt_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18888) 	union lpfc_sli4_cfg_shdr *shdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18889) 	uint32_t shdr_status, shdr_add_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18891) 	virt_addr = mboxq->sge_array->addr[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18892) 	/* The IOCTL status is embedded in the mailbox subheader. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18893) 	shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18894) 	shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18895) 	shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18897) 	if ((shdr_status || shdr_add_status) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18898) 		(shdr_status != STATUS_FCF_IN_USE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18899) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18900) 			"2558 ADD_FCF_RECORD mailbox failed with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18901) 			"status x%x add_status x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18902) 			shdr_status, shdr_add_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18904) 	lpfc_sli4_mbox_cmd_free(phba, mboxq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18905) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18907) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18908)  * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18909)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18910)  * @fcf_record:  pointer to the initialized fcf record to add.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18911)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18912)  * This routine is invoked to manually add a single FCF record. The caller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18913)  * must pass a completely initialized FCF_Record.  This routine takes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18914)  * care of the nonembedded mailbox operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18915)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18916) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18917) lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18918) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18919) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18920) 	LPFC_MBOXQ_t *mboxq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18921) 	uint8_t *bytep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18922) 	void *virt_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18923) 	struct lpfc_mbx_sge sge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18924) 	uint32_t alloc_len, req_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18925) 	uint32_t fcfindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18927) 	mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18928) 	if (!mboxq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18929) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18930) 			"2009 Failed to allocate mbox for ADD_FCF cmd\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18931) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18932) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18934) 	req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18935) 		  sizeof(uint32_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18937) 	/* Allocate DMA memory and set up the non-embedded mailbox command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18938) 	alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18939) 				     LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18940) 				     req_len, LPFC_SLI4_MBX_NEMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18941) 	if (alloc_len < req_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18942) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18943) 			"2523 Allocated DMA memory size (x%x) is "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18944) 			"less than the requested DMA memory "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18945) 			"size (x%x)\n", alloc_len, req_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18946) 		lpfc_sli4_mbox_cmd_free(phba, mboxq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18947) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18948) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18949) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18950) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18951) 	 * Get the first SGE entry from the non-embedded DMA memory.  This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18952) 	 * routine only uses a single SGE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18953) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18954) 	lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18955) 	virt_addr = mboxq->sge_array->addr[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18956) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18957) 	 * Configure the FCF record for FCFI 0.  This is the driver's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18958) 	 * hardcoded default and gets used in nonFIP mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18959) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18960) 	fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18961) 	bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18962) 	lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18964) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18965) 	 * Copy the fcf_index and the FCF Record Data. The data starts after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18966) 	 * the FCoE header plus word10. The data copy needs to be endian
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18967) 	 * correct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18968) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18969) 	bytep += sizeof(uint32_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18970) 	lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18971) 	mboxq->vport = phba->pport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18972) 	mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18973) 	rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18974) 	if (rc == MBX_NOT_FINISHED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18975) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18976) 			"2515 ADD_FCF_RECORD mailbox failed with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18977) 			"status 0x%x\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18978) 		lpfc_sli4_mbox_cmd_free(phba, mboxq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18979) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18980) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18981) 		rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18982) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18983) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18984) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18986) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18987)  * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18988)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18989)  * @fcf_record:  pointer to the fcf record to write the default data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18990)  * @fcf_index: FCF table entry index.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18991)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18992)  * This routine is invoked to build the driver's default FCF record.  The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18993)  * values used are hardcoded.  This routine handles memory initialization.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18994)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18995)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18996) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18997) lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18998) 				struct fcf_record *fcf_record,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18999) 				uint16_t fcf_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19001) 	memset(fcf_record, 0, sizeof(struct fcf_record));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19002) 	fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19003) 	fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19004) 	fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19005) 	bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19006) 	bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19007) 	bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19008) 	bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19009) 	bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19010) 	bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19011) 	bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19012) 	bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19013) 	bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19014) 	bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19015) 	bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19016) 	bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19017) 	bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19018) 		LPFC_FCF_FPMA | LPFC_FCF_SPMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19019) 	/* Set the VLAN bit map */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19020) 	if (phba->valid_vlan) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19021) 		fcf_record->vlan_bitmap[phba->vlan_id / 8]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19022) 			= 1 << (phba->vlan_id % 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19023) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19024) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19025) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19026) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19027)  * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19028)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19029)  * @fcf_index: FCF table entry offset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19030)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19031)  * This routine is invoked to scan the entire FCF table by reading FCF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19032)  * record and processing it one at a time starting from the @fcf_index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19033)  * for initial FCF discovery or fast FCF failover rediscovery.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19034)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19035)  * Return 0 if the mailbox command is submitted successfully, none 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19036)  * otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19037)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19038) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19039) lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19040) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19041) 	int rc = 0, error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19042) 	LPFC_MBOXQ_t *mboxq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19044) 	phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19045) 	phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19046) 	mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19047) 	if (!mboxq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19048) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19049) 				"2000 Failed to allocate mbox for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19050) 				"READ_FCF cmd\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19051) 		error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19052) 		goto fail_fcf_scan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19053) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19054) 	/* Construct the read FCF record mailbox command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19055) 	rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19056) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19057) 		error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19058) 		goto fail_fcf_scan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19059) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19060) 	/* Issue the mailbox command asynchronously */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19061) 	mboxq->vport = phba->pport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19062) 	mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19063) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19064) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19065) 	phba->hba_flag |= FCF_TS_INPROG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19066) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19067) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19068) 	rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19069) 	if (rc == MBX_NOT_FINISHED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19070) 		error = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19071) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19072) 		/* Reset eligible FCF count for new scan */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19073) 		if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19074) 			phba->fcf.eligible_fcf_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19075) 		error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19076) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19077) fail_fcf_scan:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19078) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19079) 		if (mboxq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19080) 			lpfc_sli4_mbox_cmd_free(phba, mboxq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19081) 		/* FCF scan failed, clear FCF_TS_INPROG flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19082) 		spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19083) 		phba->hba_flag &= ~FCF_TS_INPROG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19084) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19085) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19086) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19087) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19088) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19089) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19090)  * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19091)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19092)  * @fcf_index: FCF table entry offset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19093)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19094)  * This routine is invoked to read an FCF record indicated by @fcf_index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19095)  * and to use it for FLOGI roundrobin FCF failover.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19096)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19097)  * Return 0 if the mailbox command is submitted successfully, none 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19098)  * otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19099)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19100) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19101) lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19103) 	int rc = 0, error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19104) 	LPFC_MBOXQ_t *mboxq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19106) 	mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19107) 	if (!mboxq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19108) 		lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19109) 				"2763 Failed to allocate mbox for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19110) 				"READ_FCF cmd\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19111) 		error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19112) 		goto fail_fcf_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19113) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19114) 	/* Construct the read FCF record mailbox command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19115) 	rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19116) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19117) 		error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19118) 		goto fail_fcf_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19119) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19120) 	/* Issue the mailbox command asynchronously */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19121) 	mboxq->vport = phba->pport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19122) 	mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19123) 	rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19124) 	if (rc == MBX_NOT_FINISHED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19125) 		error = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19126) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19127) 		error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19129) fail_fcf_read:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19130) 	if (error && mboxq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19131) 		lpfc_sli4_mbox_cmd_free(phba, mboxq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19132) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19135) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19136)  * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19137)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19138)  * @fcf_index: FCF table entry offset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19139)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19140)  * This routine is invoked to read an FCF record indicated by @fcf_index to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19141)  * determine whether it's eligible for FLOGI roundrobin failover list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19142)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19143)  * Return 0 if the mailbox command is submitted successfully, none 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19144)  * otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19145)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19146) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19147) lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19149) 	int rc = 0, error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19150) 	LPFC_MBOXQ_t *mboxq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19152) 	mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19153) 	if (!mboxq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19154) 		lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19155) 				"2758 Failed to allocate mbox for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19156) 				"READ_FCF cmd\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19157) 				error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19158) 				goto fail_fcf_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19159) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19160) 	/* Construct the read FCF record mailbox command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19161) 	rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19162) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19163) 		error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19164) 		goto fail_fcf_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19165) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19166) 	/* Issue the mailbox command asynchronously */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19167) 	mboxq->vport = phba->pport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19168) 	mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19169) 	rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19170) 	if (rc == MBX_NOT_FINISHED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19171) 		error = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19172) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19173) 		error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19175) fail_fcf_read:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19176) 	if (error && mboxq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19177) 		lpfc_sli4_mbox_cmd_free(phba, mboxq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19178) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19181) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19182)  * lpfc_check_next_fcf_pri_level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19183)  * @phba: pointer to the lpfc_hba struct for this port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19184)  * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19185)  * routine when the rr_bmask is empty. The FCF indecies are put into the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19186)  * rr_bmask based on their priority level. Starting from the highest priority
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19187)  * to the lowest. The most likely FCF candidate will be in the highest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19188)  * priority group. When this routine is called it searches the fcf_pri list for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19189)  * next lowest priority group and repopulates the rr_bmask with only those
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19190)  * fcf_indexes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19191)  * returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19192)  * 1=success 0=failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19193)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19194) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19195) lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19196) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19197) 	uint16_t next_fcf_pri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19198) 	uint16_t last_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19199) 	struct lpfc_fcf_pri *fcf_pri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19200) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19201) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19203) 	last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19204) 			LPFC_SLI4_FCF_TBL_INDX_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19205) 	lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19206) 			"3060 Last IDX %d\n", last_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19208) 	/* Verify the priority list has 2 or more entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19209) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19210) 	if (list_empty(&phba->fcf.fcf_pri_list) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19211) 	    list_is_singular(&phba->fcf.fcf_pri_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19212) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19213) 		lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19214) 			"3061 Last IDX %d\n", last_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19215) 		return 0; /* Empty rr list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19216) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19217) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19219) 	next_fcf_pri = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19220) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19221) 	 * Clear the rr_bmask and set all of the bits that are at this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19222) 	 * priority.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19223) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19224) 	memset(phba->fcf.fcf_rr_bmask, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19225) 			sizeof(*phba->fcf.fcf_rr_bmask));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19226) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19227) 	list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19228) 		if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19229) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19230) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19231) 		 * the 1st priority that has not FLOGI failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19232) 		 * will be the highest.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19233) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19234) 		if (!next_fcf_pri)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19235) 			next_fcf_pri = fcf_pri->fcf_rec.priority;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19236) 		spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19237) 		if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19238) 			rc = lpfc_sli4_fcf_rr_index_set(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19239) 						fcf_pri->fcf_rec.fcf_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19240) 			if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19241) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19242) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19243) 		spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19244) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19245) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19246) 	 * if next_fcf_pri was not set above and the list is not empty then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19247) 	 * we have failed flogis on all of them. So reset flogi failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19248) 	 * and start at the beginning.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19249) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19250) 	if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19251) 		list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19252) 			fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19253) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19254) 			 * the 1st priority that has not FLOGI failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19255) 			 * will be the highest.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19256) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19257) 			if (!next_fcf_pri)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19258) 				next_fcf_pri = fcf_pri->fcf_rec.priority;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19259) 			spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19260) 			if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19261) 				rc = lpfc_sli4_fcf_rr_index_set(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19262) 						fcf_pri->fcf_rec.fcf_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19263) 				if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19264) 					return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19265) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19266) 			spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19267) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19268) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19269) 		ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19270) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19272) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19274) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19275)  * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19276)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19277)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19278)  * This routine is to get the next eligible FCF record index in a round
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19279)  * robin fashion. If the next eligible FCF record index equals to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19280)  * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19281)  * shall be returned, otherwise, the next eligible FCF record's index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19282)  * shall be returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19283)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19284) uint16_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19285) lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19287) 	uint16_t next_fcf_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19289) initial_priority:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19290) 	/* Search start from next bit of currently registered FCF index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19291) 	next_fcf_index = phba->fcf.current_rec.fcf_indx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19293) next_priority:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19294) 	/* Determine the next fcf index to check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19295) 	next_fcf_index = (next_fcf_index + 1) % LPFC_SLI4_FCF_TBL_INDX_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19296) 	next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19297) 				       LPFC_SLI4_FCF_TBL_INDX_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19298) 				       next_fcf_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19300) 	/* Wrap around condition on phba->fcf.fcf_rr_bmask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19301) 	if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19302) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19303) 		 * If we have wrapped then we need to clear the bits that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19304) 		 * have been tested so that we can detect when we should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19305) 		 * change the priority level.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19306) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19307) 		next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19308) 					       LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19309) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19312) 	/* Check roundrobin failover list empty condition */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19313) 	if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19314) 		next_fcf_index == phba->fcf.current_rec.fcf_indx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19315) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19316) 		 * If next fcf index is not found check if there are lower
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19317) 		 * Priority level fcf's in the fcf_priority list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19318) 		 * Set up the rr_bmask with all of the avaiable fcf bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19319) 		 * at that level and continue the selection process.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19320) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19321) 		if (lpfc_check_next_fcf_pri_level(phba))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19322) 			goto initial_priority;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19323) 		lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19324) 				"2844 No roundrobin failover FCF available\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19326) 		return LPFC_FCOE_FCF_NEXT_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19327) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19329) 	if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19330) 		phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19331) 		LPFC_FCF_FLOGI_FAILED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19332) 		if (list_is_singular(&phba->fcf.fcf_pri_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19333) 			return LPFC_FCOE_FCF_NEXT_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19335) 		goto next_priority;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19336) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19338) 	lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19339) 			"2845 Get next roundrobin failover FCF (x%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19340) 			next_fcf_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19342) 	return next_fcf_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19345) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19346)  * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19347)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19348)  * @fcf_index: index into the FCF table to 'set'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19349)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19350)  * This routine sets the FCF record index in to the eligible bmask for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19351)  * roundrobin failover search. It checks to make sure that the index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19352)  * does not go beyond the range of the driver allocated bmask dimension
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19353)  * before setting the bit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19354)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19355)  * Returns 0 if the index bit successfully set, otherwise, it returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19356)  * -EINVAL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19357)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19358) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19359) lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19360) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19361) 	if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19362) 		lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19363) 				"2610 FCF (x%x) reached driver's book "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19364) 				"keeping dimension:x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19365) 				fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19366) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19367) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19368) 	/* Set the eligible FCF record index bmask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19369) 	set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19371) 	lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19372) 			"2790 Set FCF (x%x) to roundrobin FCF failover "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19373) 			"bmask\n", fcf_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19375) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19378) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19379)  * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19380)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19381)  * @fcf_index: index into the FCF table to 'clear'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19382)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19383)  * This routine clears the FCF record index from the eligible bmask for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19384)  * roundrobin failover search. It checks to make sure that the index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19385)  * does not go beyond the range of the driver allocated bmask dimension
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19386)  * before clearing the bit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19387)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19388) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19389) lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19390) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19391) 	struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19392) 	if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19393) 		lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19394) 				"2762 FCF (x%x) reached driver's book "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19395) 				"keeping dimension:x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19396) 				fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19397) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19398) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19399) 	/* Clear the eligible FCF record index bmask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19400) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19401) 	list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19402) 				 list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19403) 		if (fcf_pri->fcf_rec.fcf_index == fcf_index) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19404) 			list_del_init(&fcf_pri->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19405) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19406) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19407) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19408) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19409) 	clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19411) 	lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19412) 			"2791 Clear FCF (x%x) from roundrobin failover "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19413) 			"bmask\n", fcf_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19416) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19417)  * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19418)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19419)  * @mbox: An allocated pointer to type LPFC_MBOXQ_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19420)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19421)  * This routine is the completion routine for the rediscover FCF table mailbox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19422)  * command. If the mailbox command returned failure, it will try to stop the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19423)  * FCF rediscover wait timer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19424)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19425) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19426) lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19428) 	struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19429) 	uint32_t shdr_status, shdr_add_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19431) 	redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19433) 	shdr_status = bf_get(lpfc_mbox_hdr_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19434) 			     &redisc_fcf->header.cfg_shdr.response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19435) 	shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19436) 			     &redisc_fcf->header.cfg_shdr.response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19437) 	if (shdr_status || shdr_add_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19438) 		lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19439) 				"2746 Requesting for FCF rediscovery failed "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19440) 				"status x%x add_status x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19441) 				shdr_status, shdr_add_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19442) 		if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19443) 			spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19444) 			phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19445) 			spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19446) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19447) 			 * CVL event triggered FCF rediscover request failed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19448) 			 * last resort to re-try current registered FCF entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19449) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19450) 			lpfc_retry_pport_discovery(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19451) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19452) 			spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19453) 			phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19454) 			spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19455) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19456) 			 * DEAD FCF event triggered FCF rediscover request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19457) 			 * failed, last resort to fail over as a link down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19458) 			 * to FCF registration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19459) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19460) 			lpfc_sli4_fcf_dead_failthrough(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19461) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19462) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19463) 		lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19464) 				"2775 Start FCF rediscover quiescent timer\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19465) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19466) 		 * Start FCF rediscovery wait timer for pending FCF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19467) 		 * before rescan FCF record table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19468) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19469) 		lpfc_fcf_redisc_wait_start_timer(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19470) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19472) 	mempool_free(mbox, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19475) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19476)  * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19477)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19478)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19479)  * This routine is invoked to request for rediscovery of the entire FCF table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19480)  * by the port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19481)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19482) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19483) lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19484) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19485) 	LPFC_MBOXQ_t *mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19486) 	struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19487) 	int rc, length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19489) 	/* Cancel retry delay timers to all vports before FCF rediscover */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19490) 	lpfc_cancel_all_vport_retry_delay_timer(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19492) 	mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19493) 	if (!mbox) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19494) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19495) 				"2745 Failed to allocate mbox for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19496) 				"requesting FCF rediscover.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19497) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19498) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19500) 	length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19501) 		  sizeof(struct lpfc_sli4_cfg_mhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19502) 	lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19503) 			 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19504) 			 length, LPFC_SLI4_MBX_EMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19506) 	redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19507) 	/* Set count to 0 for invalidating the entire FCF database */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19508) 	bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19510) 	/* Issue the mailbox command asynchronously */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19511) 	mbox->vport = phba->pport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19512) 	mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19513) 	rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19515) 	if (rc == MBX_NOT_FINISHED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19516) 		mempool_free(mbox, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19517) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19518) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19519) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19520) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19522) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19523)  * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19524)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19525)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19526)  * This function is the failover routine as a last resort to the FCF DEAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19527)  * event when driver failed to perform fast FCF failover.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19528)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19529) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19530) lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19531) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19532) 	uint32_t link_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19534) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19535) 	 * Last resort as FCF DEAD event failover will treat this as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19536) 	 * a link down, but save the link state because we don't want
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19537) 	 * it to be changed to Link Down unless it is already down.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19538) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19539) 	link_state = phba->link_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19540) 	lpfc_linkdown(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19541) 	phba->link_state = link_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19543) 	/* Unregister FCF if no devices connected to it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19544) 	lpfc_unregister_unused_fcf(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19547) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19548)  * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19549)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19550)  * @rgn23_data: pointer to configure region 23 data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19551)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19552)  * This function gets SLI3 port configure region 23 data through memory dump
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19553)  * mailbox command. When it successfully retrieves data, the size of the data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19554)  * will be returned, otherwise, 0 will be returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19555)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19556) static uint32_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19557) lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19558) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19559) 	LPFC_MBOXQ_t *pmb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19560) 	MAILBOX_t *mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19561) 	uint32_t offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19562) 	int i, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19564) 	if (!rgn23_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19565) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19567) 	pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19568) 	if (!pmb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19569) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19570) 				"2600 failed to allocate mailbox memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19571) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19572) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19573) 	mb = &pmb->u.mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19575) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19576) 		lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19577) 		rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19579) 		if (rc != MBX_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19580) 			lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19581) 					"2601 failed to read config "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19582) 					"region 23, rc 0x%x Status 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19583) 					rc, mb->mbxStatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19584) 			mb->un.varDmp.word_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19585) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19586) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19587) 		 * dump mem may return a zero when finished or we got a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19588) 		 * mailbox error, either way we are done.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19589) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19590) 		if (mb->un.varDmp.word_cnt == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19591) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19593) 		i =  mb->un.varDmp.word_cnt * sizeof(uint32_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19594) 		if (offset + i >  DMP_RGN23_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19595) 			i =  DMP_RGN23_SIZE - offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19596) 		lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19597) 				      rgn23_data  + offset, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19598) 		offset += i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19599) 	} while (offset < DMP_RGN23_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19601) 	mempool_free(pmb, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19602) 	return offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19605) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19606)  * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19607)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19608)  * @rgn23_data: pointer to configure region 23 data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19609)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19610)  * This function gets SLI4 port configure region 23 data through memory dump
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19611)  * mailbox command. When it successfully retrieves data, the size of the data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19612)  * will be returned, otherwise, 0 will be returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19613)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19614) static uint32_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19615) lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19616) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19617) 	LPFC_MBOXQ_t *mboxq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19618) 	struct lpfc_dmabuf *mp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19619) 	struct lpfc_mqe *mqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19620) 	uint32_t data_length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19621) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19623) 	if (!rgn23_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19624) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19626) 	mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19627) 	if (!mboxq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19628) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19629) 				"3105 failed to allocate mailbox memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19630) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19631) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19633) 	if (lpfc_sli4_dump_cfg_rg23(phba, mboxq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19634) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19635) 	mqe = &mboxq->u.mqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19636) 	mp = (struct lpfc_dmabuf *)mboxq->ctx_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19637) 	rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19638) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19639) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19640) 	data_length = mqe->un.mb_words[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19641) 	if (data_length == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19642) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19643) 	if (data_length > DMP_RGN23_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19644) 		data_length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19645) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19646) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19647) 	lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19648) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19649) 	mempool_free(mboxq, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19650) 	if (mp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19651) 		lpfc_mbuf_free(phba, mp->virt, mp->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19652) 		kfree(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19653) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19654) 	return data_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19655) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19657) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19658)  * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19659)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19660)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19661)  * This function read region 23 and parse TLV for port status to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19662)  * decide if the user disaled the port. If the TLV indicates the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19663)  * port is disabled, the hba_flag is set accordingly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19664)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19665) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19666) lpfc_sli_read_link_ste(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19667) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19668) 	uint8_t *rgn23_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19669) 	uint32_t if_type, data_size, sub_tlv_len, tlv_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19670) 	uint32_t offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19672) 	/* Get adapter Region 23 data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19673) 	rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19674) 	if (!rgn23_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19675) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19677) 	if (phba->sli_rev < LPFC_SLI_REV4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19678) 		data_size = lpfc_sli_get_config_region23(phba, rgn23_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19679) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19680) 		if_type = bf_get(lpfc_sli_intf_if_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19681) 				 &phba->sli4_hba.sli_intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19682) 		if (if_type == LPFC_SLI_INTF_IF_TYPE_0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19683) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19684) 		data_size = lpfc_sli4_get_config_region23(phba, rgn23_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19685) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19687) 	if (!data_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19688) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19690) 	/* Check the region signature first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19691) 	if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19692) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19693) 			"2619 Config region 23 has bad signature\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19694) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19695) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19696) 	offset += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19698) 	/* Check the data structure version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19699) 	if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19700) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19701) 			"2620 Config region 23 has bad version\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19702) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19703) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19704) 	offset += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19706) 	/* Parse TLV entries in the region */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19707) 	while (offset < data_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19708) 		if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19709) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19710) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19711) 		 * If the TLV is not driver specific TLV or driver id is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19712) 		 * not linux driver id, skip the record.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19713) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19714) 		if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19715) 		    (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19716) 		    (rgn23_data[offset + 3] != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19717) 			offset += rgn23_data[offset + 1] * 4 + 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19718) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19719) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19721) 		/* Driver found a driver specific TLV in the config region */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19722) 		sub_tlv_len = rgn23_data[offset + 1] * 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19723) 		offset += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19724) 		tlv_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19726) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19727) 		 * Search for configured port state sub-TLV.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19728) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19729) 		while ((offset < data_size) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19730) 			(tlv_offset < sub_tlv_len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19731) 			if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19732) 				offset += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19733) 				tlv_offset += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19734) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19735) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19736) 			if (rgn23_data[offset] != PORT_STE_TYPE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19737) 				offset += rgn23_data[offset + 1] * 4 + 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19738) 				tlv_offset += rgn23_data[offset + 1] * 4 + 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19739) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19740) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19742) 			/* This HBA contains PORT_STE configured */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19743) 			if (!rgn23_data[offset + 2])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19744) 				phba->hba_flag |= LINK_DISABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19746) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19747) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19748) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19750) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19751) 	kfree(rgn23_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19752) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19753) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19755) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19756)  * lpfc_wr_object - write an object to the firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19757)  * @phba: HBA structure that indicates port to create a queue on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19758)  * @dmabuf_list: list of dmabufs to write to the port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19759)  * @size: the total byte value of the objects to write to the port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19760)  * @offset: the current offset to be used to start the transfer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19761)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19762)  * This routine will create a wr_object mailbox command to send to the port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19763)  * the mailbox command will be constructed using the dma buffers described in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19764)  * @dmabuf_list to create a list of BDEs. This routine will fill in as many
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19765)  * BDEs that the imbedded mailbox can support. The @offset variable will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19766)  * used to indicate the starting offset of the transfer and will also return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19767)  * the offset after the write object mailbox has completed. @size is used to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19768)  * determine the end of the object and whether the eof bit should be set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19769)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19770)  * Return 0 is successful and offset will contain the the new offset to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19771)  * for the next write.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19772)  * Return negative value for error cases.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19773)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19774) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19775) lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19776) 	       uint32_t size, uint32_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19777) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19778) 	struct lpfc_mbx_wr_object *wr_object;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19779) 	LPFC_MBOXQ_t *mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19780) 	int rc = 0, i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19781) 	uint32_t shdr_status, shdr_add_status, shdr_change_status, shdr_csf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19782) 	uint32_t mbox_tmo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19783) 	struct lpfc_dmabuf *dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19784) 	uint32_t written = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19785) 	bool check_change_status = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19787) 	mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19788) 	if (!mbox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19789) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19791) 	lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19792) 			LPFC_MBOX_OPCODE_WRITE_OBJECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19793) 			sizeof(struct lpfc_mbx_wr_object) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19794) 			sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19796) 	wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19797) 	wr_object->u.request.write_offset = *offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19798) 	sprintf((uint8_t *)wr_object->u.request.object_name, "/");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19799) 	wr_object->u.request.object_name[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19800) 		cpu_to_le32(wr_object->u.request.object_name[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19801) 	bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19802) 	list_for_each_entry(dmabuf, dmabuf_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19803) 		if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19804) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19805) 		wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19806) 		wr_object->u.request.bde[i].addrHigh =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19807) 			putPaddrHigh(dmabuf->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19808) 		if (written + SLI4_PAGE_SIZE >= size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19809) 			wr_object->u.request.bde[i].tus.f.bdeSize =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19810) 				(size - written);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19811) 			written += (size - written);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19812) 			bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19813) 			bf_set(lpfc_wr_object_eas, &wr_object->u.request, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19814) 			check_change_status = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19815) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19816) 			wr_object->u.request.bde[i].tus.f.bdeSize =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19817) 				SLI4_PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19818) 			written += SLI4_PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19819) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19820) 		i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19821) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19822) 	wr_object->u.request.bde_count = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19823) 	bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19824) 	if (!phba->sli4_hba.intr_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19825) 		rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19826) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19827) 		mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19828) 		rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19829) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19830) 	/* The IOCTL status is embedded in the mailbox subheader. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19831) 	shdr_status = bf_get(lpfc_mbox_hdr_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19832) 			     &wr_object->header.cfg_shdr.response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19833) 	shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19834) 				 &wr_object->header.cfg_shdr.response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19835) 	if (check_change_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19836) 		shdr_change_status = bf_get(lpfc_wr_object_change_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19837) 					    &wr_object->u.response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19839) 		if (shdr_change_status == LPFC_CHANGE_STATUS_FW_RESET ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19840) 		    shdr_change_status == LPFC_CHANGE_STATUS_PORT_MIGRATION) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19841) 			shdr_csf = bf_get(lpfc_wr_object_csf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19842) 					  &wr_object->u.response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19843) 			if (shdr_csf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19844) 				shdr_change_status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19845) 						   LPFC_CHANGE_STATUS_PCI_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19846) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19848) 		switch (shdr_change_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19849) 		case (LPFC_CHANGE_STATUS_PHYS_DEV_RESET):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19850) 			lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19851) 					"3198 Firmware write complete: System "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19852) 					"reboot required to instantiate\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19853) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19854) 		case (LPFC_CHANGE_STATUS_FW_RESET):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19855) 			lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19856) 					"3199 Firmware write complete: Firmware"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19857) 					" reset required to instantiate\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19858) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19859) 		case (LPFC_CHANGE_STATUS_PORT_MIGRATION):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19860) 			lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19861) 					"3200 Firmware write complete: Port "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19862) 					"Migration or PCI Reset required to "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19863) 					"instantiate\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19864) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19865) 		case (LPFC_CHANGE_STATUS_PCI_RESET):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19866) 			lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19867) 					"3201 Firmware write complete: PCI "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19868) 					"Reset required to instantiate\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19869) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19870) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19871) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19872) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19873) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19874) 	if (!phba->sli4_hba.intr_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19875) 		mempool_free(mbox, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19876) 	else if (rc != MBX_TIMEOUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19877) 		mempool_free(mbox, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19878) 	if (shdr_status || shdr_add_status || rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19879) 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19880) 				"3025 Write Object mailbox failed with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19881) 				"status x%x add_status x%x, mbx status x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19882) 				shdr_status, shdr_add_status, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19883) 		rc = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19884) 		*offset = shdr_add_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19885) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19886) 		*offset += wr_object->u.response.actual_write_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19887) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19888) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19890) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19891)  * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19892)  * @vport: pointer to vport data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19893)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19894)  * This function iterate through the mailboxq and clean up all REG_LOGIN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19895)  * and REG_VPI mailbox commands associated with the vport. This function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19896)  * is called when driver want to restart discovery of the vport due to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19897)  * a Clear Virtual Link event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19898)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19899) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19900) lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19901) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19902) 	struct lpfc_hba *phba = vport->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19903) 	LPFC_MBOXQ_t *mb, *nextmb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19904) 	struct lpfc_dmabuf *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19905) 	struct lpfc_nodelist *ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19906) 	struct lpfc_nodelist *act_mbx_ndlp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19907) 	struct Scsi_Host  *shost = lpfc_shost_from_vport(vport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19908) 	LIST_HEAD(mbox_cmd_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19909) 	uint8_t restart_loop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19910) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19911) 	/* Clean up internally queued mailbox commands with the vport */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19912) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19913) 	list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19914) 		if (mb->vport != vport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19915) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19917) 		if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19918) 			(mb->u.mb.mbxCommand != MBX_REG_VPI))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19919) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19921) 		list_del(&mb->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19922) 		list_add_tail(&mb->list, &mbox_cmd_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19923) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19924) 	/* Clean up active mailbox command with the vport */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19925) 	mb = phba->sli.mbox_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19926) 	if (mb && (mb->vport == vport)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19927) 		if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19928) 			(mb->u.mb.mbxCommand == MBX_REG_VPI))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19929) 			mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19930) 		if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19931) 			act_mbx_ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19932) 			/* Put reference count for delayed processing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19933) 			act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19934) 			/* Unregister the RPI when mailbox complete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19935) 			mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19936) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19937) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19938) 	/* Cleanup any mailbox completions which are not yet processed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19939) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19940) 		restart_loop = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19941) 		list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19942) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19943) 			 * If this mailox is already processed or it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19944) 			 * for another vport ignore it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19945) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19946) 			if ((mb->vport != vport) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19947) 				(mb->mbox_flag & LPFC_MBX_IMED_UNREG))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19948) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19949) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19950) 			if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19951) 				(mb->u.mb.mbxCommand != MBX_REG_VPI))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19952) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19953) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19954) 			mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19955) 			if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19956) 				ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19957) 				/* Unregister the RPI when mailbox complete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19958) 				mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19959) 				restart_loop = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19960) 				spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19961) 				spin_lock(shost->host_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19962) 				ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19963) 				spin_unlock(shost->host_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19964) 				spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19965) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19966) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19967) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19968) 	} while (restart_loop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19969) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19970) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19972) 	/* Release the cleaned-up mailbox commands */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19973) 	while (!list_empty(&mbox_cmd_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19974) 		list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19975) 		if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19976) 			mp = (struct lpfc_dmabuf *)(mb->ctx_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19977) 			if (mp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19978) 				__lpfc_mbuf_free(phba, mp->virt, mp->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19979) 				kfree(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19980) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19981) 			mb->ctx_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19982) 			ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19983) 			mb->ctx_ndlp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19984) 			if (ndlp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19985) 				spin_lock(shost->host_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19986) 				ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19987) 				spin_unlock(shost->host_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19988) 				lpfc_nlp_put(ndlp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19989) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19990) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19991) 		mempool_free(mb, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19992) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19994) 	/* Release the ndlp with the cleaned-up active mailbox command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19995) 	if (act_mbx_ndlp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19996) 		spin_lock(shost->host_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19997) 		act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19998) 		spin_unlock(shost->host_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19999) 		lpfc_nlp_put(act_mbx_ndlp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20000) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20001) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20003) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20004)  * lpfc_drain_txq - Drain the txq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20005)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20006)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20007)  * This function attempt to submit IOCBs on the txq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20008)  * to the adapter.  For SLI4 adapters, the txq contains
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20009)  * ELS IOCBs that have been deferred because the there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20010)  * are no SGLs.  This congestion can occur with large
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20011)  * vport counts during node discovery.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20012)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20014) uint32_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20015) lpfc_drain_txq(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20016) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20017) 	LIST_HEAD(completions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20018) 	struct lpfc_sli_ring *pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20019) 	struct lpfc_iocbq *piocbq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20020) 	unsigned long iflags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20021) 	char *fail_msg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20022) 	struct lpfc_sglq *sglq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20023) 	union lpfc_wqe128 wqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20024) 	uint32_t txq_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20025) 	struct lpfc_queue *wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20026) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20027) 	if (phba->link_flag & LS_MDS_LOOPBACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20028) 		/* MDS WQE are posted only to first WQ*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20029) 		wq = phba->sli4_hba.hdwq[0].io_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20030) 		if (unlikely(!wq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20031) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20032) 		pring = wq->pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20033) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20034) 		wq = phba->sli4_hba.els_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20035) 		if (unlikely(!wq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20036) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20037) 		pring = lpfc_phba_elsring(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20038) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20039) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20040) 	if (unlikely(!pring) || list_empty(&pring->txq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20041) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20043) 	spin_lock_irqsave(&pring->ring_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20044) 	list_for_each_entry(piocbq, &pring->txq, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20045) 		txq_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20046) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20047) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20048) 	if (txq_cnt > pring->txq_max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20049) 		pring->txq_max = txq_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20051) 	spin_unlock_irqrestore(&pring->ring_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20052) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20053) 	while (!list_empty(&pring->txq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20054) 		spin_lock_irqsave(&pring->ring_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20056) 		piocbq = lpfc_sli_ringtx_get(phba, pring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20057) 		if (!piocbq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20058) 			spin_unlock_irqrestore(&pring->ring_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20059) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20060) 				"2823 txq empty and txq_cnt is %d\n ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20061) 				txq_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20062) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20063) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20064) 		sglq = __lpfc_sli_get_els_sglq(phba, piocbq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20065) 		if (!sglq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20066) 			__lpfc_sli_ringtx_put(phba, pring, piocbq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20067) 			spin_unlock_irqrestore(&pring->ring_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20068) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20069) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20070) 		txq_cnt--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20071) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20072) 		/* The xri and iocb resources secured,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20073) 		 * attempt to issue request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20074) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20075) 		piocbq->sli4_lxritag = sglq->sli4_lxritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20076) 		piocbq->sli4_xritag = sglq->sli4_xritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20077) 		if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20078) 			fail_msg = "to convert bpl to sgl";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20079) 		else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20080) 			fail_msg = "to convert iocb to wqe";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20081) 		else if (lpfc_sli4_wq_put(wq, &wqe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20082) 			fail_msg = " - Wq is full";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20083) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20084) 			lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20086) 		if (fail_msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20087) 			/* Failed means we can't issue and need to cancel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20088) 			lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20089) 					"2822 IOCB failed %s iotag 0x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20090) 					"xri 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20091) 					fail_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20092) 					piocbq->iotag, piocbq->sli4_xritag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20093) 			list_add_tail(&piocbq->list, &completions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20094) 			fail_msg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20095) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20096) 		spin_unlock_irqrestore(&pring->ring_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20097) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20098) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20099) 	/* Cancel all the IOCBs that cannot be issued */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20100) 	lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20101) 				IOERR_SLI_ABORTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20103) 	return txq_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20106) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20107)  * lpfc_wqe_bpl2sgl - Convert the bpl/bde to a sgl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20108)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20109)  * @pwqeq: Pointer to command WQE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20110)  * @sglq: Pointer to the scatter gather queue object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20111)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20112)  * This routine converts the bpl or bde that is in the WQE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20113)  * to a sgl list for the sli4 hardware. The physical address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20114)  * of the bpl/bde is converted back to a virtual address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20115)  * If the WQE contains a BPL then the list of BDE's is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20116)  * converted to sli4_sge's. If the WQE contains a single
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20117)  * BDE then it is converted to a single sli_sge.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20118)  * The WQE is still in cpu endianness so the contents of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20119)  * the bpl can be used without byte swapping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20120)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20121)  * Returns valid XRI = Success, NO_XRI = Failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20122)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20123) static uint16_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20124) lpfc_wqe_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20125) 		 struct lpfc_sglq *sglq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20127) 	uint16_t xritag = NO_XRI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20128) 	struct ulp_bde64 *bpl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20129) 	struct ulp_bde64 bde;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20130) 	struct sli4_sge *sgl  = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20131) 	struct lpfc_dmabuf *dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20132) 	union lpfc_wqe128 *wqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20133) 	int numBdes = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20134) 	int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20135) 	uint32_t offset = 0; /* accumulated offset in the sg request list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20136) 	int inbound = 0; /* number of sg reply entries inbound from firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20137) 	uint32_t cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20139) 	if (!pwqeq || !sglq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20140) 		return xritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20142) 	sgl  = (struct sli4_sge *)sglq->sgl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20143) 	wqe = &pwqeq->wqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20144) 	pwqeq->iocb.ulpIoTag = pwqeq->iotag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20146) 	cmd = bf_get(wqe_cmnd, &wqe->generic.wqe_com);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20147) 	if (cmd == CMD_XMIT_BLS_RSP64_WQE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20148) 		return sglq->sli4_xritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20149) 	numBdes = pwqeq->rsvd2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20150) 	if (numBdes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20151) 		/* The addrHigh and addrLow fields within the WQE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20152) 		 * have not been byteswapped yet so there is no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20153) 		 * need to swap them back.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20154) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20155) 		if (pwqeq->context3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20156) 			dmabuf = (struct lpfc_dmabuf *)pwqeq->context3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20157) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20158) 			return xritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20160) 		bpl  = (struct ulp_bde64 *)dmabuf->virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20161) 		if (!bpl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20162) 			return xritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20164) 		for (i = 0; i < numBdes; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20165) 			/* Should already be byte swapped. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20166) 			sgl->addr_hi = bpl->addrHigh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20167) 			sgl->addr_lo = bpl->addrLow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20169) 			sgl->word2 = le32_to_cpu(sgl->word2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20170) 			if ((i+1) == numBdes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20171) 				bf_set(lpfc_sli4_sge_last, sgl, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20172) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20173) 				bf_set(lpfc_sli4_sge_last, sgl, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20174) 			/* swap the size field back to the cpu so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20175) 			 * can assign it to the sgl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20176) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20177) 			bde.tus.w = le32_to_cpu(bpl->tus.w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20178) 			sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20179) 			/* The offsets in the sgl need to be accumulated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20180) 			 * separately for the request and reply lists.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20181) 			 * The request is always first, the reply follows.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20182) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20183) 			switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20184) 			case CMD_GEN_REQUEST64_WQE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20185) 				/* add up the reply sg entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20186) 				if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20187) 					inbound++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20188) 				/* first inbound? reset the offset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20189) 				if (inbound == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20190) 					offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20191) 				bf_set(lpfc_sli4_sge_offset, sgl, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20192) 				bf_set(lpfc_sli4_sge_type, sgl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20193) 					LPFC_SGE_TYPE_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20194) 				offset += bde.tus.f.bdeSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20195) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20196) 			case CMD_FCP_TRSP64_WQE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20197) 				bf_set(lpfc_sli4_sge_offset, sgl, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20198) 				bf_set(lpfc_sli4_sge_type, sgl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20199) 					LPFC_SGE_TYPE_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20200) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20201) 			case CMD_FCP_TSEND64_WQE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20202) 			case CMD_FCP_TRECEIVE64_WQE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20203) 				bf_set(lpfc_sli4_sge_type, sgl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20204) 					bpl->tus.f.bdeFlags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20205) 				if (i < 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20206) 					offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20207) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20208) 					offset += bde.tus.f.bdeSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20209) 				bf_set(lpfc_sli4_sge_offset, sgl, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20210) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20211) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20212) 			sgl->word2 = cpu_to_le32(sgl->word2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20213) 			bpl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20214) 			sgl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20215) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20216) 	} else if (wqe->gen_req.bde.tus.f.bdeFlags == BUFF_TYPE_BDE_64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20217) 		/* The addrHigh and addrLow fields of the BDE have not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20218) 		 * been byteswapped yet so they need to be swapped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20219) 		 * before putting them in the sgl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20220) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20221) 		sgl->addr_hi = cpu_to_le32(wqe->gen_req.bde.addrHigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20222) 		sgl->addr_lo = cpu_to_le32(wqe->gen_req.bde.addrLow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20223) 		sgl->word2 = le32_to_cpu(sgl->word2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20224) 		bf_set(lpfc_sli4_sge_last, sgl, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20225) 		sgl->word2 = cpu_to_le32(sgl->word2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20226) 		sgl->sge_len = cpu_to_le32(wqe->gen_req.bde.tus.f.bdeSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20227) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20228) 	return sglq->sli4_xritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20231) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20232)  * lpfc_sli4_issue_wqe - Issue an SLI4 Work Queue Entry (WQE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20233)  * @phba: Pointer to HBA context object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20234)  * @qp: Pointer to HDW queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20235)  * @pwqe: Pointer to command WQE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20236)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20237) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20238) lpfc_sli4_issue_wqe(struct lpfc_hba *phba, struct lpfc_sli4_hdw_queue *qp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20239) 		    struct lpfc_iocbq *pwqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20241) 	union lpfc_wqe128 *wqe = &pwqe->wqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20242) 	struct lpfc_async_xchg_ctx *ctxp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20243) 	struct lpfc_queue *wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20244) 	struct lpfc_sglq *sglq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20245) 	struct lpfc_sli_ring *pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20246) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20247) 	uint32_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20249) 	/* NVME_LS and NVME_LS ABTS requests. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20250) 	if (pwqe->iocb_flag & LPFC_IO_NVME_LS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20251) 		pring =  phba->sli4_hba.nvmels_wq->pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20252) 		lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20253) 					  qp, wq_access);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20254) 		sglq = __lpfc_sli_get_els_sglq(phba, pwqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20255) 		if (!sglq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20256) 			spin_unlock_irqrestore(&pring->ring_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20257) 			return WQE_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20258) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20259) 		pwqe->sli4_lxritag = sglq->sli4_lxritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20260) 		pwqe->sli4_xritag = sglq->sli4_xritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20261) 		if (lpfc_wqe_bpl2sgl(phba, pwqe, sglq) == NO_XRI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20262) 			spin_unlock_irqrestore(&pring->ring_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20263) 			return WQE_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20264) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20265) 		bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20266) 		       pwqe->sli4_xritag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20267) 		ret = lpfc_sli4_wq_put(phba->sli4_hba.nvmels_wq, wqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20268) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20269) 			spin_unlock_irqrestore(&pring->ring_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20270) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20271) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20273) 		lpfc_sli_ringtxcmpl_put(phba, pring, pwqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20274) 		spin_unlock_irqrestore(&pring->ring_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20276) 		lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20277) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20278) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20280) 	/* NVME_FCREQ and NVME_ABTS requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20281) 	if (pwqe->iocb_flag & LPFC_IO_NVME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20282) 		/* Get the IO distribution (hba_wqidx) for WQ assignment. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20283) 		wq = qp->io_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20284) 		pring = wq->pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20286) 		bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20288) 		lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20289) 					  qp, wq_access);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20290) 		ret = lpfc_sli4_wq_put(wq, wqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20291) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20292) 			spin_unlock_irqrestore(&pring->ring_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20293) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20294) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20295) 		lpfc_sli_ringtxcmpl_put(phba, pring, pwqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20296) 		spin_unlock_irqrestore(&pring->ring_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20298) 		lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20299) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20300) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20302) 	/* NVMET requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20303) 	if (pwqe->iocb_flag & LPFC_IO_NVMET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20304) 		/* Get the IO distribution (hba_wqidx) for WQ assignment. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20305) 		wq = qp->io_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20306) 		pring = wq->pring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20308) 		ctxp = pwqe->context2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20309) 		sglq = ctxp->ctxbuf->sglq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20310) 		if (pwqe->sli4_xritag ==  NO_XRI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20311) 			pwqe->sli4_lxritag = sglq->sli4_lxritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20312) 			pwqe->sli4_xritag = sglq->sli4_xritag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20313) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20314) 		bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20315) 		       pwqe->sli4_xritag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20316) 		bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20318) 		lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20319) 					  qp, wq_access);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20320) 		ret = lpfc_sli4_wq_put(wq, wqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20321) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20322) 			spin_unlock_irqrestore(&pring->ring_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20323) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20324) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20325) 		lpfc_sli_ringtxcmpl_put(phba, pring, pwqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20326) 		spin_unlock_irqrestore(&pring->ring_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20328) 		lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20329) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20330) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20331) 	return WQE_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20334) #ifdef LPFC_MXP_STAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20335) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20336)  * lpfc_snapshot_mxp - Snapshot pbl, pvt and busy count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20337)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20338)  * @hwqid: belong to which HWQ.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20339)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20340)  * The purpose of this routine is to take a snapshot of pbl, pvt and busy count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20341)  * 15 seconds after a test case is running.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20342)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20343)  * The user should call lpfc_debugfs_multixripools_write before running a test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20344)  * case to clear stat_snapshot_taken. Then the user starts a test case. During
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20345)  * test case is running, stat_snapshot_taken is incremented by 1 every time when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20346)  * this routine is called from heartbeat timer. When stat_snapshot_taken is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20347)  * equal to LPFC_MXP_SNAPSHOT_TAKEN, a snapshot is taken.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20348)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20349) void lpfc_snapshot_mxp(struct lpfc_hba *phba, u32 hwqid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20351) 	struct lpfc_sli4_hdw_queue *qp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20352) 	struct lpfc_multixri_pool *multixri_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20353) 	struct lpfc_pvt_pool *pvt_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20354) 	struct lpfc_pbl_pool *pbl_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20355) 	u32 txcmplq_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20357) 	qp = &phba->sli4_hba.hdwq[hwqid];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20358) 	multixri_pool = qp->p_multixri_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20359) 	if (!multixri_pool)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20360) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20362) 	if (multixri_pool->stat_snapshot_taken == LPFC_MXP_SNAPSHOT_TAKEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20363) 		pvt_pool = &qp->p_multixri_pool->pvt_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20364) 		pbl_pool = &qp->p_multixri_pool->pbl_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20365) 		txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20367) 		multixri_pool->stat_pbl_count = pbl_pool->count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20368) 		multixri_pool->stat_pvt_count = pvt_pool->count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20369) 		multixri_pool->stat_busy_count = txcmplq_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20370) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20372) 	multixri_pool->stat_snapshot_taken++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20374) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20376) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20377)  * lpfc_adjust_pvt_pool_count - Adjust private pool count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20378)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20379)  * @hwqid: belong to which HWQ.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20380)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20381)  * This routine moves some XRIs from private to public pool when private pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20382)  * is not busy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20383)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20384) void lpfc_adjust_pvt_pool_count(struct lpfc_hba *phba, u32 hwqid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20386) 	struct lpfc_multixri_pool *multixri_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20387) 	u32 io_req_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20388) 	u32 prev_io_req_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20390) 	multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20391) 	if (!multixri_pool)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20392) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20393) 	io_req_count = multixri_pool->io_req_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20394) 	prev_io_req_count = multixri_pool->prev_io_req_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20396) 	if (prev_io_req_count != io_req_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20397) 		/* Private pool is busy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20398) 		multixri_pool->prev_io_req_count = io_req_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20399) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20400) 		/* Private pool is not busy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20401) 		 * Move XRIs from private to public pool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20402) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20403) 		lpfc_move_xri_pvt_to_pbl(phba, hwqid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20404) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20407) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20408)  * lpfc_adjust_high_watermark - Adjust high watermark
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20409)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20410)  * @hwqid: belong to which HWQ.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20411)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20412)  * This routine sets high watermark as number of outstanding XRIs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20413)  * but make sure the new value is between xri_limit/2 and xri_limit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20414)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20415) void lpfc_adjust_high_watermark(struct lpfc_hba *phba, u32 hwqid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20416) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20417) 	u32 new_watermark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20418) 	u32 watermark_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20419) 	u32 watermark_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20420) 	u32 xri_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20421) 	u32 txcmplq_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20422) 	u32 abts_io_bufs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20423) 	struct lpfc_multixri_pool *multixri_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20424) 	struct lpfc_sli4_hdw_queue *qp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20426) 	qp = &phba->sli4_hba.hdwq[hwqid];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20427) 	multixri_pool = qp->p_multixri_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20428) 	if (!multixri_pool)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20429) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20430) 	xri_limit = multixri_pool->xri_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20432) 	watermark_max = xri_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20433) 	watermark_min = xri_limit / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20435) 	txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20436) 	abts_io_bufs = qp->abts_scsi_io_bufs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20437) 	abts_io_bufs += qp->abts_nvme_io_bufs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20439) 	new_watermark = txcmplq_cnt + abts_io_bufs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20440) 	new_watermark = min(watermark_max, new_watermark);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20441) 	new_watermark = max(watermark_min, new_watermark);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20442) 	multixri_pool->pvt_pool.high_watermark = new_watermark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20444) #ifdef LPFC_MXP_STAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20445) 	multixri_pool->stat_max_hwm = max(multixri_pool->stat_max_hwm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20446) 					  new_watermark);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20447) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20450) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20451)  * lpfc_move_xri_pvt_to_pbl - Move some XRIs from private to public pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20452)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20453)  * @hwqid: belong to which HWQ.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20454)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20455)  * This routine is called from hearbeat timer when pvt_pool is idle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20456)  * All free XRIs are moved from private to public pool on hwqid with 2 steps.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20457)  * The first step moves (all - low_watermark) amount of XRIs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20458)  * The second step moves the rest of XRIs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20459)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20460) void lpfc_move_xri_pvt_to_pbl(struct lpfc_hba *phba, u32 hwqid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20461) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20462) 	struct lpfc_pbl_pool *pbl_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20463) 	struct lpfc_pvt_pool *pvt_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20464) 	struct lpfc_sli4_hdw_queue *qp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20465) 	struct lpfc_io_buf *lpfc_ncmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20466) 	struct lpfc_io_buf *lpfc_ncmd_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20467) 	unsigned long iflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20468) 	struct list_head tmp_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20469) 	u32 tmp_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20471) 	qp = &phba->sli4_hba.hdwq[hwqid];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20472) 	pbl_pool = &qp->p_multixri_pool->pbl_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20473) 	pvt_pool = &qp->p_multixri_pool->pvt_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20474) 	tmp_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20476) 	lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag, qp, mv_to_pub_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20477) 	lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_from_pvt_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20479) 	if (pvt_pool->count > pvt_pool->low_watermark) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20480) 		/* Step 1: move (all - low_watermark) from pvt_pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20481) 		 * to pbl_pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20482) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20484) 		/* Move low watermark of bufs from pvt_pool to tmp_list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20485) 		INIT_LIST_HEAD(&tmp_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20486) 		list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20487) 					 &pvt_pool->list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20488) 			list_move_tail(&lpfc_ncmd->list, &tmp_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20489) 			tmp_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20490) 			if (tmp_count >= pvt_pool->low_watermark)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20491) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20492) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20494) 		/* Move all bufs from pvt_pool to pbl_pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20495) 		list_splice_init(&pvt_pool->list, &pbl_pool->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20497) 		/* Move all bufs from tmp_list to pvt_pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20498) 		list_splice(&tmp_list, &pvt_pool->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20500) 		pbl_pool->count += (pvt_pool->count - tmp_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20501) 		pvt_pool->count = tmp_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20502) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20503) 		/* Step 2: move the rest from pvt_pool to pbl_pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20504) 		list_splice_init(&pvt_pool->list, &pbl_pool->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20505) 		pbl_pool->count += pvt_pool->count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20506) 		pvt_pool->count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20507) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20509) 	spin_unlock(&pvt_pool->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20510) 	spin_unlock_irqrestore(&pbl_pool->lock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20513) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20514)  * _lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20515)  * @phba: pointer to lpfc hba data structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20516)  * @qp: pointer to HDW queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20517)  * @pbl_pool: specified public free XRI pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20518)  * @pvt_pool: specified private free XRI pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20519)  * @count: number of XRIs to move
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20520)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20521)  * This routine tries to move some free common bufs from the specified pbl_pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20522)  * to the specified pvt_pool. It might move less than count XRIs if there's not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20523)  * enough in public pool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20524)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20525)  * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20526)  *   true - if XRIs are successfully moved from the specified pbl_pool to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20527)  *          specified pvt_pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20528)  *   false - if the specified pbl_pool is empty or locked by someone else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20529)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20530) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20531) _lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, struct lpfc_sli4_hdw_queue *qp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20532) 			  struct lpfc_pbl_pool *pbl_pool,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20533) 			  struct lpfc_pvt_pool *pvt_pool, u32 count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20534) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20535) 	struct lpfc_io_buf *lpfc_ncmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20536) 	struct lpfc_io_buf *lpfc_ncmd_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20537) 	unsigned long iflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20538) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20540) 	ret = spin_trylock_irqsave(&pbl_pool->lock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20541) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20542) 		if (pbl_pool->count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20543) 			/* Move a batch of XRIs from public to private pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20544) 			lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_to_pvt_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20545) 			list_for_each_entry_safe(lpfc_ncmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20546) 						 lpfc_ncmd_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20547) 						 &pbl_pool->list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20548) 						 list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20549) 				list_move_tail(&lpfc_ncmd->list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20550) 					       &pvt_pool->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20551) 				pvt_pool->count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20552) 				pbl_pool->count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20553) 				count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20554) 				if (count == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20555) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20556) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20558) 			spin_unlock(&pvt_pool->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20559) 			spin_unlock_irqrestore(&pbl_pool->lock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20560) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20561) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20562) 		spin_unlock_irqrestore(&pbl_pool->lock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20563) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20565) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20568) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20569)  * lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20570)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20571)  * @hwqid: belong to which HWQ.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20572)  * @count: number of XRIs to move
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20573)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20574)  * This routine tries to find some free common bufs in one of public pools with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20575)  * Round Robin method. The search always starts from local hwqid, then the next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20576)  * HWQ which was found last time (rrb_next_hwqid). Once a public pool is found,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20577)  * a batch of free common bufs are moved to private pool on hwqid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20578)  * It might move less than count XRIs if there's not enough in public pool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20579)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20580) void lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, u32 hwqid, u32 count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20581) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20582) 	struct lpfc_multixri_pool *multixri_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20583) 	struct lpfc_multixri_pool *next_multixri_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20584) 	struct lpfc_pvt_pool *pvt_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20585) 	struct lpfc_pbl_pool *pbl_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20586) 	struct lpfc_sli4_hdw_queue *qp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20587) 	u32 next_hwqid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20588) 	u32 hwq_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20589) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20591) 	qp = &phba->sli4_hba.hdwq[hwqid];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20592) 	multixri_pool = qp->p_multixri_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20593) 	pvt_pool = &multixri_pool->pvt_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20594) 	pbl_pool = &multixri_pool->pbl_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20596) 	/* Check if local pbl_pool is available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20597) 	ret = _lpfc_move_xri_pbl_to_pvt(phba, qp, pbl_pool, pvt_pool, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20598) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20599) #ifdef LPFC_MXP_STAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20600) 		multixri_pool->local_pbl_hit_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20601) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20602) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20603) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20605) 	hwq_count = phba->cfg_hdw_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20607) 	/* Get the next hwqid which was found last time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20608) 	next_hwqid = multixri_pool->rrb_next_hwqid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20610) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20611) 		/* Go to next hwq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20612) 		next_hwqid = (next_hwqid + 1) % hwq_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20614) 		next_multixri_pool =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20615) 			phba->sli4_hba.hdwq[next_hwqid].p_multixri_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20616) 		pbl_pool = &next_multixri_pool->pbl_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20618) 		/* Check if the public free xri pool is available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20619) 		ret = _lpfc_move_xri_pbl_to_pvt(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20620) 			phba, qp, pbl_pool, pvt_pool, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20622) 		/* Exit while-loop if success or all hwqid are checked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20623) 	} while (!ret && next_hwqid != multixri_pool->rrb_next_hwqid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20625) 	/* Starting point for the next time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20626) 	multixri_pool->rrb_next_hwqid = next_hwqid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20628) 	if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20629) 		/* stats: all public pools are empty*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20630) 		multixri_pool->pbl_empty_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20631) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20633) #ifdef LPFC_MXP_STAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20634) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20635) 		if (next_hwqid == hwqid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20636) 			multixri_pool->local_pbl_hit_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20637) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20638) 			multixri_pool->other_pbl_hit_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20639) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20640) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20641) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20643) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20644)  * lpfc_keep_pvt_pool_above_lowwm - Keep pvt_pool above low watermark
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20645)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20646)  * @hwqid: belong to which HWQ.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20647)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20648)  * This routine get a batch of XRIs from pbl_pool if pvt_pool is less than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20649)  * low watermark.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20650)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20651) void lpfc_keep_pvt_pool_above_lowwm(struct lpfc_hba *phba, u32 hwqid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20652) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20653) 	struct lpfc_multixri_pool *multixri_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20654) 	struct lpfc_pvt_pool *pvt_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20656) 	multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20657) 	pvt_pool = &multixri_pool->pvt_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20659) 	if (pvt_pool->count < pvt_pool->low_watermark)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20660) 		lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20661) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20663) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20664)  * lpfc_release_io_buf - Return one IO buf back to free pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20665)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20666)  * @lpfc_ncmd: IO buf to be returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20667)  * @qp: belong to which HWQ.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20668)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20669)  * This routine returns one IO buf back to free pool. If this is an urgent IO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20670)  * the IO buf is returned to expedite pool. If cfg_xri_rebalancing==1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20671)  * the IO buf is returned to pbl_pool or pvt_pool based on watermark and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20672)  * xri_limit.  If cfg_xri_rebalancing==0, the IO buf is returned to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20673)  * lpfc_io_buf_list_put.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20674)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20675) void lpfc_release_io_buf(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_ncmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20676) 			 struct lpfc_sli4_hdw_queue *qp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20677) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20678) 	unsigned long iflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20679) 	struct lpfc_pbl_pool *pbl_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20680) 	struct lpfc_pvt_pool *pvt_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20681) 	struct lpfc_epd_pool *epd_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20682) 	u32 txcmplq_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20683) 	u32 xri_owned;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20684) 	u32 xri_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20685) 	u32 abts_io_bufs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20687) 	/* MUST zero fields if buffer is reused by another protocol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20688) 	lpfc_ncmd->nvmeCmd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20689) 	lpfc_ncmd->cur_iocbq.wqe_cmpl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20690) 	lpfc_ncmd->cur_iocbq.iocb_cmpl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20692) 	if (phba->cfg_xpsgl && !phba->nvmet_support &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20693) 	    !list_empty(&lpfc_ncmd->dma_sgl_xtra_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20694) 		lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20696) 	if (!list_empty(&lpfc_ncmd->dma_cmd_rsp_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20697) 		lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20699) 	if (phba->cfg_xri_rebalancing) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20700) 		if (lpfc_ncmd->expedite) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20701) 			/* Return to expedite pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20702) 			epd_pool = &phba->epd_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20703) 			spin_lock_irqsave(&epd_pool->lock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20704) 			list_add_tail(&lpfc_ncmd->list, &epd_pool->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20705) 			epd_pool->count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20706) 			spin_unlock_irqrestore(&epd_pool->lock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20707) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20708) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20710) 		/* Avoid invalid access if an IO sneaks in and is being rejected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20711) 		 * just _after_ xri pools are destroyed in lpfc_offline.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20712) 		 * Nothing much can be done at this point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20713) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20714) 		if (!qp->p_multixri_pool)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20715) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20717) 		pbl_pool = &qp->p_multixri_pool->pbl_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20718) 		pvt_pool = &qp->p_multixri_pool->pvt_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20720) 		txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20721) 		abts_io_bufs = qp->abts_scsi_io_bufs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20722) 		abts_io_bufs += qp->abts_nvme_io_bufs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20724) 		xri_owned = pvt_pool->count + txcmplq_cnt + abts_io_bufs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20725) 		xri_limit = qp->p_multixri_pool->xri_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20727) #ifdef LPFC_MXP_STAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20728) 		if (xri_owned <= xri_limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20729) 			qp->p_multixri_pool->below_limit_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20730) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20731) 			qp->p_multixri_pool->above_limit_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20732) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20734) 		/* XRI goes to either public or private free xri pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20735) 		 *     based on watermark and xri_limit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20736) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20737) 		if ((pvt_pool->count < pvt_pool->low_watermark) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20738) 		    (xri_owned < xri_limit &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20739) 		     pvt_pool->count < pvt_pool->high_watermark)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20740) 			lpfc_qp_spin_lock_irqsave(&pvt_pool->lock, iflag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20741) 						  qp, free_pvt_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20742) 			list_add_tail(&lpfc_ncmd->list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20743) 				      &pvt_pool->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20744) 			pvt_pool->count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20745) 			spin_unlock_irqrestore(&pvt_pool->lock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20746) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20747) 			lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20748) 						  qp, free_pub_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20749) 			list_add_tail(&lpfc_ncmd->list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20750) 				      &pbl_pool->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20751) 			pbl_pool->count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20752) 			spin_unlock_irqrestore(&pbl_pool->lock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20753) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20754) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20755) 		lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20756) 					  qp, free_xri);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20757) 		list_add_tail(&lpfc_ncmd->list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20758) 			      &qp->lpfc_io_buf_list_put);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20759) 		qp->put_io_bufs++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20760) 		spin_unlock_irqrestore(&qp->io_buf_list_put_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20761) 				       iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20762) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20763) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20765) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20766)  * lpfc_get_io_buf_from_private_pool - Get one free IO buf from private pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20767)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20768)  * @qp: pointer to HDW queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20769)  * @pvt_pool: pointer to private pool data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20770)  * @ndlp: pointer to lpfc nodelist data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20771)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20772)  * This routine tries to get one free IO buf from private pool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20773)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20774)  * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20775)  *   pointer to one free IO buf - if private pool is not empty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20776)  *   NULL - if private pool is empty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20777)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20778) static struct lpfc_io_buf *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20779) lpfc_get_io_buf_from_private_pool(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20780) 				  struct lpfc_sli4_hdw_queue *qp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20781) 				  struct lpfc_pvt_pool *pvt_pool,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20782) 				  struct lpfc_nodelist *ndlp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20783) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20784) 	struct lpfc_io_buf *lpfc_ncmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20785) 	struct lpfc_io_buf *lpfc_ncmd_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20786) 	unsigned long iflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20788) 	lpfc_qp_spin_lock_irqsave(&pvt_pool->lock, iflag, qp, alloc_pvt_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20789) 	list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20790) 				 &pvt_pool->list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20791) 		if (lpfc_test_rrq_active(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20792) 			phba, ndlp, lpfc_ncmd->cur_iocbq.sli4_lxritag))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20793) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20794) 		list_del(&lpfc_ncmd->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20795) 		pvt_pool->count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20796) 		spin_unlock_irqrestore(&pvt_pool->lock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20797) 		return lpfc_ncmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20798) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20799) 	spin_unlock_irqrestore(&pvt_pool->lock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20801) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20804) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20805)  * lpfc_get_io_buf_from_expedite_pool - Get one free IO buf from expedite pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20806)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20807)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20808)  * This routine tries to get one free IO buf from expedite pool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20809)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20810)  * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20811)  *   pointer to one free IO buf - if expedite pool is not empty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20812)  *   NULL - if expedite pool is empty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20813)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20814) static struct lpfc_io_buf *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20815) lpfc_get_io_buf_from_expedite_pool(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20816) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20817) 	struct lpfc_io_buf *lpfc_ncmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20818) 	struct lpfc_io_buf *lpfc_ncmd_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20819) 	unsigned long iflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20820) 	struct lpfc_epd_pool *epd_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20822) 	epd_pool = &phba->epd_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20823) 	lpfc_ncmd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20825) 	spin_lock_irqsave(&epd_pool->lock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20826) 	if (epd_pool->count > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20827) 		list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20828) 					 &epd_pool->list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20829) 			list_del(&lpfc_ncmd->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20830) 			epd_pool->count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20831) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20832) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20833) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20834) 	spin_unlock_irqrestore(&epd_pool->lock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20836) 	return lpfc_ncmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20837) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20839) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20840)  * lpfc_get_io_buf_from_multixri_pools - Get one free IO bufs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20841)  * @phba: pointer to lpfc hba data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20842)  * @ndlp: pointer to lpfc nodelist data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20843)  * @hwqid: belong to which HWQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20844)  * @expedite: 1 means this request is urgent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20845)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20846)  * This routine will do the following actions and then return a pointer to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20847)  * one free IO buf.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20848)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20849)  * 1. If private free xri count is empty, move some XRIs from public to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20850)  *    private pool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20851)  * 2. Get one XRI from private free xri pool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20852)  * 3. If we fail to get one from pvt_pool and this is an expedite request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20853)  *    get one free xri from expedite pool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20854)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20855)  * Note: ndlp is only used on SCSI side for RRQ testing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20856)  *       The caller should pass NULL for ndlp on NVME side.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20857)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20858)  * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20859)  *   pointer to one free IO buf - if private pool is not empty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20860)  *   NULL - if private pool is empty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20861)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20862) static struct lpfc_io_buf *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20863) lpfc_get_io_buf_from_multixri_pools(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20864) 				    struct lpfc_nodelist *ndlp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20865) 				    int hwqid, int expedite)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20866) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20867) 	struct lpfc_sli4_hdw_queue *qp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20868) 	struct lpfc_multixri_pool *multixri_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20869) 	struct lpfc_pvt_pool *pvt_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20870) 	struct lpfc_io_buf *lpfc_ncmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20872) 	qp = &phba->sli4_hba.hdwq[hwqid];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20873) 	lpfc_ncmd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20874) 	multixri_pool = qp->p_multixri_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20875) 	pvt_pool = &multixri_pool->pvt_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20876) 	multixri_pool->io_req_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20878) 	/* If pvt_pool is empty, move some XRIs from public to private pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20879) 	if (pvt_pool->count == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20880) 		lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20882) 	/* Get one XRI from private free xri pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20883) 	lpfc_ncmd = lpfc_get_io_buf_from_private_pool(phba, qp, pvt_pool, ndlp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20885) 	if (lpfc_ncmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20886) 		lpfc_ncmd->hdwq = qp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20887) 		lpfc_ncmd->hdwq_no = hwqid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20888) 	} else if (expedite) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20889) 		/* If we fail to get one from pvt_pool and this is an expedite
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20890) 		 * request, get one free xri from expedite pool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20891) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20892) 		lpfc_ncmd = lpfc_get_io_buf_from_expedite_pool(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20893) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20895) 	return lpfc_ncmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20896) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20898) static inline struct lpfc_io_buf *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20899) lpfc_io_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20900) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20901) 	struct lpfc_sli4_hdw_queue *qp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20902) 	struct lpfc_io_buf *lpfc_cmd, *lpfc_cmd_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20904) 	qp = &phba->sli4_hba.hdwq[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20905) 	list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20906) 				 &qp->lpfc_io_buf_list_get, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20907) 		if (lpfc_test_rrq_active(phba, ndlp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20908) 					 lpfc_cmd->cur_iocbq.sli4_lxritag))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20909) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20910) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20911) 		if (lpfc_cmd->flags & LPFC_SBUF_NOT_POSTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20912) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20914) 		list_del_init(&lpfc_cmd->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20915) 		qp->get_io_bufs--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20916) 		lpfc_cmd->hdwq = qp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20917) 		lpfc_cmd->hdwq_no = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20918) 		return lpfc_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20919) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20920) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20921) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20923) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20924)  * lpfc_get_io_buf - Get one IO buffer from free pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20925)  * @phba: The HBA for which this call is being executed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20926)  * @ndlp: pointer to lpfc nodelist data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20927)  * @hwqid: belong to which HWQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20928)  * @expedite: 1 means this request is urgent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20929)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20930)  * This routine gets one IO buffer from free pool. If cfg_xri_rebalancing==1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20931)  * removes a IO buffer from multiXRI pools. If cfg_xri_rebalancing==0, removes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20932)  * a IO buffer from head of @hdwq io_buf_list and returns to caller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20933)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20934)  * Note: ndlp is only used on SCSI side for RRQ testing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20935)  *       The caller should pass NULL for ndlp on NVME side.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20936)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20937)  * Return codes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20938)  *   NULL - Error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20939)  *   Pointer to lpfc_io_buf - Success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20940)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20941) struct lpfc_io_buf *lpfc_get_io_buf(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20942) 				    struct lpfc_nodelist *ndlp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20943) 				    u32 hwqid, int expedite)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20944) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20945) 	struct lpfc_sli4_hdw_queue *qp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20946) 	unsigned long iflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20947) 	struct lpfc_io_buf *lpfc_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20949) 	qp = &phba->sli4_hba.hdwq[hwqid];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20950) 	lpfc_cmd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20952) 	if (phba->cfg_xri_rebalancing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20953) 		lpfc_cmd = lpfc_get_io_buf_from_multixri_pools(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20954) 			phba, ndlp, hwqid, expedite);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20955) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20956) 		lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_get_lock, iflag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20957) 					  qp, alloc_xri_get);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20958) 		if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT || expedite)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20959) 			lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20960) 		if (!lpfc_cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20961) 			lpfc_qp_spin_lock(&qp->io_buf_list_put_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20962) 					  qp, alloc_xri_put);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20963) 			list_splice(&qp->lpfc_io_buf_list_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20964) 				    &qp->lpfc_io_buf_list_get);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20965) 			qp->get_io_bufs += qp->put_io_bufs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20966) 			INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20967) 			qp->put_io_bufs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20968) 			spin_unlock(&qp->io_buf_list_put_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20969) 			if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20970) 			    expedite)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20971) 				lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20972) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20973) 		spin_unlock_irqrestore(&qp->io_buf_list_get_lock, iflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20974) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20976) 	return lpfc_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20977) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20979) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20980)  * lpfc_get_sgl_per_hdwq - Get one SGL chunk from hdwq's pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20981)  * @phba: The HBA for which this call is being executed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20982)  * @lpfc_buf: IO buf structure to append the SGL chunk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20983)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20984)  * This routine gets one SGL chunk buffer from hdwq's SGL chunk pool,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20985)  * and will allocate an SGL chunk if the pool is empty.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20986)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20987)  * Return codes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20988)  *   NULL - Error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20989)  *   Pointer to sli4_hybrid_sgl - Success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20990)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20991) struct sli4_hybrid_sgl *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20992) lpfc_get_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20993) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20994) 	struct sli4_hybrid_sgl *list_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20995) 	struct sli4_hybrid_sgl *tmp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20996) 	struct sli4_hybrid_sgl *allocated_sgl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20997) 	struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20998) 	struct list_head *buf_list = &hdwq->sgl_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20999) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21001) 	spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21003) 	if (likely(!list_empty(buf_list))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21004) 		/* break off 1 chunk from the sgl_list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21005) 		list_for_each_entry_safe(list_entry, tmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21006) 					 buf_list, list_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21007) 			list_move_tail(&list_entry->list_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21008) 				       &lpfc_buf->dma_sgl_xtra_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21009) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21010) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21011) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21012) 		/* allocate more */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21013) 		spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21014) 		tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21015) 				   cpu_to_node(hdwq->io_wq->chann));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21016) 		if (!tmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21017) 			lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21018) 					"8353 error kmalloc memory for HDWQ "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21019) 					"%d %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21020) 					lpfc_buf->hdwq_no, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21021) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21022) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21024) 		tmp->dma_sgl = dma_pool_alloc(phba->lpfc_sg_dma_buf_pool,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21025) 					      GFP_ATOMIC, &tmp->dma_phys_sgl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21026) 		if (!tmp->dma_sgl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21027) 			lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21028) 					"8354 error pool_alloc memory for HDWQ "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21029) 					"%d %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21030) 					lpfc_buf->hdwq_no, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21031) 			kfree(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21032) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21033) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21035) 		spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21036) 		list_add_tail(&tmp->list_node, &lpfc_buf->dma_sgl_xtra_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21037) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21038) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21039) 	allocated_sgl = list_last_entry(&lpfc_buf->dma_sgl_xtra_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21040) 					struct sli4_hybrid_sgl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21041) 					list_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21043) 	spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21044) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21045) 	return allocated_sgl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21046) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21047) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21048) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21049)  * lpfc_put_sgl_per_hdwq - Put one SGL chunk into hdwq pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21050)  * @phba: The HBA for which this call is being executed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21051)  * @lpfc_buf: IO buf structure with the SGL chunk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21052)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21053)  * This routine puts one SGL chunk buffer into hdwq's SGL chunk pool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21054)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21055)  * Return codes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21056)  *   0 - Success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21057)  *   -EINVAL - Error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21058)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21059) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21060) lpfc_put_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21061) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21062) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21063) 	struct sli4_hybrid_sgl *list_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21064) 	struct sli4_hybrid_sgl *tmp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21065) 	struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21066) 	struct list_head *buf_list = &hdwq->sgl_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21067) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21069) 	spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21070) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21071) 	if (likely(!list_empty(&lpfc_buf->dma_sgl_xtra_list))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21072) 		list_for_each_entry_safe(list_entry, tmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21073) 					 &lpfc_buf->dma_sgl_xtra_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21074) 					 list_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21075) 			list_move_tail(&list_entry->list_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21076) 				       buf_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21077) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21078) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21079) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21080) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21082) 	spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21083) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21084) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21086) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21087)  * lpfc_free_sgl_per_hdwq - Free all SGL chunks of hdwq pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21088)  * @phba: phba object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21089)  * @hdwq: hdwq to cleanup sgl buff resources on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21090)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21091)  * This routine frees all SGL chunks of hdwq SGL chunk pool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21092)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21093)  * Return codes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21094)  *   None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21095)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21096) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21097) lpfc_free_sgl_per_hdwq(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21098) 		       struct lpfc_sli4_hdw_queue *hdwq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21099) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21100) 	struct list_head *buf_list = &hdwq->sgl_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21101) 	struct sli4_hybrid_sgl *list_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21102) 	struct sli4_hybrid_sgl *tmp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21103) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21105) 	spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21107) 	/* Free sgl pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21108) 	list_for_each_entry_safe(list_entry, tmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21109) 				 buf_list, list_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21110) 		dma_pool_free(phba->lpfc_sg_dma_buf_pool,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21111) 			      list_entry->dma_sgl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21112) 			      list_entry->dma_phys_sgl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21113) 		list_del(&list_entry->list_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21114) 		kfree(list_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21115) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21117) 	spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21120) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21121)  * lpfc_get_cmd_rsp_buf_per_hdwq - Get one CMD/RSP buffer from hdwq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21122)  * @phba: The HBA for which this call is being executed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21123)  * @lpfc_buf: IO buf structure to attach the CMD/RSP buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21124)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21125)  * This routine gets one CMD/RSP buffer from hdwq's CMD/RSP pool,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21126)  * and will allocate an CMD/RSP buffer if the pool is empty.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21127)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21128)  * Return codes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21129)  *   NULL - Error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21130)  *   Pointer to fcp_cmd_rsp_buf - Success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21131)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21132) struct fcp_cmd_rsp_buf *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21133) lpfc_get_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21134) 			      struct lpfc_io_buf *lpfc_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21136) 	struct fcp_cmd_rsp_buf *list_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21137) 	struct fcp_cmd_rsp_buf *tmp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21138) 	struct fcp_cmd_rsp_buf *allocated_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21139) 	struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21140) 	struct list_head *buf_list = &hdwq->cmd_rsp_buf_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21141) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21143) 	spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21145) 	if (likely(!list_empty(buf_list))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21146) 		/* break off 1 chunk from the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21147) 		list_for_each_entry_safe(list_entry, tmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21148) 					 buf_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21149) 					 list_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21150) 			list_move_tail(&list_entry->list_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21151) 				       &lpfc_buf->dma_cmd_rsp_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21152) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21153) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21154) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21155) 		/* allocate more */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21156) 		spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21157) 		tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21158) 				   cpu_to_node(hdwq->io_wq->chann));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21159) 		if (!tmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21160) 			lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21161) 					"8355 error kmalloc memory for HDWQ "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21162) 					"%d %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21163) 					lpfc_buf->hdwq_no, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21164) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21165) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21167) 		tmp->fcp_cmnd = dma_pool_alloc(phba->lpfc_cmd_rsp_buf_pool,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21168) 						GFP_ATOMIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21169) 						&tmp->fcp_cmd_rsp_dma_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21171) 		if (!tmp->fcp_cmnd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21172) 			lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21173) 					"8356 error pool_alloc memory for HDWQ "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21174) 					"%d %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21175) 					lpfc_buf->hdwq_no, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21176) 			kfree(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21177) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21178) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21180) 		tmp->fcp_rsp = (struct fcp_rsp *)((uint8_t *)tmp->fcp_cmnd +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21181) 				sizeof(struct fcp_cmnd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21183) 		spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21184) 		list_add_tail(&tmp->list_node, &lpfc_buf->dma_cmd_rsp_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21185) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21187) 	allocated_buf = list_last_entry(&lpfc_buf->dma_cmd_rsp_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21188) 					struct fcp_cmd_rsp_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21189) 					list_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21191) 	spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21193) 	return allocated_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21196) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21197)  * lpfc_put_cmd_rsp_buf_per_hdwq - Put one CMD/RSP buffer into hdwq pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21198)  * @phba: The HBA for which this call is being executed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21199)  * @lpfc_buf: IO buf structure with the CMD/RSP buf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21200)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21201)  * This routine puts one CMD/RSP buffer into executing CPU's CMD/RSP pool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21202)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21203)  * Return codes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21204)  *   0 - Success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21205)  *   -EINVAL - Error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21206)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21207) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21208) lpfc_put_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21209) 			      struct lpfc_io_buf *lpfc_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21211) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21212) 	struct fcp_cmd_rsp_buf *list_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21213) 	struct fcp_cmd_rsp_buf *tmp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21214) 	struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21215) 	struct list_head *buf_list = &hdwq->cmd_rsp_buf_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21216) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21218) 	spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21220) 	if (likely(!list_empty(&lpfc_buf->dma_cmd_rsp_list))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21221) 		list_for_each_entry_safe(list_entry, tmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21222) 					 &lpfc_buf->dma_cmd_rsp_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21223) 					 list_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21224) 			list_move_tail(&list_entry->list_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21225) 				       buf_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21226) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21227) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21228) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21229) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21231) 	spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21232) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21235) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21236)  * lpfc_free_cmd_rsp_buf_per_hdwq - Free all CMD/RSP chunks of hdwq pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21237)  * @phba: phba object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21238)  * @hdwq: hdwq to cleanup cmd rsp buff resources on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21239)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21240)  * This routine frees all CMD/RSP buffers of hdwq's CMD/RSP buf pool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21241)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21242)  * Return codes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21243)  *   None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21244)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21245) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21246) lpfc_free_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21247) 			       struct lpfc_sli4_hdw_queue *hdwq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21249) 	struct list_head *buf_list = &hdwq->cmd_rsp_buf_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21250) 	struct fcp_cmd_rsp_buf *list_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21251) 	struct fcp_cmd_rsp_buf *tmp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21252) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21254) 	spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21256) 	/* Free cmd_rsp buf pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21257) 	list_for_each_entry_safe(list_entry, tmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21258) 				 buf_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21259) 				 list_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21260) 		dma_pool_free(phba->lpfc_cmd_rsp_buf_pool,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21261) 			      list_entry->fcp_cmnd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21262) 			      list_entry->fcp_cmd_rsp_dma_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21263) 		list_del(&list_entry->list_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21264) 		kfree(list_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21265) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21267) 	spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21268) }