xref: /freebsd/sys/dev/cxgbe/cxgbei/cxgbei.h (revision 8aac90f18aef7c9eea906c3ff9a001ca7b94f375)
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  */
27 
28 #ifndef __CXGBEI_OFLD_H__
29 #define __CXGBEI_OFLD_H__
30 
31 #include <dev/iscsi/icl.h>
32 
33 #define CXGBEI_CONN_SIGNATURE 0x56788765
34 
35 struct cxgbei_cmp {
36 	LIST_ENTRY(cxgbei_cmp) link;
37 
38 	uint32_t tt;		/* Transfer tag. */
39 
40 	uint32_t next_buffer_offset;
41 	uint32_t last_datasn;
42 };
43 LIST_HEAD(cxgbei_cmp_head, cxgbei_cmp);
44 
45 struct icl_cxgbei_conn {
46 	struct icl_conn ic;
47 
48 	/* cxgbei specific stuff goes here. */
49 	uint32_t icc_signature;
50 	int ulp_submode;
51 	struct adapter *sc;
52 	struct toepcb *toep;
53 
54 	/* Receive related. */
55 	bool rx_active;				/* protected by so_rcv lock */
56 	bool rx_exiting;			/* protected by so_rcv lock */
57 	STAILQ_HEAD(, icl_pdu) rcvd_pdus;	/* protected by so_rcv lock */
58 	struct thread *rx_thread;
59 
60 	struct cxgbei_cmp_head *cmp_table;	/* protected by cmp_lock */
61 	struct mtx cmp_lock;
62 	unsigned long cmp_hash_mask;
63 
64 	/* Transmit related. */
65 	bool tx_active;				/* protected by ic lock */
66 	STAILQ_HEAD(, icl_pdu) sent_pdus;	/* protected by ic lock */
67 	struct thread *tx_thread;
68 };
69 
70 static inline struct icl_cxgbei_conn *
71 ic_to_icc(struct icl_conn *ic)
72 {
73 
74 	return (__containerof(ic, struct icl_cxgbei_conn, ic));
75 }
76 
77 /* PDU flags and signature. */
78 enum {
79 	ICPF_RX_HDR	= 1 << 0, /* PDU header received. */
80 	ICPF_RX_FLBUF	= 1 << 1, /* PDU payload received in a freelist. */
81 	ICPF_RX_DDP	= 1 << 2, /* PDU payload DDP'd. */
82 	ICPF_RX_STATUS	= 1 << 3, /* Rx status received. */
83 
84 	CXGBEI_PDU_SIGNATURE = 0x12344321
85 };
86 
87 struct icl_cxgbei_pdu {
88 	struct icl_pdu ip;
89 
90 	/* cxgbei specific stuff goes here. */
91 	uint32_t icp_signature;
92 	uint32_t icp_seq;	/* For debug only */
93 	u_int icp_flags;
94 
95 	u_int ref_cnt;
96 	icl_pdu_cb cb;
97 	int error;
98 };
99 
100 static inline struct icl_cxgbei_pdu *
101 ip_to_icp(struct icl_pdu *ip)
102 {
103 
104 	return (__containerof(ip, struct icl_cxgbei_pdu, ip));
105 }
106 
107 struct cxgbei_data {
108 	u_int max_tx_data_len;
109 	u_int max_rx_data_len;
110 
111 	u_int ddp_threshold;
112 	struct ppod_region pr;
113 
114 	struct sysctl_ctx_list ctx;	/* from uld_activate to deactivate */
115 };
116 
117 #define CXGBEI_MAX_ISO_PAYLOAD	65535
118 
119 /* cxgbei.c */
120 u_int cxgbei_select_worker_thread(struct icl_cxgbei_conn *);
121 void cwt_queue_for_tx(struct icl_cxgbei_conn *);
122 void parse_pdus(struct icl_cxgbei_conn *, struct sockbuf *);
123 
124 /* icl_cxgbei.c */
125 void cwt_tx_main(void *);
126 int icl_cxgbei_mod_load(void);
127 int icl_cxgbei_mod_unload(void);
128 struct icl_pdu *icl_cxgbei_new_pdu(int);
129 void icl_cxgbei_new_pdu_set_conn(struct icl_pdu *, struct icl_conn *);
130 void icl_cxgbei_conn_pdu_free(struct icl_conn *, struct icl_pdu *);
131 struct cxgbei_cmp *cxgbei_find_cmp(struct icl_cxgbei_conn *, uint32_t);
132 
133 #endif
134