1/*
2 * Copyright (c) 2017-2018 Cavium, 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 *
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 COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 *  AND 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 COPYRIGHT OWNER OR CONTRIBUTORS BE
19 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 *  POSSIBILITY OF SUCH DAMAGE.
26 *
27 */
28
29#ifndef __ECORE_ISCSI_API_H__
30#define __ECORE_ISCSI_API_H__
31
32#ifndef __EXTRACT__LINUX__IF__
33typedef enum _ecore_status_t (*iscsi_event_cb_t)(void *context,
34						 u8 fw_event_code,
35						 void *fw_handle);
36
37struct ecore_iscsi_stats
38{
39	u64 iscsi_rx_bytes_cnt;
40	u64 iscsi_rx_packet_cnt;
41	u64 iscsi_rx_new_ooo_isle_events_cnt;
42	u32 iscsi_cmdq_threshold_cnt;
43	u32 iscsi_rq_threshold_cnt;
44	u32 iscsi_immq_threshold_cnt;
45
46	u64 iscsi_rx_dropped_pdus_task_not_valid;
47
48	u64 iscsi_rx_data_pdu_cnt;
49	u64 iscsi_rx_r2t_pdu_cnt;
50	u64 iscsi_rx_total_pdu_cnt;
51
52	u64 iscsi_tx_go_to_slow_start_event_cnt;
53	u64 iscsi_tx_fast_retransmit_event_cnt;
54
55	u64 iscsi_tx_data_pdu_cnt;
56	u64 iscsi_tx_r2t_pdu_cnt;
57	u64 iscsi_tx_total_pdu_cnt;
58
59	u64 iscsi_tx_bytes_cnt;
60	u64 iscsi_tx_packet_cnt;
61
62	u64 iscsi_rx_tcp_payload_bytes_cnt;
63	u64 iscsi_rx_tcp_pkt_cnt;
64	u64 iscsi_rx_pure_ack_cnt;
65
66	u64 iscsi_rx_dup_ack_cnt;
67
68	u64 iscsi_tx_pure_ack_cnt;
69	u64 iscsi_tx_delayed_ack_cnt;
70
71	u64 iscsi_tx_tcp_payload_bytes_cnt;
72	u64 iscsi_tx_tcp_pkt_cnt;
73};
74
75struct ecore_iscsi_tcp_stats
76{
77	u64 iscsi_tcp_tx_packets_cnt;
78	u64 iscsi_tcp_tx_bytes_cnt;
79	u64 iscsi_tcp_tx_rxmit_cnt;
80	u64 iscsi_tcp_rx_packets_cnt;
81	u64 iscsi_tcp_rx_bytes_cnt;
82	u64 iscsi_tcp_rx_dup_ack_cnt;
83	u32 iscsi_tcp_rx_chksum_err_cnt;
84};
85#endif
86
87#ifndef __EXTRACT__LINUX__C__
88struct ecore_iscsi_conn {
89	osal_list_entry_t	list_entry;
90	bool			free_on_delete;
91
92	u16			conn_id;
93	u32			icid;
94	u32			fw_cid;
95
96	u8			layer_code;
97	u8			offl_flags;
98	u8			connect_mode;
99	u32			initial_ack;
100	dma_addr_t		sq_pbl_addr;
101	struct ecore_chain	r2tq;
102	struct ecore_chain	xhq;
103	struct ecore_chain	uhq;
104
105	struct tcp_upload_params *tcp_upload_params_virt_addr;
106	dma_addr_t		tcp_upload_params_phys_addr;
107	struct iscsi_conn_stats_params *conn_stats_params_virt_addr;
108	dma_addr_t		conn_stats_params_phys_addr;
109	struct scsi_terminate_extra_params *queue_cnts_virt_addr;
110	dma_addr_t		queue_cnts_phys_addr;
111	dma_addr_t		syn_phy_addr;
112
113	u16			syn_ip_payload_length;
114	u8			local_mac[6];
115	u8			remote_mac[6];
116	u16			vlan_id;
117	u16			tcp_flags;
118	u8			ip_version;
119	u32			remote_ip[4];
120	u32			local_ip[4];
121	u8			ka_max_probe_cnt;
122	u8			dup_ack_theshold;
123	u32			rcv_next;
124	u32			snd_una;
125	u32			snd_next;
126	u32			snd_max;
127	u32			snd_wnd;
128	u32			rcv_wnd;
129	u32			snd_wl1;
130	u32			cwnd;
131	u32			ss_thresh;
132	u16			srtt;
133	u16			rtt_var;
134	u32			ts_recent;
135	u32			ts_recent_age;
136	u32			total_rt;
137	u32			ka_timeout_delta;
138	u32			rt_timeout_delta;
139	u8			dup_ack_cnt;
140	u8			snd_wnd_probe_cnt;
141	u8			ka_probe_cnt;
142	u8			rt_cnt;
143	u32			flow_label;
144	u32			ka_timeout;
145	u32			ka_interval;
146	u32			max_rt_time;
147	u32			initial_rcv_wnd;
148	u8			ttl;
149	u8			tos_or_tc;
150	u16			remote_port;
151	u16			local_port;
152	u16			mss;
153	u8			snd_wnd_scale;
154	u8			rcv_wnd_scale;
155	u16			da_timeout_value;
156	u8			ack_frequency;
157
158	u8			update_flag;
159#define	ECORE_ISCSI_CONN_HD_EN		0x01
160#define	ECORE_ISCSI_CONN_DD_EN		0x02
161#define	ECORE_ISCSI_CONN_INITIAL_R2T	0x04
162#define	ECORE_ISCSI_CONN_IMMEDIATE_DATA	0x08
163
164	u8			default_cq;
165	u32			max_seq_size;
166	u32			max_recv_pdu_length;
167	u32			max_send_pdu_length;
168	u32			first_seq_length;
169	u32			exp_stat_sn;
170	u32			stat_sn;
171	u16			physical_q0;
172	u16			physical_q1;
173	u8			abortive_dsconnect;
174	u8			dif_on_immediate;
175#define ECORE_ISCSI_CONN_DIF_ON_IMM_DIS		0
176#define ECORE_ISCSI_CONN_DIF_ON_IMM_DEFAULT	1
177#define ECORE_ISCSI_CONN_DIF_ON_IMM_LUN_MAPPER	2
178
179	dma_addr_t		lun_mapper_phys_addr;
180	u32			initial_ref_tag;
181	u16			application_tag;
182	u16			application_tag_mask;
183	u8			validate_guard;
184	u8			validate_app_tag;
185	u8			validate_ref_tag;
186	u8			forward_guard;
187	u8			forward_app_tag;
188	u8			forward_ref_tag;
189	u8			interval_size;		/* 0=512B, 1=4KB */
190	u8			network_interface;	/* 0=None, 1=DIF */
191	u8			host_interface;		/* 0=None, 1=DIF, 2=DIX */
192	u8			ref_tag_mask;		/* mask for refernce tag handling */
193	u8			forward_app_tag_with_mask;
194	u8			forward_ref_tag_with_mask;
195
196	u8			ignore_app_tag;
197	u8			initial_ref_tag_is_valid;
198	u8			host_guard_type;	/* 0 = IP checksum, 1 = CRC */
199	u8			protection_type;	/* 1/2/3 - Protection Type */
200	u8			crc_seed;		/* 0=0x0000, 1=0xffff */
201	u8			keep_ref_tag_const;
202};
203#endif
204
205/**
206 * @brief ecore_iscsi_acquire_connection - allocate resources,
207 *        provides connecion handle (CID)as out parameter.
208 *
209 * @param p_path
210 * @param p_conn  partially initialized incoming container of
211 *                iSCSI connection data
212 * @return enum _ecore_status_t
213 */
214enum _ecore_status_t
215ecore_iscsi_acquire_connection(struct ecore_hwfn *p_hwfn,
216			       struct ecore_iscsi_conn *p_in_conn,
217			       struct ecore_iscsi_conn **p_out_conn);
218
219/**
220 * @brief ecore_iscsi_setup_connection- initialize connection data.
221 *
222 * @param p_conn  container of iSCSI connection data
223 * @return enum _ecore_status_t
224 */
225enum _ecore_status_t
226ecore_iscsi_setup_connection(struct ecore_iscsi_conn *p_conn);
227
228void OSAL_IOMEM *ecore_iscsi_get_db_addr(struct ecore_hwfn *p_hwfn,
229					 u32 cid);
230
231void OSAL_IOMEM *ecore_iscsi_get_global_cmdq_cons(struct ecore_hwfn *p_hwfn,
232						  u8 relative_q_id);
233
234void OSAL_IOMEM *ecore_iscsi_get_primary_bdq_prod(struct ecore_hwfn *p_hwfn,
235						  u8 bdq_id);
236
237void OSAL_IOMEM *ecore_iscsi_get_secondary_bdq_prod(struct ecore_hwfn *p_hwfn,
238						    u8 bdq_id);
239
240/**
241 * @brief ecore_iscsi_offload_connection - offload previously
242 *        allocated iSCSI connection
243 *
244 * @param p_path
245 * @param p_conn  container of iSCSI connection data
246 *
247 * @return enum _ecore_status_t
248 */
249enum _ecore_status_t
250ecore_iscsi_offload_connection(struct ecore_hwfn *p_hwfn,
251			       struct ecore_iscsi_conn *p_conn);
252
253/**
254 * @brief ecore_iscsi_release_connection - deletes connecton
255 *        resources (incliding container of iSCSI connection
256 *        data)
257 *
258 * @param p_path
259 * @param p_conn  container of iSCSI connection data
260 */
261void ecore_iscsi_release_connection(struct ecore_hwfn *p_hwfn,
262				    struct ecore_iscsi_conn *p_conn);
263
264/**
265 * @brief ecore_iscsi_terminate_connection - destroys previously
266 *        offloaded iSCSI connection
267 *
268 * @param p_path
269 * @param p_conn  container of iSCSI connection data
270 *
271 * @return enum _ecore_status_t
272 */
273enum _ecore_status_t
274ecore_iscsi_terminate_connection(struct ecore_hwfn *p_hwfn,
275				 struct ecore_iscsi_conn *p_conn);
276
277/**
278 * @brief ecore_iscsi_update_connection - updates previously
279 *        offloaded iSCSI connection
280 *
281 *
282 * @param p_path
283 * @param p_conn  container of iSCSI connection data
284 *
285 * @return enum _ecore_status_t
286 */
287enum _ecore_status_t
288ecore_iscsi_update_connection(struct ecore_hwfn *p_hwfn,
289			      struct ecore_iscsi_conn *p_conn);
290
291/**
292 * @brief ecore_iscsi_mac_update_connection - updates remote MAC for previously
293 *        offloaded iSCSI connection
294 *
295 *
296 * @param p_path
297 * @param p_conn  container of iSCSI connection data
298 *
299 * @return enum _ecore_status_t
300 */
301enum _ecore_status_t
302ecore_iscsi_update_remote_mac(struct ecore_hwfn *p_hwfn,
303			      struct ecore_iscsi_conn *p_conn);
304
305/**
306 * @brief ecore_iscsi_get_tcp_stats - get and optionally reset TCP statistics
307 *        of offloaded iSCSI connection
308 *
309 *
310 * @param p_path
311 * @param p_conn  container of iSCSI connection data
312 * @param p_stats - buffer to place extracted stats
313 * @param reset - 1 - for reset stats (after extraction of accumulated
314 *                statistics in optionally provided buffer)
315 * @return enum _ecore_status_t
316 */
317enum _ecore_status_t
318ecore_iscsi_get_tcp_stats(struct ecore_hwfn *p_hwfn,
319			  struct ecore_iscsi_conn *p_conn,
320			  struct ecore_iscsi_tcp_stats *p_stats,
321			  u8 reset);
322
323/**
324 * @brief ecore_iscsi_clear_connection_sq - clear SQ
325 *        offloaded iSCSI connection
326 *
327 *
328 * @param p_path
329 * @param p_conn  container of iSCSI connection data
330 *
331 * @return enum _ecore_status_t
332 */
333enum _ecore_status_t
334ecore_iscsi_clear_connection_sq(struct ecore_hwfn *p_hwfn,
335				struct ecore_iscsi_conn *p_conn);
336
337/**
338 * @brief ecore_sp_iscsi_func_start
339 *
340 * This ramrod inits iSCSI functionality in FW
341 *
342 * @param p_path
343 * @param comp_mode
344 * @param comp_addr
345 *
346 * @return enum _ecore_status_t
347 */
348enum _ecore_status_t
349ecore_sp_iscsi_func_start(struct ecore_hwfn *p_hwfn,
350			  enum spq_mode comp_mode,
351			  struct ecore_spq_comp_cb *p_comp_addr,
352			  void *async_event_context,
353			  iscsi_event_cb_t async_event_cb);
354
355enum _ecore_status_t
356ecore_sp_iscsi_func_stop(struct ecore_hwfn *p_hwfn,
357			 enum spq_mode comp_mode,
358			 struct ecore_spq_comp_cb *p_comp_addr);
359
360enum _ecore_status_t
361ecore_iscsi_get_stats(struct ecore_hwfn *p_hwfn,
362		      struct ecore_iscsi_stats *stats);
363
364#endif
365