1*3ec648c6SKrzysztof Kozlowski /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2f48ad614SDennis Dalessandro /*
35da0fc9dSDennis Dalessandro * Copyright(c) 2015 - 2018 Intel Corporation.
4f48ad614SDennis Dalessandro */
5f48ad614SDennis Dalessandro
6145eba1aSCai Huoqing #ifndef _HFI1_SDMA_H
7145eba1aSCai Huoqing #define _HFI1_SDMA_H
8145eba1aSCai Huoqing
9f48ad614SDennis Dalessandro #include <linux/types.h>
10f48ad614SDennis Dalessandro #include <linux/list.h>
11f48ad614SDennis Dalessandro #include <asm/byteorder.h>
12f48ad614SDennis Dalessandro #include <linux/workqueue.h>
13f48ad614SDennis Dalessandro #include <linux/rculist.h>
14f48ad614SDennis Dalessandro
15f48ad614SDennis Dalessandro #include "hfi.h"
16f48ad614SDennis Dalessandro #include "verbs.h"
17f48ad614SDennis Dalessandro #include "sdma_txreq.h"
18f48ad614SDennis Dalessandro
19f48ad614SDennis Dalessandro /* Hardware limit */
20f48ad614SDennis Dalessandro #define MAX_DESC 64
21f48ad614SDennis Dalessandro /* Hardware limit for SDMA packet size */
22f48ad614SDennis Dalessandro #define MAX_SDMA_PKT_SIZE ((16 * 1024) - 1)
23f48ad614SDennis Dalessandro
24f48ad614SDennis Dalessandro #define SDMA_MAP_NONE 0
25f48ad614SDennis Dalessandro #define SDMA_MAP_SINGLE 1
26f48ad614SDennis Dalessandro #define SDMA_MAP_PAGE 2
27f48ad614SDennis Dalessandro
28f48ad614SDennis Dalessandro #define SDMA_AHG_VALUE_MASK 0xffff
29f48ad614SDennis Dalessandro #define SDMA_AHG_VALUE_SHIFT 0
30f48ad614SDennis Dalessandro #define SDMA_AHG_INDEX_MASK 0xf
31f48ad614SDennis Dalessandro #define SDMA_AHG_INDEX_SHIFT 16
32f48ad614SDennis Dalessandro #define SDMA_AHG_FIELD_LEN_MASK 0xf
33f48ad614SDennis Dalessandro #define SDMA_AHG_FIELD_LEN_SHIFT 20
34f48ad614SDennis Dalessandro #define SDMA_AHG_FIELD_START_MASK 0x1f
35f48ad614SDennis Dalessandro #define SDMA_AHG_FIELD_START_SHIFT 24
36f48ad614SDennis Dalessandro #define SDMA_AHG_UPDATE_ENABLE_MASK 0x1
37f48ad614SDennis Dalessandro #define SDMA_AHG_UPDATE_ENABLE_SHIFT 31
38f48ad614SDennis Dalessandro
39f48ad614SDennis Dalessandro /* AHG modes */
40f48ad614SDennis Dalessandro
41f48ad614SDennis Dalessandro /*
42f48ad614SDennis Dalessandro * Be aware the ordering and values
43f48ad614SDennis Dalessandro * for SDMA_AHG_APPLY_UPDATE[123]
44f48ad614SDennis Dalessandro * are assumed in generating a skip
45f48ad614SDennis Dalessandro * count in submit_tx() in sdma.c
46f48ad614SDennis Dalessandro */
47f48ad614SDennis Dalessandro #define SDMA_AHG_NO_AHG 0
48f48ad614SDennis Dalessandro #define SDMA_AHG_COPY 1
49f48ad614SDennis Dalessandro #define SDMA_AHG_APPLY_UPDATE1 2
50f48ad614SDennis Dalessandro #define SDMA_AHG_APPLY_UPDATE2 3
51f48ad614SDennis Dalessandro #define SDMA_AHG_APPLY_UPDATE3 4
52f48ad614SDennis Dalessandro
53f48ad614SDennis Dalessandro /*
54f48ad614SDennis Dalessandro * Bits defined in the send DMA descriptor.
55f48ad614SDennis Dalessandro */
56f48ad614SDennis Dalessandro #define SDMA_DESC0_FIRST_DESC_FLAG BIT_ULL(63)
57f48ad614SDennis Dalessandro #define SDMA_DESC0_LAST_DESC_FLAG BIT_ULL(62)
58f48ad614SDennis Dalessandro #define SDMA_DESC0_BYTE_COUNT_SHIFT 48
59f48ad614SDennis Dalessandro #define SDMA_DESC0_BYTE_COUNT_WIDTH 14
60f48ad614SDennis Dalessandro #define SDMA_DESC0_BYTE_COUNT_MASK \
61f48ad614SDennis Dalessandro ((1ULL << SDMA_DESC0_BYTE_COUNT_WIDTH) - 1)
62f48ad614SDennis Dalessandro #define SDMA_DESC0_BYTE_COUNT_SMASK \
63f48ad614SDennis Dalessandro (SDMA_DESC0_BYTE_COUNT_MASK << SDMA_DESC0_BYTE_COUNT_SHIFT)
64f48ad614SDennis Dalessandro #define SDMA_DESC0_PHY_ADDR_SHIFT 0
65f48ad614SDennis Dalessandro #define SDMA_DESC0_PHY_ADDR_WIDTH 48
66f48ad614SDennis Dalessandro #define SDMA_DESC0_PHY_ADDR_MASK \
67f48ad614SDennis Dalessandro ((1ULL << SDMA_DESC0_PHY_ADDR_WIDTH) - 1)
68f48ad614SDennis Dalessandro #define SDMA_DESC0_PHY_ADDR_SMASK \
69f48ad614SDennis Dalessandro (SDMA_DESC0_PHY_ADDR_MASK << SDMA_DESC0_PHY_ADDR_SHIFT)
70f48ad614SDennis Dalessandro
71f48ad614SDennis Dalessandro #define SDMA_DESC1_HEADER_UPDATE1_SHIFT 32
72f48ad614SDennis Dalessandro #define SDMA_DESC1_HEADER_UPDATE1_WIDTH 32
73f48ad614SDennis Dalessandro #define SDMA_DESC1_HEADER_UPDATE1_MASK \
74f48ad614SDennis Dalessandro ((1ULL << SDMA_DESC1_HEADER_UPDATE1_WIDTH) - 1)
75f48ad614SDennis Dalessandro #define SDMA_DESC1_HEADER_UPDATE1_SMASK \
76f48ad614SDennis Dalessandro (SDMA_DESC1_HEADER_UPDATE1_MASK << SDMA_DESC1_HEADER_UPDATE1_SHIFT)
77f48ad614SDennis Dalessandro #define SDMA_DESC1_HEADER_MODE_SHIFT 13
78f48ad614SDennis Dalessandro #define SDMA_DESC1_HEADER_MODE_WIDTH 3
79f48ad614SDennis Dalessandro #define SDMA_DESC1_HEADER_MODE_MASK \
80f48ad614SDennis Dalessandro ((1ULL << SDMA_DESC1_HEADER_MODE_WIDTH) - 1)
81f48ad614SDennis Dalessandro #define SDMA_DESC1_HEADER_MODE_SMASK \
82f48ad614SDennis Dalessandro (SDMA_DESC1_HEADER_MODE_MASK << SDMA_DESC1_HEADER_MODE_SHIFT)
83f48ad614SDennis Dalessandro #define SDMA_DESC1_HEADER_INDEX_SHIFT 8
84f48ad614SDennis Dalessandro #define SDMA_DESC1_HEADER_INDEX_WIDTH 5
85f48ad614SDennis Dalessandro #define SDMA_DESC1_HEADER_INDEX_MASK \
86f48ad614SDennis Dalessandro ((1ULL << SDMA_DESC1_HEADER_INDEX_WIDTH) - 1)
87f48ad614SDennis Dalessandro #define SDMA_DESC1_HEADER_INDEX_SMASK \
88f48ad614SDennis Dalessandro (SDMA_DESC1_HEADER_INDEX_MASK << SDMA_DESC1_HEADER_INDEX_SHIFT)
89f48ad614SDennis Dalessandro #define SDMA_DESC1_HEADER_DWS_SHIFT 4
90f48ad614SDennis Dalessandro #define SDMA_DESC1_HEADER_DWS_WIDTH 4
91f48ad614SDennis Dalessandro #define SDMA_DESC1_HEADER_DWS_MASK \
92f48ad614SDennis Dalessandro ((1ULL << SDMA_DESC1_HEADER_DWS_WIDTH) - 1)
93f48ad614SDennis Dalessandro #define SDMA_DESC1_HEADER_DWS_SMASK \
94f48ad614SDennis Dalessandro (SDMA_DESC1_HEADER_DWS_MASK << SDMA_DESC1_HEADER_DWS_SHIFT)
95f48ad614SDennis Dalessandro #define SDMA_DESC1_GENERATION_SHIFT 2
96f48ad614SDennis Dalessandro #define SDMA_DESC1_GENERATION_WIDTH 2
97f48ad614SDennis Dalessandro #define SDMA_DESC1_GENERATION_MASK \
98f48ad614SDennis Dalessandro ((1ULL << SDMA_DESC1_GENERATION_WIDTH) - 1)
99f48ad614SDennis Dalessandro #define SDMA_DESC1_GENERATION_SMASK \
100f48ad614SDennis Dalessandro (SDMA_DESC1_GENERATION_MASK << SDMA_DESC1_GENERATION_SHIFT)
101f48ad614SDennis Dalessandro #define SDMA_DESC1_INT_REQ_FLAG BIT_ULL(1)
102f48ad614SDennis Dalessandro #define SDMA_DESC1_HEAD_TO_HOST_FLAG BIT_ULL(0)
103f48ad614SDennis Dalessandro
104f48ad614SDennis Dalessandro enum sdma_states {
105f48ad614SDennis Dalessandro sdma_state_s00_hw_down,
106f48ad614SDennis Dalessandro sdma_state_s10_hw_start_up_halt_wait,
107f48ad614SDennis Dalessandro sdma_state_s15_hw_start_up_clean_wait,
108f48ad614SDennis Dalessandro sdma_state_s20_idle,
109f48ad614SDennis Dalessandro sdma_state_s30_sw_clean_up_wait,
110f48ad614SDennis Dalessandro sdma_state_s40_hw_clean_up_wait,
111f48ad614SDennis Dalessandro sdma_state_s50_hw_halt_wait,
112f48ad614SDennis Dalessandro sdma_state_s60_idle_halt_wait,
113f48ad614SDennis Dalessandro sdma_state_s80_hw_freeze,
114f48ad614SDennis Dalessandro sdma_state_s82_freeze_sw_clean,
115f48ad614SDennis Dalessandro sdma_state_s99_running,
116f48ad614SDennis Dalessandro };
117f48ad614SDennis Dalessandro
118f48ad614SDennis Dalessandro enum sdma_events {
119f48ad614SDennis Dalessandro sdma_event_e00_go_hw_down,
120f48ad614SDennis Dalessandro sdma_event_e10_go_hw_start,
121f48ad614SDennis Dalessandro sdma_event_e15_hw_halt_done,
122f48ad614SDennis Dalessandro sdma_event_e25_hw_clean_up_done,
123f48ad614SDennis Dalessandro sdma_event_e30_go_running,
124f48ad614SDennis Dalessandro sdma_event_e40_sw_cleaned,
125f48ad614SDennis Dalessandro sdma_event_e50_hw_cleaned,
126f48ad614SDennis Dalessandro sdma_event_e60_hw_halted,
127f48ad614SDennis Dalessandro sdma_event_e70_go_idle,
128f48ad614SDennis Dalessandro sdma_event_e80_hw_freeze,
129f48ad614SDennis Dalessandro sdma_event_e81_hw_frozen,
130f48ad614SDennis Dalessandro sdma_event_e82_hw_unfreeze,
131f48ad614SDennis Dalessandro sdma_event_e85_link_down,
132f48ad614SDennis Dalessandro sdma_event_e90_sw_halted,
133f48ad614SDennis Dalessandro };
134f48ad614SDennis Dalessandro
135f48ad614SDennis Dalessandro struct sdma_set_state_action {
136f48ad614SDennis Dalessandro unsigned op_enable:1;
137f48ad614SDennis Dalessandro unsigned op_intenable:1;
138f48ad614SDennis Dalessandro unsigned op_halt:1;
139f48ad614SDennis Dalessandro unsigned op_cleanup:1;
140f48ad614SDennis Dalessandro unsigned go_s99_running_tofalse:1;
141f48ad614SDennis Dalessandro unsigned go_s99_running_totrue:1;
142f48ad614SDennis Dalessandro };
143f48ad614SDennis Dalessandro
144f48ad614SDennis Dalessandro struct sdma_state {
145f48ad614SDennis Dalessandro struct kref kref;
146f48ad614SDennis Dalessandro struct completion comp;
147f48ad614SDennis Dalessandro enum sdma_states current_state;
148f48ad614SDennis Dalessandro unsigned current_op;
149f48ad614SDennis Dalessandro unsigned go_s99_running;
150f48ad614SDennis Dalessandro /* debugging/development */
151f48ad614SDennis Dalessandro enum sdma_states previous_state;
152f48ad614SDennis Dalessandro unsigned previous_op;
153f48ad614SDennis Dalessandro enum sdma_events last_event;
154f48ad614SDennis Dalessandro };
155f48ad614SDennis Dalessandro
156f48ad614SDennis Dalessandro /**
157f48ad614SDennis Dalessandro * DOC: sdma exported routines
158f48ad614SDennis Dalessandro *
159f48ad614SDennis Dalessandro * These sdma routines fit into three categories:
160f48ad614SDennis Dalessandro * - The SDMA API for building and submitting packets
161f48ad614SDennis Dalessandro * to the ring
162f48ad614SDennis Dalessandro *
163f48ad614SDennis Dalessandro * - Initialization and tear down routines to buildup
164f48ad614SDennis Dalessandro * and tear down SDMA
165f48ad614SDennis Dalessandro *
166f48ad614SDennis Dalessandro * - ISR entrances to handle interrupts, state changes
167f48ad614SDennis Dalessandro * and errors
168f48ad614SDennis Dalessandro */
169f48ad614SDennis Dalessandro
170f48ad614SDennis Dalessandro /**
171f48ad614SDennis Dalessandro * DOC: sdma PSM/verbs API
172f48ad614SDennis Dalessandro *
173f48ad614SDennis Dalessandro * The sdma API is designed to be used by both PSM
174f48ad614SDennis Dalessandro * and verbs to supply packets to the SDMA ring.
175f48ad614SDennis Dalessandro *
176f48ad614SDennis Dalessandro * The usage of the API is as follows:
177f48ad614SDennis Dalessandro *
178f48ad614SDennis Dalessandro * Embed a struct iowait in the QP or
179f48ad614SDennis Dalessandro * PQ. The iowait should be initialized with a
180f48ad614SDennis Dalessandro * call to iowait_init().
181f48ad614SDennis Dalessandro *
182f48ad614SDennis Dalessandro * The user of the API should create an allocation method
183f48ad614SDennis Dalessandro * for their version of the txreq. slabs, pre-allocated lists,
184f48ad614SDennis Dalessandro * and dma pools can be used. Once the user's overload of
185f48ad614SDennis Dalessandro * the sdma_txreq has been allocated, the sdma_txreq member
186f48ad614SDennis Dalessandro * must be initialized with sdma_txinit() or sdma_txinit_ahg().
187f48ad614SDennis Dalessandro *
188f48ad614SDennis Dalessandro * The txreq must be declared with the sdma_txreq first.
189f48ad614SDennis Dalessandro *
190f48ad614SDennis Dalessandro * The tx request, once initialized, is manipulated with calls to
191f48ad614SDennis Dalessandro * sdma_txadd_daddr(), sdma_txadd_page(), or sdma_txadd_kvaddr()
192f48ad614SDennis Dalessandro * for each disjoint memory location. It is the user's responsibility
193f48ad614SDennis Dalessandro * to understand the packet boundaries and page boundaries to do the
194f48ad614SDennis Dalessandro * appropriate number of sdma_txadd_* calls.. The user
195f48ad614SDennis Dalessandro * must be prepared to deal with failures from these routines due to
196f48ad614SDennis Dalessandro * either memory allocation or dma_mapping failures.
197f48ad614SDennis Dalessandro *
198f48ad614SDennis Dalessandro * The mapping specifics for each memory location are recorded
199f48ad614SDennis Dalessandro * in the tx. Memory locations added with sdma_txadd_page()
200f48ad614SDennis Dalessandro * and sdma_txadd_kvaddr() are automatically mapped when added
201f48ad614SDennis Dalessandro * to the tx and nmapped as part of the progress processing in the
202f48ad614SDennis Dalessandro * SDMA interrupt handling.
203f48ad614SDennis Dalessandro *
204f48ad614SDennis Dalessandro * sdma_txadd_daddr() is used to add an dma_addr_t memory to the
205f48ad614SDennis Dalessandro * tx. An example of a use case would be a pre-allocated
206f48ad614SDennis Dalessandro * set of headers allocated via dma_pool_alloc() or
207f48ad614SDennis Dalessandro * dma_alloc_coherent(). For these memory locations, it
208f48ad614SDennis Dalessandro * is the responsibility of the user to handle that unmapping.
209f48ad614SDennis Dalessandro * (This would usually be at an unload or job termination.)
210f48ad614SDennis Dalessandro *
211f48ad614SDennis Dalessandro * The routine sdma_send_txreq() is used to submit
212f48ad614SDennis Dalessandro * a tx to the ring after the appropriate number of
213f48ad614SDennis Dalessandro * sdma_txadd_* have been done.
214f48ad614SDennis Dalessandro *
215f48ad614SDennis Dalessandro * If it is desired to send a burst of sdma_txreqs, sdma_send_txlist()
216f48ad614SDennis Dalessandro * can be used to submit a list of packets.
217f48ad614SDennis Dalessandro *
218f48ad614SDennis Dalessandro * The user is free to use the link overhead in the struct sdma_txreq as
219f48ad614SDennis Dalessandro * long as the tx isn't in flight.
220f48ad614SDennis Dalessandro *
221f48ad614SDennis Dalessandro * The extreme degenerate case of the number of descriptors
222f48ad614SDennis Dalessandro * exceeding the ring size is automatically handled as
223f48ad614SDennis Dalessandro * memory locations are added. An overflow of the descriptor
224f48ad614SDennis Dalessandro * array that is part of the sdma_txreq is also automatically
225f48ad614SDennis Dalessandro * handled.
226f48ad614SDennis Dalessandro *
227f48ad614SDennis Dalessandro */
228f48ad614SDennis Dalessandro
229f48ad614SDennis Dalessandro /**
230f48ad614SDennis Dalessandro * DOC: Infrastructure calls
231f48ad614SDennis Dalessandro *
232f48ad614SDennis Dalessandro * sdma_init() is used to initialize data structures and
233f48ad614SDennis Dalessandro * CSRs for the desired number of SDMA engines.
234f48ad614SDennis Dalessandro *
235f48ad614SDennis Dalessandro * sdma_start() is used to kick the SDMA engines initialized
236f48ad614SDennis Dalessandro * with sdma_init(). Interrupts must be enabled at this
237f48ad614SDennis Dalessandro * point since aspects of the state machine are interrupt
238f48ad614SDennis Dalessandro * driven.
239f48ad614SDennis Dalessandro *
240f48ad614SDennis Dalessandro * sdma_engine_error() and sdma_engine_interrupt() are
241f48ad614SDennis Dalessandro * entrances for interrupts.
242f48ad614SDennis Dalessandro *
243f48ad614SDennis Dalessandro * sdma_map_init() is for the management of the mapping
244f48ad614SDennis Dalessandro * table when the number of vls is changed.
245f48ad614SDennis Dalessandro *
246f48ad614SDennis Dalessandro */
247f48ad614SDennis Dalessandro
248f48ad614SDennis Dalessandro /*
249f48ad614SDennis Dalessandro * struct hw_sdma_desc - raw 128 bit SDMA descriptor
250f48ad614SDennis Dalessandro *
251f48ad614SDennis Dalessandro * This is the raw descriptor in the SDMA ring
252f48ad614SDennis Dalessandro */
253f48ad614SDennis Dalessandro struct hw_sdma_desc {
254f48ad614SDennis Dalessandro /* private: don't use directly */
255f48ad614SDennis Dalessandro __le64 qw[2];
256f48ad614SDennis Dalessandro };
257f48ad614SDennis Dalessandro
258f48ad614SDennis Dalessandro /**
259f48ad614SDennis Dalessandro * struct sdma_engine - Data pertaining to each SDMA engine.
260f48ad614SDennis Dalessandro * @dd: a back-pointer to the device data
261f48ad614SDennis Dalessandro * @ppd: per port back-pointer
262f48ad614SDennis Dalessandro * @imask: mask for irq manipulation
263f48ad614SDennis Dalessandro * @idle_mask: mask for determining if an interrupt is due to sdma_idle
264f48ad614SDennis Dalessandro *
265f48ad614SDennis Dalessandro * This structure has the state for each sdma_engine.
266f48ad614SDennis Dalessandro *
267f48ad614SDennis Dalessandro * Accessing to non public fields are not supported
268f48ad614SDennis Dalessandro * since the private members are subject to change.
269f48ad614SDennis Dalessandro */
270f48ad614SDennis Dalessandro struct sdma_engine {
271f48ad614SDennis Dalessandro /* read mostly */
272f48ad614SDennis Dalessandro struct hfi1_devdata *dd;
273f48ad614SDennis Dalessandro struct hfi1_pportdata *ppd;
274f48ad614SDennis Dalessandro /* private: */
275f48ad614SDennis Dalessandro void __iomem *tail_csr;
276f48ad614SDennis Dalessandro u64 imask; /* clear interrupt mask */
277f48ad614SDennis Dalessandro u64 idle_mask;
278f48ad614SDennis Dalessandro u64 progress_mask;
279f48ad614SDennis Dalessandro u64 int_mask;
280f48ad614SDennis Dalessandro /* private: */
281f48ad614SDennis Dalessandro volatile __le64 *head_dma; /* DMA'ed by chip */
282f48ad614SDennis Dalessandro /* private: */
283f48ad614SDennis Dalessandro dma_addr_t head_phys;
284f48ad614SDennis Dalessandro /* private: */
285f48ad614SDennis Dalessandro struct hw_sdma_desc *descq;
286f48ad614SDennis Dalessandro /* private: */
287f48ad614SDennis Dalessandro unsigned descq_full_count;
288f48ad614SDennis Dalessandro struct sdma_txreq **tx_ring;
289f48ad614SDennis Dalessandro /* private: */
290f48ad614SDennis Dalessandro dma_addr_t descq_phys;
291f48ad614SDennis Dalessandro /* private */
292f48ad614SDennis Dalessandro u32 sdma_mask;
293f48ad614SDennis Dalessandro /* private */
294f48ad614SDennis Dalessandro struct sdma_state state;
295f48ad614SDennis Dalessandro /* private */
296f48ad614SDennis Dalessandro int cpu;
297f48ad614SDennis Dalessandro /* private: */
298f48ad614SDennis Dalessandro u8 sdma_shift;
299f48ad614SDennis Dalessandro /* private: */
300f48ad614SDennis Dalessandro u8 this_idx; /* zero relative engine */
301f48ad614SDennis Dalessandro /* protect changes to senddmactrl shadow */
302f48ad614SDennis Dalessandro spinlock_t senddmactrl_lock;
303f48ad614SDennis Dalessandro /* private: */
304f48ad614SDennis Dalessandro u64 p_senddmactrl; /* shadow per-engine SendDmaCtrl */
305f48ad614SDennis Dalessandro
306f48ad614SDennis Dalessandro /* read/write using tail_lock */
307f48ad614SDennis Dalessandro spinlock_t tail_lock ____cacheline_aligned_in_smp;
308f48ad614SDennis Dalessandro #ifdef CONFIG_HFI1_DEBUG_SDMA_ORDER
309f48ad614SDennis Dalessandro /* private: */
310f48ad614SDennis Dalessandro u64 tail_sn;
311f48ad614SDennis Dalessandro #endif
312f48ad614SDennis Dalessandro /* private: */
313f48ad614SDennis Dalessandro u32 descq_tail;
314f48ad614SDennis Dalessandro /* private: */
315f48ad614SDennis Dalessandro unsigned long ahg_bits;
316f48ad614SDennis Dalessandro /* private: */
317f48ad614SDennis Dalessandro u16 desc_avail;
318f48ad614SDennis Dalessandro /* private: */
319f48ad614SDennis Dalessandro u16 tx_tail;
320f48ad614SDennis Dalessandro /* private: */
321f48ad614SDennis Dalessandro u16 descq_cnt;
322f48ad614SDennis Dalessandro
323f48ad614SDennis Dalessandro /* read/write using head_lock */
324f48ad614SDennis Dalessandro /* private: */
325f48ad614SDennis Dalessandro seqlock_t head_lock ____cacheline_aligned_in_smp;
326f48ad614SDennis Dalessandro #ifdef CONFIG_HFI1_DEBUG_SDMA_ORDER
327f48ad614SDennis Dalessandro /* private: */
328f48ad614SDennis Dalessandro u64 head_sn;
329f48ad614SDennis Dalessandro #endif
330f48ad614SDennis Dalessandro /* private: */
331f48ad614SDennis Dalessandro u32 descq_head;
332f48ad614SDennis Dalessandro /* private: */
333f48ad614SDennis Dalessandro u16 tx_head;
334f48ad614SDennis Dalessandro /* private: */
335f48ad614SDennis Dalessandro u64 last_status;
336f48ad614SDennis Dalessandro /* private */
337f48ad614SDennis Dalessandro u64 err_cnt;
338f48ad614SDennis Dalessandro /* private */
339f48ad614SDennis Dalessandro u64 sdma_int_cnt;
340f48ad614SDennis Dalessandro u64 idle_int_cnt;
341f48ad614SDennis Dalessandro u64 progress_int_cnt;
342f48ad614SDennis Dalessandro
343f48ad614SDennis Dalessandro /* private: */
3449aefcabeSMike Marciniszyn seqlock_t waitlock;
345f48ad614SDennis Dalessandro struct list_head dmawait;
346f48ad614SDennis Dalessandro
347f48ad614SDennis Dalessandro /* CONFIG SDMA for now, just blindly duplicate */
348f48ad614SDennis Dalessandro /* private: */
349f48ad614SDennis Dalessandro struct tasklet_struct sdma_hw_clean_up_task
350f48ad614SDennis Dalessandro ____cacheline_aligned_in_smp;
351f48ad614SDennis Dalessandro
352f48ad614SDennis Dalessandro /* private: */
353f48ad614SDennis Dalessandro struct tasklet_struct sdma_sw_clean_up_task
354f48ad614SDennis Dalessandro ____cacheline_aligned_in_smp;
355f48ad614SDennis Dalessandro /* private: */
356f48ad614SDennis Dalessandro struct work_struct err_halt_worker;
357f48ad614SDennis Dalessandro /* private */
358f48ad614SDennis Dalessandro struct timer_list err_progress_check_timer;
359f48ad614SDennis Dalessandro u32 progress_check_head;
360f48ad614SDennis Dalessandro /* private: */
361f48ad614SDennis Dalessandro struct work_struct flush_worker;
362f48ad614SDennis Dalessandro /* protect flush list */
363f48ad614SDennis Dalessandro spinlock_t flushlist_lock;
364f48ad614SDennis Dalessandro /* private: */
365f48ad614SDennis Dalessandro struct list_head flushlist;
3660cb2aa69STadeusz Struk struct cpumask cpu_mask;
3670cb2aa69STadeusz Struk struct kobject kobj;
3686eb4eb10SMichael J. Ruhl u32 msix_intr;
369f48ad614SDennis Dalessandro };
370f48ad614SDennis Dalessandro
371f48ad614SDennis Dalessandro int sdma_init(struct hfi1_devdata *dd, u8 port);
372f48ad614SDennis Dalessandro void sdma_start(struct hfi1_devdata *dd);
373f48ad614SDennis Dalessandro void sdma_exit(struct hfi1_devdata *dd);
374473291b3SAlex Estrin void sdma_clean(struct hfi1_devdata *dd, size_t num_engines);
375f48ad614SDennis Dalessandro void sdma_all_running(struct hfi1_devdata *dd);
376f48ad614SDennis Dalessandro void sdma_all_idle(struct hfi1_devdata *dd);
377f48ad614SDennis Dalessandro void sdma_freeze_notify(struct hfi1_devdata *dd, int go_idle);
378f48ad614SDennis Dalessandro void sdma_freeze(struct hfi1_devdata *dd);
379f48ad614SDennis Dalessandro void sdma_unfreeze(struct hfi1_devdata *dd);
380f48ad614SDennis Dalessandro void sdma_wait(struct hfi1_devdata *dd);
381f48ad614SDennis Dalessandro
382f48ad614SDennis Dalessandro /**
383f48ad614SDennis Dalessandro * sdma_empty() - idle engine test
384f48ad614SDennis Dalessandro * @engine: sdma engine
385f48ad614SDennis Dalessandro *
386f48ad614SDennis Dalessandro * Currently used by verbs as a latency optimization.
387f48ad614SDennis Dalessandro *
388f48ad614SDennis Dalessandro * Return:
389f48ad614SDennis Dalessandro * 1 - empty, 0 - non-empty
390f48ad614SDennis Dalessandro */
sdma_empty(struct sdma_engine * sde)391f48ad614SDennis Dalessandro static inline int sdma_empty(struct sdma_engine *sde)
392f48ad614SDennis Dalessandro {
393f48ad614SDennis Dalessandro return sde->descq_tail == sde->descq_head;
394f48ad614SDennis Dalessandro }
395f48ad614SDennis Dalessandro
sdma_descq_freecnt(struct sdma_engine * sde)396f48ad614SDennis Dalessandro static inline u16 sdma_descq_freecnt(struct sdma_engine *sde)
397f48ad614SDennis Dalessandro {
398f48ad614SDennis Dalessandro return sde->descq_cnt -
399f48ad614SDennis Dalessandro (sde->descq_tail -
4006aa7de05SMark Rutland READ_ONCE(sde->descq_head)) - 1;
401f48ad614SDennis Dalessandro }
402f48ad614SDennis Dalessandro
sdma_descq_inprocess(struct sdma_engine * sde)403f48ad614SDennis Dalessandro static inline u16 sdma_descq_inprocess(struct sdma_engine *sde)
404f48ad614SDennis Dalessandro {
405f48ad614SDennis Dalessandro return sde->descq_cnt - sdma_descq_freecnt(sde);
406f48ad614SDennis Dalessandro }
407f48ad614SDennis Dalessandro
408f48ad614SDennis Dalessandro /*
409f48ad614SDennis Dalessandro * Either head_lock or tail lock required to see
410f48ad614SDennis Dalessandro * a steady state.
411f48ad614SDennis Dalessandro */
__sdma_running(struct sdma_engine * engine)412f48ad614SDennis Dalessandro static inline int __sdma_running(struct sdma_engine *engine)
413f48ad614SDennis Dalessandro {
414f48ad614SDennis Dalessandro return engine->state.current_state == sdma_state_s99_running;
415f48ad614SDennis Dalessandro }
416f48ad614SDennis Dalessandro
417f48ad614SDennis Dalessandro /**
418f48ad614SDennis Dalessandro * sdma_running() - state suitability test
419f48ad614SDennis Dalessandro * @engine: sdma engine
420f48ad614SDennis Dalessandro *
421f48ad614SDennis Dalessandro * sdma_running probes the internal state to determine if it is suitable
422f48ad614SDennis Dalessandro * for submitting packets.
423f48ad614SDennis Dalessandro *
424f48ad614SDennis Dalessandro * Return:
425f48ad614SDennis Dalessandro * 1 - ok to submit, 0 - not ok to submit
426f48ad614SDennis Dalessandro *
427f48ad614SDennis Dalessandro */
sdma_running(struct sdma_engine * engine)428f48ad614SDennis Dalessandro static inline int sdma_running(struct sdma_engine *engine)
429f48ad614SDennis Dalessandro {
430f48ad614SDennis Dalessandro unsigned long flags;
431f48ad614SDennis Dalessandro int ret;
432f48ad614SDennis Dalessandro
433f48ad614SDennis Dalessandro spin_lock_irqsave(&engine->tail_lock, flags);
434f48ad614SDennis Dalessandro ret = __sdma_running(engine);
435f48ad614SDennis Dalessandro spin_unlock_irqrestore(&engine->tail_lock, flags);
436f48ad614SDennis Dalessandro return ret;
437f48ad614SDennis Dalessandro }
438f48ad614SDennis Dalessandro
439f48ad614SDennis Dalessandro void _sdma_txreq_ahgadd(
440f48ad614SDennis Dalessandro struct sdma_txreq *tx,
441f48ad614SDennis Dalessandro u8 num_ahg,
442f48ad614SDennis Dalessandro u8 ahg_entry,
443f48ad614SDennis Dalessandro u32 *ahg,
444f48ad614SDennis Dalessandro u8 ahg_hlen);
445f48ad614SDennis Dalessandro
446f48ad614SDennis Dalessandro /**
447f48ad614SDennis Dalessandro * sdma_txinit_ahg() - initialize an sdma_txreq struct with AHG
448f48ad614SDennis Dalessandro * @tx: tx request to initialize
449f48ad614SDennis Dalessandro * @flags: flags to key last descriptor additions
450f48ad614SDennis Dalessandro * @tlen: total packet length (pbc + headers + data)
451f48ad614SDennis Dalessandro * @ahg_entry: ahg entry to use (0 - 31)
452f48ad614SDennis Dalessandro * @num_ahg: ahg descriptor for first descriptor (0 - 9)
453f48ad614SDennis Dalessandro * @ahg: array of AHG descriptors (up to 9 entries)
454f48ad614SDennis Dalessandro * @ahg_hlen: number of bytes from ASIC entry to use
455f48ad614SDennis Dalessandro * @cb: callback
456f48ad614SDennis Dalessandro *
457f48ad614SDennis Dalessandro * The allocation of the sdma_txreq and it enclosing structure is user
458f48ad614SDennis Dalessandro * dependent. This routine must be called to initialize the user independent
459f48ad614SDennis Dalessandro * fields.
460f48ad614SDennis Dalessandro *
461f48ad614SDennis Dalessandro * The currently supported flags are SDMA_TXREQ_F_URGENT,
462f48ad614SDennis Dalessandro * SDMA_TXREQ_F_AHG_COPY, and SDMA_TXREQ_F_USE_AHG.
463f48ad614SDennis Dalessandro *
464f48ad614SDennis Dalessandro * SDMA_TXREQ_F_URGENT is used for latency sensitive situations where the
465f48ad614SDennis Dalessandro * completion is desired as soon as possible.
466f48ad614SDennis Dalessandro *
467f48ad614SDennis Dalessandro * SDMA_TXREQ_F_AHG_COPY causes the header in the first descriptor to be
468f48ad614SDennis Dalessandro * copied to chip entry. SDMA_TXREQ_F_USE_AHG causes the code to add in
469f48ad614SDennis Dalessandro * the AHG descriptors into the first 1 to 3 descriptors.
470f48ad614SDennis Dalessandro *
471f48ad614SDennis Dalessandro * Completions of submitted requests can be gotten on selected
472f48ad614SDennis Dalessandro * txreqs by giving a completion routine callback to sdma_txinit() or
473f48ad614SDennis Dalessandro * sdma_txinit_ahg(). The environment in which the callback runs
474f48ad614SDennis Dalessandro * can be from an ISR, a tasklet, or a thread, so no sleeping
475f48ad614SDennis Dalessandro * kernel routines can be used. Aspects of the sdma ring may
476f48ad614SDennis Dalessandro * be locked so care should be taken with locking.
477f48ad614SDennis Dalessandro *
478f48ad614SDennis Dalessandro * The callback pointer can be NULL to avoid any callback for the packet
479f48ad614SDennis Dalessandro * being submitted. The callback will be provided this tx, a status, and a flag.
480f48ad614SDennis Dalessandro *
481f48ad614SDennis Dalessandro * The status will be one of SDMA_TXREQ_S_OK, SDMA_TXREQ_S_SENDERROR,
482f48ad614SDennis Dalessandro * SDMA_TXREQ_S_ABORTED, or SDMA_TXREQ_S_SHUTDOWN.
483f48ad614SDennis Dalessandro *
484f48ad614SDennis Dalessandro * The flag, if the is the iowait had been used, indicates the iowait
485f48ad614SDennis Dalessandro * sdma_busy count has reached zero.
486f48ad614SDennis Dalessandro *
487f48ad614SDennis Dalessandro * user data portion of tlen should be precise. The sdma_txadd_* entrances
488f48ad614SDennis Dalessandro * will pad with a descriptor references 1 - 3 bytes when the number of bytes
489f48ad614SDennis Dalessandro * specified in tlen have been supplied to the sdma_txreq.
490f48ad614SDennis Dalessandro *
491f48ad614SDennis Dalessandro * ahg_hlen is used to determine the number of on-chip entry bytes to
492f48ad614SDennis Dalessandro * use as the header. This is for cases where the stored header is
493f48ad614SDennis Dalessandro * larger than the header to be used in a packet. This is typical
494f48ad614SDennis Dalessandro * for verbs where an RDMA_WRITE_FIRST is larger than the packet in
495f48ad614SDennis Dalessandro * and RDMA_WRITE_MIDDLE.
496f48ad614SDennis Dalessandro *
497f48ad614SDennis Dalessandro */
sdma_txinit_ahg(struct sdma_txreq * tx,u16 flags,u16 tlen,u8 ahg_entry,u8 num_ahg,u32 * ahg,u8 ahg_hlen,void (* cb)(struct sdma_txreq *,int))498f48ad614SDennis Dalessandro static inline int sdma_txinit_ahg(
499f48ad614SDennis Dalessandro struct sdma_txreq *tx,
500f48ad614SDennis Dalessandro u16 flags,
501f48ad614SDennis Dalessandro u16 tlen,
502f48ad614SDennis Dalessandro u8 ahg_entry,
503f48ad614SDennis Dalessandro u8 num_ahg,
504f48ad614SDennis Dalessandro u32 *ahg,
505f48ad614SDennis Dalessandro u8 ahg_hlen,
506f48ad614SDennis Dalessandro void (*cb)(struct sdma_txreq *, int))
507f48ad614SDennis Dalessandro {
508f48ad614SDennis Dalessandro if (tlen == 0)
509f48ad614SDennis Dalessandro return -ENODATA;
510f48ad614SDennis Dalessandro if (tlen > MAX_SDMA_PKT_SIZE)
511f48ad614SDennis Dalessandro return -EMSGSIZE;
512f48ad614SDennis Dalessandro tx->desc_limit = ARRAY_SIZE(tx->descs);
513f48ad614SDennis Dalessandro tx->descp = &tx->descs[0];
514f48ad614SDennis Dalessandro INIT_LIST_HEAD(&tx->list);
515f48ad614SDennis Dalessandro tx->num_desc = 0;
516f48ad614SDennis Dalessandro tx->flags = flags;
517f48ad614SDennis Dalessandro tx->complete = cb;
518f48ad614SDennis Dalessandro tx->coalesce_buf = NULL;
519f48ad614SDennis Dalessandro tx->wait = NULL;
520f48ad614SDennis Dalessandro tx->packet_len = tlen;
521f48ad614SDennis Dalessandro tx->tlen = tx->packet_len;
522f48ad614SDennis Dalessandro tx->descs[0].qw[0] = SDMA_DESC0_FIRST_DESC_FLAG;
523f48ad614SDennis Dalessandro tx->descs[0].qw[1] = 0;
524f48ad614SDennis Dalessandro if (flags & SDMA_TXREQ_F_AHG_COPY)
525f48ad614SDennis Dalessandro tx->descs[0].qw[1] |=
526f48ad614SDennis Dalessandro (((u64)ahg_entry & SDMA_DESC1_HEADER_INDEX_MASK)
527f48ad614SDennis Dalessandro << SDMA_DESC1_HEADER_INDEX_SHIFT) |
528f48ad614SDennis Dalessandro (((u64)SDMA_AHG_COPY & SDMA_DESC1_HEADER_MODE_MASK)
529f48ad614SDennis Dalessandro << SDMA_DESC1_HEADER_MODE_SHIFT);
530f48ad614SDennis Dalessandro else if (flags & SDMA_TXREQ_F_USE_AHG && num_ahg)
531f48ad614SDennis Dalessandro _sdma_txreq_ahgadd(tx, num_ahg, ahg_entry, ahg, ahg_hlen);
532f48ad614SDennis Dalessandro return 0;
533f48ad614SDennis Dalessandro }
534f48ad614SDennis Dalessandro
535f48ad614SDennis Dalessandro /**
536f48ad614SDennis Dalessandro * sdma_txinit() - initialize an sdma_txreq struct (no AHG)
537f48ad614SDennis Dalessandro * @tx: tx request to initialize
538f48ad614SDennis Dalessandro * @flags: flags to key last descriptor additions
539f48ad614SDennis Dalessandro * @tlen: total packet length (pbc + headers + data)
540f48ad614SDennis Dalessandro * @cb: callback pointer
541f48ad614SDennis Dalessandro *
542f48ad614SDennis Dalessandro * The allocation of the sdma_txreq and it enclosing structure is user
543f48ad614SDennis Dalessandro * dependent. This routine must be called to initialize the user
544f48ad614SDennis Dalessandro * independent fields.
545f48ad614SDennis Dalessandro *
546f48ad614SDennis Dalessandro * The currently supported flags is SDMA_TXREQ_F_URGENT.
547f48ad614SDennis Dalessandro *
548f48ad614SDennis Dalessandro * SDMA_TXREQ_F_URGENT is used for latency sensitive situations where the
549f48ad614SDennis Dalessandro * completion is desired as soon as possible.
550f48ad614SDennis Dalessandro *
551f48ad614SDennis Dalessandro * Completions of submitted requests can be gotten on selected
552f48ad614SDennis Dalessandro * txreqs by giving a completion routine callback to sdma_txinit() or
553f48ad614SDennis Dalessandro * sdma_txinit_ahg(). The environment in which the callback runs
554f48ad614SDennis Dalessandro * can be from an ISR, a tasklet, or a thread, so no sleeping
555f48ad614SDennis Dalessandro * kernel routines can be used. The head size of the sdma ring may
556f48ad614SDennis Dalessandro * be locked so care should be taken with locking.
557f48ad614SDennis Dalessandro *
558f48ad614SDennis Dalessandro * The callback pointer can be NULL to avoid any callback for the packet
559f48ad614SDennis Dalessandro * being submitted.
560f48ad614SDennis Dalessandro *
561f48ad614SDennis Dalessandro * The callback, if non-NULL, will be provided this tx and a status. The
562f48ad614SDennis Dalessandro * status will be one of SDMA_TXREQ_S_OK, SDMA_TXREQ_S_SENDERROR,
563f48ad614SDennis Dalessandro * SDMA_TXREQ_S_ABORTED, or SDMA_TXREQ_S_SHUTDOWN.
564f48ad614SDennis Dalessandro *
565f48ad614SDennis Dalessandro */
sdma_txinit(struct sdma_txreq * tx,u16 flags,u16 tlen,void (* cb)(struct sdma_txreq *,int))566f48ad614SDennis Dalessandro static inline int sdma_txinit(
567f48ad614SDennis Dalessandro struct sdma_txreq *tx,
568f48ad614SDennis Dalessandro u16 flags,
569f48ad614SDennis Dalessandro u16 tlen,
570f48ad614SDennis Dalessandro void (*cb)(struct sdma_txreq *, int))
571f48ad614SDennis Dalessandro {
572f48ad614SDennis Dalessandro return sdma_txinit_ahg(tx, flags, tlen, 0, 0, NULL, 0, cb);
573f48ad614SDennis Dalessandro }
574f48ad614SDennis Dalessandro
575f48ad614SDennis Dalessandro /* helpers - don't use */
sdma_mapping_type(struct sdma_desc * d)576f48ad614SDennis Dalessandro static inline int sdma_mapping_type(struct sdma_desc *d)
577f48ad614SDennis Dalessandro {
578f48ad614SDennis Dalessandro return (d->qw[1] & SDMA_DESC1_GENERATION_SMASK)
579f48ad614SDennis Dalessandro >> SDMA_DESC1_GENERATION_SHIFT;
580f48ad614SDennis Dalessandro }
581f48ad614SDennis Dalessandro
sdma_mapping_len(struct sdma_desc * d)582f48ad614SDennis Dalessandro static inline size_t sdma_mapping_len(struct sdma_desc *d)
583f48ad614SDennis Dalessandro {
584f48ad614SDennis Dalessandro return (d->qw[0] & SDMA_DESC0_BYTE_COUNT_SMASK)
585f48ad614SDennis Dalessandro >> SDMA_DESC0_BYTE_COUNT_SHIFT;
586f48ad614SDennis Dalessandro }
587f48ad614SDennis Dalessandro
sdma_mapping_addr(struct sdma_desc * d)588f48ad614SDennis Dalessandro static inline dma_addr_t sdma_mapping_addr(struct sdma_desc *d)
589f48ad614SDennis Dalessandro {
590f48ad614SDennis Dalessandro return (d->qw[0] & SDMA_DESC0_PHY_ADDR_SMASK)
591f48ad614SDennis Dalessandro >> SDMA_DESC0_PHY_ADDR_SHIFT;
592f48ad614SDennis Dalessandro }
593f48ad614SDennis Dalessandro
make_tx_sdma_desc(struct sdma_txreq * tx,int type,dma_addr_t addr,size_t len,void * pinning_ctx,void (* ctx_get)(void *),void (* ctx_put)(void *))594f48ad614SDennis Dalessandro static inline void make_tx_sdma_desc(
595f48ad614SDennis Dalessandro struct sdma_txreq *tx,
596f48ad614SDennis Dalessandro int type,
597f48ad614SDennis Dalessandro dma_addr_t addr,
598c9358de1SBrendan Cunningham size_t len,
599c9358de1SBrendan Cunningham void *pinning_ctx,
600c9358de1SBrendan Cunningham void (*ctx_get)(void *),
601c9358de1SBrendan Cunningham void (*ctx_put)(void *))
602f48ad614SDennis Dalessandro {
603f48ad614SDennis Dalessandro struct sdma_desc *desc = &tx->descp[tx->num_desc];
604f48ad614SDennis Dalessandro
605f48ad614SDennis Dalessandro if (!tx->num_desc) {
606f48ad614SDennis Dalessandro /* qw[0] zero; qw[1] first, ahg mode already in from init */
607f48ad614SDennis Dalessandro desc->qw[1] |= ((u64)type & SDMA_DESC1_GENERATION_MASK)
608f48ad614SDennis Dalessandro << SDMA_DESC1_GENERATION_SHIFT;
609f48ad614SDennis Dalessandro } else {
610f48ad614SDennis Dalessandro desc->qw[0] = 0;
611f48ad614SDennis Dalessandro desc->qw[1] = ((u64)type & SDMA_DESC1_GENERATION_MASK)
612f48ad614SDennis Dalessandro << SDMA_DESC1_GENERATION_SHIFT;
613f48ad614SDennis Dalessandro }
614f48ad614SDennis Dalessandro desc->qw[0] |= (((u64)addr & SDMA_DESC0_PHY_ADDR_MASK)
615f48ad614SDennis Dalessandro << SDMA_DESC0_PHY_ADDR_SHIFT) |
616f48ad614SDennis Dalessandro (((u64)len & SDMA_DESC0_BYTE_COUNT_MASK)
617f48ad614SDennis Dalessandro << SDMA_DESC0_BYTE_COUNT_SHIFT);
618c9358de1SBrendan Cunningham
61900cbce5cSPatrick Kelsey desc->pinning_ctx = pinning_ctx;
620c9358de1SBrendan Cunningham desc->ctx_put = ctx_put;
621c9358de1SBrendan Cunningham if (pinning_ctx && ctx_get)
622c9358de1SBrendan Cunningham ctx_get(pinning_ctx);
623f48ad614SDennis Dalessandro }
624f48ad614SDennis Dalessandro
625f48ad614SDennis Dalessandro /* helper to extend txreq */
626f48ad614SDennis Dalessandro int ext_coal_sdma_tx_descs(struct hfi1_devdata *dd, struct sdma_txreq *tx,
627f48ad614SDennis Dalessandro int type, void *kvaddr, struct page *page,
628f48ad614SDennis Dalessandro unsigned long offset, u16 len);
629f48ad614SDennis Dalessandro int _pad_sdma_tx_descs(struct hfi1_devdata *, struct sdma_txreq *);
63063df8e09SMike Marciniszyn void __sdma_txclean(struct hfi1_devdata *, struct sdma_txreq *);
63163df8e09SMike Marciniszyn
sdma_txclean(struct hfi1_devdata * dd,struct sdma_txreq * tx)63263df8e09SMike Marciniszyn static inline void sdma_txclean(struct hfi1_devdata *dd, struct sdma_txreq *tx)
63363df8e09SMike Marciniszyn {
63463df8e09SMike Marciniszyn if (tx->num_desc)
63563df8e09SMike Marciniszyn __sdma_txclean(dd, tx);
63663df8e09SMike Marciniszyn }
637f48ad614SDennis Dalessandro
638f48ad614SDennis Dalessandro /* helpers used by public routines */
_sdma_close_tx(struct hfi1_devdata * dd,struct sdma_txreq * tx)639f48ad614SDennis Dalessandro static inline void _sdma_close_tx(struct hfi1_devdata *dd,
640f48ad614SDennis Dalessandro struct sdma_txreq *tx)
641f48ad614SDennis Dalessandro {
642fd8958efSPatrick Kelsey u16 last_desc = tx->num_desc - 1;
643fd8958efSPatrick Kelsey
644fd8958efSPatrick Kelsey tx->descp[last_desc].qw[0] |= SDMA_DESC0_LAST_DESC_FLAG;
645fd8958efSPatrick Kelsey tx->descp[last_desc].qw[1] |= dd->default_desc1;
646f48ad614SDennis Dalessandro if (tx->flags & SDMA_TXREQ_F_URGENT)
647fd8958efSPatrick Kelsey tx->descp[last_desc].qw[1] |= (SDMA_DESC1_HEAD_TO_HOST_FLAG |
648f48ad614SDennis Dalessandro SDMA_DESC1_INT_REQ_FLAG);
649f48ad614SDennis Dalessandro }
650f48ad614SDennis Dalessandro
_sdma_txadd_daddr(struct hfi1_devdata * dd,int type,struct sdma_txreq * tx,dma_addr_t addr,u16 len,void * pinning_ctx,void (* ctx_get)(void *),void (* ctx_put)(void *))651f48ad614SDennis Dalessandro static inline int _sdma_txadd_daddr(
652f48ad614SDennis Dalessandro struct hfi1_devdata *dd,
653f48ad614SDennis Dalessandro int type,
654f48ad614SDennis Dalessandro struct sdma_txreq *tx,
655f48ad614SDennis Dalessandro dma_addr_t addr,
656c9358de1SBrendan Cunningham u16 len,
657c9358de1SBrendan Cunningham void *pinning_ctx,
658c9358de1SBrendan Cunningham void (*ctx_get)(void *),
659c9358de1SBrendan Cunningham void (*ctx_put)(void *))
660f48ad614SDennis Dalessandro {
661f48ad614SDennis Dalessandro int rval = 0;
662f48ad614SDennis Dalessandro
663f48ad614SDennis Dalessandro make_tx_sdma_desc(
664f48ad614SDennis Dalessandro tx,
665f48ad614SDennis Dalessandro type,
666c9358de1SBrendan Cunningham addr, len,
667c9358de1SBrendan Cunningham pinning_ctx, ctx_get, ctx_put);
668f48ad614SDennis Dalessandro WARN_ON(len > tx->tlen);
669fd8958efSPatrick Kelsey tx->num_desc++;
670f48ad614SDennis Dalessandro tx->tlen -= len;
671f48ad614SDennis Dalessandro /* special cases for last */
672f48ad614SDennis Dalessandro if (!tx->tlen) {
673f48ad614SDennis Dalessandro if (tx->packet_len & (sizeof(u32) - 1)) {
674f48ad614SDennis Dalessandro rval = _pad_sdma_tx_descs(dd, tx);
675f48ad614SDennis Dalessandro if (rval)
676f48ad614SDennis Dalessandro return rval;
677f48ad614SDennis Dalessandro } else {
678f48ad614SDennis Dalessandro _sdma_close_tx(dd, tx);
679f48ad614SDennis Dalessandro }
680f48ad614SDennis Dalessandro }
681f48ad614SDennis Dalessandro return rval;
682f48ad614SDennis Dalessandro }
683f48ad614SDennis Dalessandro
684f48ad614SDennis Dalessandro /**
685f48ad614SDennis Dalessandro * sdma_txadd_page() - add a page to the sdma_txreq
686f48ad614SDennis Dalessandro * @dd: the device to use for mapping
687f48ad614SDennis Dalessandro * @tx: tx request to which the page is added
688f48ad614SDennis Dalessandro * @page: page to map
689f48ad614SDennis Dalessandro * @offset: offset within the page
690f48ad614SDennis Dalessandro * @len: length in bytes
691c9358de1SBrendan Cunningham * @pinning_ctx: context to be stored on struct sdma_desc .pinning_ctx. Not
692c9358de1SBrendan Cunningham * added if coalesce buffer is used. E.g. pointer to pinned-page
693c9358de1SBrendan Cunningham * cache entry for the sdma_desc.
694c9358de1SBrendan Cunningham * @ctx_get: optional function to take reference to @pinning_ctx. Not called if
695c9358de1SBrendan Cunningham * @pinning_ctx is NULL.
696c9358de1SBrendan Cunningham * @ctx_put: optional function to release reference to @pinning_ctx after
697c9358de1SBrendan Cunningham * sdma_desc completes. May be called in interrupt context so must
698c9358de1SBrendan Cunningham * not sleep. Not called if @pinning_ctx is NULL.
699f48ad614SDennis Dalessandro *
700f48ad614SDennis Dalessandro * This is used to add a page/offset/length descriptor.
701f48ad614SDennis Dalessandro *
702f48ad614SDennis Dalessandro * The mapping/unmapping of the page/offset/len is automatically handled.
703f48ad614SDennis Dalessandro *
704f48ad614SDennis Dalessandro * Return:
705f48ad614SDennis Dalessandro * 0 - success, -ENOSPC - mapping fail, -ENOMEM - couldn't
706f48ad614SDennis Dalessandro * extend/coalesce descriptor array
707f48ad614SDennis Dalessandro */
sdma_txadd_page(struct hfi1_devdata * dd,struct sdma_txreq * tx,struct page * page,unsigned long offset,u16 len,void * pinning_ctx,void (* ctx_get)(void *),void (* ctx_put)(void *))708f48ad614SDennis Dalessandro static inline int sdma_txadd_page(
709f48ad614SDennis Dalessandro struct hfi1_devdata *dd,
710f48ad614SDennis Dalessandro struct sdma_txreq *tx,
711f48ad614SDennis Dalessandro struct page *page,
712f48ad614SDennis Dalessandro unsigned long offset,
713c9358de1SBrendan Cunningham u16 len,
714c9358de1SBrendan Cunningham void *pinning_ctx,
715c9358de1SBrendan Cunningham void (*ctx_get)(void *),
716c9358de1SBrendan Cunningham void (*ctx_put)(void *))
717f48ad614SDennis Dalessandro {
718f48ad614SDennis Dalessandro dma_addr_t addr;
719f48ad614SDennis Dalessandro int rval;
720f48ad614SDennis Dalessandro
721f48ad614SDennis Dalessandro if ((unlikely(tx->num_desc == tx->desc_limit))) {
722f48ad614SDennis Dalessandro rval = ext_coal_sdma_tx_descs(dd, tx, SDMA_MAP_PAGE,
723f48ad614SDennis Dalessandro NULL, page, offset, len);
724f48ad614SDennis Dalessandro if (rval <= 0)
725f48ad614SDennis Dalessandro return rval;
726f48ad614SDennis Dalessandro }
727f48ad614SDennis Dalessandro
728f48ad614SDennis Dalessandro addr = dma_map_page(
729f48ad614SDennis Dalessandro &dd->pcidev->dev,
730f48ad614SDennis Dalessandro page,
731f48ad614SDennis Dalessandro offset,
732f48ad614SDennis Dalessandro len,
733f48ad614SDennis Dalessandro DMA_TO_DEVICE);
734f48ad614SDennis Dalessandro
735f48ad614SDennis Dalessandro if (unlikely(dma_mapping_error(&dd->pcidev->dev, addr))) {
73663df8e09SMike Marciniszyn __sdma_txclean(dd, tx);
737f48ad614SDennis Dalessandro return -ENOSPC;
738f48ad614SDennis Dalessandro }
739f48ad614SDennis Dalessandro
740c9358de1SBrendan Cunningham return _sdma_txadd_daddr(dd, SDMA_MAP_PAGE, tx, addr, len,
741c9358de1SBrendan Cunningham pinning_ctx, ctx_get, ctx_put);
742f48ad614SDennis Dalessandro }
743f48ad614SDennis Dalessandro
744f48ad614SDennis Dalessandro /**
745f48ad614SDennis Dalessandro * sdma_txadd_daddr() - add a dma address to the sdma_txreq
746f48ad614SDennis Dalessandro * @dd: the device to use for mapping
747f48ad614SDennis Dalessandro * @tx: sdma_txreq to which the page is added
748f48ad614SDennis Dalessandro * @addr: dma address mapped by caller
749f48ad614SDennis Dalessandro * @len: length in bytes
750f48ad614SDennis Dalessandro *
751f48ad614SDennis Dalessandro * This is used to add a descriptor for memory that is already dma mapped.
752f48ad614SDennis Dalessandro *
753f48ad614SDennis Dalessandro * In this case, there is no unmapping as part of the progress processing for
754f48ad614SDennis Dalessandro * this memory location.
755f48ad614SDennis Dalessandro *
756f48ad614SDennis Dalessandro * Return:
757f48ad614SDennis Dalessandro * 0 - success, -ENOMEM - couldn't extend descriptor array
758f48ad614SDennis Dalessandro */
759f48ad614SDennis Dalessandro
sdma_txadd_daddr(struct hfi1_devdata * dd,struct sdma_txreq * tx,dma_addr_t addr,u16 len)760f48ad614SDennis Dalessandro static inline int sdma_txadd_daddr(
761f48ad614SDennis Dalessandro struct hfi1_devdata *dd,
762f48ad614SDennis Dalessandro struct sdma_txreq *tx,
763f48ad614SDennis Dalessandro dma_addr_t addr,
764f48ad614SDennis Dalessandro u16 len)
765f48ad614SDennis Dalessandro {
766f48ad614SDennis Dalessandro int rval;
767f48ad614SDennis Dalessandro
768f48ad614SDennis Dalessandro if ((unlikely(tx->num_desc == tx->desc_limit))) {
769f48ad614SDennis Dalessandro rval = ext_coal_sdma_tx_descs(dd, tx, SDMA_MAP_NONE,
770f48ad614SDennis Dalessandro NULL, NULL, 0, 0);
771f48ad614SDennis Dalessandro if (rval <= 0)
772f48ad614SDennis Dalessandro return rval;
773f48ad614SDennis Dalessandro }
774f48ad614SDennis Dalessandro
775c9358de1SBrendan Cunningham return _sdma_txadd_daddr(dd, SDMA_MAP_NONE, tx, addr, len,
776c9358de1SBrendan Cunningham NULL, NULL, NULL);
777f48ad614SDennis Dalessandro }
778f48ad614SDennis Dalessandro
779f48ad614SDennis Dalessandro /**
780f48ad614SDennis Dalessandro * sdma_txadd_kvaddr() - add a kernel virtual address to sdma_txreq
781f48ad614SDennis Dalessandro * @dd: the device to use for mapping
782f48ad614SDennis Dalessandro * @tx: sdma_txreq to which the page is added
783f48ad614SDennis Dalessandro * @kvaddr: the kernel virtual address
784f48ad614SDennis Dalessandro * @len: length in bytes
785f48ad614SDennis Dalessandro *
786f48ad614SDennis Dalessandro * This is used to add a descriptor referenced by the indicated kvaddr and
787f48ad614SDennis Dalessandro * len.
788f48ad614SDennis Dalessandro *
789f48ad614SDennis Dalessandro * The mapping/unmapping of the kvaddr and len is automatically handled.
790f48ad614SDennis Dalessandro *
791f48ad614SDennis Dalessandro * Return:
792f48ad614SDennis Dalessandro * 0 - success, -ENOSPC - mapping fail, -ENOMEM - couldn't extend/coalesce
793f48ad614SDennis Dalessandro * descriptor array
794f48ad614SDennis Dalessandro */
sdma_txadd_kvaddr(struct hfi1_devdata * dd,struct sdma_txreq * tx,void * kvaddr,u16 len)795f48ad614SDennis Dalessandro static inline int sdma_txadd_kvaddr(
796f48ad614SDennis Dalessandro struct hfi1_devdata *dd,
797f48ad614SDennis Dalessandro struct sdma_txreq *tx,
798f48ad614SDennis Dalessandro void *kvaddr,
799f48ad614SDennis Dalessandro u16 len)
800f48ad614SDennis Dalessandro {
801f48ad614SDennis Dalessandro dma_addr_t addr;
802f48ad614SDennis Dalessandro int rval;
803f48ad614SDennis Dalessandro
804f48ad614SDennis Dalessandro if ((unlikely(tx->num_desc == tx->desc_limit))) {
805f48ad614SDennis Dalessandro rval = ext_coal_sdma_tx_descs(dd, tx, SDMA_MAP_SINGLE,
806f48ad614SDennis Dalessandro kvaddr, NULL, 0, len);
807f48ad614SDennis Dalessandro if (rval <= 0)
808f48ad614SDennis Dalessandro return rval;
809f48ad614SDennis Dalessandro }
810f48ad614SDennis Dalessandro
811f48ad614SDennis Dalessandro addr = dma_map_single(
812f48ad614SDennis Dalessandro &dd->pcidev->dev,
813f48ad614SDennis Dalessandro kvaddr,
814f48ad614SDennis Dalessandro len,
815f48ad614SDennis Dalessandro DMA_TO_DEVICE);
816f48ad614SDennis Dalessandro
817f48ad614SDennis Dalessandro if (unlikely(dma_mapping_error(&dd->pcidev->dev, addr))) {
81863df8e09SMike Marciniszyn __sdma_txclean(dd, tx);
819f48ad614SDennis Dalessandro return -ENOSPC;
820f48ad614SDennis Dalessandro }
821f48ad614SDennis Dalessandro
822c9358de1SBrendan Cunningham return _sdma_txadd_daddr(dd, SDMA_MAP_SINGLE, tx, addr, len,
823c9358de1SBrendan Cunningham NULL, NULL, NULL);
824f48ad614SDennis Dalessandro }
825f48ad614SDennis Dalessandro
8265da0fc9dSDennis Dalessandro struct iowait_work;
827f48ad614SDennis Dalessandro
828f48ad614SDennis Dalessandro int sdma_send_txreq(struct sdma_engine *sde,
8295da0fc9dSDennis Dalessandro struct iowait_work *wait,
830bcad2913SKaike Wan struct sdma_txreq *tx,
831bcad2913SKaike Wan bool pkts_sent);
832f48ad614SDennis Dalessandro int sdma_send_txlist(struct sdma_engine *sde,
8335da0fc9dSDennis Dalessandro struct iowait_work *wait,
8340b115ef1SHarish Chegondi struct list_head *tx_list,
8353ca633f1SMichael J. Ruhl u16 *count_out);
836f48ad614SDennis Dalessandro
837f48ad614SDennis Dalessandro int sdma_ahg_alloc(struct sdma_engine *sde);
838f48ad614SDennis Dalessandro void sdma_ahg_free(struct sdma_engine *sde, int ahg_index);
839f48ad614SDennis Dalessandro
840f48ad614SDennis Dalessandro /**
841f48ad614SDennis Dalessandro * sdma_build_ahg - build ahg descriptor
842f48ad614SDennis Dalessandro * @data
843f48ad614SDennis Dalessandro * @dwindex
844f48ad614SDennis Dalessandro * @startbit
845f48ad614SDennis Dalessandro * @bits
846f48ad614SDennis Dalessandro *
847f48ad614SDennis Dalessandro * Build and return a 32 bit descriptor.
848f48ad614SDennis Dalessandro */
sdma_build_ahg_descriptor(u16 data,u8 dwindex,u8 startbit,u8 bits)849f48ad614SDennis Dalessandro static inline u32 sdma_build_ahg_descriptor(
850f48ad614SDennis Dalessandro u16 data,
851f48ad614SDennis Dalessandro u8 dwindex,
852f48ad614SDennis Dalessandro u8 startbit,
853f48ad614SDennis Dalessandro u8 bits)
854f48ad614SDennis Dalessandro {
855f48ad614SDennis Dalessandro return (u32)(1UL << SDMA_AHG_UPDATE_ENABLE_SHIFT |
856f48ad614SDennis Dalessandro ((startbit & SDMA_AHG_FIELD_START_MASK) <<
857f48ad614SDennis Dalessandro SDMA_AHG_FIELD_START_SHIFT) |
858f48ad614SDennis Dalessandro ((bits & SDMA_AHG_FIELD_LEN_MASK) <<
859f48ad614SDennis Dalessandro SDMA_AHG_FIELD_LEN_SHIFT) |
860f48ad614SDennis Dalessandro ((dwindex & SDMA_AHG_INDEX_MASK) <<
861f48ad614SDennis Dalessandro SDMA_AHG_INDEX_SHIFT) |
862f48ad614SDennis Dalessandro ((data & SDMA_AHG_VALUE_MASK) <<
863f48ad614SDennis Dalessandro SDMA_AHG_VALUE_SHIFT));
864f48ad614SDennis Dalessandro }
865f48ad614SDennis Dalessandro
866f48ad614SDennis Dalessandro /**
867f48ad614SDennis Dalessandro * sdma_progress - use seq number of detect head progress
868f48ad614SDennis Dalessandro * @sde: sdma_engine to check
869f48ad614SDennis Dalessandro * @seq: base seq count
870f48ad614SDennis Dalessandro * @tx: txreq for which we need to check descriptor availability
871f48ad614SDennis Dalessandro *
872f48ad614SDennis Dalessandro * This is used in the appropriate spot in the sleep routine
873f48ad614SDennis Dalessandro * to check for potential ring progress. This routine gets the
874f48ad614SDennis Dalessandro * seqcount before queuing the iowait structure for progress.
875f48ad614SDennis Dalessandro *
876f48ad614SDennis Dalessandro * If the seqcount indicates that progress needs to be checked,
877f48ad614SDennis Dalessandro * re-submission is detected by checking whether the descriptor
878f48ad614SDennis Dalessandro * queue has enough descriptor for the txreq.
879f48ad614SDennis Dalessandro */
sdma_progress(struct sdma_engine * sde,unsigned seq,struct sdma_txreq * tx)880f48ad614SDennis Dalessandro static inline unsigned sdma_progress(struct sdma_engine *sde, unsigned seq,
881f48ad614SDennis Dalessandro struct sdma_txreq *tx)
882f48ad614SDennis Dalessandro {
883f48ad614SDennis Dalessandro if (read_seqretry(&sde->head_lock, seq)) {
884f48ad614SDennis Dalessandro sde->desc_avail = sdma_descq_freecnt(sde);
885f48ad614SDennis Dalessandro if (tx->num_desc > sde->desc_avail)
886f48ad614SDennis Dalessandro return 0;
887f48ad614SDennis Dalessandro return 1;
888f48ad614SDennis Dalessandro }
889f48ad614SDennis Dalessandro return 0;
890f48ad614SDennis Dalessandro }
891f48ad614SDennis Dalessandro
892f48ad614SDennis Dalessandro /* for use by interrupt handling */
893f48ad614SDennis Dalessandro void sdma_engine_error(struct sdma_engine *sde, u64 status);
894f48ad614SDennis Dalessandro void sdma_engine_interrupt(struct sdma_engine *sde, u64 status);
895f48ad614SDennis Dalessandro
896f48ad614SDennis Dalessandro /*
897f48ad614SDennis Dalessandro *
898f48ad614SDennis Dalessandro * The diagram below details the relationship of the mapping structures
899f48ad614SDennis Dalessandro *
900f48ad614SDennis Dalessandro * Since the mapping now allows for non-uniform engines per vl, the
901f48ad614SDennis Dalessandro * number of engines for a vl is either the vl_engines[vl] or
902f48ad614SDennis Dalessandro * a computation based on num_sdma/num_vls:
903f48ad614SDennis Dalessandro *
904f48ad614SDennis Dalessandro * For example:
905f48ad614SDennis Dalessandro * nactual = vl_engines ? vl_engines[vl] : num_sdma/num_vls
906f48ad614SDennis Dalessandro *
907f48ad614SDennis Dalessandro * n = roundup to next highest power of 2 using nactual
908f48ad614SDennis Dalessandro *
909f48ad614SDennis Dalessandro * In the case where there are num_sdma/num_vls doesn't divide
910f48ad614SDennis Dalessandro * evenly, the extras are added from the last vl downward.
911f48ad614SDennis Dalessandro *
912f48ad614SDennis Dalessandro * For the case where n > nactual, the engines are assigned
913f48ad614SDennis Dalessandro * in a round robin fashion wrapping back to the first engine
914f48ad614SDennis Dalessandro * for a particular vl.
915f48ad614SDennis Dalessandro *
916f48ad614SDennis Dalessandro * dd->sdma_map
917f48ad614SDennis Dalessandro * | sdma_map_elem[0]
918f48ad614SDennis Dalessandro * | +--------------------+
919f48ad614SDennis Dalessandro * v | mask |
920f48ad614SDennis Dalessandro * sdma_vl_map |--------------------|
921f48ad614SDennis Dalessandro * +--------------------------+ | sde[0] -> eng 1 |
922f48ad614SDennis Dalessandro * | list (RCU) | |--------------------|
923f48ad614SDennis Dalessandro * |--------------------------| ->| sde[1] -> eng 2 |
924f48ad614SDennis Dalessandro * | mask | --/ |--------------------|
925f48ad614SDennis Dalessandro * |--------------------------| -/ | * |
926f48ad614SDennis Dalessandro * | actual_vls (max 8) | -/ |--------------------|
927e8ea95afSIra Weiny * |--------------------------| --/ | sde[n-1] -> eng n |
928f48ad614SDennis Dalessandro * | vls (max 8) | -/ +--------------------+
929f48ad614SDennis Dalessandro * |--------------------------| --/
930f48ad614SDennis Dalessandro * | map[0] |-/
931e8ea95afSIra Weiny * |--------------------------| +---------------------+
932f48ad614SDennis Dalessandro * | map[1] |--- | mask |
933e8ea95afSIra Weiny * |--------------------------| \---- |---------------------|
934f48ad614SDennis Dalessandro * | * | \-- | sde[0] -> eng 1+n |
935e8ea95afSIra Weiny * | * | \---- |---------------------|
936f48ad614SDennis Dalessandro * | * | \->| sde[1] -> eng 2+n |
937e8ea95afSIra Weiny * |--------------------------| |---------------------|
938f48ad614SDennis Dalessandro * | map[vls - 1] |- | * |
939e8ea95afSIra Weiny * +--------------------------+ \- |---------------------|
940e8ea95afSIra Weiny * \- | sde[m-1] -> eng m+n |
941e8ea95afSIra Weiny * \ +---------------------+
942f48ad614SDennis Dalessandro * \-
943f48ad614SDennis Dalessandro * \
944e8ea95afSIra Weiny * \- +----------------------+
945f48ad614SDennis Dalessandro * \- | mask |
946e8ea95afSIra Weiny * \ |----------------------|
947f48ad614SDennis Dalessandro * \- | sde[0] -> eng 1+m+n |
948e8ea95afSIra Weiny * \- |----------------------|
949f48ad614SDennis Dalessandro * >| sde[1] -> eng 2+m+n |
950e8ea95afSIra Weiny * |----------------------|
951f48ad614SDennis Dalessandro * | * |
952e8ea95afSIra Weiny * |----------------------|
953e8ea95afSIra Weiny * | sde[o-1] -> eng o+m+n|
954e8ea95afSIra Weiny * +----------------------+
955f48ad614SDennis Dalessandro *
956f48ad614SDennis Dalessandro */
957f48ad614SDennis Dalessandro
958f48ad614SDennis Dalessandro /**
959f48ad614SDennis Dalessandro * struct sdma_map_elem - mapping for a vl
960f48ad614SDennis Dalessandro * @mask - selector mask
961f48ad614SDennis Dalessandro * @sde - array of engines for this vl
962f48ad614SDennis Dalessandro *
963f48ad614SDennis Dalessandro * The mask is used to "mod" the selector
964f48ad614SDennis Dalessandro * to produce index into the trailing
965f48ad614SDennis Dalessandro * array of sdes.
966f48ad614SDennis Dalessandro */
967f48ad614SDennis Dalessandro struct sdma_map_elem {
968f48ad614SDennis Dalessandro u32 mask;
9695b361328SGustavo A. R. Silva struct sdma_engine *sde[];
970f48ad614SDennis Dalessandro };
971f48ad614SDennis Dalessandro
972f48ad614SDennis Dalessandro /**
973f48ad614SDennis Dalessandro * struct sdma_map_el - mapping for a vl
974f48ad614SDennis Dalessandro * @engine_to_vl - map of an engine to a vl
975f48ad614SDennis Dalessandro * @list - rcu head for free callback
976f48ad614SDennis Dalessandro * @mask - vl mask to "mod" the vl to produce an index to map array
977f48ad614SDennis Dalessandro * @actual_vls - number of vls
978f48ad614SDennis Dalessandro * @vls - number of vls rounded to next power of 2
979f48ad614SDennis Dalessandro * @map - array of sdma_map_elem entries
980f48ad614SDennis Dalessandro *
981f48ad614SDennis Dalessandro * This is the parent mapping structure. The trailing
982f48ad614SDennis Dalessandro * members of the struct point to sdma_map_elem entries, which
983f48ad614SDennis Dalessandro * in turn point to an array of sde's for that vl.
984f48ad614SDennis Dalessandro */
985f48ad614SDennis Dalessandro struct sdma_vl_map {
986f48ad614SDennis Dalessandro s8 engine_to_vl[TXE_NUM_SDMA_ENGINES];
987f48ad614SDennis Dalessandro struct rcu_head list;
988f48ad614SDennis Dalessandro u32 mask;
989f48ad614SDennis Dalessandro u8 actual_vls;
990f48ad614SDennis Dalessandro u8 vls;
9915b361328SGustavo A. R. Silva struct sdma_map_elem *map[];
992f48ad614SDennis Dalessandro };
993f48ad614SDennis Dalessandro
994f48ad614SDennis Dalessandro int sdma_map_init(
995f48ad614SDennis Dalessandro struct hfi1_devdata *dd,
996f48ad614SDennis Dalessandro u8 port,
997f48ad614SDennis Dalessandro u8 num_vls,
998f48ad614SDennis Dalessandro u8 *vl_engines);
999f48ad614SDennis Dalessandro
1000f48ad614SDennis Dalessandro /* slow path */
1001f48ad614SDennis Dalessandro void _sdma_engine_progress_schedule(struct sdma_engine *sde);
1002f48ad614SDennis Dalessandro
1003f48ad614SDennis Dalessandro /**
1004f48ad614SDennis Dalessandro * sdma_engine_progress_schedule() - schedule progress on engine
1005f48ad614SDennis Dalessandro * @sde: sdma_engine to schedule progress
1006f48ad614SDennis Dalessandro *
1007f48ad614SDennis Dalessandro * This is the fast path.
1008f48ad614SDennis Dalessandro *
1009f48ad614SDennis Dalessandro */
sdma_engine_progress_schedule(struct sdma_engine * sde)1010f48ad614SDennis Dalessandro static inline void sdma_engine_progress_schedule(
1011f48ad614SDennis Dalessandro struct sdma_engine *sde)
1012f48ad614SDennis Dalessandro {
1013f48ad614SDennis Dalessandro if (!sde || sdma_descq_inprocess(sde) < (sde->descq_cnt / 8))
1014f48ad614SDennis Dalessandro return;
1015f48ad614SDennis Dalessandro _sdma_engine_progress_schedule(sde);
1016f48ad614SDennis Dalessandro }
1017f48ad614SDennis Dalessandro
1018f48ad614SDennis Dalessandro struct sdma_engine *sdma_select_engine_sc(
1019f48ad614SDennis Dalessandro struct hfi1_devdata *dd,
1020f48ad614SDennis Dalessandro u32 selector,
1021f48ad614SDennis Dalessandro u8 sc5);
1022f48ad614SDennis Dalessandro
1023f48ad614SDennis Dalessandro struct sdma_engine *sdma_select_engine_vl(
1024f48ad614SDennis Dalessandro struct hfi1_devdata *dd,
1025f48ad614SDennis Dalessandro u32 selector,
1026f48ad614SDennis Dalessandro u8 vl);
1027f48ad614SDennis Dalessandro
10280cb2aa69STadeusz Struk struct sdma_engine *sdma_select_user_engine(struct hfi1_devdata *dd,
10290cb2aa69STadeusz Struk u32 selector, u8 vl);
10300cb2aa69STadeusz Struk ssize_t sdma_get_cpu_to_sde_map(struct sdma_engine *sde, char *buf);
10310cb2aa69STadeusz Struk ssize_t sdma_set_cpu_to_sde_map(struct sdma_engine *sde, const char *buf,
10320cb2aa69STadeusz Struk size_t count);
10330cb2aa69STadeusz Struk int sdma_engine_get_vl(struct sdma_engine *sde);
1034f48ad614SDennis Dalessandro void sdma_seqfile_dump_sde(struct seq_file *s, struct sdma_engine *);
1035af3674d6STadeusz Struk void sdma_seqfile_dump_cpu_list(struct seq_file *s, struct hfi1_devdata *dd,
1036af3674d6STadeusz Struk unsigned long cpuid);
1037f48ad614SDennis Dalessandro
1038f48ad614SDennis Dalessandro #ifdef CONFIG_SDMA_VERBOSITY
1039f48ad614SDennis Dalessandro void sdma_dumpstate(struct sdma_engine *);
1040f48ad614SDennis Dalessandro #endif
slashstrip(char * s)1041f48ad614SDennis Dalessandro static inline char *slashstrip(char *s)
1042f48ad614SDennis Dalessandro {
1043f48ad614SDennis Dalessandro char *r = s;
1044f48ad614SDennis Dalessandro
1045f48ad614SDennis Dalessandro while (*s)
1046f48ad614SDennis Dalessandro if (*s++ == '/')
1047f48ad614SDennis Dalessandro r = s;
1048f48ad614SDennis Dalessandro return r;
1049f48ad614SDennis Dalessandro }
1050f48ad614SDennis Dalessandro
1051f48ad614SDennis Dalessandro u16 sdma_get_descq_cnt(void);
1052f48ad614SDennis Dalessandro
1053f48ad614SDennis Dalessandro extern uint mod_num_sdma;
1054f48ad614SDennis Dalessandro
1055f48ad614SDennis Dalessandro void sdma_update_lmc(struct hfi1_devdata *dd, u64 mask, u32 lid);
1056f48ad614SDennis Dalessandro #endif
1057