xref: /openbmc/linux/drivers/net/ethernet/sfc/efx.h (revision b03afaa8)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /****************************************************************************
3  * Driver for Solarflare network controllers and boards
4  * Copyright 2005-2006 Fen Systems Ltd.
5  * Copyright 2006-2013 Solarflare Communications Inc.
6  */
7 
8 #ifndef EFX_EFX_H
9 #define EFX_EFX_H
10 
11 #include "net_driver.h"
12 #include "filter.h"
13 
14 int efx_net_open(struct net_device *net_dev);
15 int efx_net_stop(struct net_device *net_dev);
16 
17 /* TX */
18 void efx_init_tx_queue_core_txq(struct efx_tx_queue *tx_queue);
19 netdev_tx_t efx_hard_start_xmit(struct sk_buff *skb,
20 				struct net_device *net_dev);
21 netdev_tx_t efx_enqueue_skb(struct efx_tx_queue *tx_queue, struct sk_buff *skb);
22 void efx_xmit_done(struct efx_tx_queue *tx_queue, unsigned int index);
23 void efx_xmit_done_single(struct efx_tx_queue *tx_queue);
24 int efx_setup_tc(struct net_device *net_dev, enum tc_setup_type type,
25 		 void *type_data);
26 extern unsigned int efx_piobuf_size;
27 extern bool efx_separate_tx_channels;
28 
29 /* RX */
30 void __efx_rx_packet(struct efx_channel *channel);
31 void efx_rx_packet(struct efx_rx_queue *rx_queue, unsigned int index,
32 		   unsigned int n_frags, unsigned int len, u16 flags);
33 static inline void efx_rx_flush_packet(struct efx_channel *channel)
34 {
35 	if (channel->rx_pkt_n_frags)
36 		__efx_rx_packet(channel);
37 }
38 
39 /* Maximum number of TCP segments we support for soft-TSO */
40 #define EFX_TSO_MAX_SEGS	100
41 
42 /* The smallest [rt]xq_entries that the driver supports.  RX minimum
43  * is a bit arbitrary.  For TX, we must have space for at least 2
44  * TSO skbs.
45  */
46 #define EFX_RXQ_MIN_ENT		128U
47 #define EFX_TXQ_MIN_ENT(efx)	(2 * efx_tx_max_skb_descs(efx))
48 
49 /* All EF10 architecture NICs steal one bit of the DMAQ size for various
50  * other purposes when counting TxQ entries, so we halve the queue size.
51  */
52 #define EFX_TXQ_MAX_ENT(efx)	(EFX_WORKAROUND_EF10(efx) ? \
53 				 EFX_MAX_DMAQ_SIZE / 2 : EFX_MAX_DMAQ_SIZE)
54 
55 static inline bool efx_rss_enabled(struct efx_nic *efx)
56 {
57 	return efx->rss_spread > 1;
58 }
59 
60 /* Filters */
61 
62 /**
63  * efx_filter_insert_filter - add or replace a filter
64  * @efx: NIC in which to insert the filter
65  * @spec: Specification for the filter
66  * @replace_equal: Flag for whether the specified filter may replace an
67  *	existing filter with equal priority
68  *
69  * On success, return the filter ID.
70  * On failure, return a negative error code.
71  *
72  * If existing filters have equal match values to the new filter spec,
73  * then the new filter might replace them or the function might fail,
74  * as follows.
75  *
76  * 1. If the existing filters have lower priority, or @replace_equal
77  *    is set and they have equal priority, replace them.
78  *
79  * 2. If the existing filters have higher priority, return -%EPERM.
80  *
81  * 3. If !efx_filter_is_mc_recipient(@spec), or the NIC does not
82  *    support delivery to multiple recipients, return -%EEXIST.
83  *
84  * This implies that filters for multiple multicast recipients must
85  * all be inserted with the same priority and @replace_equal = %false.
86  */
87 static inline s32 efx_filter_insert_filter(struct efx_nic *efx,
88 					   struct efx_filter_spec *spec,
89 					   bool replace_equal)
90 {
91 	return efx->type->filter_insert(efx, spec, replace_equal);
92 }
93 
94 /**
95  * efx_filter_remove_id_safe - remove a filter by ID, carefully
96  * @efx: NIC from which to remove the filter
97  * @priority: Priority of filter, as passed to @efx_filter_insert_filter
98  * @filter_id: ID of filter, as returned by @efx_filter_insert_filter
99  *
100  * This function will range-check @filter_id, so it is safe to call
101  * with a value passed from userland.
102  */
103 static inline int efx_filter_remove_id_safe(struct efx_nic *efx,
104 					    enum efx_filter_priority priority,
105 					    u32 filter_id)
106 {
107 	return efx->type->filter_remove_safe(efx, priority, filter_id);
108 }
109 
110 /**
111  * efx_filter_get_filter_safe - retrieve a filter by ID, carefully
112  * @efx: NIC from which to remove the filter
113  * @priority: Priority of filter, as passed to @efx_filter_insert_filter
114  * @filter_id: ID of filter, as returned by @efx_filter_insert_filter
115  * @spec: Buffer in which to store filter specification
116  *
117  * This function will range-check @filter_id, so it is safe to call
118  * with a value passed from userland.
119  */
120 static inline int
121 efx_filter_get_filter_safe(struct efx_nic *efx,
122 			   enum efx_filter_priority priority,
123 			   u32 filter_id, struct efx_filter_spec *spec)
124 {
125 	return efx->type->filter_get_safe(efx, priority, filter_id, spec);
126 }
127 
128 static inline u32 efx_filter_count_rx_used(struct efx_nic *efx,
129 					   enum efx_filter_priority priority)
130 {
131 	return efx->type->filter_count_rx_used(efx, priority);
132 }
133 static inline u32 efx_filter_get_rx_id_limit(struct efx_nic *efx)
134 {
135 	return efx->type->filter_get_rx_id_limit(efx);
136 }
137 static inline s32 efx_filter_get_rx_ids(struct efx_nic *efx,
138 					enum efx_filter_priority priority,
139 					u32 *buf, u32 size)
140 {
141 	return efx->type->filter_get_rx_ids(efx, priority, buf, size);
142 }
143 
144 /* RSS contexts */
145 static inline bool efx_rss_active(struct efx_rss_context *ctx)
146 {
147 	return ctx->context_id != EFX_MCDI_RSS_CONTEXT_INVALID;
148 }
149 
150 /* Ethtool support */
151 extern const struct ethtool_ops efx_ethtool_ops;
152 
153 /* Global */
154 unsigned int efx_usecs_to_ticks(struct efx_nic *efx, unsigned int usecs);
155 unsigned int efx_ticks_to_usecs(struct efx_nic *efx, unsigned int ticks);
156 int efx_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs,
157 			    unsigned int rx_usecs, bool rx_adaptive,
158 			    bool rx_may_override_tx);
159 void efx_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs,
160 			    unsigned int *rx_usecs, bool *rx_adaptive);
161 
162 /* Update the generic software stats in the passed stats array */
163 void efx_update_sw_stats(struct efx_nic *efx, u64 *stats);
164 
165 /* MTD */
166 #ifdef CONFIG_SFC_MTD
167 int efx_mtd_add(struct efx_nic *efx, struct efx_mtd_partition *parts,
168 		size_t n_parts, size_t sizeof_part);
169 static inline int efx_mtd_probe(struct efx_nic *efx)
170 {
171 	return efx->type->mtd_probe(efx);
172 }
173 void efx_mtd_rename(struct efx_nic *efx);
174 void efx_mtd_remove(struct efx_nic *efx);
175 #else
176 static inline int efx_mtd_probe(struct efx_nic *efx) { return 0; }
177 static inline void efx_mtd_rename(struct efx_nic *efx) {}
178 static inline void efx_mtd_remove(struct efx_nic *efx) {}
179 #endif
180 
181 #ifdef CONFIG_SFC_SRIOV
182 static inline unsigned int efx_vf_size(struct efx_nic *efx)
183 {
184 	return 1 << efx->vi_scale;
185 }
186 #endif
187 
188 static inline void efx_device_detach_sync(struct efx_nic *efx)
189 {
190 	struct net_device *dev = efx->net_dev;
191 
192 	/* Lock/freeze all TX queues so that we can be sure the
193 	 * TX scheduler is stopped when we're done and before
194 	 * netif_device_present() becomes false.
195 	 */
196 	netif_tx_lock_bh(dev);
197 	netif_device_detach(dev);
198 	netif_tx_unlock_bh(dev);
199 }
200 
201 static inline void efx_device_attach_if_not_resetting(struct efx_nic *efx)
202 {
203 	if ((efx->state != STATE_DISABLED) && !efx->reset_pending)
204 		netif_device_attach(efx->net_dev);
205 }
206 
207 static inline bool efx_rwsem_assert_write_locked(struct rw_semaphore *sem)
208 {
209 	if (WARN_ON(down_read_trylock(sem))) {
210 		up_read(sem);
211 		return false;
212 	}
213 	return true;
214 }
215 
216 int efx_xdp_tx_buffers(struct efx_nic *efx, int n, struct xdp_frame **xdpfs,
217 		       bool flush);
218 
219 #endif /* EFX_EFX_H */
220