1/* SPDX-License-Identifier: BSD-3-Clause */
2/*  Copyright (c) 2024, Intel Corporation
3 *  All rights reserved.
4 *
5 *  Redistribution and use in source and binary forms, with or without
6 *  modification, are permitted provided that the following conditions are met:
7 *
8 *   1. Redistributions of source code must retain the above copyright notice,
9 *      this list of conditions and the following disclaimer.
10 *
11 *   2. Redistributions in binary form must reproduce the above copyright
12 *      notice, this list of conditions and the following disclaimer in the
13 *      documentation and/or other materials provided with the distribution.
14 *
15 *   3. Neither the name of the Intel Corporation nor the names of its
16 *      contributors may be used to endorse or promote products derived from
17 *      this software without specific prior written permission.
18 *
19 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 *  POSSIBILITY OF SUCH DAMAGE.
30 */
31
32/**
33 * @file ice_rdma_internal.h
34 * @brief internal header for the RMDA driver interface setup
35 *
36 * Contains the definitions and functions used by the ice driver to setup the
37 * RDMA driver interface. Functions and definitions in this file are not
38 * shared with the RDMA client driver.
39 */
40#ifndef _ICE_RDMA_INTERNAL_H_
41#define _ICE_RDMA_INTERNAL_H_
42
43#include "ice_rdma.h"
44
45/* Forward declare the softc structure */
46struct ice_softc;
47
48/* Global sysctl variable indicating if the RDMA client interface is enabled */
49extern bool ice_enable_irdma;
50
51/**
52 * @struct ice_rdma_entry
53 * @brief RDMA peer list node
54 *
55 * Structure used to store peer entries for each PF in a linked list.
56 * @var ice_rdma_entry::attached
57 * 	check for irdma driver attached
58 * @var ice_rdma_entry::initiated
59 * 	check for irdma driver ready to use
60 * @var ice_rdma_entry::node
61 * 	list node of the RDMA entry
62 * @var ice_rdma_entry::peer
63 * 	pointer to peer
64 */
65struct ice_rdma_entry {
66	LIST_ENTRY(ice_rdma_entry) node;
67	struct ice_rdma_peer peer;
68	bool attached;
69	bool initiated;
70};
71
72#define ice_rdma_peer_to_entry(p) __containerof(p, struct ice_rdma_entry, peer)
73#define ice_rdma_entry_to_sc(e) __containerof(e, struct ice_softc, rdma_entry)
74#define ice_rdma_peer_to_sc(p) ice_rdma_entry_to_sc(ice_rdma_peer_to_entry(p))
75
76/**
77 * @struct ice_rdma_peers
78 * @brief Head list structure for the RDMA entry list
79 *
80 * Type defining the head of the linked list of RDMA entries.
81 */
82LIST_HEAD(ice_rdma_peers, ice_rdma_entry);
83
84/**
85 * @struct ice_rdma_state
86 * @brief global driver state for RDMA
87 *
88 * Contains global state shared across all PFs by the device driver, such as
89 * the kobject class of the currently connected peer driver, and the linked
90 * list of peer entries for each PF.
91 *
92 * @var ice_rdma_state::registered
93 * 	check forr irdma driver registered
94 * @var ice_rdma_state::peer_class
95 * 	kobject class for irdma driver
96 * @var ice_rdma_state::mtx
97 * 	mutex for protecting irdma operations
98 * @var ice_rdma_state::peers
99 * 	list of RDMA entries
100 */
101struct ice_rdma_state {
102	bool registered;
103	kobj_class_t peer_class;
104	struct sx mtx;
105	struct ice_rdma_peers peers;
106};
107
108void ice_rdma_init(void);
109void ice_rdma_exit(void);
110
111int  ice_rdma_pf_attach(struct ice_softc *sc);
112void ice_rdma_pf_detach(struct ice_softc *sc);
113int  ice_rdma_pf_init(struct ice_softc *sc);
114int  ice_rdma_pf_stop(struct ice_softc *sc);
115void ice_rdma_link_change(struct ice_softc *sc, int linkstate, uint64_t baudrate);
116void ice_rdma_notify_dcb_qos_change(struct ice_softc *sc);
117void ice_rdma_dcb_qos_update(struct ice_softc *sc, struct ice_port_info *pi);
118void ice_rdma_notify_pe_intr(struct ice_softc *sc, uint32_t oicr);
119void ice_rdma_notify_reset(struct ice_softc *sc);
120#endif
121