xref: /freebsd/sys/dev/iscsi/icl_wrappers.h (revision 4f52dfbb8d6c4d446500c5b097e3806ec219fbd4)
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_free(struct icl_pdu *ip)
84 {
85 
86 	ICL_CONN_PDU_FREE(ip->ip_conn, ip);
87 }
88 
89 static inline void
90 icl_conn_free(struct icl_conn *ic)
91 {
92 
93 	ICL_CONN_FREE(ic);
94 }
95 
96 static inline int
97 icl_conn_handoff(struct icl_conn *ic, int fd)
98 {
99 
100 	return (ICL_CONN_HANDOFF(ic, fd));
101 }
102 
103 static inline void
104 icl_conn_close(struct icl_conn *ic)
105 {
106 
107 	ICL_CONN_CLOSE(ic);
108 }
109 
110 static inline int
111 icl_conn_task_setup(struct icl_conn *ic, struct icl_pdu *ip,
112     struct ccb_scsiio *csio, uint32_t *task_tagp, void **prvp)
113 {
114 
115 	return (ICL_CONN_TASK_SETUP(ic, ip, csio, task_tagp, prvp));
116 }
117 
118 static inline void
119 icl_conn_task_done(struct icl_conn *ic, void *prv)
120 {
121 
122 	ICL_CONN_TASK_DONE(ic, prv);
123 }
124 
125 static inline int
126 icl_conn_transfer_setup(struct icl_conn *ic, union ctl_io *io,
127     uint32_t *transfer_tagp, void **prvp)
128 {
129 
130 	return (ICL_CONN_TRANSFER_SETUP(ic, io, transfer_tagp, prvp));
131 }
132 
133 static inline void
134 icl_conn_transfer_done(struct icl_conn *ic, void *prv)
135 {
136 
137 	ICL_CONN_TRANSFER_DONE(ic, prv);
138 }
139 
140 /*
141  * The function below is only used with ICL_KERNEL_PROXY.
142  */
143 static inline int
144 icl_conn_connect(struct icl_conn *ic, int domain, int socktype,
145     int protocol, struct sockaddr *from_sa, struct sockaddr *to_sa)
146 {
147 
148 	return (ICL_CONN_CONNECT(ic, domain, socktype, protocol,
149 	    from_sa, to_sa));
150 }
151 
152 #endif /* !ICL_WRAPPERS_H */
153