xref: /freebsd/sys/dev/cxgbe/cxgbei/cxgbei.h (revision 3332f1b444d4a73238e9f59cca27bfc95fe936bd)
1 /*-
2  * Copyright (c) 2012, 2015 Chelsio Communications, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  *
28  */
29 
30 #ifndef __CXGBEI_OFLD_H__
31 #define __CXGBEI_OFLD_H__
32 
33 #include <dev/iscsi/icl.h>
34 
35 enum {
36 	CWT_SLEEPING	= 1,
37 	CWT_RUNNING	= 2,
38 	CWT_STOP	= 3,
39 	CWT_STOPPED	= 4,
40 };
41 
42 struct cxgbei_worker_thread_softc {
43 	struct mtx	cwt_lock;
44 	struct cv	cwt_cv;
45 	volatile int	cwt_state;
46 
47 	TAILQ_HEAD(, icl_cxgbei_conn) rx_head;
48 } __aligned(CACHE_LINE_SIZE);
49 
50 #define CXGBEI_CONN_SIGNATURE 0x56788765
51 
52 enum {
53 	RXF_ACTIVE	= 1 << 0,	/* In the worker thread's queue */
54 };
55 
56 struct cxgbei_cmp {
57 	LIST_ENTRY(cxgbei_cmp) link;
58 
59 	uint32_t tt;		/* Transfer tag. */
60 
61 	uint32_t next_buffer_offset;
62 	uint32_t last_datasn;
63 };
64 LIST_HEAD(cxgbei_cmp_head, cxgbei_cmp);
65 
66 struct icl_cxgbei_conn {
67 	struct icl_conn ic;
68 
69 	/* cxgbei specific stuff goes here. */
70 	uint32_t icc_signature;
71 	int ulp_submode;
72 	struct adapter *sc;
73 	struct toepcb *toep;
74 
75 	/* Receive related. */
76 	u_int rx_flags;				/* protected by so_rcv lock */
77 	u_int cwt;
78 	STAILQ_HEAD(, icl_pdu) rcvd_pdus;	/* protected by so_rcv lock */
79 	TAILQ_ENTRY(icl_cxgbei_conn) rx_link;	/* protected by cwt lock */
80 
81 	struct cxgbei_cmp_head *cmp_table;	/* protected by cmp_lock */
82 	struct mtx cmp_lock;
83 	unsigned long cmp_hash_mask;
84 };
85 
86 static inline struct icl_cxgbei_conn *
87 ic_to_icc(struct icl_conn *ic)
88 {
89 
90 	return (__containerof(ic, struct icl_cxgbei_conn, ic));
91 }
92 
93 /* PDU flags and signature. */
94 enum {
95 	ICPF_RX_HDR	= 1 << 0, /* PDU header received. */
96 	ICPF_RX_FLBUF	= 1 << 1, /* PDU payload received in a freelist. */
97 	ICPF_RX_DDP	= 1 << 2, /* PDU payload DDP'd. */
98 	ICPF_RX_STATUS	= 1 << 3, /* Rx status received. */
99 
100 	CXGBEI_PDU_SIGNATURE = 0x12344321
101 };
102 
103 struct icl_cxgbei_pdu {
104 	struct icl_pdu ip;
105 
106 	/* cxgbei specific stuff goes here. */
107 	uint32_t icp_signature;
108 	uint32_t icp_seq;	/* For debug only */
109 	u_int icp_flags;
110 
111 	u_int ref_cnt;
112 	icl_pdu_cb cb;
113 	int error;
114 };
115 
116 static inline struct icl_cxgbei_pdu *
117 ip_to_icp(struct icl_pdu *ip)
118 {
119 
120 	return (__containerof(ip, struct icl_cxgbei_pdu, ip));
121 }
122 
123 struct cxgbei_data {
124 	u_int max_tx_data_len;
125 	u_int max_rx_data_len;
126 
127 	u_int ddp_threshold;
128 	struct ppod_region pr;
129 
130 	struct sysctl_ctx_list ctx;	/* from uld_activate to deactivate */
131 };
132 
133 #define CXGBEI_MAX_ISO_PAYLOAD	65535
134 
135 /* cxgbei.c */
136 u_int cxgbei_select_worker_thread(struct icl_cxgbei_conn *);
137 
138 /* icl_cxgbei.c */
139 int icl_cxgbei_mod_load(void);
140 int icl_cxgbei_mod_unload(void);
141 struct icl_pdu *icl_cxgbei_new_pdu(int);
142 void icl_cxgbei_new_pdu_set_conn(struct icl_pdu *, struct icl_conn *);
143 void icl_cxgbei_conn_pdu_free(struct icl_conn *, struct icl_pdu *);
144 struct cxgbei_cmp *cxgbei_find_cmp(struct icl_cxgbei_conn *, uint32_t);
145 
146 #endif
147