1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (c) 2020, Oracle and/or its affiliates
9 #include <linux/list.h>
11 struct svc_rdma_segment {
17 struct svc_rdma_chunk {
18 struct list_head ch_list;
22 u32 ch_payload_length;
25 struct svc_rdma_segment ch_segments[];
29 unsigned int cl_count;
30 struct list_head cl_chunks;
34 * pcl_init - Initialize a parsed chunk list
35 * @pcl: parsed chunk list to initialize
38 static inline void pcl_init(struct svc_rdma_pcl *pcl)
40 INIT_LIST_HEAD(&pcl->cl_chunks);
44 * pcl_is_empty - Return true if parsed chunk list is empty
45 * @pcl: parsed chunk list
48 static inline bool pcl_is_empty(const struct svc_rdma_pcl *pcl)
50 return list_empty(&pcl->cl_chunks);
54 * pcl_first_chunk - Return first chunk in a parsed chunk list
55 * @pcl: parsed chunk list
57 * Returns the first chunk in the list, or NULL if the list is empty.
59 static inline struct svc_rdma_chunk *
60 pcl_first_chunk(const struct svc_rdma_pcl *pcl)
62 if (pcl_is_empty(pcl))
64 return list_first_entry(&pcl->cl_chunks, struct svc_rdma_chunk,
69 * pcl_next_chunk - Return next chunk in a parsed chunk list
70 * @pcl: a parsed chunk list
71 * @chunk: chunk in @pcl
73 * Returns the next chunk in the list, or NULL if @chunk is already last.
75 static inline struct svc_rdma_chunk *
76 pcl_next_chunk(const struct svc_rdma_pcl *pcl, struct svc_rdma_chunk *chunk)
78 if (list_is_last(&chunk->ch_list, &pcl->cl_chunks))
80 return list_next_entry(chunk, ch_list);
84 * pcl_for_each_chunk - Iterate over chunks in a parsed chunk list
85 * @pos: the loop cursor
86 * @pcl: a parsed chunk list
88 #define pcl_for_each_chunk(pos, pcl) \
89 for (pos = list_first_entry(&(pcl)->cl_chunks, struct svc_rdma_chunk, ch_list); \
90 &pos->ch_list != &(pcl)->cl_chunks; \
91 pos = list_next_entry(pos, ch_list))
94 * pcl_for_each_segment - Iterate over segments in a parsed chunk
95 * @pos: the loop cursor
96 * @chunk: a parsed chunk
98 #define pcl_for_each_segment(pos, chunk) \
99 for (pos = &(chunk)->ch_segments[0]; \
100 pos <= &(chunk)->ch_segments[(chunk)->ch_segcount - 1]; \
104 * pcl_chunk_end_offset - Return offset of byte range following @chunk
105 * @chunk: chunk in @pcl
107 * Returns starting offset of the region just after @chunk
109 static inline unsigned int
110 pcl_chunk_end_offset(const struct svc_rdma_chunk *chunk)
112 return xdr_align_size(chunk->ch_position + chunk->ch_payload_length);
115 struct svc_rdma_recv_ctxt;
117 extern void pcl_free(struct svc_rdma_pcl *pcl);
118 extern bool pcl_alloc_call(struct svc_rdma_recv_ctxt *rctxt, __be32 *p);
119 extern bool pcl_alloc_read(struct svc_rdma_recv_ctxt *rctxt, __be32 *p);
120 extern bool pcl_alloc_write(struct svc_rdma_recv_ctxt *rctxt,
121 struct svc_rdma_pcl *pcl, __be32 *p);
122 extern int pcl_process_nonpayloads(const struct svc_rdma_pcl *pcl,
123 const struct xdr_buf *xdr,
124 int (*actor)(const struct xdr_buf *,
128 #endif /* SVC_RDMA_PCL_H */