1009ea47eSEdward Tomasz Napierala /*- 2718cf2ccSPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 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 /* 79009ea47eSEdward Tomasz Napierala * User (initiator or provider) private fields. 80009ea47eSEdward Tomasz Napierala */ 819a4510acSAlexander Motin void *ip_prv0; 829a4510acSAlexander Motin void *ip_prv1; 83009ea47eSEdward Tomasz Napierala }; 84009ea47eSEdward Tomasz Napierala 859a4510acSAlexander Motin #define ICL_NOCOPY (1 << 30) 869a4510acSAlexander Motin 87009ea47eSEdward Tomasz Napierala struct icl_conn { 88321b17ecSEdward Tomasz Napierala KOBJ_FIELDS; 896ed8f5d2SEdward Tomasz Napierala struct mtx *ic_lock; 90009ea47eSEdward Tomasz Napierala struct socket *ic_socket; 91717f4815SEdward Tomasz Napierala #ifdef DIAGNOSTIC 92009ea47eSEdward Tomasz Napierala volatile u_int ic_outstanding_pdus; 93717f4815SEdward Tomasz Napierala #endif 940cc7d64aSJohn Baldwin uint32_t ic_max_recv_data_segment_length; 950cc7d64aSJohn Baldwin uint32_t ic_max_send_data_segment_length; 96b218ca6fSEdward Tomasz Napierala size_t ic_maxtags; 97*87322a90SJohn Baldwin bool ic_header_crc32c; 98*87322a90SJohn Baldwin bool ic_data_crc32c; 99009ea47eSEdward Tomasz Napierala bool ic_disconnecting; 100009ea47eSEdward Tomasz Napierala bool ic_iser; 1017deb68abSEdward Tomasz Napierala bool ic_unmapped; 102ecba49ddSEdward Tomasz Napierala const char *ic_name; 10382babffbSEdward Tomasz Napierala const char *ic_offload; 104009ea47eSEdward Tomasz Napierala 105009ea47eSEdward Tomasz Napierala void (*ic_receive)(struct icl_pdu *); 106009ea47eSEdward Tomasz Napierala void (*ic_error)(struct icl_conn *); 107009ea47eSEdward Tomasz Napierala 108009ea47eSEdward Tomasz Napierala /* 109009ea47eSEdward Tomasz Napierala * User (initiator or provider) private fields. 110009ea47eSEdward Tomasz Napierala */ 111009ea47eSEdward Tomasz Napierala void *ic_prv0; 112009ea47eSEdward Tomasz Napierala }; 113009ea47eSEdward Tomasz Napierala 11497b84d34SNavdeep Parhar struct icl_drv_limits { 11597b84d34SNavdeep Parhar int idl_max_recv_data_segment_length; 11697b84d34SNavdeep Parhar int idl_max_send_data_segment_length; 11797b84d34SNavdeep Parhar int idl_max_burst_length; 11897b84d34SNavdeep Parhar int idl_first_burst_length; 11997b84d34SNavdeep Parhar int spare[4]; 12097b84d34SNavdeep Parhar }; 12197b84d34SNavdeep Parhar 1229a4510acSAlexander Motin typedef void (*icl_pdu_cb)(struct icl_pdu *, int error); 1239a4510acSAlexander Motin 124b8911594SEdward Tomasz Napierala struct icl_conn *icl_new_conn(const char *offload, bool iser, const char *name, 125321b17ecSEdward Tomasz Napierala struct mtx *lock); 12697b84d34SNavdeep Parhar int icl_limits(const char *offload, bool iser, 12797b84d34SNavdeep Parhar struct icl_drv_limits *idl); 128b8911594SEdward Tomasz Napierala int icl_register(const char *offload, bool iser, int priority, 12997b84d34SNavdeep Parhar int (*limits)(struct icl_drv_limits *), 130321b17ecSEdward Tomasz Napierala struct icl_conn *(*new_conn)(const char *, struct mtx *)); 131b8911594SEdward Tomasz Napierala int icl_unregister(const char *offload, bool rdma); 132009ea47eSEdward Tomasz Napierala 133009ea47eSEdward Tomasz Napierala #ifdef ICL_KERNEL_PROXY 134009ea47eSEdward Tomasz Napierala 135009ea47eSEdward Tomasz Napierala struct sockaddr; 136009ea47eSEdward Tomasz Napierala struct icl_listen; 137009ea47eSEdward Tomasz Napierala 138009ea47eSEdward Tomasz Napierala /* 139009ea47eSEdward Tomasz Napierala * Target part. 140009ea47eSEdward Tomasz Napierala */ 1418eab95d6SEdward Tomasz Napierala struct icl_listen *icl_listen_new(void (*accept_cb)(struct socket *, 1428eab95d6SEdward Tomasz Napierala struct sockaddr *, int)); 143009ea47eSEdward Tomasz Napierala void icl_listen_free(struct icl_listen *il); 1448cab2ed4SEdward Tomasz Napierala int icl_listen_add(struct icl_listen *il, bool rdma, 1458cab2ed4SEdward Tomasz Napierala int domain, int socktype, int protocol, 1468cab2ed4SEdward Tomasz Napierala struct sockaddr *sa, int portal_id); 147009ea47eSEdward Tomasz Napierala int icl_listen_remove(struct icl_listen *il, struct sockaddr *sa); 148009ea47eSEdward Tomasz Napierala 149009ea47eSEdward Tomasz Napierala /* 150257cbe34SEdward Tomasz Napierala * Those two are not a public API; only to be used between icl_soft.c 151257cbe34SEdward Tomasz Napierala * and icl_soft_proxy.c. 152009ea47eSEdward Tomasz Napierala */ 153f41492b0SEdward Tomasz Napierala int icl_soft_handoff_sock(struct icl_conn *ic, struct socket *so); 154f41492b0SEdward Tomasz Napierala int icl_soft_proxy_connect(struct icl_conn *ic, int domain, 155f41492b0SEdward Tomasz Napierala int socktype, int protocol, struct sockaddr *from_sa, 156f41492b0SEdward Tomasz Napierala struct sockaddr *to_sa); 157009ea47eSEdward Tomasz Napierala #endif /* ICL_KERNEL_PROXY */ 158009ea47eSEdward Tomasz Napierala #endif /* !ICL_H */ 159