1009ea47eSEdward Tomasz Napierala /*- 2*4d846d26SWarner 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 31009ea47eSEdward Tomasz Napierala #ifndef ICL_H 32009ea47eSEdward Tomasz Napierala #define ICL_H 33009ea47eSEdward Tomasz Napierala 34009ea47eSEdward Tomasz Napierala /* 35009ea47eSEdward Tomasz Napierala * iSCSI Common Layer. It's used by both the initiator and target to send 36009ea47eSEdward Tomasz Napierala * and receive iSCSI PDUs. 37009ea47eSEdward Tomasz Napierala */ 38009ea47eSEdward Tomasz Napierala 39321b17ecSEdward Tomasz Napierala #include <sys/types.h> 40321b17ecSEdward Tomasz Napierala #include <sys/kobj.h> 41321b17ecSEdward Tomasz Napierala #include <sys/condvar.h> 42321b17ecSEdward Tomasz Napierala #include <sys/sysctl.h> 43321b17ecSEdward Tomasz Napierala 44321b17ecSEdward Tomasz Napierala SYSCTL_DECL(_kern_icl); 45321b17ecSEdward Tomasz Napierala 46321b17ecSEdward Tomasz Napierala extern int icl_debug; 47321b17ecSEdward Tomasz Napierala 48321b17ecSEdward Tomasz Napierala #define ICL_DEBUG(X, ...) \ 49321b17ecSEdward Tomasz Napierala do { \ 50321b17ecSEdward Tomasz Napierala if (icl_debug > 1) \ 51321b17ecSEdward Tomasz Napierala printf("%s: " X "\n", __func__, ## __VA_ARGS__);\ 52321b17ecSEdward Tomasz Napierala } while (0) 53321b17ecSEdward Tomasz Napierala 54321b17ecSEdward Tomasz Napierala #define ICL_WARN(X, ...) \ 55321b17ecSEdward Tomasz Napierala do { \ 56321b17ecSEdward Tomasz Napierala if (icl_debug > 0) { \ 57321b17ecSEdward Tomasz Napierala printf("WARNING: %s: " X "\n", \ 58321b17ecSEdward Tomasz Napierala __func__, ## __VA_ARGS__); \ 59321b17ecSEdward Tomasz Napierala } \ 60321b17ecSEdward Tomasz Napierala } while (0) 61321b17ecSEdward Tomasz Napierala 62009ea47eSEdward Tomasz Napierala struct icl_conn; 63321b17ecSEdward Tomasz Napierala struct ccb_scsiio; 64321b17ecSEdward Tomasz Napierala union ctl_io; 65009ea47eSEdward Tomasz Napierala 66009ea47eSEdward Tomasz Napierala struct icl_pdu { 6716c158a5SEdward Tomasz Napierala STAILQ_ENTRY(icl_pdu) ip_next; 68009ea47eSEdward Tomasz Napierala struct icl_conn *ip_conn; 69009ea47eSEdward Tomasz Napierala struct iscsi_bhs *ip_bhs; 70009ea47eSEdward Tomasz Napierala struct mbuf *ip_bhs_mbuf; 71009ea47eSEdward Tomasz Napierala size_t ip_ahs_len; 72009ea47eSEdward Tomasz Napierala struct mbuf *ip_ahs_mbuf; 73009ea47eSEdward Tomasz Napierala size_t ip_data_len; 74009ea47eSEdward Tomasz Napierala struct mbuf *ip_data_mbuf; 75009ea47eSEdward Tomasz Napierala 76009ea47eSEdward Tomasz Napierala /* 77c261b6eaSJohn Baldwin * When a "large" received PDU represents multiple on-the-wire 78c261b6eaSJohn Baldwin * PDUs, this is the count of additional on-the-wire PDUs. 79c261b6eaSJohn Baldwin * For PDUs that match on-the-wire PDUs, this should be set to 80c261b6eaSJohn Baldwin * zero. 81c261b6eaSJohn Baldwin */ 82c261b6eaSJohn Baldwin u_int ip_additional_pdus; 83c261b6eaSJohn Baldwin 84c261b6eaSJohn Baldwin /* 85009ea47eSEdward Tomasz Napierala * User (initiator or provider) private fields. 86009ea47eSEdward Tomasz Napierala */ 879a4510acSAlexander Motin void *ip_prv0; 889a4510acSAlexander Motin void *ip_prv1; 89009ea47eSEdward Tomasz Napierala }; 90009ea47eSEdward Tomasz Napierala 919a4510acSAlexander Motin #define ICL_NOCOPY (1 << 30) 929a4510acSAlexander Motin 93009ea47eSEdward Tomasz Napierala struct icl_conn { 94321b17ecSEdward Tomasz Napierala KOBJ_FIELDS; 956ed8f5d2SEdward Tomasz Napierala struct mtx *ic_lock; 96009ea47eSEdward Tomasz Napierala struct socket *ic_socket; 97717f4815SEdward Tomasz Napierala #ifdef DIAGNOSTIC 98009ea47eSEdward Tomasz Napierala volatile u_int ic_outstanding_pdus; 99717f4815SEdward Tomasz Napierala #endif 1000cc7d64aSJohn Baldwin uint32_t ic_max_recv_data_segment_length; 1010cc7d64aSJohn Baldwin uint32_t ic_max_send_data_segment_length; 102f0594f52SJohn Baldwin size_t ic_hw_isomax; 103b218ca6fSEdward Tomasz Napierala size_t ic_maxtags; 10487322a90SJohn Baldwin bool ic_header_crc32c; 10587322a90SJohn Baldwin bool ic_data_crc32c; 106009ea47eSEdward Tomasz Napierala bool ic_disconnecting; 107009ea47eSEdward Tomasz Napierala bool ic_iser; 1087deb68abSEdward Tomasz Napierala bool ic_unmapped; 109ecba49ddSEdward Tomasz Napierala const char *ic_name; 11082babffbSEdward Tomasz Napierala const char *ic_offload; 111009ea47eSEdward Tomasz Napierala 112009ea47eSEdward Tomasz Napierala void (*ic_receive)(struct icl_pdu *); 113009ea47eSEdward Tomasz Napierala void (*ic_error)(struct icl_conn *); 114009ea47eSEdward Tomasz Napierala 115009ea47eSEdward Tomasz Napierala /* 116009ea47eSEdward Tomasz Napierala * User (initiator or provider) private fields. 117009ea47eSEdward Tomasz Napierala */ 118009ea47eSEdward Tomasz Napierala void *ic_prv0; 119009ea47eSEdward Tomasz Napierala }; 120009ea47eSEdward Tomasz Napierala 121e900338cSJohn Baldwin #define ICL_CONN_LOCK(X) mtx_lock(X->ic_lock) 122e900338cSJohn Baldwin #define ICL_CONN_UNLOCK(X) mtx_unlock(X->ic_lock) 123e900338cSJohn Baldwin #define ICL_CONN_LOCK_ASSERT(X) mtx_assert(X->ic_lock, MA_OWNED) 124e900338cSJohn Baldwin #define ICL_CONN_LOCK_ASSERT_NOT(X) mtx_assert(X->ic_lock, MA_NOTOWNED) 125e900338cSJohn Baldwin 12697b84d34SNavdeep Parhar struct icl_drv_limits { 12797b84d34SNavdeep Parhar int idl_max_recv_data_segment_length; 12897b84d34SNavdeep Parhar int idl_max_send_data_segment_length; 12997b84d34SNavdeep Parhar int idl_max_burst_length; 13097b84d34SNavdeep Parhar int idl_first_burst_length; 13197b84d34SNavdeep Parhar int spare[4]; 13297b84d34SNavdeep Parhar }; 13397b84d34SNavdeep Parhar 1349a4510acSAlexander Motin typedef void (*icl_pdu_cb)(struct icl_pdu *, int error); 1359a4510acSAlexander Motin 136b8911594SEdward Tomasz Napierala struct icl_conn *icl_new_conn(const char *offload, bool iser, const char *name, 137321b17ecSEdward Tomasz Napierala struct mtx *lock); 1387b02c1e8SJohn Baldwin int icl_limits(const char *offload, bool iser, int socket, 13997b84d34SNavdeep Parhar struct icl_drv_limits *idl); 140b8911594SEdward Tomasz Napierala int icl_register(const char *offload, bool iser, int priority, 1417b02c1e8SJohn Baldwin int (*limits)(struct icl_drv_limits *, int), 142321b17ecSEdward Tomasz Napierala struct icl_conn *(*new_conn)(const char *, struct mtx *)); 143b8911594SEdward Tomasz Napierala int icl_unregister(const char *offload, bool rdma); 144009ea47eSEdward Tomasz Napierala 145009ea47eSEdward Tomasz Napierala #ifdef ICL_KERNEL_PROXY 146009ea47eSEdward Tomasz Napierala 147009ea47eSEdward Tomasz Napierala struct sockaddr; 148009ea47eSEdward Tomasz Napierala struct icl_listen; 149009ea47eSEdward Tomasz Napierala 150009ea47eSEdward Tomasz Napierala /* 151009ea47eSEdward Tomasz Napierala * Target part. 152009ea47eSEdward Tomasz Napierala */ 1538eab95d6SEdward Tomasz Napierala struct icl_listen *icl_listen_new(void (*accept_cb)(struct socket *, 1548eab95d6SEdward Tomasz Napierala struct sockaddr *, int)); 155009ea47eSEdward Tomasz Napierala void icl_listen_free(struct icl_listen *il); 1568cab2ed4SEdward Tomasz Napierala int icl_listen_add(struct icl_listen *il, bool rdma, 1578cab2ed4SEdward Tomasz Napierala int domain, int socktype, int protocol, 1588cab2ed4SEdward Tomasz Napierala struct sockaddr *sa, int portal_id); 159009ea47eSEdward Tomasz Napierala int icl_listen_remove(struct icl_listen *il, struct sockaddr *sa); 160009ea47eSEdward Tomasz Napierala 161009ea47eSEdward Tomasz Napierala /* 162257cbe34SEdward Tomasz Napierala * Those two are not a public API; only to be used between icl_soft.c 163257cbe34SEdward Tomasz Napierala * and icl_soft_proxy.c. 164009ea47eSEdward Tomasz Napierala */ 165f41492b0SEdward Tomasz Napierala int icl_soft_handoff_sock(struct icl_conn *ic, struct socket *so); 166f41492b0SEdward Tomasz Napierala int icl_soft_proxy_connect(struct icl_conn *ic, int domain, 167f41492b0SEdward Tomasz Napierala int socktype, int protocol, struct sockaddr *from_sa, 168f41492b0SEdward Tomasz Napierala struct sockaddr *to_sa); 169009ea47eSEdward Tomasz Napierala #endif /* ICL_KERNEL_PROXY */ 170009ea47eSEdward Tomasz Napierala #endif /* !ICL_H */ 171