1 /**
2  * Copyright (C) Mellanox Technologies Ltd. 2001-2015.  ALL RIGHTS RESERVED.
3  *
4  * See file LICENSE for terms.
5  */
6 
7 
8 #ifndef UCP_DT_IOV_H_
9 #define UCP_DT_IOV_H_
10 
11 #include <ucp/api/ucp.h>
12 
13 
14 #define UCP_DT_IS_IOV(_datatype) \
15     (((_datatype) & UCP_DATATYPE_CLASS_MASK) == UCP_DATATYPE_IOV)
16 
17 
18 /**
19  * Get the total length of the data in @a iov buffers
20  *
21  * @param [in]     iov            @ref ucp_dt_iov_t buffer
22  * @param [in]     iovcnt         Number of entries in the @a iov buffer
23  *
24  * @return Total length of data in the @a iov buffers
25  */
ucp_dt_iov_length(const ucp_dt_iov_t * iov,size_t iovcnt)26 static inline size_t ucp_dt_iov_length(const ucp_dt_iov_t *iov, size_t iovcnt)
27 {
28     size_t iov_it, total_length = 0;
29 
30     for (iov_it = 0; iov_it < iovcnt; ++iov_it) {
31         /* cppcheck-suppress nullPointer */
32         total_length += iov[iov_it].length;
33     }
34 
35     return total_length;
36 }
37 
38 /**
39  * Copy iov data buffers from @a iov to contiguous buffer @a dest with
40  * an iov item data @a iov_offset and iov item @a iovcnt_offset
41  *
42  * @param [in]     dest           Destination contiguous buffer
43  *                                (no offset applicable)
44  * @param [in]     iov            Source @ref ucp_dt_iov_t buffer
45  * @param [in]     length         Total data length to copy in bytes
46  * @param [inout]  iov_offset     The offset in bytes to start copying
47  *                                from an @a iov item pointed by
48  *                                @a iovcnt_offset. The @a iov_offset is not aligned
49  *                                by @ref ucp_dt_iov_t items length.
50  * @param [inout]  iovcnt_offset  Auxiliary offset to select @a iov item that
51  *                                belongs to the @a iov_offset. The point to start
52  *                                copying from should be selected as
53  *                                iov[iovcnt_offset].buffer + iov_offset
54  */
55 void ucp_dt_iov_gather(void *dest, const ucp_dt_iov_t *iov, size_t length,
56                        size_t *iov_offset, size_t *iovcnt_offset);
57 
58 /**
59  * Copy contiguous buffer @a src into @ref ucp_dt_iov_t data buffers in @a iov
60  * with an iov item data @a iov_offset and iov item @a iovcnt_offset
61  *
62  * @param [in]     iov            Destination @ref ucp_dt_iov_t buffer
63  * @param [in]     iovcnt         Size of the @a iov buffer
64  * @param [in]     src            Source contiguous buffer (no offset applicable)
65  * @param [in]     length         Total data length to copy in bytes
66  * @param [inout]  iov_offset     The offset in bytes to start copying
67  *                                to an @a iov item pointed by @a iovcnt_offset.
68  *                                The @a iov_offset is not aligned by
69  *                                @ref ucp_dt_iov_t items length.
70  * @param [inout]  iovcnt_offset  Auxiliary offset to select @a iov item that
71  *                                belongs to the @a iov_offset. The point to
72  *                                start copying to should be selected as
73  *                                iov[iovcnt_offset].buffer + iov_offset
74  *
75  * @return Size in bytes that was actually copied from @a src to @a iov. It must
76  *         be less or equal to @a length.
77  */
78 size_t ucp_dt_iov_scatter(ucp_dt_iov_t *iov, size_t iovcnt, const void *src,
79                           size_t length, size_t *iov_offset, size_t *iovcnt_offset);
80 
81 
82 /**
83  * Seek to a logical offset in the iov
84  *
85  * @param [in]     iov            @ref ucp_dt_iov_t buffer to seek in
86  * @param [in]     iovcnt         Number of entries in the @a iov buffer
87  * @param [in]     distance       Distance to move, relative to the current
88  *                                location
89  * @param [inout]  iov_offset     The offset in bytes from the beginning of the
90  *                                current iov entry
91  * @param [inout]  iovcnt_offset  Current @a iov item index
92  */
93 void ucp_dt_iov_seek(ucp_dt_iov_t *iov, size_t iovcnt, ptrdiff_t distance,
94                      size_t *iov_offset, size_t *iovcnt_offset);
95 
96 
97 /**
98  * Count non-empty entries in the @a iov array
99  *
100  * @param [in]     iov            @ref ucp_dt_iov_t buffer to count
101  * @param [in]     iovcnt         Number of entries in the @a iov buffer
102  *
103  * @return Number of non-empty entries in the @a iov array
104  */
105 size_t ucp_dt_iov_count_nonempty(const ucp_dt_iov_t *iov, size_t iovcnt);
106 
107 #endif
108