Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /****************************************************************************
0003  * Driver for Solarflare network controllers and boards
0004  * Copyright 2005-2006 Fen Systems Ltd.
0005  * Copyright 2006-2013 Solarflare Communications Inc.
0006  */
0007 
0008 #ifndef EFX_EFX_H
0009 #define EFX_EFX_H
0010 
0011 #include <linux/indirect_call_wrapper.h>
0012 #include "net_driver.h"
0013 #include "filter.h"
0014 
0015 /* TX */
0016 void efx_siena_init_tx_queue_core_txq(struct efx_tx_queue *tx_queue);
0017 netdev_tx_t efx_siena_hard_start_xmit(struct sk_buff *skb,
0018                       struct net_device *net_dev);
0019 netdev_tx_t __efx_siena_enqueue_skb(struct efx_tx_queue *tx_queue,
0020                     struct sk_buff *skb);
0021 static inline netdev_tx_t efx_enqueue_skb(struct efx_tx_queue *tx_queue, struct sk_buff *skb)
0022 {
0023     return INDIRECT_CALL_1(tx_queue->efx->type->tx_enqueue,
0024                    __efx_siena_enqueue_skb, tx_queue, skb);
0025 }
0026 int efx_siena_setup_tc(struct net_device *net_dev, enum tc_setup_type type,
0027                void *type_data);
0028 
0029 /* RX */
0030 void __efx_siena_rx_packet(struct efx_channel *channel);
0031 void efx_siena_rx_packet(struct efx_rx_queue *rx_queue, unsigned int index,
0032              unsigned int n_frags, unsigned int len, u16 flags);
0033 static inline void efx_rx_flush_packet(struct efx_channel *channel)
0034 {
0035     if (channel->rx_pkt_n_frags)
0036         __efx_siena_rx_packet(channel);
0037 }
0038 
0039 /* Maximum number of TCP segments we support for soft-TSO */
0040 #define EFX_TSO_MAX_SEGS    100
0041 
0042 /* The smallest [rt]xq_entries that the driver supports.  RX minimum
0043  * is a bit arbitrary.  For TX, we must have space for at least 2
0044  * TSO skbs.
0045  */
0046 #define EFX_RXQ_MIN_ENT     128U
0047 #define EFX_TXQ_MIN_ENT(efx)    (2 * efx_siena_tx_max_skb_descs(efx))
0048 
0049 /* All EF10 architecture NICs steal one bit of the DMAQ size for various
0050  * other purposes when counting TxQ entries, so we halve the queue size.
0051  */
0052 #define EFX_TXQ_MAX_ENT(efx)    (EFX_WORKAROUND_EF10(efx) ? \
0053                  EFX_MAX_DMAQ_SIZE / 2 : EFX_MAX_DMAQ_SIZE)
0054 
0055 static inline bool efx_rss_enabled(struct efx_nic *efx)
0056 {
0057     return efx->rss_spread > 1;
0058 }
0059 
0060 /* Filters */
0061 
0062 /**
0063  * efx_filter_insert_filter - add or replace a filter
0064  * @efx: NIC in which to insert the filter
0065  * @spec: Specification for the filter
0066  * @replace_equal: Flag for whether the specified filter may replace an
0067  *  existing filter with equal priority
0068  *
0069  * On success, return the filter ID.
0070  * On failure, return a negative error code.
0071  *
0072  * If existing filters have equal match values to the new filter spec,
0073  * then the new filter might replace them or the function might fail,
0074  * as follows.
0075  *
0076  * 1. If the existing filters have lower priority, or @replace_equal
0077  *    is set and they have equal priority, replace them.
0078  *
0079  * 2. If the existing filters have higher priority, return -%EPERM.
0080  *
0081  * 3. If !efx_siena_filter_is_mc_recipient(@spec), or the NIC does not
0082  *    support delivery to multiple recipients, return -%EEXIST.
0083  *
0084  * This implies that filters for multiple multicast recipients must
0085  * all be inserted with the same priority and @replace_equal = %false.
0086  */
0087 static inline s32 efx_filter_insert_filter(struct efx_nic *efx,
0088                        struct efx_filter_spec *spec,
0089                        bool replace_equal)
0090 {
0091     return efx->type->filter_insert(efx, spec, replace_equal);
0092 }
0093 
0094 /**
0095  * efx_filter_remove_id_safe - remove a filter by ID, carefully
0096  * @efx: NIC from which to remove the filter
0097  * @priority: Priority of filter, as passed to @efx_filter_insert_filter
0098  * @filter_id: ID of filter, as returned by @efx_filter_insert_filter
0099  *
0100  * This function will range-check @filter_id, so it is safe to call
0101  * with a value passed from userland.
0102  */
0103 static inline int efx_filter_remove_id_safe(struct efx_nic *efx,
0104                         enum efx_filter_priority priority,
0105                         u32 filter_id)
0106 {
0107     return efx->type->filter_remove_safe(efx, priority, filter_id);
0108 }
0109 
0110 /**
0111  * efx_filter_get_filter_safe - retrieve a filter by ID, carefully
0112  * @efx: NIC from which to remove the filter
0113  * @priority: Priority of filter, as passed to @efx_filter_insert_filter
0114  * @filter_id: ID of filter, as returned by @efx_filter_insert_filter
0115  * @spec: Buffer in which to store filter specification
0116  *
0117  * This function will range-check @filter_id, so it is safe to call
0118  * with a value passed from userland.
0119  */
0120 static inline int
0121 efx_filter_get_filter_safe(struct efx_nic *efx,
0122                enum efx_filter_priority priority,
0123                u32 filter_id, struct efx_filter_spec *spec)
0124 {
0125     return efx->type->filter_get_safe(efx, priority, filter_id, spec);
0126 }
0127 
0128 static inline u32 efx_filter_count_rx_used(struct efx_nic *efx,
0129                        enum efx_filter_priority priority)
0130 {
0131     return efx->type->filter_count_rx_used(efx, priority);
0132 }
0133 static inline u32 efx_filter_get_rx_id_limit(struct efx_nic *efx)
0134 {
0135     return efx->type->filter_get_rx_id_limit(efx);
0136 }
0137 static inline s32 efx_filter_get_rx_ids(struct efx_nic *efx,
0138                     enum efx_filter_priority priority,
0139                     u32 *buf, u32 size)
0140 {
0141     return efx->type->filter_get_rx_ids(efx, priority, buf, size);
0142 }
0143 
0144 /* RSS contexts */
0145 static inline bool efx_rss_active(struct efx_rss_context *ctx)
0146 {
0147     return ctx->context_id != EFX_MCDI_RSS_CONTEXT_INVALID;
0148 }
0149 
0150 /* Ethtool support */
0151 extern const struct ethtool_ops efx_siena_ethtool_ops;
0152 
0153 /* Global */
0154 unsigned int efx_siena_usecs_to_ticks(struct efx_nic *efx, unsigned int usecs);
0155 int efx_siena_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs,
0156                   unsigned int rx_usecs, bool rx_adaptive,
0157                   bool rx_may_override_tx);
0158 void efx_siena_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs,
0159                   unsigned int *rx_usecs, bool *rx_adaptive);
0160 
0161 /* Update the generic software stats in the passed stats array */
0162 void efx_siena_update_sw_stats(struct efx_nic *efx, u64 *stats);
0163 
0164 /* MTD */
0165 #ifdef CONFIG_SFC_SIENA_MTD
0166 int efx_siena_mtd_add(struct efx_nic *efx, struct efx_mtd_partition *parts,
0167               size_t n_parts, size_t sizeof_part);
0168 static inline int efx_mtd_probe(struct efx_nic *efx)
0169 {
0170     return efx->type->mtd_probe(efx);
0171 }
0172 void efx_siena_mtd_rename(struct efx_nic *efx);
0173 void efx_siena_mtd_remove(struct efx_nic *efx);
0174 #else
0175 static inline int efx_mtd_probe(struct efx_nic *efx) { return 0; }
0176 static inline void efx_siena_mtd_rename(struct efx_nic *efx) {}
0177 static inline void efx_siena_mtd_remove(struct efx_nic *efx) {}
0178 #endif
0179 
0180 #ifdef CONFIG_SFC_SIENA_SRIOV
0181 static inline unsigned int efx_vf_size(struct efx_nic *efx)
0182 {
0183     return 1 << efx->vi_scale;
0184 }
0185 #endif
0186 
0187 static inline void efx_device_detach_sync(struct efx_nic *efx)
0188 {
0189     struct net_device *dev = efx->net_dev;
0190 
0191     /* Lock/freeze all TX queues so that we can be sure the
0192      * TX scheduler is stopped when we're done and before
0193      * netif_device_present() becomes false.
0194      */
0195     netif_tx_lock_bh(dev);
0196     netif_device_detach(dev);
0197     netif_tx_unlock_bh(dev);
0198 }
0199 
0200 static inline void efx_device_attach_if_not_resetting(struct efx_nic *efx)
0201 {
0202     if ((efx->state != STATE_DISABLED) && !efx->reset_pending)
0203         netif_device_attach(efx->net_dev);
0204 }
0205 
0206 static inline bool efx_rwsem_assert_write_locked(struct rw_semaphore *sem)
0207 {
0208     if (WARN_ON(down_read_trylock(sem))) {
0209         up_read(sem);
0210         return false;
0211     }
0212     return true;
0213 }
0214 
0215 int efx_siena_xdp_tx_buffers(struct efx_nic *efx, int n,
0216                  struct xdp_frame **xdpfs, bool flush);
0217 
0218 #endif /* EFX_EFX_H */