1 /*- 2 * Copyright (c) 2010 Chelsio Communications, Inc. 3 * All rights reserved. 4 * Written by: Navdeep Parhar <np@FreeBSD.org> 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * $FreeBSD$ 28 * 29 */ 30 31 #ifndef __T4_OFFLOAD_H__ 32 #define __T4_OFFLOAD_H__ 33 #include <sys/param.h> 34 #include <sys/proc.h> 35 #include <sys/condvar.h> 36 37 #define INIT_ULPTX_WRH(w, wrlen, atomic, tid) do { \ 38 (w)->wr_hi = htonl(V_FW_WR_OP(FW_ULPTX_WR) | V_FW_WR_ATOMIC(atomic)); \ 39 (w)->wr_mid = htonl(V_FW_WR_LEN16(DIV_ROUND_UP(wrlen, 16)) | \ 40 V_FW_WR_FLOWID(tid)); \ 41 (w)->wr_lo = cpu_to_be64(0); \ 42 } while (0) 43 44 #define INIT_ULPTX_WR(w, wrlen, atomic, tid) \ 45 INIT_ULPTX_WRH(&((w)->wr), wrlen, atomic, tid) 46 47 #define INIT_TP_WR(w, tid) do { \ 48 (w)->wr.wr_hi = htonl(V_FW_WR_OP(FW_TP_WR) | \ 49 V_FW_WR_IMMDLEN(sizeof(*w) - sizeof(w->wr))); \ 50 (w)->wr.wr_mid = htonl(V_FW_WR_LEN16(DIV_ROUND_UP(sizeof(*w), 16)) | \ 51 V_FW_WR_FLOWID(tid)); \ 52 (w)->wr.wr_lo = cpu_to_be64(0); \ 53 } while (0) 54 55 #define INIT_TP_WR_MIT_CPL(w, cpl, tid) do { \ 56 INIT_TP_WR(w, tid); \ 57 OPCODE_TID(w) = htonl(MK_OPCODE_TID(cpl, tid)); \ 58 } while (0) 59 60 TAILQ_HEAD(stid_head, stid_region); 61 struct listen_ctx; 62 63 struct stid_region { 64 TAILQ_ENTRY(stid_region) link; 65 u_int used; /* # of stids used by this region */ 66 u_int free; /* # of contiguous stids free right after this region */ 67 }; 68 69 /* 70 * Max # of ATIDs. The absolute HW max is 14b (enough for 16K) but we reserve 71 * the upper 3b for use as a cookie to demux the reply. 72 */ 73 #define MAX_ATIDS 2048U 74 75 union aopen_entry { 76 void *data; 77 union aopen_entry *next; 78 }; 79 80 /* 81 * Holds the size, base address, start, end, etc. of various types of TIDs. The 82 * tables themselves are allocated dynamically. 83 */ 84 struct tid_info { 85 u_int nstids; 86 u_int stid_base; 87 88 u_int natids; 89 90 u_int nftids; 91 u_int ftid_base; 92 u_int ftid_end; 93 94 u_int nhpftids; 95 u_int hpftid_base; 96 u_int hpftid_end; 97 98 u_int ntids; 99 u_int tid_base; 100 101 u_int netids; 102 u_int etid_base; 103 u_int etid_end; 104 105 struct mtx stid_lock __aligned(CACHE_LINE_SIZE); 106 struct listen_ctx **stid_tab; 107 u_int stids_in_use; 108 u_int nstids_free_head; /* # of available stids at the beginning */ 109 struct stid_head stids; 110 111 struct mtx atid_lock __aligned(CACHE_LINE_SIZE); 112 union aopen_entry *atid_tab; 113 union aopen_entry *afree; 114 u_int atids_in_use; 115 116 /* High priority filters and normal filters share the lock and cv. */ 117 struct mtx ftid_lock __aligned(CACHE_LINE_SIZE); 118 struct cv ftid_cv; 119 struct filter_entry *ftid_tab; 120 struct filter_entry *hpftid_tab; 121 u_int ftids_in_use; 122 u_int hpftids_in_use; 123 124 /* 125 * hashfilter and TOE are mutually exclusive and both use ntids and 126 * tids_in_use. The lock and cv are used only by hashfilter. 127 */ 128 struct mtx hftid_lock __aligned(CACHE_LINE_SIZE); 129 struct cv hftid_cv; 130 void **tid_tab; 131 u_int tids_in_use; 132 133 void *hftid_hash_4t; /* LIST_HEAD(, filter_entry) *hftid_hash_4t; */ 134 u_long hftid_4t_mask; 135 void *hftid_hash_tid; /* LIST_HEAD(, filter_entry) *hftid_hash_tid; */ 136 u_long hftid_tid_mask; 137 }; 138 139 struct t4_range { 140 u_int start; 141 u_int size; 142 }; 143 144 struct t4_virt_res { /* virtualized HW resources */ 145 struct t4_range ddp; 146 struct t4_range iscsi; 147 struct t4_range stag; 148 struct t4_range rq; 149 struct t4_range pbl; 150 struct t4_range qp; 151 struct t4_range cq; 152 struct t4_range srq; 153 struct t4_range ocq; 154 struct t4_range l2t; 155 struct t4_range key; 156 }; 157 158 enum { 159 ULD_TOM = 0, 160 ULD_IWARP, 161 ULD_ISCSI, 162 ULD_MAX = ULD_ISCSI 163 }; 164 165 struct adapter; 166 struct port_info; 167 struct uld_info { 168 SLIST_ENTRY(uld_info) link; 169 int refcount; 170 int uld_id; 171 int (*activate)(struct adapter *); 172 int (*deactivate)(struct adapter *); 173 }; 174 175 struct tom_tunables { 176 int cong_algorithm; 177 int sndbuf; 178 int ddp; 179 int rx_coalesce; 180 int tls; 181 int *tls_rx_ports; 182 int num_tls_rx_ports; 183 int tx_align; 184 int tx_zcopy; 185 int cop_managed_offloading; 186 }; 187 /* iWARP driver tunables */ 188 struct iw_tunables { 189 int wc_en; 190 }; 191 #ifdef TCP_OFFLOAD 192 int t4_register_uld(struct uld_info *); 193 int t4_unregister_uld(struct uld_info *); 194 int t4_activate_uld(struct adapter *, int); 195 int t4_deactivate_uld(struct adapter *, int); 196 void t4_iscsi_init(struct adapter *, u_int, const u_int *); 197 int uld_active(struct adapter *, int); 198 #endif 199 #endif 200