1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2012 The FreeBSD Foundation 5 * 6 * This software was developed by Edward Tomasz Napierala under sponsorship 7 * from the FreeBSD Foundation. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 * 30 * $FreeBSD$ 31 */ 32 33 #ifndef ICL_H 34 #define ICL_H 35 36 /* 37 * iSCSI Common Layer. It's used by both the initiator and target to send 38 * and receive iSCSI PDUs. 39 */ 40 41 #include <sys/types.h> 42 #include <sys/kobj.h> 43 #include <sys/condvar.h> 44 #include <sys/sysctl.h> 45 46 SYSCTL_DECL(_kern_icl); 47 48 extern int icl_debug; 49 50 #define ICL_DEBUG(X, ...) \ 51 do { \ 52 if (icl_debug > 1) \ 53 printf("%s: " X "\n", __func__, ## __VA_ARGS__);\ 54 } while (0) 55 56 #define ICL_WARN(X, ...) \ 57 do { \ 58 if (icl_debug > 0) { \ 59 printf("WARNING: %s: " X "\n", \ 60 __func__, ## __VA_ARGS__); \ 61 } \ 62 } while (0) 63 64 struct icl_conn; 65 struct ccb_scsiio; 66 union ctl_io; 67 68 struct icl_pdu { 69 STAILQ_ENTRY(icl_pdu) ip_next; 70 struct icl_conn *ip_conn; 71 struct iscsi_bhs *ip_bhs; 72 struct mbuf *ip_bhs_mbuf; 73 size_t ip_ahs_len; 74 struct mbuf *ip_ahs_mbuf; 75 size_t ip_data_len; 76 struct mbuf *ip_data_mbuf; 77 78 /* 79 * User (initiator or provider) private fields. 80 */ 81 void *ip_prv0; 82 void *ip_prv1; 83 }; 84 85 #define ICL_NOCOPY (1 << 30) 86 87 struct icl_conn { 88 KOBJ_FIELDS; 89 struct mtx *ic_lock; 90 struct socket *ic_socket; 91 #ifdef DIAGNOSTIC 92 volatile u_int ic_outstanding_pdus; 93 #endif 94 uint32_t ic_max_recv_data_segment_length; 95 uint32_t ic_max_send_data_segment_length; 96 size_t ic_maxtags; 97 bool ic_header_crc32c; 98 bool ic_data_crc32c; 99 bool ic_disconnecting; 100 bool ic_iser; 101 bool ic_unmapped; 102 const char *ic_name; 103 const char *ic_offload; 104 105 void (*ic_receive)(struct icl_pdu *); 106 void (*ic_error)(struct icl_conn *); 107 108 /* 109 * User (initiator or provider) private fields. 110 */ 111 void *ic_prv0; 112 }; 113 114 struct icl_drv_limits { 115 int idl_max_recv_data_segment_length; 116 int idl_max_send_data_segment_length; 117 int idl_max_burst_length; 118 int idl_first_burst_length; 119 int spare[4]; 120 }; 121 122 typedef void (*icl_pdu_cb)(struct icl_pdu *, int error); 123 124 struct icl_conn *icl_new_conn(const char *offload, bool iser, const char *name, 125 struct mtx *lock); 126 int icl_limits(const char *offload, bool iser, 127 struct icl_drv_limits *idl); 128 int icl_register(const char *offload, bool iser, int priority, 129 int (*limits)(struct icl_drv_limits *), 130 struct icl_conn *(*new_conn)(const char *, struct mtx *)); 131 int icl_unregister(const char *offload, bool rdma); 132 133 #ifdef ICL_KERNEL_PROXY 134 135 struct sockaddr; 136 struct icl_listen; 137 138 /* 139 * Target part. 140 */ 141 struct icl_listen *icl_listen_new(void (*accept_cb)(struct socket *, 142 struct sockaddr *, int)); 143 void icl_listen_free(struct icl_listen *il); 144 int icl_listen_add(struct icl_listen *il, bool rdma, 145 int domain, int socktype, int protocol, 146 struct sockaddr *sa, int portal_id); 147 int icl_listen_remove(struct icl_listen *il, struct sockaddr *sa); 148 149 /* 150 * Those two are not a public API; only to be used between icl_soft.c 151 * and icl_soft_proxy.c. 152 */ 153 int icl_soft_handoff_sock(struct icl_conn *ic, struct socket *so); 154 int icl_soft_proxy_connect(struct icl_conn *ic, int domain, 155 int socktype, int protocol, struct sockaddr *from_sa, 156 struct sockaddr *to_sa); 157 #endif /* ICL_KERNEL_PROXY */ 158 #endif /* !ICL_H */ 159