xref: /freebsd/sys/dev/bnxt/bnxt_en/bnxt_ulp.h (revision 050d28e13cdede7528944c0abf8d0455729c63fd)
1 /*-
2  * Broadcom NetXtreme-C/E network driver.
3  *
4  * Copyright (c) 2024 Broadcom, All Rights Reserved.
5  * The term Broadcom refers to Broadcom Limited and/or its subsidiaries
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS'
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26  * THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef BNXT_ULP_H
30 #define BNXT_ULP_H
31 
32 #include <linux/rcupdate.h>
33 #include "bnxt.h"
34 
35 #define BNXT_ROCE_ULP	0
36 #define BNXT_OTHER_ULP	1
37 #define BNXT_MAX_ULP	2
38 
39 #define BNXT_MIN_ROCE_CP_RINGS	2
40 #define BNXT_MIN_ROCE_STAT_CTXS	1
41 
42 struct hwrm_async_event_cmpl;
43 struct bnxt_softc;
44 struct bnxt_bar_info;
45 
46 struct bnxt_msix_entry {
47 	uint32_t	vector;
48 	uint32_t	ring_idx;
49 	uint32_t	db_offset;
50 };
51 
52 struct bnxt_ulp_ops {
53 	void (*ulp_async_notifier)(void *, struct hwrm_async_event_cmpl *);
54 	void (*ulp_stop)(void *);
55 	void (*ulp_start)(void *);
56 	void (*ulp_sriov_config)(void *, int);
57 	void (*ulp_shutdown)(void *);
58 	void (*ulp_irq_stop)(void *);
59 	void (*ulp_irq_restart)(void *, struct bnxt_msix_entry *);
60 };
61 
62 struct bnxt_fw_msg {
63 	void	*msg;
64 	int	msg_len;
65 	void	*resp;
66 	int	resp_max_len;
67 	int	timeout;
68 };
69 
70 struct bnxt_ulp {
71 	void		*handle;
72 	struct bnxt_ulp_ops __rcu *ulp_ops;
73 	unsigned long	*async_events_bmap;
74 	u16		max_async_event_id;
75 	u16		msix_requested;
76 	u16		msix_base;
77 	atomic_t	ref_count;
78 };
79 
80 struct bnxt_en_dev {
81 	struct ifnet *net;
82 	struct pci_dev *pdev;
83 	struct bnxt_softc *softc;
84 	u32 flags;
85 	#define BNXT_EN_FLAG_ROCEV1_CAP		0x1
86 	#define BNXT_EN_FLAG_ROCEV2_CAP		0x2
87 	#define BNXT_EN_FLAG_ROCE_CAP		(BNXT_EN_FLAG_ROCEV1_CAP | \
88 						 BNXT_EN_FLAG_ROCEV2_CAP)
89 	#define BNXT_EN_FLAG_MSIX_REQUESTED	0x4
90 	#define BNXT_EN_FLAG_ULP_STOPPED	0x8
91 	#define BNXT_EN_FLAG_ASYM_Q		0x10
92 	#define BNXT_EN_FLAG_MULTI_HOST		0x20
93 #define BNXT_EN_ASYM_Q(edev)		((edev)->flags & BNXT_EN_FLAG_ASYM_Q)
94 #define BNXT_EN_MH(edev)		((edev)->flags & BNXT_EN_FLAG_MULTI_HOST)
95 	const struct bnxt_en_ops	*en_ops;
96 	struct bnxt_ulp			ulp_tbl[BNXT_MAX_ULP];
97 	int				l2_db_size;	/* Doorbell BAR size in
98 							 * bytes mapped by L2
99 							 * driver.
100 							 */
101 	int				l2_db_size_nc;	/* Doorbell BAR size in
102 							 * bytes mapped as non-
103 							 * cacheable.
104 							 */
105 	u32				ulp_version;	/* bnxt_re checks the
106 							 * ulp_version is correct
107 							 * to ensure compatibility
108 							 * with bnxt_en.
109 							 */
110 	#define BNXT_ULP_VERSION	0x695a0008	/* Change this when any interface
111 							 * structure or API changes
112 							 * between bnxt_en and bnxt_re.
113 							 */
114 	unsigned long			en_state;
115 	void __iomem			*bar0;
116 	u16				hw_ring_stats_size;
117 	u16				pf_port_id;
118 	u8				port_partition_type;
119 #define BNXT_EN_NPAR(edev)		((edev)->port_partition_type)
120 	u8				port_count;
121 	struct bnxt_dbr			*en_dbr;
122 	struct bnxt_bar_info		hwrm_bar;
123 	u32				espeed;
124 };
125 
126 struct bnxt_en_ops {
127 	int (*bnxt_register_device)(struct bnxt_en_dev *, int,
128 				    struct bnxt_ulp_ops *, void *);
129 	int (*bnxt_unregister_device)(struct bnxt_en_dev *, int);
130 	int (*bnxt_request_msix)(struct bnxt_en_dev *, int,
131 				 struct bnxt_msix_entry *, int);
132 	int (*bnxt_free_msix)(struct bnxt_en_dev *, int);
133 	int (*bnxt_send_fw_msg)(struct bnxt_en_dev *, int,
134 				struct bnxt_fw_msg *);
135 	int (*bnxt_register_fw_async_events)(struct bnxt_en_dev *, int,
136 					     unsigned long *, u16);
137 	int (*bnxt_dbr_complete)(struct bnxt_en_dev *, int, u32);
138 };
139 
bnxt_ulp_registered(struct bnxt_en_dev * edev,int ulp_id)140 static inline bool bnxt_ulp_registered(struct bnxt_en_dev *edev, int ulp_id)
141 {
142 	if (edev && rcu_access_pointer(edev->ulp_tbl[ulp_id].ulp_ops))
143 		return true;
144 	return false;
145 }
146 
147 int bnxt_get_ulp_msix_num(struct bnxt_softc *bp);
148 int bnxt_get_ulp_msix_base(struct bnxt_softc *bp);
149 int bnxt_get_ulp_stat_ctxs(struct bnxt_softc *bp);
150 void bnxt_ulp_stop(struct bnxt_softc *bp);
151 void bnxt_ulp_start(struct bnxt_softc *bp, int err);
152 void bnxt_ulp_sriov_cfg(struct bnxt_softc *bp, int num_vfs);
153 void bnxt_ulp_shutdown(struct bnxt_softc *bp);
154 void bnxt_ulp_irq_stop(struct bnxt_softc *bp);
155 void bnxt_ulp_irq_restart(struct bnxt_softc *bp, int err);
156 void bnxt_ulp_async_events(struct bnxt_softc *bp, struct hwrm_async_event_cmpl *cmpl);
157 struct bnxt_en_dev *bnxt_ulp_probe(struct net_device *dev);
158 void bnxt_aux_dev_release(struct device *dev);
159 int bnxt_rdma_aux_device_add(struct bnxt_softc *bp);
160 int bnxt_rdma_aux_device_del(struct bnxt_softc *bp);
161 #endif
162