162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/****************************************************************************
362306a36Sopenharmony_ci * Driver for Solarflare network controllers and boards
462306a36Sopenharmony_ci * Copyright 2005-2006 Fen Systems Ltd.
562306a36Sopenharmony_ci * Copyright 2006-2013 Solarflare Communications Inc.
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#ifndef EFX_EFX_H
962306a36Sopenharmony_ci#define EFX_EFX_H
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include <linux/indirect_call_wrapper.h>
1262306a36Sopenharmony_ci#include "net_driver.h"
1362306a36Sopenharmony_ci#include "filter.h"
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci/* TX */
1662306a36Sopenharmony_civoid efx_siena_init_tx_queue_core_txq(struct efx_tx_queue *tx_queue);
1762306a36Sopenharmony_cinetdev_tx_t efx_siena_hard_start_xmit(struct sk_buff *skb,
1862306a36Sopenharmony_ci				      struct net_device *net_dev);
1962306a36Sopenharmony_cinetdev_tx_t __efx_siena_enqueue_skb(struct efx_tx_queue *tx_queue,
2062306a36Sopenharmony_ci				    struct sk_buff *skb);
2162306a36Sopenharmony_cistatic inline netdev_tx_t efx_enqueue_skb(struct efx_tx_queue *tx_queue, struct sk_buff *skb)
2262306a36Sopenharmony_ci{
2362306a36Sopenharmony_ci	return INDIRECT_CALL_1(tx_queue->efx->type->tx_enqueue,
2462306a36Sopenharmony_ci			       __efx_siena_enqueue_skb, tx_queue, skb);
2562306a36Sopenharmony_ci}
2662306a36Sopenharmony_ciint efx_siena_setup_tc(struct net_device *net_dev, enum tc_setup_type type,
2762306a36Sopenharmony_ci		       void *type_data);
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci/* RX */
3062306a36Sopenharmony_civoid __efx_siena_rx_packet(struct efx_channel *channel);
3162306a36Sopenharmony_civoid efx_siena_rx_packet(struct efx_rx_queue *rx_queue, unsigned int index,
3262306a36Sopenharmony_ci			 unsigned int n_frags, unsigned int len, u16 flags);
3362306a36Sopenharmony_cistatic inline void efx_rx_flush_packet(struct efx_channel *channel)
3462306a36Sopenharmony_ci{
3562306a36Sopenharmony_ci	if (channel->rx_pkt_n_frags)
3662306a36Sopenharmony_ci		__efx_siena_rx_packet(channel);
3762306a36Sopenharmony_ci}
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci/* Maximum number of TCP segments we support for soft-TSO */
4062306a36Sopenharmony_ci#define EFX_TSO_MAX_SEGS	100
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci/* The smallest [rt]xq_entries that the driver supports.  RX minimum
4362306a36Sopenharmony_ci * is a bit arbitrary.  For TX, we must have space for at least 2
4462306a36Sopenharmony_ci * TSO skbs.
4562306a36Sopenharmony_ci */
4662306a36Sopenharmony_ci#define EFX_RXQ_MIN_ENT		128U
4762306a36Sopenharmony_ci#define EFX_TXQ_MIN_ENT(efx)	(2 * efx_siena_tx_max_skb_descs(efx))
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci/* All EF10 architecture NICs steal one bit of the DMAQ size for various
5062306a36Sopenharmony_ci * other purposes when counting TxQ entries, so we halve the queue size.
5162306a36Sopenharmony_ci */
5262306a36Sopenharmony_ci#define EFX_TXQ_MAX_ENT(efx)	(EFX_WORKAROUND_EF10(efx) ? \
5362306a36Sopenharmony_ci				 EFX_MAX_DMAQ_SIZE / 2 : EFX_MAX_DMAQ_SIZE)
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_cistatic inline bool efx_rss_enabled(struct efx_nic *efx)
5662306a36Sopenharmony_ci{
5762306a36Sopenharmony_ci	return efx->rss_spread > 1;
5862306a36Sopenharmony_ci}
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci/* Filters */
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci/**
6362306a36Sopenharmony_ci * efx_filter_insert_filter - add or replace a filter
6462306a36Sopenharmony_ci * @efx: NIC in which to insert the filter
6562306a36Sopenharmony_ci * @spec: Specification for the filter
6662306a36Sopenharmony_ci * @replace_equal: Flag for whether the specified filter may replace an
6762306a36Sopenharmony_ci *	existing filter with equal priority
6862306a36Sopenharmony_ci *
6962306a36Sopenharmony_ci * On success, return the filter ID.
7062306a36Sopenharmony_ci * On failure, return a negative error code.
7162306a36Sopenharmony_ci *
7262306a36Sopenharmony_ci * If existing filters have equal match values to the new filter spec,
7362306a36Sopenharmony_ci * then the new filter might replace them or the function might fail,
7462306a36Sopenharmony_ci * as follows.
7562306a36Sopenharmony_ci *
7662306a36Sopenharmony_ci * 1. If the existing filters have lower priority, or @replace_equal
7762306a36Sopenharmony_ci *    is set and they have equal priority, replace them.
7862306a36Sopenharmony_ci *
7962306a36Sopenharmony_ci * 2. If the existing filters have higher priority, return -%EPERM.
8062306a36Sopenharmony_ci *
8162306a36Sopenharmony_ci * 3. If !efx_siena_filter_is_mc_recipient(@spec), or the NIC does not
8262306a36Sopenharmony_ci *    support delivery to multiple recipients, return -%EEXIST.
8362306a36Sopenharmony_ci *
8462306a36Sopenharmony_ci * This implies that filters for multiple multicast recipients must
8562306a36Sopenharmony_ci * all be inserted with the same priority and @replace_equal = %false.
8662306a36Sopenharmony_ci */
8762306a36Sopenharmony_cistatic inline s32 efx_filter_insert_filter(struct efx_nic *efx,
8862306a36Sopenharmony_ci					   struct efx_filter_spec *spec,
8962306a36Sopenharmony_ci					   bool replace_equal)
9062306a36Sopenharmony_ci{
9162306a36Sopenharmony_ci	return efx->type->filter_insert(efx, spec, replace_equal);
9262306a36Sopenharmony_ci}
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci/**
9562306a36Sopenharmony_ci * efx_filter_remove_id_safe - remove a filter by ID, carefully
9662306a36Sopenharmony_ci * @efx: NIC from which to remove the filter
9762306a36Sopenharmony_ci * @priority: Priority of filter, as passed to @efx_filter_insert_filter
9862306a36Sopenharmony_ci * @filter_id: ID of filter, as returned by @efx_filter_insert_filter
9962306a36Sopenharmony_ci *
10062306a36Sopenharmony_ci * This function will range-check @filter_id, so it is safe to call
10162306a36Sopenharmony_ci * with a value passed from userland.
10262306a36Sopenharmony_ci */
10362306a36Sopenharmony_cistatic inline int efx_filter_remove_id_safe(struct efx_nic *efx,
10462306a36Sopenharmony_ci					    enum efx_filter_priority priority,
10562306a36Sopenharmony_ci					    u32 filter_id)
10662306a36Sopenharmony_ci{
10762306a36Sopenharmony_ci	return efx->type->filter_remove_safe(efx, priority, filter_id);
10862306a36Sopenharmony_ci}
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci/**
11162306a36Sopenharmony_ci * efx_filter_get_filter_safe - retrieve a filter by ID, carefully
11262306a36Sopenharmony_ci * @efx: NIC from which to remove the filter
11362306a36Sopenharmony_ci * @priority: Priority of filter, as passed to @efx_filter_insert_filter
11462306a36Sopenharmony_ci * @filter_id: ID of filter, as returned by @efx_filter_insert_filter
11562306a36Sopenharmony_ci * @spec: Buffer in which to store filter specification
11662306a36Sopenharmony_ci *
11762306a36Sopenharmony_ci * This function will range-check @filter_id, so it is safe to call
11862306a36Sopenharmony_ci * with a value passed from userland.
11962306a36Sopenharmony_ci */
12062306a36Sopenharmony_cistatic inline int
12162306a36Sopenharmony_ciefx_filter_get_filter_safe(struct efx_nic *efx,
12262306a36Sopenharmony_ci			   enum efx_filter_priority priority,
12362306a36Sopenharmony_ci			   u32 filter_id, struct efx_filter_spec *spec)
12462306a36Sopenharmony_ci{
12562306a36Sopenharmony_ci	return efx->type->filter_get_safe(efx, priority, filter_id, spec);
12662306a36Sopenharmony_ci}
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_cistatic inline u32 efx_filter_count_rx_used(struct efx_nic *efx,
12962306a36Sopenharmony_ci					   enum efx_filter_priority priority)
13062306a36Sopenharmony_ci{
13162306a36Sopenharmony_ci	return efx->type->filter_count_rx_used(efx, priority);
13262306a36Sopenharmony_ci}
13362306a36Sopenharmony_cistatic inline u32 efx_filter_get_rx_id_limit(struct efx_nic *efx)
13462306a36Sopenharmony_ci{
13562306a36Sopenharmony_ci	return efx->type->filter_get_rx_id_limit(efx);
13662306a36Sopenharmony_ci}
13762306a36Sopenharmony_cistatic inline s32 efx_filter_get_rx_ids(struct efx_nic *efx,
13862306a36Sopenharmony_ci					enum efx_filter_priority priority,
13962306a36Sopenharmony_ci					u32 *buf, u32 size)
14062306a36Sopenharmony_ci{
14162306a36Sopenharmony_ci	return efx->type->filter_get_rx_ids(efx, priority, buf, size);
14262306a36Sopenharmony_ci}
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ci/* RSS contexts */
14562306a36Sopenharmony_cistatic inline bool efx_rss_active(struct efx_rss_context *ctx)
14662306a36Sopenharmony_ci{
14762306a36Sopenharmony_ci	return ctx->context_id != EFX_MCDI_RSS_CONTEXT_INVALID;
14862306a36Sopenharmony_ci}
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_ci/* Ethtool support */
15162306a36Sopenharmony_ciextern const struct ethtool_ops efx_siena_ethtool_ops;
15262306a36Sopenharmony_ci
15362306a36Sopenharmony_ci/* Global */
15462306a36Sopenharmony_ciunsigned int efx_siena_usecs_to_ticks(struct efx_nic *efx, unsigned int usecs);
15562306a36Sopenharmony_ciint efx_siena_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs,
15662306a36Sopenharmony_ci				  unsigned int rx_usecs, bool rx_adaptive,
15762306a36Sopenharmony_ci				  bool rx_may_override_tx);
15862306a36Sopenharmony_civoid efx_siena_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs,
15962306a36Sopenharmony_ci				  unsigned int *rx_usecs, bool *rx_adaptive);
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_ci/* Update the generic software stats in the passed stats array */
16262306a36Sopenharmony_civoid efx_siena_update_sw_stats(struct efx_nic *efx, u64 *stats);
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ci/* MTD */
16562306a36Sopenharmony_ci#ifdef CONFIG_SFC_SIENA_MTD
16662306a36Sopenharmony_ciint efx_siena_mtd_add(struct efx_nic *efx, struct efx_mtd_partition *parts,
16762306a36Sopenharmony_ci		      size_t n_parts, size_t sizeof_part);
16862306a36Sopenharmony_cistatic inline int efx_mtd_probe(struct efx_nic *efx)
16962306a36Sopenharmony_ci{
17062306a36Sopenharmony_ci	return efx->type->mtd_probe(efx);
17162306a36Sopenharmony_ci}
17262306a36Sopenharmony_civoid efx_siena_mtd_rename(struct efx_nic *efx);
17362306a36Sopenharmony_civoid efx_siena_mtd_remove(struct efx_nic *efx);
17462306a36Sopenharmony_ci#else
17562306a36Sopenharmony_cistatic inline int efx_mtd_probe(struct efx_nic *efx) { return 0; }
17662306a36Sopenharmony_cistatic inline void efx_siena_mtd_rename(struct efx_nic *efx) {}
17762306a36Sopenharmony_cistatic inline void efx_siena_mtd_remove(struct efx_nic *efx) {}
17862306a36Sopenharmony_ci#endif
17962306a36Sopenharmony_ci
18062306a36Sopenharmony_ci#ifdef CONFIG_SFC_SIENA_SRIOV
18162306a36Sopenharmony_cistatic inline unsigned int efx_vf_size(struct efx_nic *efx)
18262306a36Sopenharmony_ci{
18362306a36Sopenharmony_ci	return 1 << efx->vi_scale;
18462306a36Sopenharmony_ci}
18562306a36Sopenharmony_ci#endif
18662306a36Sopenharmony_ci
18762306a36Sopenharmony_cistatic inline void efx_device_detach_sync(struct efx_nic *efx)
18862306a36Sopenharmony_ci{
18962306a36Sopenharmony_ci	struct net_device *dev = efx->net_dev;
19062306a36Sopenharmony_ci
19162306a36Sopenharmony_ci	/* Lock/freeze all TX queues so that we can be sure the
19262306a36Sopenharmony_ci	 * TX scheduler is stopped when we're done and before
19362306a36Sopenharmony_ci	 * netif_device_present() becomes false.
19462306a36Sopenharmony_ci	 */
19562306a36Sopenharmony_ci	netif_tx_lock_bh(dev);
19662306a36Sopenharmony_ci	netif_device_detach(dev);
19762306a36Sopenharmony_ci	netif_tx_unlock_bh(dev);
19862306a36Sopenharmony_ci}
19962306a36Sopenharmony_ci
20062306a36Sopenharmony_cistatic inline void efx_device_attach_if_not_resetting(struct efx_nic *efx)
20162306a36Sopenharmony_ci{
20262306a36Sopenharmony_ci	if ((efx->state != STATE_DISABLED) && !efx->reset_pending)
20362306a36Sopenharmony_ci		netif_device_attach(efx->net_dev);
20462306a36Sopenharmony_ci}
20562306a36Sopenharmony_ci
20662306a36Sopenharmony_cistatic inline bool efx_rwsem_assert_write_locked(struct rw_semaphore *sem)
20762306a36Sopenharmony_ci{
20862306a36Sopenharmony_ci	if (WARN_ON(down_read_trylock(sem))) {
20962306a36Sopenharmony_ci		up_read(sem);
21062306a36Sopenharmony_ci		return false;
21162306a36Sopenharmony_ci	}
21262306a36Sopenharmony_ci	return true;
21362306a36Sopenharmony_ci}
21462306a36Sopenharmony_ci
21562306a36Sopenharmony_ciint efx_siena_xdp_tx_buffers(struct efx_nic *efx, int n,
21662306a36Sopenharmony_ci			     struct xdp_frame **xdpfs, bool flush);
21762306a36Sopenharmony_ci
21862306a36Sopenharmony_ci#endif /* EFX_EFX_H */
219