Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / net / ethernet / sfc / siena / efx.h
blob27d1d3f19cae9a4457d4f504e553a15d6a1bff6a
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 */
8 #ifndef EFX_EFX_H
9 #define EFX_EFX_H
11 #include <linux/indirect_call_wrapper.h>
12 #include "net_driver.h"
13 #include "filter.h"
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)
23 return INDIRECT_CALL_1(tx_queue->efx->type->tx_enqueue,
24 __efx_siena_enqueue_skb, tx_queue, skb);
26 int efx_siena_setup_tc(struct net_device *net_dev, enum tc_setup_type type,
27 void *type_data);
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)
35 if (channel->rx_pkt_n_frags)
36 __efx_siena_rx_packet(channel);
39 /* Maximum number of TCP segments we support for soft-TSO */
40 #define EFX_TSO_MAX_SEGS 100
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.
46 #define EFX_RXQ_MIN_ENT 128U
47 #define EFX_TXQ_MIN_ENT(efx) (2 * efx_siena_tx_max_skb_descs(efx))
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.
52 #define EFX_TXQ_MAX_ENT(efx) (EFX_WORKAROUND_EF10(efx) ? \
53 EFX_MAX_DMAQ_SIZE / 2 : EFX_MAX_DMAQ_SIZE)
55 static inline bool efx_rss_enabled(struct efx_nic *efx)
57 return efx->rss_spread > 1;
60 /* Filters */
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
69 * On success, return the filter ID.
70 * On failure, return a negative error code.
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.
76 * 1. If the existing filters have lower priority, or @replace_equal
77 * is set and they have equal priority, replace them.
79 * 2. If the existing filters have higher priority, return -%EPERM.
81 * 3. If !efx_siena_filter_is_mc_recipient(@spec), or the NIC does not
82 * support delivery to multiple recipients, return -%EEXIST.
84 * This implies that filters for multiple multicast recipients must
85 * all be inserted with the same priority and @replace_equal = %false.
87 static inline s32 efx_filter_insert_filter(struct efx_nic *efx,
88 struct efx_filter_spec *spec,
89 bool replace_equal)
91 return efx->type->filter_insert(efx, spec, replace_equal);
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
100 * This function will range-check @filter_id, so it is safe to call
101 * with a value passed from userland.
103 static inline int efx_filter_remove_id_safe(struct efx_nic *efx,
104 enum efx_filter_priority priority,
105 u32 filter_id)
107 return efx->type->filter_remove_safe(efx, priority, filter_id);
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
117 * This function will range-check @filter_id, so it is safe to call
118 * with a value passed from userland.
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)
125 return efx->type->filter_get_safe(efx, priority, filter_id, spec);
128 static inline u32 efx_filter_count_rx_used(struct efx_nic *efx,
129 enum efx_filter_priority priority)
131 return efx->type->filter_count_rx_used(efx, priority);
133 static inline u32 efx_filter_get_rx_id_limit(struct efx_nic *efx)
135 return efx->type->filter_get_rx_id_limit(efx);
137 static inline s32 efx_filter_get_rx_ids(struct efx_nic *efx,
138 enum efx_filter_priority priority,
139 u32 *buf, u32 size)
141 return efx->type->filter_get_rx_ids(efx, priority, buf, size);
144 /* RSS contexts */
145 static inline bool efx_rss_active(struct efx_rss_context *ctx)
147 return ctx->context_id != EFX_MCDI_RSS_CONTEXT_INVALID;
150 /* Ethtool support */
151 extern const struct ethtool_ops efx_siena_ethtool_ops;
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);
161 /* Update the generic software stats in the passed stats array */
162 void efx_siena_update_sw_stats(struct efx_nic *efx, u64 *stats);
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)
170 return efx->type->mtd_probe(efx);
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
180 #ifdef CONFIG_SFC_SIENA_SRIOV
181 static inline unsigned int efx_vf_size(struct efx_nic *efx)
183 return 1 << efx->vi_scale;
185 #endif
187 static inline void efx_device_detach_sync(struct efx_nic *efx)
189 struct net_device *dev = efx->net_dev;
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.
195 netif_tx_lock_bh(dev);
196 netif_device_detach(dev);
197 netif_tx_unlock_bh(dev);
200 static inline void efx_device_attach_if_not_resetting(struct efx_nic *efx)
202 if ((efx->state != STATE_DISABLED) && !efx->reset_pending)
203 netif_device_attach(efx->net_dev);
206 static inline bool efx_rwsem_assert_write_locked(struct rw_semaphore *sem)
208 if (WARN_ON(down_read_trylock(sem))) {
209 up_read(sem);
210 return false;
212 return true;
215 int efx_siena_xdp_tx_buffers(struct efx_nic *efx, int n,
216 struct xdp_frame **xdpfs, bool flush);
218 #endif /* EFX_EFX_H */