171d10453SEric Joyner /* SPDX-License-Identifier: BSD-3-Clause */
2*015f8cc5SEric Joyner /*  Copyright (c) 2024, Intel Corporation
371d10453SEric Joyner  *  All rights reserved.
471d10453SEric Joyner  *
571d10453SEric Joyner  *  Redistribution and use in source and binary forms, with or without
671d10453SEric Joyner  *  modification, are permitted provided that the following conditions are met:
771d10453SEric Joyner  *
871d10453SEric Joyner  *   1. Redistributions of source code must retain the above copyright notice,
971d10453SEric Joyner  *      this list of conditions and the following disclaimer.
1071d10453SEric Joyner  *
1171d10453SEric Joyner  *   2. Redistributions in binary form must reproduce the above copyright
1271d10453SEric Joyner  *      notice, this list of conditions and the following disclaimer in the
1371d10453SEric Joyner  *      documentation and/or other materials provided with the distribution.
1471d10453SEric Joyner  *
1571d10453SEric Joyner  *   3. Neither the name of the Intel Corporation nor the names of its
1671d10453SEric Joyner  *      contributors may be used to endorse or promote products derived from
1771d10453SEric Joyner  *      this software without specific prior written permission.
1871d10453SEric Joyner  *
1971d10453SEric Joyner  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2071d10453SEric Joyner  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2171d10453SEric Joyner  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2271d10453SEric Joyner  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
2371d10453SEric Joyner  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2471d10453SEric Joyner  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2571d10453SEric Joyner  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2671d10453SEric Joyner  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2771d10453SEric Joyner  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2871d10453SEric Joyner  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2971d10453SEric Joyner  *  POSSIBILITY OF SUCH DAMAGE.
3071d10453SEric Joyner  */
3171d10453SEric Joyner 
3271d10453SEric Joyner /**
3371d10453SEric Joyner  * @file ice_iflib_recovery_txrx.c
3471d10453SEric Joyner  * @brief iflib Tx/Rx ops for recovery mode
3571d10453SEric Joyner  *
3671d10453SEric Joyner  * Contains the if_txrx structure of operations used when the driver detects
3771d10453SEric Joyner  * that the firmware is in recovery mode. These ops essentially do nothing and
3871d10453SEric Joyner  * exist to prevent any chance that the stack could attempt to transmit or
3971d10453SEric Joyner  * receive when the device is in firmware recovery mode.
4071d10453SEric Joyner  */
4171d10453SEric Joyner 
4271d10453SEric Joyner #include "ice_iflib.h"
4371d10453SEric Joyner 
4471d10453SEric Joyner /*
4571d10453SEric Joyner  * iflib txrx methods used when in recovery mode
4671d10453SEric Joyner  */
4771d10453SEric Joyner static int ice_recovery_txd_encap(void *arg, if_pkt_info_t pi);
4871d10453SEric Joyner static int ice_recovery_rxd_pkt_get(void *arg, if_rxd_info_t ri);
4971d10453SEric Joyner static void ice_recovery_txd_flush(void *arg, uint16_t txqid, qidx_t pidx);
5071d10453SEric Joyner static int ice_recovery_txd_credits_update(void *arg, uint16_t txqid, bool clear);
5171d10453SEric Joyner static int ice_recovery_rxd_available(void *arg, uint16_t rxqid, qidx_t pidx, qidx_t budget);
5271d10453SEric Joyner static void ice_recovery_rxd_flush(void *arg, uint16_t rxqid, uint8_t flidx, qidx_t pidx);
5371d10453SEric Joyner static void ice_recovery_rxd_refill(void *arg, if_rxd_update_t iru);
5471d10453SEric Joyner 
5571d10453SEric Joyner /**
5671d10453SEric Joyner  * @var ice_recovery_txrx
5771d10453SEric Joyner  * @brief Tx/Rx operations for recovery mode
5871d10453SEric Joyner  *
5971d10453SEric Joyner  * Similar to ice_txrx, but contains pointers to functions which are no-ops.
6071d10453SEric Joyner  * Used when the driver is in firmware recovery mode to prevent any attempt to
6171d10453SEric Joyner  * transmit or receive packets while the hardware is not initialized.
6271d10453SEric Joyner  */
6371d10453SEric Joyner struct if_txrx ice_recovery_txrx = {
6471d10453SEric Joyner 	.ift_txd_encap = ice_recovery_txd_encap,
6571d10453SEric Joyner 	.ift_txd_flush = ice_recovery_txd_flush,
6671d10453SEric Joyner 	.ift_txd_credits_update = ice_recovery_txd_credits_update,
6771d10453SEric Joyner 	.ift_rxd_available = ice_recovery_rxd_available,
6871d10453SEric Joyner 	.ift_rxd_pkt_get = ice_recovery_rxd_pkt_get,
6971d10453SEric Joyner 	.ift_rxd_refill = ice_recovery_rxd_refill,
7071d10453SEric Joyner 	.ift_rxd_flush = ice_recovery_rxd_flush,
7171d10453SEric Joyner };
7271d10453SEric Joyner 
7371d10453SEric Joyner /**
7471d10453SEric Joyner  * ice_recovery_txd_encap - prepare Tx descriptors for a packet
7571d10453SEric Joyner  * @arg: the iflib softc structure pointer
7671d10453SEric Joyner  * @pi: packet info
7771d10453SEric Joyner  *
7871d10453SEric Joyner  * Since the Tx queues are not initialized during recovery mode, this function
7971d10453SEric Joyner  * does nothing.
8071d10453SEric Joyner  *
8171d10453SEric Joyner  * @returns ENOSYS
8271d10453SEric Joyner  */
8371d10453SEric Joyner static int
ice_recovery_txd_encap(void __unused * arg,if_pkt_info_t __unused pi)8471d10453SEric Joyner ice_recovery_txd_encap(void __unused *arg, if_pkt_info_t __unused pi)
8571d10453SEric Joyner {
8671d10453SEric Joyner 	return (ENOSYS);
8771d10453SEric Joyner }
8871d10453SEric Joyner 
8971d10453SEric Joyner /**
9071d10453SEric Joyner  * ice_recovery_txd_flush - Flush Tx descriptors to hardware
9171d10453SEric Joyner  * @arg: device specific softc pointer
9271d10453SEric Joyner  * @txqid: the Tx queue to flush
9371d10453SEric Joyner  * @pidx: descriptor index to advance tail to
9471d10453SEric Joyner  *
9571d10453SEric Joyner  * Since the Tx queues are not initialized during recovery mode, this function
9671d10453SEric Joyner  * does nothing.
9771d10453SEric Joyner  */
9871d10453SEric Joyner static void
ice_recovery_txd_flush(void __unused * arg,uint16_t __unused txqid,qidx_t __unused pidx)9971d10453SEric Joyner ice_recovery_txd_flush(void __unused *arg, uint16_t __unused txqid,
10071d10453SEric Joyner 		       qidx_t __unused pidx)
10171d10453SEric Joyner {
10271d10453SEric Joyner 	;
10371d10453SEric Joyner }
10471d10453SEric Joyner 
10571d10453SEric Joyner /**
10671d10453SEric Joyner  * ice_recovery_txd_credits_update - cleanup Tx descriptors
10771d10453SEric Joyner  * @arg: device private softc
10871d10453SEric Joyner  * @txqid: the Tx queue to update
10971d10453SEric Joyner  * @clear: if false, only report, do not actually clean
11071d10453SEric Joyner  *
11171d10453SEric Joyner  * Since the Tx queues are not initialized during recovery mode, this function
11271d10453SEric Joyner  * always reports that no descriptors are ready.
11371d10453SEric Joyner  *
11471d10453SEric Joyner  * @returns 0
11571d10453SEric Joyner  */
11671d10453SEric Joyner static int
ice_recovery_txd_credits_update(void __unused * arg,uint16_t __unused txqid,bool __unused clear)11771d10453SEric Joyner ice_recovery_txd_credits_update(void __unused *arg, uint16_t __unused txqid,
11871d10453SEric Joyner 				bool __unused clear)
11971d10453SEric Joyner {
12071d10453SEric Joyner 	return (0);
12171d10453SEric Joyner }
12271d10453SEric Joyner 
12371d10453SEric Joyner /**
12471d10453SEric Joyner  * ice_recovery_rxd_available - Return number of available Rx packets
12571d10453SEric Joyner  * @arg: device private softc
12671d10453SEric Joyner  * @rxqid: the Rx queue id
12771d10453SEric Joyner  * @pidx: descriptor start point
12871d10453SEric Joyner  * @budget: maximum Rx budget
12971d10453SEric Joyner  *
13071d10453SEric Joyner  * Since the Rx queues are not initialized during recovery mode, this function
13171d10453SEric Joyner  * always reports that no packets are ready.
13271d10453SEric Joyner  *
13371d10453SEric Joyner  * @returns 0
13471d10453SEric Joyner  */
13571d10453SEric Joyner static int
ice_recovery_rxd_available(void __unused * arg,uint16_t __unused rxqid,qidx_t __unused pidx,qidx_t __unused budget)13671d10453SEric Joyner ice_recovery_rxd_available(void __unused *arg, uint16_t __unused rxqid,
13771d10453SEric Joyner 			   qidx_t __unused pidx, qidx_t __unused budget)
13871d10453SEric Joyner {
13971d10453SEric Joyner 	return (0);
14071d10453SEric Joyner }
14171d10453SEric Joyner 
14271d10453SEric Joyner /**
14371d10453SEric Joyner  * ice_recovery_rxd_pkt_get - Called by iflib to send data to upper layer
14471d10453SEric Joyner  * @arg: device specific softc
14571d10453SEric Joyner  * @ri: receive packet info
14671d10453SEric Joyner  *
14771d10453SEric Joyner  * Since the Rx queues are not initialized during recovery mode this function
14871d10453SEric Joyner  * always returns an error indicating that nothing could be done.
14971d10453SEric Joyner  *
15071d10453SEric Joyner  * @returns ENOSYS
15171d10453SEric Joyner  */
15271d10453SEric Joyner static int
ice_recovery_rxd_pkt_get(void __unused * arg,if_rxd_info_t __unused ri)15371d10453SEric Joyner ice_recovery_rxd_pkt_get(void __unused *arg, if_rxd_info_t __unused ri)
15471d10453SEric Joyner {
15571d10453SEric Joyner 	return (ENOSYS);
15671d10453SEric Joyner }
15771d10453SEric Joyner 
15871d10453SEric Joyner /**
15971d10453SEric Joyner  * ice_recovery_rxd_refill - Prepare Rx descriptors for re-use by hardware
16071d10453SEric Joyner  * @arg: device specific softc structure
16171d10453SEric Joyner  * @iru: the Rx descriptor update structure
16271d10453SEric Joyner  *
16371d10453SEric Joyner  * Since the Rx queues are not initialized during Recovery mode, this function
16471d10453SEric Joyner  * does nothing.
16571d10453SEric Joyner  */
16671d10453SEric Joyner static void
ice_recovery_rxd_refill(void __unused * arg,if_rxd_update_t __unused iru)16771d10453SEric Joyner ice_recovery_rxd_refill(void __unused *arg, if_rxd_update_t __unused iru)
16871d10453SEric Joyner {
16971d10453SEric Joyner 	;
17071d10453SEric Joyner }
17171d10453SEric Joyner 
17271d10453SEric Joyner /**
17371d10453SEric Joyner  * ice_recovery_rxd_flush - Flush Rx descriptors to hardware
17471d10453SEric Joyner  * @arg: device specific softc pointer
17571d10453SEric Joyner  * @rxqid: the Rx queue to flush
17671d10453SEric Joyner  * @flidx: unused parameter
17771d10453SEric Joyner  * @pidx: descriptor index to advance tail to
17871d10453SEric Joyner  *
17971d10453SEric Joyner  * Since the Rx queues are not initialized during Recovery mode, this function
18071d10453SEric Joyner  * does nothing.
18171d10453SEric Joyner  */
18271d10453SEric Joyner static void
ice_recovery_rxd_flush(void __unused * arg,uint16_t __unused rxqid,uint8_t flidx __unused,qidx_t __unused pidx)18371d10453SEric Joyner ice_recovery_rxd_flush(void __unused *arg, uint16_t __unused rxqid,
18471d10453SEric Joyner 		       uint8_t flidx __unused, qidx_t __unused pidx)
18571d10453SEric Joyner {
18671d10453SEric Joyner 	;
18771d10453SEric Joyner }
188