xref: /freebsd/sys/dev/cxgbe/cxgbei/cxgbei.h (revision 0b3105a37d7adcadcb720112fed4dc4e8040be99)
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 icl_cxgbei_conn {
57 	struct icl_conn ic;
58 
59 	/* cxgbei specific stuff goes here. */
60 	uint32_t icc_signature;
61 	int ulp_submode;
62 	struct adapter *sc;
63 	struct toepcb *toep;
64 
65 	/* Receive related. */
66 	u_int rx_flags;				/* protected by so_rcv lock */
67 	u_int cwt;
68 	STAILQ_HEAD(, icl_pdu) rcvd_pdus;	/* protected by so_rcv lock */
69 	TAILQ_ENTRY(icl_cxgbei_conn) rx_link;	/* protected by cwt lock */
70 };
71 
72 static inline struct icl_cxgbei_conn *
73 ic_to_icc(struct icl_conn *ic)
74 {
75 
76 	return (__containerof(ic, struct icl_cxgbei_conn, ic));
77 }
78 
79 #define CXGBEI_PDU_SIGNATURE 0x12344321
80 
81 struct icl_cxgbei_pdu {
82 	struct icl_pdu ip;
83 
84 	/* cxgbei specific stuff goes here. */
85 	uint32_t icp_signature;
86 	uint32_t pdu_seq;	/* For debug only */
87 	u_int pdu_flags;
88 };
89 
90 static inline struct icl_cxgbei_pdu *
91 ip_to_icp(struct icl_pdu *ip)
92 {
93 
94 	return (__containerof(ip, struct icl_cxgbei_pdu, ip));
95 }
96 
97 struct cxgbei_sgl {
98         int     sg_flag;
99         void    *sg_addr;
100         void    *sg_dma_addr;
101         size_t  sg_offset;
102         size_t  sg_length;
103 };
104 
105 #define cxgbei_scsi_for_each_sg(_sgl, _sgel, _n, _i)      \
106         for (_i = 0, _sgel = (cxgbei_sgl*) (_sgl); _i < _n; _i++, \
107                         _sgel++)
108 #define sg_dma_addr(_sgel)      _sgel->sg_dma_addr
109 #define sg_virt(_sgel)          _sgel->sg_addr
110 #define sg_len(_sgel)           _sgel->sg_length
111 #define sg_off(_sgel)           _sgel->sg_offset
112 #define sg_next(_sgel)          _sgel + 1
113 
114 #define SBUF_ULP_FLAG_HDR_RCVD          0x1
115 #define SBUF_ULP_FLAG_DATA_RCVD         0x2
116 #define SBUF_ULP_FLAG_STATUS_RCVD       0x4
117 #define SBUF_ULP_FLAG_HCRC_ERROR        0x10
118 #define SBUF_ULP_FLAG_DCRC_ERROR        0x20
119 #define SBUF_ULP_FLAG_PAD_ERROR         0x40
120 #define SBUF_ULP_FLAG_DATA_DDPED        0x80
121 
122 /* private data for each scsi task */
123 struct cxgbei_task_data {
124 	struct cxgbei_sgl sgl[256];
125 	u_int	nsge;
126 	u_int	sc_ddp_tag;
127 };
128 
129 struct cxgbei_ulp2_tag_format {
130 	u_char sw_bits;
131 	u_char rsvd_bits;
132 	u_char rsvd_shift;
133 	u_char filler[1];
134 	uint32_t rsvd_mask;
135 };
136 
137 struct cxgbei_data {
138 	u_int max_txsz;
139 	u_int max_rxsz;
140 	u_int llimit;
141 	u_int ulimit;
142 	u_int nppods;
143 	u_int idx_last;
144 	u_char idx_bits;
145 	uint32_t idx_mask;
146 	uint32_t rsvd_tag_mask;
147 
148 	struct mtx map_lock;
149 	bus_dma_tag_t ulp_ddp_tag;
150 	unsigned char *colors;
151 	struct cxgbei_ulp2_gather_list **gl_map;
152 
153 	struct cxgbei_ulp2_tag_format tag_format;
154 };
155 
156 void cxgbei_conn_task_reserve_itt(void *, void **, void *, unsigned int *);
157 void cxgbei_conn_transfer_reserve_ttt(void *, void **, void *, unsigned int *);
158 void cxgbei_cleanup_task(void *, void *);
159 u_int cxgbei_select_worker_thread(struct icl_cxgbei_conn *);
160 
161 struct cxgbei_ulp2_pagepod_hdr;
162 int t4_ddp_set_map(struct cxgbei_data *, void *,
163     struct cxgbei_ulp2_pagepod_hdr *, u_int, u_int,
164     struct cxgbei_ulp2_gather_list *, int);
165 void t4_ddp_clear_map(struct cxgbei_data *, struct cxgbei_ulp2_gather_list *,
166     u_int, u_int, u_int, struct icl_cxgbei_conn *);
167 #endif
168