xref: /freebsd/sys/dev/cxgbe/cxgbei/cxgbei.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1e3148e46SNavdeep Parhar /*-
2e3148e46SNavdeep Parhar  * Copyright (c) 2012, 2015 Chelsio Communications, Inc.
3e3148e46SNavdeep Parhar  * All rights reserved.
4e3148e46SNavdeep Parhar  *
5e3148e46SNavdeep Parhar  * Redistribution and use in source and binary forms, with or without
6e3148e46SNavdeep Parhar  * modification, are permitted provided that the following conditions
7e3148e46SNavdeep Parhar  * are met:
8e3148e46SNavdeep Parhar  * 1. Redistributions of source code must retain the above copyright
9e3148e46SNavdeep Parhar  *    notice, this list of conditions and the following disclaimer.
10e3148e46SNavdeep Parhar  * 2. Redistributions in binary form must reproduce the above copyright
11e3148e46SNavdeep Parhar  *    notice, this list of conditions and the following disclaimer in the
12e3148e46SNavdeep Parhar  *    documentation and/or other materials provided with the distribution.
13e3148e46SNavdeep Parhar  *
14e3148e46SNavdeep Parhar  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15e3148e46SNavdeep Parhar  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16e3148e46SNavdeep Parhar  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17e3148e46SNavdeep Parhar  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18e3148e46SNavdeep Parhar  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19e3148e46SNavdeep Parhar  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20e3148e46SNavdeep Parhar  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21e3148e46SNavdeep Parhar  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22e3148e46SNavdeep Parhar  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23e3148e46SNavdeep Parhar  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24e3148e46SNavdeep Parhar  * SUCH DAMAGE.
25e3148e46SNavdeep Parhar  *
26e3148e46SNavdeep Parhar  */
27e3148e46SNavdeep Parhar 
28e3148e46SNavdeep Parhar #ifndef __CXGBEI_OFLD_H__
29e3148e46SNavdeep Parhar #define __CXGBEI_OFLD_H__
30e3148e46SNavdeep Parhar 
31e3148e46SNavdeep Parhar #include <dev/iscsi/icl.h>
32e3148e46SNavdeep Parhar 
33e3148e46SNavdeep Parhar #define CXGBEI_CONN_SIGNATURE 0x56788765
34e3148e46SNavdeep Parhar 
3567360f7bSJohn Baldwin struct cxgbei_cmp {
3667360f7bSJohn Baldwin 	LIST_ENTRY(cxgbei_cmp) link;
3767360f7bSJohn Baldwin 
3867360f7bSJohn Baldwin 	uint32_t tt;		/* Transfer tag. */
3967360f7bSJohn Baldwin 
4067360f7bSJohn Baldwin 	uint32_t next_buffer_offset;
4167360f7bSJohn Baldwin 	uint32_t last_datasn;
4267360f7bSJohn Baldwin };
4367360f7bSJohn Baldwin LIST_HEAD(cxgbei_cmp_head, cxgbei_cmp);
4467360f7bSJohn Baldwin 
45e3148e46SNavdeep Parhar struct icl_cxgbei_conn {
46e3148e46SNavdeep Parhar 	struct icl_conn ic;
47e3148e46SNavdeep Parhar 
48e3148e46SNavdeep Parhar 	/* cxgbei specific stuff goes here. */
49e3148e46SNavdeep Parhar 	uint32_t icc_signature;
50e3148e46SNavdeep Parhar 	int ulp_submode;
51e3148e46SNavdeep Parhar 	struct adapter *sc;
52e3148e46SNavdeep Parhar 	struct toepcb *toep;
53e3148e46SNavdeep Parhar 
54e3148e46SNavdeep Parhar 	/* Receive related. */
55fd8f61d6SJohn Baldwin 	bool rx_active;				/* protected by so_rcv lock */
56*511b83b1SJohn Baldwin 	bool rx_exiting;			/* protected by so_rcv lock */
57e3148e46SNavdeep Parhar 	STAILQ_HEAD(, icl_pdu) rcvd_pdus;	/* protected by so_rcv lock */
58*511b83b1SJohn Baldwin 	struct thread *rx_thread;
5967360f7bSJohn Baldwin 
6067360f7bSJohn Baldwin 	struct cxgbei_cmp_head *cmp_table;	/* protected by cmp_lock */
6167360f7bSJohn Baldwin 	struct mtx cmp_lock;
6267360f7bSJohn Baldwin 	unsigned long cmp_hash_mask;
63fd8f61d6SJohn Baldwin 
64fd8f61d6SJohn Baldwin 	/* Transmit related. */
65fd8f61d6SJohn Baldwin 	bool tx_active;				/* protected by ic lock */
66fd8f61d6SJohn Baldwin 	STAILQ_HEAD(, icl_pdu) sent_pdus;	/* protected by ic lock */
67*511b83b1SJohn Baldwin 	struct thread *tx_thread;
68e3148e46SNavdeep Parhar };
69e3148e46SNavdeep Parhar 
70e3148e46SNavdeep Parhar static inline struct icl_cxgbei_conn *
ic_to_icc(struct icl_conn * ic)71e3148e46SNavdeep Parhar ic_to_icc(struct icl_conn *ic)
72e3148e46SNavdeep Parhar {
73e3148e46SNavdeep Parhar 
74e3148e46SNavdeep Parhar 	return (__containerof(ic, struct icl_cxgbei_conn, ic));
75e3148e46SNavdeep Parhar }
76e3148e46SNavdeep Parhar 
77a95e0bfbSNavdeep Parhar /* PDU flags and signature. */
78a95e0bfbSNavdeep Parhar enum {
79a95e0bfbSNavdeep Parhar 	ICPF_RX_HDR	= 1 << 0, /* PDU header received. */
80a95e0bfbSNavdeep Parhar 	ICPF_RX_FLBUF	= 1 << 1, /* PDU payload received in a freelist. */
81a95e0bfbSNavdeep Parhar 	ICPF_RX_DDP	= 1 << 2, /* PDU payload DDP'd. */
82a95e0bfbSNavdeep Parhar 	ICPF_RX_STATUS	= 1 << 3, /* Rx status received. */
83a95e0bfbSNavdeep Parhar 
84a95e0bfbSNavdeep Parhar 	CXGBEI_PDU_SIGNATURE = 0x12344321
85a95e0bfbSNavdeep Parhar };
86e3148e46SNavdeep Parhar 
87e3148e46SNavdeep Parhar struct icl_cxgbei_pdu {
88e3148e46SNavdeep Parhar 	struct icl_pdu ip;
89e3148e46SNavdeep Parhar 
90e3148e46SNavdeep Parhar 	/* cxgbei specific stuff goes here. */
91e3148e46SNavdeep Parhar 	uint32_t icp_signature;
92a95e0bfbSNavdeep Parhar 	uint32_t icp_seq;	/* For debug only */
93a95e0bfbSNavdeep Parhar 	u_int icp_flags;
94a1c68734SJohn Baldwin 
95a1c68734SJohn Baldwin 	u_int ref_cnt;
96a1c68734SJohn Baldwin 	icl_pdu_cb cb;
97a1c68734SJohn Baldwin 	int error;
98e3148e46SNavdeep Parhar };
99e3148e46SNavdeep Parhar 
100e3148e46SNavdeep Parhar static inline struct icl_cxgbei_pdu *
ip_to_icp(struct icl_pdu * ip)101e3148e46SNavdeep Parhar ip_to_icp(struct icl_pdu *ip)
102e3148e46SNavdeep Parhar {
103e3148e46SNavdeep Parhar 
104e3148e46SNavdeep Parhar 	return (__containerof(ip, struct icl_cxgbei_pdu, ip));
105e3148e46SNavdeep Parhar }
106e3148e46SNavdeep Parhar 
107e3148e46SNavdeep Parhar struct cxgbei_data {
108cbc18636SJohn Baldwin 	u_int max_tx_data_len;
109cbc18636SJohn Baldwin 	u_int max_rx_data_len;
110e3148e46SNavdeep Parhar 
1117cba15b1SNavdeep Parhar 	u_int ddp_threshold;
1127cba15b1SNavdeep Parhar 	struct ppod_region pr;
113e3148e46SNavdeep Parhar 
11422536e15SNavdeep Parhar 	struct sysctl_ctx_list ctx;	/* from uld_activate to deactivate */
115e3148e46SNavdeep Parhar };
116e3148e46SNavdeep Parhar 
1175b27e4b2SJohn Baldwin #define CXGBEI_MAX_ISO_PAYLOAD	65535
1185b27e4b2SJohn Baldwin 
1197cba15b1SNavdeep Parhar /* cxgbei.c */
120e3148e46SNavdeep Parhar u_int cxgbei_select_worker_thread(struct icl_cxgbei_conn *);
121fd8f61d6SJohn Baldwin void cwt_queue_for_tx(struct icl_cxgbei_conn *);
122*511b83b1SJohn Baldwin void parse_pdus(struct icl_cxgbei_conn *, struct sockbuf *);
123e3148e46SNavdeep Parhar 
124c149da16SNavdeep Parhar /* icl_cxgbei.c */
125fd8f61d6SJohn Baldwin void cwt_tx_main(void *);
126c149da16SNavdeep Parhar int icl_cxgbei_mod_load(void);
127c149da16SNavdeep Parhar int icl_cxgbei_mod_unload(void);
12845eed233SJohn Baldwin struct icl_pdu *icl_cxgbei_new_pdu(int);
12945eed233SJohn Baldwin void icl_cxgbei_new_pdu_set_conn(struct icl_pdu *, struct icl_conn *);
13045eed233SJohn Baldwin void icl_cxgbei_conn_pdu_free(struct icl_conn *, struct icl_pdu *);
13167360f7bSJohn Baldwin struct cxgbei_cmp *cxgbei_find_cmp(struct icl_cxgbei_conn *, uint32_t);
13245eed233SJohn Baldwin 
133e3148e46SNavdeep Parhar #endif
134