xref: /linux/drivers/net/ethernet/sfc/siena/efx.h (revision 0526b56cbc3c489642bd6a5fe4b718dea7ef0ee8)
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 <linux/indirect_call_wrapper.h>
12 #include "net_driver.h"
13 #include "filter.h"
14 
15 /* TX */
16 void efx_siena_init_tx_queue_core_txq(struct efx_tx_queue *tx_queue);
17 netdev_tx_t efx_siena_hard_start_xmit(struct sk_buff *skb,
18 				      struct net_device *net_dev);
19 netdev_tx_t __efx_siena_enqueue_skb(struct efx_tx_queue *tx_queue,
20 				    struct sk_buff *skb);
21 static inline netdev_tx_t efx_enqueue_skb(struct efx_tx_queue *tx_queue, struct sk_buff *skb)
22 {
23 	return INDIRECT_CALL_1(tx_queue->efx->type->tx_enqueue,
24 			       __efx_siena_enqueue_skb, tx_queue, skb);
25 }
26 int efx_siena_setup_tc(struct net_device *net_dev, enum tc_setup_type type,
27 		       void *type_data);
28 
29 /* RX */
30 void __efx_siena_rx_packet(struct efx_channel *channel);
31 void efx_siena_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_siena_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_siena_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_siena_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_siena_ethtool_ops;
152 
153 /* Global */
154 unsigned int efx_siena_usecs_to_ticks(struct efx_nic *efx, unsigned int usecs);
155 int efx_siena_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs,
156 				  unsigned int rx_usecs, bool rx_adaptive,
157 				  bool rx_may_override_tx);
158 void efx_siena_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs,
159 				  unsigned int *rx_usecs, bool *rx_adaptive);
160 
161 /* Update the generic software stats in the passed stats array */
162 void efx_siena_update_sw_stats(struct efx_nic *efx, u64 *stats);
163 
164 /* MTD */
165 #ifdef CONFIG_SFC_SIENA_MTD
166 int efx_siena_mtd_add(struct efx_nic *efx, struct efx_mtd_partition *parts,
167 		      size_t n_parts, size_t sizeof_part);
168 static inline int efx_mtd_probe(struct efx_nic *efx)
169 {
170 	return efx->type->mtd_probe(efx);
171 }
172 void efx_siena_mtd_rename(struct efx_nic *efx);
173 void efx_siena_mtd_remove(struct efx_nic *efx);
174 #else
175 static inline int efx_mtd_probe(struct efx_nic *efx) { return 0; }
176 static inline void efx_siena_mtd_rename(struct efx_nic *efx) {}
177 static inline void efx_siena_mtd_remove(struct efx_nic *efx) {}
178 #endif
179 
180 #ifdef CONFIG_SFC_SIENA_SRIOV
181 static inline unsigned int efx_vf_size(struct efx_nic *efx)
182 {
183 	return 1 << efx->vi_scale;
184 }
185 #endif
186 
187 static inline void efx_device_detach_sync(struct efx_nic *efx)
188 {
189 	struct net_device *dev = efx->net_dev;
190 
191 	/* Lock/freeze all TX queues so that we can be sure the
192 	 * TX scheduler is stopped when we're done and before
193 	 * netif_device_present() becomes false.
194 	 */
195 	netif_tx_lock_bh(dev);
196 	netif_device_detach(dev);
197 	netif_tx_unlock_bh(dev);
198 }
199 
200 static inline void efx_device_attach_if_not_resetting(struct efx_nic *efx)
201 {
202 	if ((efx->state != STATE_DISABLED) && !efx->reset_pending)
203 		netif_device_attach(efx->net_dev);
204 }
205 
206 static inline bool efx_rwsem_assert_write_locked(struct rw_semaphore *sem)
207 {
208 	if (WARN_ON(down_read_trylock(sem))) {
209 		up_read(sem);
210 		return false;
211 	}
212 	return true;
213 }
214 
215 int efx_siena_xdp_tx_buffers(struct efx_nic *efx, int n,
216 			     struct xdp_frame **xdpfs, bool flush);
217 
218 #endif /* EFX_EFX_H */
219