219 lines · c
1/* SPDX-License-Identifier: GPL-2.0-only */2/****************************************************************************3 * Driver for Solarflare network controllers and boards4 * Copyright 2005-2006 Fen Systems Ltd.5 * Copyright 2006-2013 Solarflare Communications Inc.6 */7 8#ifndef EFX_EFX_H9#define EFX_EFX_H10 11#include <linux/indirect_call_wrapper.h>12#include "net_driver.h"13#include "filter.h"14 15/* TX */16void efx_siena_init_tx_queue_core_txq(struct efx_tx_queue *tx_queue);17netdev_tx_t efx_siena_hard_start_xmit(struct sk_buff *skb,18 struct net_device *net_dev);19netdev_tx_t __efx_siena_enqueue_skb(struct efx_tx_queue *tx_queue,20 struct sk_buff *skb);21static 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}26int efx_siena_setup_tc(struct net_device *net_dev, enum tc_setup_type type,27 void *type_data);28 29/* RX */30void __efx_siena_rx_packet(struct efx_channel *channel);31void efx_siena_rx_packet(struct efx_rx_queue *rx_queue, unsigned int index,32 unsigned int n_frags, unsigned int len, u16 flags);33static 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 10041 42/* The smallest [rt]xq_entries that the driver supports. RX minimum43 * is a bit arbitrary. For TX, we must have space for at least 244 * TSO skbs.45 */46#define EFX_RXQ_MIN_ENT 128U47#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 various50 * 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 55static 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 filter64 * @efx: NIC in which to insert the filter65 * @spec: Specification for the filter66 * @replace_equal: Flag for whether the specified filter may replace an67 * existing filter with equal priority68 *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_equal77 * 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 not82 * support delivery to multiple recipients, return -%EEXIST.83 *84 * This implies that filters for multiple multicast recipients must85 * all be inserted with the same priority and @replace_equal = %false.86 */87static 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, carefully96 * @efx: NIC from which to remove the filter97 * @priority: Priority of filter, as passed to @efx_filter_insert_filter98 * @filter_id: ID of filter, as returned by @efx_filter_insert_filter99 *100 * This function will range-check @filter_id, so it is safe to call101 * with a value passed from userland.102 */103static 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, carefully112 * @efx: NIC from which to remove the filter113 * @priority: Priority of filter, as passed to @efx_filter_insert_filter114 * @filter_id: ID of filter, as returned by @efx_filter_insert_filter115 * @spec: Buffer in which to store filter specification116 *117 * This function will range-check @filter_id, so it is safe to call118 * with a value passed from userland.119 */120static inline int121efx_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 128static 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}133static inline u32 efx_filter_get_rx_id_limit(struct efx_nic *efx)134{135 return efx->type->filter_get_rx_id_limit(efx);136}137static 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 */145static 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 */151extern const struct ethtool_ops efx_siena_ethtool_ops;152 153/* Global */154unsigned int efx_siena_usecs_to_ticks(struct efx_nic *efx, unsigned int usecs);155int 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);158void 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 */162void efx_siena_update_sw_stats(struct efx_nic *efx, u64 *stats);163 164/* MTD */165#ifdef CONFIG_SFC_SIENA_MTD166int efx_siena_mtd_add(struct efx_nic *efx, struct efx_mtd_partition *parts,167 size_t n_parts, size_t sizeof_part);168static inline int efx_mtd_probe(struct efx_nic *efx)169{170 return efx->type->mtd_probe(efx);171}172void efx_siena_mtd_rename(struct efx_nic *efx);173void efx_siena_mtd_remove(struct efx_nic *efx);174#else175static inline int efx_mtd_probe(struct efx_nic *efx) { return 0; }176static inline void efx_siena_mtd_rename(struct efx_nic *efx) {}177static inline void efx_siena_mtd_remove(struct efx_nic *efx) {}178#endif179 180#ifdef CONFIG_SFC_SIENA_SRIOV181static inline unsigned int efx_vf_size(struct efx_nic *efx)182{183 return 1 << efx->vi_scale;184}185#endif186 187static 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 the192 * TX scheduler is stopped when we're done and before193 * 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 200static 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 206static 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 215int 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