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