1009ea47eSEdward Tomasz Napierala /*- 24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3718cf2ccSPedro F. Giffuni * 4009ea47eSEdward Tomasz Napierala * Copyright (c) 2012 The FreeBSD Foundation 5009ea47eSEdward Tomasz Napierala * 6009ea47eSEdward Tomasz Napierala * This software was developed by Edward Tomasz Napierala under sponsorship 7009ea47eSEdward Tomasz Napierala * from the FreeBSD Foundation. 8009ea47eSEdward Tomasz Napierala * 9009ea47eSEdward Tomasz Napierala * Redistribution and use in source and binary forms, with or without 10009ea47eSEdward Tomasz Napierala * modification, are permitted provided that the following conditions 11009ea47eSEdward Tomasz Napierala * are met: 12009ea47eSEdward Tomasz Napierala * 1. Redistributions of source code must retain the above copyright 13009ea47eSEdward Tomasz Napierala * notice, this list of conditions and the following disclaimer. 14009ea47eSEdward Tomasz Napierala * 2. Redistributions in binary form must reproduce the above copyright 15009ea47eSEdward Tomasz Napierala * notice, this list of conditions and the following disclaimer in the 16009ea47eSEdward Tomasz Napierala * documentation and/or other materials provided with the distribution. 17009ea47eSEdward Tomasz Napierala * 18009ea47eSEdward Tomasz Napierala * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19009ea47eSEdward Tomasz Napierala * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20009ea47eSEdward Tomasz Napierala * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21009ea47eSEdward Tomasz Napierala * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22009ea47eSEdward Tomasz Napierala * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23009ea47eSEdward Tomasz Napierala * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24009ea47eSEdward Tomasz Napierala * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25009ea47eSEdward Tomasz Napierala * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26009ea47eSEdward Tomasz Napierala * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27009ea47eSEdward Tomasz Napierala * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28009ea47eSEdward Tomasz Napierala * SUCH DAMAGE. 29009ea47eSEdward Tomasz Napierala * 30009ea47eSEdward Tomasz Napierala * $FreeBSD$ 31009ea47eSEdward Tomasz Napierala */ 32009ea47eSEdward Tomasz Napierala 33009ea47eSEdward Tomasz Napierala #ifndef ICL_H 34009ea47eSEdward Tomasz Napierala #define ICL_H 35009ea47eSEdward Tomasz Napierala 36009ea47eSEdward Tomasz Napierala /* 37009ea47eSEdward Tomasz Napierala * iSCSI Common Layer. It's used by both the initiator and target to send 38009ea47eSEdward Tomasz Napierala * and receive iSCSI PDUs. 39009ea47eSEdward Tomasz Napierala */ 40009ea47eSEdward Tomasz Napierala 41321b17ecSEdward Tomasz Napierala #include <sys/types.h> 42321b17ecSEdward Tomasz Napierala #include <sys/kobj.h> 43321b17ecSEdward Tomasz Napierala #include <sys/condvar.h> 44321b17ecSEdward Tomasz Napierala #include <sys/sysctl.h> 45321b17ecSEdward Tomasz Napierala 46321b17ecSEdward Tomasz Napierala SYSCTL_DECL(_kern_icl); 47321b17ecSEdward Tomasz Napierala 48321b17ecSEdward Tomasz Napierala extern int icl_debug; 49321b17ecSEdward Tomasz Napierala 50321b17ecSEdward Tomasz Napierala #define ICL_DEBUG(X, ...) \ 51321b17ecSEdward Tomasz Napierala do { \ 52321b17ecSEdward Tomasz Napierala if (icl_debug > 1) \ 53321b17ecSEdward Tomasz Napierala printf("%s: " X "\n", __func__, ## __VA_ARGS__);\ 54321b17ecSEdward Tomasz Napierala } while (0) 55321b17ecSEdward Tomasz Napierala 56321b17ecSEdward Tomasz Napierala #define ICL_WARN(X, ...) \ 57321b17ecSEdward Tomasz Napierala do { \ 58321b17ecSEdward Tomasz Napierala if (icl_debug > 0) { \ 59321b17ecSEdward Tomasz Napierala printf("WARNING: %s: " X "\n", \ 60321b17ecSEdward Tomasz Napierala __func__, ## __VA_ARGS__); \ 61321b17ecSEdward Tomasz Napierala } \ 62321b17ecSEdward Tomasz Napierala } while (0) 63321b17ecSEdward Tomasz Napierala 64009ea47eSEdward Tomasz Napierala struct icl_conn; 65321b17ecSEdward Tomasz Napierala struct ccb_scsiio; 66321b17ecSEdward Tomasz Napierala union ctl_io; 67009ea47eSEdward Tomasz Napierala 68009ea47eSEdward Tomasz Napierala struct icl_pdu { 6916c158a5SEdward Tomasz Napierala STAILQ_ENTRY(icl_pdu) ip_next; 70009ea47eSEdward Tomasz Napierala struct icl_conn *ip_conn; 71009ea47eSEdward Tomasz Napierala struct iscsi_bhs *ip_bhs; 72009ea47eSEdward Tomasz Napierala struct mbuf *ip_bhs_mbuf; 73009ea47eSEdward Tomasz Napierala size_t ip_ahs_len; 74009ea47eSEdward Tomasz Napierala struct mbuf *ip_ahs_mbuf; 75009ea47eSEdward Tomasz Napierala size_t ip_data_len; 76009ea47eSEdward Tomasz Napierala struct mbuf *ip_data_mbuf; 77009ea47eSEdward Tomasz Napierala 78009ea47eSEdward Tomasz Napierala /* 79c261b6eaSJohn Baldwin * When a "large" received PDU represents multiple on-the-wire 80c261b6eaSJohn Baldwin * PDUs, this is the count of additional on-the-wire PDUs. 81c261b6eaSJohn Baldwin * For PDUs that match on-the-wire PDUs, this should be set to 82c261b6eaSJohn Baldwin * zero. 83c261b6eaSJohn Baldwin */ 84c261b6eaSJohn Baldwin u_int ip_additional_pdus; 85c261b6eaSJohn Baldwin 86c261b6eaSJohn Baldwin /* 87009ea47eSEdward Tomasz Napierala * User (initiator or provider) private fields. 88009ea47eSEdward Tomasz Napierala */ 899a4510acSAlexander Motin void *ip_prv0; 909a4510acSAlexander Motin void *ip_prv1; 91009ea47eSEdward Tomasz Napierala }; 92009ea47eSEdward Tomasz Napierala 939a4510acSAlexander Motin #define ICL_NOCOPY (1 << 30) 949a4510acSAlexander Motin 95009ea47eSEdward Tomasz Napierala struct icl_conn { 96321b17ecSEdward Tomasz Napierala KOBJ_FIELDS; 976ed8f5d2SEdward Tomasz Napierala struct mtx *ic_lock; 98009ea47eSEdward Tomasz Napierala struct socket *ic_socket; 99717f4815SEdward Tomasz Napierala #ifdef DIAGNOSTIC 100009ea47eSEdward Tomasz Napierala volatile u_int ic_outstanding_pdus; 101717f4815SEdward Tomasz Napierala #endif 1020cc7d64aSJohn Baldwin uint32_t ic_max_recv_data_segment_length; 1030cc7d64aSJohn Baldwin uint32_t ic_max_send_data_segment_length; 104f0594f52SJohn Baldwin size_t ic_hw_isomax; 105b218ca6fSEdward Tomasz Napierala size_t ic_maxtags; 10687322a90SJohn Baldwin bool ic_header_crc32c; 10787322a90SJohn Baldwin bool ic_data_crc32c; 108009ea47eSEdward Tomasz Napierala bool ic_disconnecting; 109009ea47eSEdward Tomasz Napierala bool ic_iser; 1107deb68abSEdward Tomasz Napierala bool ic_unmapped; 111ecba49ddSEdward Tomasz Napierala const char *ic_name; 11282babffbSEdward Tomasz Napierala const char *ic_offload; 113009ea47eSEdward Tomasz Napierala 114009ea47eSEdward Tomasz Napierala void (*ic_receive)(struct icl_pdu *); 115009ea47eSEdward Tomasz Napierala void (*ic_error)(struct icl_conn *); 116009ea47eSEdward Tomasz Napierala 117009ea47eSEdward Tomasz Napierala /* 118009ea47eSEdward Tomasz Napierala * User (initiator or provider) private fields. 119009ea47eSEdward Tomasz Napierala */ 120009ea47eSEdward Tomasz Napierala void *ic_prv0; 121009ea47eSEdward Tomasz Napierala }; 122009ea47eSEdward Tomasz Napierala 123e900338cSJohn Baldwin #define ICL_CONN_LOCK(X) mtx_lock(X->ic_lock) 124e900338cSJohn Baldwin #define ICL_CONN_UNLOCK(X) mtx_unlock(X->ic_lock) 125e900338cSJohn Baldwin #define ICL_CONN_LOCK_ASSERT(X) mtx_assert(X->ic_lock, MA_OWNED) 126e900338cSJohn Baldwin #define ICL_CONN_LOCK_ASSERT_NOT(X) mtx_assert(X->ic_lock, MA_NOTOWNED) 127e900338cSJohn Baldwin 12897b84d34SNavdeep Parhar struct icl_drv_limits { 12997b84d34SNavdeep Parhar int idl_max_recv_data_segment_length; 13097b84d34SNavdeep Parhar int idl_max_send_data_segment_length; 13197b84d34SNavdeep Parhar int idl_max_burst_length; 13297b84d34SNavdeep Parhar int idl_first_burst_length; 13397b84d34SNavdeep Parhar int spare[4]; 13497b84d34SNavdeep Parhar }; 13597b84d34SNavdeep Parhar 1369a4510acSAlexander Motin typedef void (*icl_pdu_cb)(struct icl_pdu *, int error); 1379a4510acSAlexander Motin 138b8911594SEdward Tomasz Napierala struct icl_conn *icl_new_conn(const char *offload, bool iser, const char *name, 139321b17ecSEdward Tomasz Napierala struct mtx *lock); 1407b02c1e8SJohn Baldwin int icl_limits(const char *offload, bool iser, int socket, 14197b84d34SNavdeep Parhar struct icl_drv_limits *idl); 142b8911594SEdward Tomasz Napierala int icl_register(const char *offload, bool iser, int priority, 1437b02c1e8SJohn Baldwin int (*limits)(struct icl_drv_limits *, int), 144321b17ecSEdward Tomasz Napierala struct icl_conn *(*new_conn)(const char *, struct mtx *)); 145b8911594SEdward Tomasz Napierala int icl_unregister(const char *offload, bool rdma); 146009ea47eSEdward Tomasz Napierala 147009ea47eSEdward Tomasz Napierala #ifdef ICL_KERNEL_PROXY 148009ea47eSEdward Tomasz Napierala 149009ea47eSEdward Tomasz Napierala struct sockaddr; 150009ea47eSEdward Tomasz Napierala struct icl_listen; 151009ea47eSEdward Tomasz Napierala 152009ea47eSEdward Tomasz Napierala /* 153009ea47eSEdward Tomasz Napierala * Target part. 154009ea47eSEdward Tomasz Napierala */ 1558eab95d6SEdward Tomasz Napierala struct icl_listen *icl_listen_new(void (*accept_cb)(struct socket *, 1568eab95d6SEdward Tomasz Napierala struct sockaddr *, int)); 157009ea47eSEdward Tomasz Napierala void icl_listen_free(struct icl_listen *il); 1588cab2ed4SEdward Tomasz Napierala int icl_listen_add(struct icl_listen *il, bool rdma, 1598cab2ed4SEdward Tomasz Napierala int domain, int socktype, int protocol, 1608cab2ed4SEdward Tomasz Napierala struct sockaddr *sa, int portal_id); 161009ea47eSEdward Tomasz Napierala int icl_listen_remove(struct icl_listen *il, struct sockaddr *sa); 162009ea47eSEdward Tomasz Napierala 163009ea47eSEdward Tomasz Napierala /* 164257cbe34SEdward Tomasz Napierala * Those two are not a public API; only to be used between icl_soft.c 165257cbe34SEdward Tomasz Napierala * and icl_soft_proxy.c. 166009ea47eSEdward Tomasz Napierala */ 167f41492b0SEdward Tomasz Napierala int icl_soft_handoff_sock(struct icl_conn *ic, struct socket *so); 168f41492b0SEdward Tomasz Napierala int icl_soft_proxy_connect(struct icl_conn *ic, int domain, 169f41492b0SEdward Tomasz Napierala int socktype, int protocol, struct sockaddr *from_sa, 170f41492b0SEdward Tomasz Napierala struct sockaddr *to_sa); 171009ea47eSEdward Tomasz Napierala #endif /* ICL_KERNEL_PROXY */ 172009ea47eSEdward Tomasz Napierala #endif /* !ICL_H */ 173