xref: /linux/drivers/net/ethernet/sfc/rx_common.h (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
1e1253f39SAlex Maftei (amaftei) /* SPDX-License-Identifier: GPL-2.0-only */
2e1253f39SAlex Maftei (amaftei) /****************************************************************************
3e1253f39SAlex Maftei (amaftei)  * Driver for Solarflare network controllers and boards
4e1253f39SAlex Maftei (amaftei)  * Copyright 2018 Solarflare Communications Inc.
5e1253f39SAlex Maftei (amaftei)  *
6e1253f39SAlex Maftei (amaftei)  * This program is free software; you can redistribute it and/or modify it
7e1253f39SAlex Maftei (amaftei)  * under the terms of the GNU General Public License version 2 as published
8e1253f39SAlex Maftei (amaftei)  * by the Free Software Foundation, incorporated herein by reference.
9e1253f39SAlex Maftei (amaftei)  */
10e1253f39SAlex Maftei (amaftei) 
11e1253f39SAlex Maftei (amaftei) #ifndef EFX_RX_COMMON_H
12e1253f39SAlex Maftei (amaftei) #define EFX_RX_COMMON_H
13e1253f39SAlex Maftei (amaftei) 
14e1253f39SAlex Maftei (amaftei) /* Preferred number of descriptors to fill at once */
15e1253f39SAlex Maftei (amaftei) #define EFX_RX_PREFERRED_BATCH 8U
16e1253f39SAlex Maftei (amaftei) 
17e1253f39SAlex Maftei (amaftei) /* Each packet can consume up to ceil(max_frame_len / buffer_size) buffers */
18e1253f39SAlex Maftei (amaftei) #define EFX_RX_MAX_FRAGS DIV_ROUND_UP(EFX_MAX_FRAME_LEN(EFX_MAX_MTU), \
19e1253f39SAlex Maftei (amaftei) 				      EFX_RX_USR_BUF_SIZE)
20e1253f39SAlex Maftei (amaftei) 
21000fe940SMartin Habets /* Number of RX buffers to recycle pages for.  When creating the RX page recycle
22000fe940SMartin Habets  * ring, this number is divided by the number of buffers per page to calculate
23000fe940SMartin Habets  * the number of pages to store in the RX page recycle ring.
24000fe940SMartin Habets  */
25000fe940SMartin Habets #define EFX_RECYCLE_RING_SIZE_10G	256
26000fe940SMartin Habets 
efx_rx_buf_va(struct efx_rx_buffer * buf)273d95b884SAlex Maftei (amaftei) static inline u8 *efx_rx_buf_va(struct efx_rx_buffer *buf)
283d95b884SAlex Maftei (amaftei) {
293d95b884SAlex Maftei (amaftei) 	return page_address(buf->page) + buf->page_offset;
303d95b884SAlex Maftei (amaftei) }
313d95b884SAlex Maftei (amaftei) 
efx_rx_buf_hash(struct efx_nic * efx,const u8 * eh)323d95b884SAlex Maftei (amaftei) static inline u32 efx_rx_buf_hash(struct efx_nic *efx, const u8 *eh)
333d95b884SAlex Maftei (amaftei) {
343d95b884SAlex Maftei (amaftei) #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
353d95b884SAlex Maftei (amaftei) 	return __le32_to_cpup((const __le32 *)(eh + efx->rx_packet_hash_offset));
363d95b884SAlex Maftei (amaftei) #else
373d95b884SAlex Maftei (amaftei) 	const u8 *data = eh + efx->rx_packet_hash_offset;
383d95b884SAlex Maftei (amaftei) 
393d95b884SAlex Maftei (amaftei) 	return (u32)data[0]	  |
403d95b884SAlex Maftei (amaftei) 	       (u32)data[1] << 8  |
413d95b884SAlex Maftei (amaftei) 	       (u32)data[2] << 16 |
423d95b884SAlex Maftei (amaftei) 	       (u32)data[3] << 24;
433d95b884SAlex Maftei (amaftei) #endif
443d95b884SAlex Maftei (amaftei) }
453d95b884SAlex Maftei (amaftei) 
46e1253f39SAlex Maftei (amaftei) void efx_rx_slow_fill(struct timer_list *t);
47e1253f39SAlex Maftei (amaftei) 
483d95b884SAlex Maftei (amaftei) void efx_recycle_rx_pages(struct efx_channel *channel,
493d95b884SAlex Maftei (amaftei) 			  struct efx_rx_buffer *rx_buf,
503d95b884SAlex Maftei (amaftei) 			  unsigned int n_frags);
513d95b884SAlex Maftei (amaftei) void efx_discard_rx_packet(struct efx_channel *channel,
523d95b884SAlex Maftei (amaftei) 			   struct efx_rx_buffer *rx_buf,
533d95b884SAlex Maftei (amaftei) 			   unsigned int n_frags);
543d95b884SAlex Maftei (amaftei) 
55e1253f39SAlex Maftei (amaftei) int efx_probe_rx_queue(struct efx_rx_queue *rx_queue);
56e1253f39SAlex Maftei (amaftei) void efx_init_rx_queue(struct efx_rx_queue *rx_queue);
57e1253f39SAlex Maftei (amaftei) void efx_fini_rx_queue(struct efx_rx_queue *rx_queue);
58e1253f39SAlex Maftei (amaftei) void efx_remove_rx_queue(struct efx_rx_queue *rx_queue);
59e1253f39SAlex Maftei (amaftei) void efx_destroy_rx_queue(struct efx_rx_queue *rx_queue);
60e1253f39SAlex Maftei (amaftei) 
61e1253f39SAlex Maftei (amaftei) void efx_init_rx_buffer(struct efx_rx_queue *rx_queue,
62e1253f39SAlex Maftei (amaftei) 			struct page *page,
63e1253f39SAlex Maftei (amaftei) 			unsigned int page_offset,
64e1253f39SAlex Maftei (amaftei) 			u16 flags);
65e1253f39SAlex Maftei (amaftei) void efx_unmap_rx_buffer(struct efx_nic *efx, struct efx_rx_buffer *rx_buf);
6680a0074eSEdward Cree 
efx_sync_rx_buffer(struct efx_nic * efx,struct efx_rx_buffer * rx_buf,unsigned int len)6780a0074eSEdward Cree static inline void efx_sync_rx_buffer(struct efx_nic *efx,
6880a0074eSEdward Cree 				      struct efx_rx_buffer *rx_buf,
6980a0074eSEdward Cree 				      unsigned int len)
7080a0074eSEdward Cree {
7180a0074eSEdward Cree 	dma_sync_single_for_cpu(&efx->pci_dev->dev, rx_buf->dma_addr, len,
7280a0074eSEdward Cree 				DMA_FROM_DEVICE);
7380a0074eSEdward Cree }
7480a0074eSEdward Cree 
75e1253f39SAlex Maftei (amaftei) void efx_free_rx_buffers(struct efx_rx_queue *rx_queue,
76e1253f39SAlex Maftei (amaftei) 			 struct efx_rx_buffer *rx_buf,
77e1253f39SAlex Maftei (amaftei) 			 unsigned int num_bufs);
78e1253f39SAlex Maftei (amaftei) 
79e1253f39SAlex Maftei (amaftei) void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue);
80e1253f39SAlex Maftei (amaftei) void efx_rx_config_page_split(struct efx_nic *efx);
81e1253f39SAlex Maftei (amaftei) void efx_fast_push_rx_descriptors(struct efx_rx_queue *rx_queue, bool atomic);
82e1253f39SAlex Maftei (amaftei) 
833d95b884SAlex Maftei (amaftei) void
843d95b884SAlex Maftei (amaftei) efx_rx_packet_gro(struct efx_channel *channel, struct efx_rx_buffer *rx_buf,
854d9c0a2dSEdward Cree 		  unsigned int n_frags, u8 *eh, __wsum csum);
86960f1627SAlex Maftei (amaftei) 
87*a9ee8d4aSEdward Cree struct efx_rss_context_priv *efx_find_rss_context_entry(struct efx_nic *efx,
88*a9ee8d4aSEdward Cree 							u32 id);
89*a9ee8d4aSEdward Cree void efx_set_default_rx_indir_table(struct efx_nic *efx, u32 *indir);
90f7226e0fSAlex Maftei (amaftei) 
91f7226e0fSAlex Maftei (amaftei) bool efx_filter_is_mc_recipient(const struct efx_filter_spec *spec);
92f7226e0fSAlex Maftei (amaftei) bool efx_filter_spec_equal(const struct efx_filter_spec *left,
93f7226e0fSAlex Maftei (amaftei) 			   const struct efx_filter_spec *right);
94f7226e0fSAlex Maftei (amaftei) u32 efx_filter_spec_hash(const struct efx_filter_spec *spec);
95f7226e0fSAlex Maftei (amaftei) 
96f7226e0fSAlex Maftei (amaftei) #ifdef CONFIG_RFS_ACCEL
97f7226e0fSAlex Maftei (amaftei) bool efx_rps_check_rule(struct efx_arfs_rule *rule, unsigned int filter_idx,
98f7226e0fSAlex Maftei (amaftei) 			bool *force);
99f7226e0fSAlex Maftei (amaftei) struct efx_arfs_rule *efx_rps_hash_find(struct efx_nic *efx,
100f7226e0fSAlex Maftei (amaftei) 					const struct efx_filter_spec *spec);
101f7226e0fSAlex Maftei (amaftei) struct efx_arfs_rule *efx_rps_hash_add(struct efx_nic *efx,
102f7226e0fSAlex Maftei (amaftei) 				       const struct efx_filter_spec *spec,
103f7226e0fSAlex Maftei (amaftei) 				       bool *new);
104f7226e0fSAlex Maftei (amaftei) void efx_rps_hash_del(struct efx_nic *efx, const struct efx_filter_spec *spec);
10528abe825SEdward Cree 
10628abe825SEdward Cree int efx_filter_rfs(struct net_device *net_dev, const struct sk_buff *skb,
10728abe825SEdward Cree 		   u16 rxq_index, u32 flow_id);
10828abe825SEdward Cree bool __efx_filter_rfs_expire(struct efx_channel *channel, unsigned int quota);
109f7226e0fSAlex Maftei (amaftei) #endif
110f7226e0fSAlex Maftei (amaftei) 
111f7226e0fSAlex Maftei (amaftei) int efx_probe_filters(struct efx_nic *efx);
112f7226e0fSAlex Maftei (amaftei) void efx_remove_filters(struct efx_nic *efx);
113f7226e0fSAlex Maftei (amaftei) 
114e1253f39SAlex Maftei (amaftei) #endif
115