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