xref: /freebsd/sys/dev/iscsi/icl_wrappers.h (revision f126890ac5386406dadf7c4cfa9566cbb56537c5)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2014 The FreeBSD Foundation
5  *
6  * This software was developed by Edward Tomasz Napierala under sponsorship
7  * from the FreeBSD Foundation.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 /*
32  * This file is used to provide the initiator and target with a prettier
33  * interface.  It must not be included by ICL modules, such as icl_soft.c.
34  */
35 
36 #ifndef ICL_WRAPPERS_H
37 #define	ICL_WRAPPERS_H
38 
39 #include <sys/bio.h>
40 #include <sys/kobj.h>
41 
42 #include <dev/iscsi/icl.h>
43 #include <icl_conn_if.h>
44 
45 static inline struct icl_pdu *
46 icl_pdu_new(struct icl_conn *ic, int flags)
47 {
48 
49 	return (ICL_CONN_NEW_PDU(ic, flags));
50 }
51 
52 static inline size_t
53 icl_pdu_data_segment_length(const struct icl_pdu *ip)
54 {
55 
56 	return (ICL_CONN_PDU_DATA_SEGMENT_LENGTH(ip->ip_conn, ip));
57 }
58 
59 static inline int
60 icl_pdu_append_bio(struct icl_pdu *ip, struct bio *bp, size_t offset,
61     size_t len, int flags)
62 {
63 
64 	return (ICL_CONN_PDU_APPEND_BIO(ip->ip_conn, ip, bp, offset, len,
65 	    flags));
66 }
67 
68 static inline int
69 icl_pdu_append_data(struct icl_pdu *ip, const void *addr, size_t len, int flags)
70 {
71 
72 	return (ICL_CONN_PDU_APPEND_DATA(ip->ip_conn, ip, addr, len, flags));
73 }
74 
75 static inline void
76 icl_pdu_get_bio(struct icl_pdu *ip, size_t pdu_off, struct bio *bp,
77     size_t bio_off, size_t len)
78 {
79 
80 	ICL_CONN_PDU_GET_BIO(ip->ip_conn, ip, pdu_off, bp, bio_off, len);
81 }
82 
83 static inline void
84 icl_pdu_get_data(struct icl_pdu *ip, size_t off, void *addr, size_t len)
85 {
86 
87 	ICL_CONN_PDU_GET_DATA(ip->ip_conn, ip, off, addr, len);
88 }
89 
90 static inline void
91 icl_pdu_queue(struct icl_pdu *ip)
92 {
93 
94 	ICL_CONN_PDU_QUEUE(ip->ip_conn, ip);
95 }
96 
97 static inline void
98 icl_pdu_queue_cb(struct icl_pdu *ip, icl_pdu_cb cb)
99 {
100 
101 	ICL_CONN_PDU_QUEUE_CB(ip->ip_conn, ip, cb);
102 }
103 
104 static inline void
105 icl_pdu_free(struct icl_pdu *ip)
106 {
107 
108 	ICL_CONN_PDU_FREE(ip->ip_conn, ip);
109 }
110 
111 static inline void
112 icl_conn_free(struct icl_conn *ic)
113 {
114 
115 	ICL_CONN_FREE(ic);
116 }
117 
118 static inline int
119 icl_conn_handoff(struct icl_conn *ic, int fd)
120 {
121 
122 	return (ICL_CONN_HANDOFF(ic, fd));
123 }
124 
125 static inline void
126 icl_conn_close(struct icl_conn *ic)
127 {
128 
129 	ICL_CONN_CLOSE(ic);
130 }
131 
132 static inline int
133 icl_conn_task_setup(struct icl_conn *ic, struct icl_pdu *ip,
134     struct ccb_scsiio *csio, uint32_t *task_tagp, void **prvp)
135 {
136 
137 	return (ICL_CONN_TASK_SETUP(ic, ip, csio, task_tagp, prvp));
138 }
139 
140 static inline void
141 icl_conn_task_done(struct icl_conn *ic, void *prv)
142 {
143 
144 	ICL_CONN_TASK_DONE(ic, prv);
145 }
146 
147 static inline int
148 icl_conn_transfer_setup(struct icl_conn *ic, struct icl_pdu *ip,
149     union ctl_io *io, uint32_t *transfer_tagp, void **prvp)
150 {
151 
152 	return (ICL_CONN_TRANSFER_SETUP(ic, ip, io, transfer_tagp, prvp));
153 }
154 
155 static inline void
156 icl_conn_transfer_done(struct icl_conn *ic, void *prv)
157 {
158 
159 	ICL_CONN_TRANSFER_DONE(ic, prv);
160 }
161 
162 /*
163  * The function below is only used with ICL_KERNEL_PROXY.
164  */
165 static inline int
166 icl_conn_connect(struct icl_conn *ic, int domain, int socktype,
167     int protocol, struct sockaddr *from_sa, struct sockaddr *to_sa)
168 {
169 
170 	return (ICL_CONN_CONNECT(ic, domain, socktype, protocol,
171 	    from_sa, to_sa));
172 }
173 
174 #endif /* !ICL_WRAPPERS_H */
175