efx.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. */
  7. #ifndef EFX_EFX_H
  8. #define EFX_EFX_H
  9. #include <linux/indirect_call_wrapper.h>
  10. #include "net_driver.h"
  11. #include "filter.h"
  12. /* TX */
  13. void efx_siena_init_tx_queue_core_txq(struct efx_tx_queue *tx_queue);
  14. netdev_tx_t efx_siena_hard_start_xmit(struct sk_buff *skb,
  15. struct net_device *net_dev);
  16. netdev_tx_t __efx_siena_enqueue_skb(struct efx_tx_queue *tx_queue,
  17. struct sk_buff *skb);
  18. static inline netdev_tx_t efx_enqueue_skb(struct efx_tx_queue *tx_queue, struct sk_buff *skb)
  19. {
  20. return INDIRECT_CALL_1(tx_queue->efx->type->tx_enqueue,
  21. __efx_siena_enqueue_skb, tx_queue, skb);
  22. }
  23. int efx_siena_setup_tc(struct net_device *net_dev, enum tc_setup_type type,
  24. void *type_data);
  25. /* RX */
  26. void __efx_siena_rx_packet(struct efx_channel *channel);
  27. void efx_siena_rx_packet(struct efx_rx_queue *rx_queue, unsigned int index,
  28. unsigned int n_frags, unsigned int len, u16 flags);
  29. static inline void efx_rx_flush_packet(struct efx_channel *channel)
  30. {
  31. if (channel->rx_pkt_n_frags)
  32. __efx_siena_rx_packet(channel);
  33. }
  34. /* Maximum number of TCP segments we support for soft-TSO */
  35. #define EFX_TSO_MAX_SEGS 100
  36. /* The smallest [rt]xq_entries that the driver supports. RX minimum
  37. * is a bit arbitrary. For TX, we must have space for at least 2
  38. * TSO skbs.
  39. */
  40. #define EFX_RXQ_MIN_ENT 128U
  41. #define EFX_TXQ_MIN_ENT(efx) (2 * efx_siena_tx_max_skb_descs(efx))
  42. /* All EF10 architecture NICs steal one bit of the DMAQ size for various
  43. * other purposes when counting TxQ entries, so we halve the queue size.
  44. */
  45. #define EFX_TXQ_MAX_ENT(efx) (EFX_WORKAROUND_EF10(efx) ? \
  46. EFX_MAX_DMAQ_SIZE / 2 : EFX_MAX_DMAQ_SIZE)
  47. static inline bool efx_rss_enabled(struct efx_nic *efx)
  48. {
  49. return efx->rss_spread > 1;
  50. }
  51. /* Filters */
  52. /**
  53. * efx_filter_insert_filter - add or replace a filter
  54. * @efx: NIC in which to insert the filter
  55. * @spec: Specification for the filter
  56. * @replace_equal: Flag for whether the specified filter may replace an
  57. * existing filter with equal priority
  58. *
  59. * On success, return the filter ID.
  60. * On failure, return a negative error code.
  61. *
  62. * If existing filters have equal match values to the new filter spec,
  63. * then the new filter might replace them or the function might fail,
  64. * as follows.
  65. *
  66. * 1. If the existing filters have lower priority, or @replace_equal
  67. * is set and they have equal priority, replace them.
  68. *
  69. * 2. If the existing filters have higher priority, return -%EPERM.
  70. *
  71. * 3. If !efx_siena_filter_is_mc_recipient(@spec), or the NIC does not
  72. * support delivery to multiple recipients, return -%EEXIST.
  73. *
  74. * This implies that filters for multiple multicast recipients must
  75. * all be inserted with the same priority and @replace_equal = %false.
  76. */
  77. static inline s32 efx_filter_insert_filter(struct efx_nic *efx,
  78. struct efx_filter_spec *spec,
  79. bool replace_equal)
  80. {
  81. return efx->type->filter_insert(efx, spec, replace_equal);
  82. }
  83. /**
  84. * efx_filter_remove_id_safe - remove a filter by ID, carefully
  85. * @efx: NIC from which to remove the filter
  86. * @priority: Priority of filter, as passed to @efx_filter_insert_filter
  87. * @filter_id: ID of filter, as returned by @efx_filter_insert_filter
  88. *
  89. * This function will range-check @filter_id, so it is safe to call
  90. * with a value passed from userland.
  91. */
  92. static inline int efx_filter_remove_id_safe(struct efx_nic *efx,
  93. enum efx_filter_priority priority,
  94. u32 filter_id)
  95. {
  96. return efx->type->filter_remove_safe(efx, priority, filter_id);
  97. }
  98. /**
  99. * efx_filter_get_filter_safe - retrieve a filter by ID, carefully
  100. * @efx: NIC from which to remove the filter
  101. * @priority: Priority of filter, as passed to @efx_filter_insert_filter
  102. * @filter_id: ID of filter, as returned by @efx_filter_insert_filter
  103. * @spec: Buffer in which to store filter specification
  104. *
  105. * This function will range-check @filter_id, so it is safe to call
  106. * with a value passed from userland.
  107. */
  108. static inline int
  109. efx_filter_get_filter_safe(struct efx_nic *efx,
  110. enum efx_filter_priority priority,
  111. u32 filter_id, struct efx_filter_spec *spec)
  112. {
  113. return efx->type->filter_get_safe(efx, priority, filter_id, spec);
  114. }
  115. static inline u32 efx_filter_count_rx_used(struct efx_nic *efx,
  116. enum efx_filter_priority priority)
  117. {
  118. return efx->type->filter_count_rx_used(efx, priority);
  119. }
  120. static inline u32 efx_filter_get_rx_id_limit(struct efx_nic *efx)
  121. {
  122. return efx->type->filter_get_rx_id_limit(efx);
  123. }
  124. static inline s32 efx_filter_get_rx_ids(struct efx_nic *efx,
  125. enum efx_filter_priority priority,
  126. u32 *buf, u32 size)
  127. {
  128. return efx->type->filter_get_rx_ids(efx, priority, buf, size);
  129. }
  130. /* RSS contexts */
  131. static inline bool efx_rss_active(struct efx_rss_context *ctx)
  132. {
  133. return ctx->context_id != EFX_MCDI_RSS_CONTEXT_INVALID;
  134. }
  135. /* Ethtool support */
  136. extern const struct ethtool_ops efx_siena_ethtool_ops;
  137. /* Global */
  138. unsigned int efx_siena_usecs_to_ticks(struct efx_nic *efx, unsigned int usecs);
  139. int efx_siena_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs,
  140. unsigned int rx_usecs, bool rx_adaptive,
  141. bool rx_may_override_tx);
  142. void efx_siena_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs,
  143. unsigned int *rx_usecs, bool *rx_adaptive);
  144. /* Update the generic software stats in the passed stats array */
  145. void efx_siena_update_sw_stats(struct efx_nic *efx, u64 *stats);
  146. /* MTD */
  147. #ifdef CONFIG_SFC_SIENA_MTD
  148. int efx_siena_mtd_add(struct efx_nic *efx, struct efx_mtd_partition *parts,
  149. size_t n_parts, size_t sizeof_part);
  150. static inline int efx_mtd_probe(struct efx_nic *efx)
  151. {
  152. return efx->type->mtd_probe(efx);
  153. }
  154. void efx_siena_mtd_rename(struct efx_nic *efx);
  155. void efx_siena_mtd_remove(struct efx_nic *efx);
  156. #else
  157. static inline int efx_mtd_probe(struct efx_nic *efx) { return 0; }
  158. static inline void efx_siena_mtd_rename(struct efx_nic *efx) {}
  159. static inline void efx_siena_mtd_remove(struct efx_nic *efx) {}
  160. #endif
  161. #ifdef CONFIG_SFC_SIENA_SRIOV
  162. static inline unsigned int efx_vf_size(struct efx_nic *efx)
  163. {
  164. return 1 << efx->vi_scale;
  165. }
  166. #endif
  167. static inline void efx_device_detach_sync(struct efx_nic *efx)
  168. {
  169. struct net_device *dev = efx->net_dev;
  170. /* Lock/freeze all TX queues so that we can be sure the
  171. * TX scheduler is stopped when we're done and before
  172. * netif_device_present() becomes false.
  173. */
  174. netif_tx_lock_bh(dev);
  175. netif_device_detach(dev);
  176. netif_tx_unlock_bh(dev);
  177. }
  178. static inline void efx_device_attach_if_not_resetting(struct efx_nic *efx)
  179. {
  180. if ((efx->state != STATE_DISABLED) && !efx->reset_pending)
  181. netif_device_attach(efx->net_dev);
  182. }
  183. static inline bool efx_rwsem_assert_write_locked(struct rw_semaphore *sem)
  184. {
  185. if (WARN_ON(down_read_trylock(sem))) {
  186. up_read(sem);
  187. return false;
  188. }
  189. return true;
  190. }
  191. int efx_siena_xdp_tx_buffers(struct efx_nic *efx, int n,
  192. struct xdp_frame **xdpfs, bool flush);
  193. #endif /* EFX_EFX_H */