167b40dccSKalderon, Michal /* QLogic qed NIC Driver
267b40dccSKalderon, Michal  * Copyright (c) 2015-2017  QLogic Corporation
367b40dccSKalderon, Michal  *
467b40dccSKalderon, Michal  * This software is available to you under a choice of one of two
567b40dccSKalderon, Michal  * licenses.  You may choose to be licensed under the terms of the GNU
667b40dccSKalderon, Michal  * General Public License (GPL) Version 2, available from the file
767b40dccSKalderon, Michal  * COPYING in the main directory of this source tree, or the
867b40dccSKalderon, Michal  * OpenIB.org BSD license below:
967b40dccSKalderon, Michal  *
1067b40dccSKalderon, Michal  *     Redistribution and use in source and binary forms, with or
1167b40dccSKalderon, Michal  *     without modification, are permitted provided that the following
1267b40dccSKalderon, Michal  *     conditions are met:
1367b40dccSKalderon, Michal  *
1467b40dccSKalderon, Michal  *      - Redistributions of source code must retain the above
1567b40dccSKalderon, Michal  *        copyright notice, this list of conditions and the following
1667b40dccSKalderon, Michal  *        disclaimer.
1767b40dccSKalderon, Michal  *
1867b40dccSKalderon, Michal  *      - Redistributions in binary form must reproduce the above
1967b40dccSKalderon, Michal  *        copyright notice, this list of conditions and the following
2067b40dccSKalderon, Michal  *        disclaimer in the documentation and /or other materials
2167b40dccSKalderon, Michal  *        provided with the distribution.
2267b40dccSKalderon, Michal  *
2367b40dccSKalderon, Michal  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2467b40dccSKalderon, Michal  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2567b40dccSKalderon, Michal  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2667b40dccSKalderon, Michal  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2767b40dccSKalderon, Michal  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2867b40dccSKalderon, Michal  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2967b40dccSKalderon, Michal  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3067b40dccSKalderon, Michal  * SOFTWARE.
3167b40dccSKalderon, Michal  */
3267b40dccSKalderon, Michal #ifndef _QED_IWARP_H
3367b40dccSKalderon, Michal #define _QED_IWARP_H
3467b40dccSKalderon, Michal 
3567b40dccSKalderon, Michal enum qed_iwarp_qp_state {
3667b40dccSKalderon, Michal 	QED_IWARP_QP_STATE_IDLE,
3767b40dccSKalderon, Michal 	QED_IWARP_QP_STATE_RTS,
3867b40dccSKalderon, Michal 	QED_IWARP_QP_STATE_TERMINATE,
3967b40dccSKalderon, Michal 	QED_IWARP_QP_STATE_CLOSING,
4067b40dccSKalderon, Michal 	QED_IWARP_QP_STATE_ERROR,
4167b40dccSKalderon, Michal };
4267b40dccSKalderon, Michal 
4367b40dccSKalderon, Michal enum qed_iwarp_qp_state qed_roce2iwarp_state(enum qed_roce_qp_state state);
4467b40dccSKalderon, Michal 
45456a5849SKalderon, Michal #define QED_IWARP_PREALLOC_CNT  (256)
46456a5849SKalderon, Michal 
47b5c29ca7SKalderon, Michal #define QED_IWARP_LL2_SYN_TX_SIZE       (128)
48b5c29ca7SKalderon, Michal #define QED_IWARP_LL2_SYN_RX_SIZE       (256)
49d1abfd0bSMichal Kalderon 
50d1abfd0bSMichal Kalderon #define QED_IWARP_LL2_OOO_DEF_TX_SIZE   (256)
51d1abfd0bSMichal Kalderon #define QED_IWARP_MAX_OOO		(16)
52d1abfd0bSMichal Kalderon #define QED_IWARP_LL2_OOO_MAX_RX_SIZE   (16384)
53d1abfd0bSMichal Kalderon 
54b5c29ca7SKalderon, Michal #define QED_IWARP_HANDLE_INVAL		(0xff)
55b5c29ca7SKalderon, Michal 
56b5c29ca7SKalderon, Michal struct qed_iwarp_ll2_buff {
57d531038eSMichal Kalderon 	struct qed_iwarp_ll2_buff *piggy_buf;
58b5c29ca7SKalderon, Michal 	void *data;
59b5c29ca7SKalderon, Michal 	dma_addr_t data_phys_addr;
60b5c29ca7SKalderon, Michal 	u32 buff_size;
61b5c29ca7SKalderon, Michal };
62b5c29ca7SKalderon, Michal 
63fcb39f6cSMichal Kalderon struct qed_iwarp_ll2_mpa_buf {
64fcb39f6cSMichal Kalderon 	struct list_head list_entry;
65fcb39f6cSMichal Kalderon 	struct qed_iwarp_ll2_buff *ll2_buf;
66fcb39f6cSMichal Kalderon 	struct unaligned_opaque_data data;
67fcb39f6cSMichal Kalderon 	u16 tcp_payload_len;
68fcb39f6cSMichal Kalderon 	u8 placement_offset;
69fcb39f6cSMichal Kalderon };
70fcb39f6cSMichal Kalderon 
71c7d1d839SMichal Kalderon /* In some cases a fpdu will arrive with only one byte of the header, in this
72c7d1d839SMichal Kalderon  * case the fpdu_length will be partial (contain only higher byte and
73c7d1d839SMichal Kalderon  * incomplete bytes will contain the invalid value
74c7d1d839SMichal Kalderon  */
75c7d1d839SMichal Kalderon #define QED_IWARP_INVALID_INCOMPLETE_BYTES 0xffff
76c7d1d839SMichal Kalderon 
77469981b1SMichal Kalderon struct qed_iwarp_fpdu {
78469981b1SMichal Kalderon 	struct qed_iwarp_ll2_buff *mpa_buf;
79469981b1SMichal Kalderon 	void *mpa_frag_virt;
80469981b1SMichal Kalderon 	dma_addr_t mpa_frag;
81469981b1SMichal Kalderon 	dma_addr_t pkt_hdr;
82469981b1SMichal Kalderon 	u16 mpa_frag_len;
83469981b1SMichal Kalderon 	u16 fpdu_length;
84469981b1SMichal Kalderon 	u16 incomplete_bytes;
85469981b1SMichal Kalderon 	u8 pkt_hdr_size;
86469981b1SMichal Kalderon };
87469981b1SMichal Kalderon 
8867b40dccSKalderon, Michal struct qed_iwarp_info {
8965a91a6cSKalderon, Michal 	struct list_head listen_list;	/* qed_iwarp_listener */
90456a5849SKalderon, Michal 	struct list_head ep_list;	/* qed_iwarp_ep */
91456a5849SKalderon, Michal 	struct list_head ep_free_list;	/* pre-allocated ep's */
92fcb39f6cSMichal Kalderon 	struct list_head mpa_buf_list;	/* list of mpa_bufs */
93fcb39f6cSMichal Kalderon 	struct list_head mpa_buf_pending_list;
9467b40dccSKalderon, Michal 	spinlock_t iw_lock;	/* for iwarp resources */
9567b40dccSKalderon, Michal 	spinlock_t qp_lock;	/* for teardown races */
9667b40dccSKalderon, Michal 	u32 rcv_wnd_scale;
97da090917STomer Tayar 	u16 rcv_wnd_size;
9867b40dccSKalderon, Michal 	u16 max_mtu;
9967b40dccSKalderon, Michal 	u8 mac_addr[ETH_ALEN];
10067b40dccSKalderon, Michal 	u8 crc_needed;
10167b40dccSKalderon, Michal 	u8 tcp_flags;
102b5c29ca7SKalderon, Michal 	u8 ll2_syn_handle;
103d1abfd0bSMichal Kalderon 	u8 ll2_ooo_handle;
104ae3488ffSMichal Kalderon 	u8 ll2_mpa_handle;
10567b40dccSKalderon, Michal 	u8 peer2peer;
10667b40dccSKalderon, Michal 	enum mpa_negotiation_mode mpa_rev;
10767b40dccSKalderon, Michal 	enum mpa_rtr_type rtr_type;
108469981b1SMichal Kalderon 	struct qed_iwarp_fpdu *partial_fpdus;
109fcb39f6cSMichal Kalderon 	struct qed_iwarp_ll2_mpa_buf *mpa_bufs;
1101e28eaadSMichal Kalderon 	u8 *mpa_intermediate_buf;
111469981b1SMichal Kalderon 	u16 max_num_partial_fpdus;
11267b40dccSKalderon, Michal };
11367b40dccSKalderon, Michal 
114456a5849SKalderon, Michal enum qed_iwarp_ep_state {
115456a5849SKalderon, Michal 	QED_IWARP_EP_INIT,
116456a5849SKalderon, Michal 	QED_IWARP_EP_MPA_REQ_RCVD,
117456a5849SKalderon, Michal 	QED_IWARP_EP_MPA_OFFLOADED,
118456a5849SKalderon, Michal 	QED_IWARP_EP_ESTABLISHED,
119456a5849SKalderon, Michal 	QED_IWARP_EP_CLOSED
120456a5849SKalderon, Michal };
121456a5849SKalderon, Michal 
122456a5849SKalderon, Michal union async_output {
123456a5849SKalderon, Michal 	struct iwarp_eqe_data_mpa_async_completion mpa_response;
124456a5849SKalderon, Michal 	struct iwarp_eqe_data_tcp_async_completion mpa_request;
125456a5849SKalderon, Michal };
126456a5849SKalderon, Michal 
127456a5849SKalderon, Michal #define QED_MAX_PRIV_DATA_LEN (512)
128456a5849SKalderon, Michal struct qed_iwarp_ep_memory {
129456a5849SKalderon, Michal 	u8 in_pdata[QED_MAX_PRIV_DATA_LEN];
130456a5849SKalderon, Michal 	u8 out_pdata[QED_MAX_PRIV_DATA_LEN];
131456a5849SKalderon, Michal 	union async_output async_output;
132456a5849SKalderon, Michal };
133456a5849SKalderon, Michal 
134456a5849SKalderon, Michal /* Endpoint structure represents a TCP connection. This connection can be
135456a5849SKalderon, Michal  * associated with a QP or not (in which case QP==NULL)
136456a5849SKalderon, Michal  */
137456a5849SKalderon, Michal struct qed_iwarp_ep {
138456a5849SKalderon, Michal 	struct list_head list_entry;
139456a5849SKalderon, Michal 	struct qed_rdma_qp *qp;
140456a5849SKalderon, Michal 	struct qed_iwarp_ep_memory *ep_buffer_virt;
141456a5849SKalderon, Michal 	dma_addr_t ep_buffer_phys;
142456a5849SKalderon, Michal 	enum qed_iwarp_ep_state state;
143456a5849SKalderon, Michal 	int sig;
144456a5849SKalderon, Michal 	struct qed_iwarp_cm_info cm_info;
145456a5849SKalderon, Michal 	enum tcp_connect_mode connect_mode;
146456a5849SKalderon, Michal 	enum mpa_rtr_type rtr_type;
147456a5849SKalderon, Michal 	enum mpa_negotiation_mode mpa_rev;
148456a5849SKalderon, Michal 	u32 tcp_cid;
149456a5849SKalderon, Michal 	u32 cid;
150456a5849SKalderon, Michal 	u16 mss;
151456a5849SKalderon, Michal 	u8 remote_mac_addr[6];
152456a5849SKalderon, Michal 	u8 local_mac_addr[6];
153456a5849SKalderon, Michal 	bool mpa_reply_processed;
154456a5849SKalderon, Michal 
155456a5849SKalderon, Michal 	/* For Passive side - syn packet related data */
156456a5849SKalderon, Michal 	u16 syn_ip_payload_length;
157456a5849SKalderon, Michal 	struct qed_iwarp_ll2_buff *syn;
158456a5849SKalderon, Michal 	dma_addr_t syn_phy_addr;
159456a5849SKalderon, Michal 
160456a5849SKalderon, Michal 	/* The event_cb function is called for asynchrounous events associated
161456a5849SKalderon, Michal 	 * with the ep. It is initialized at different entry points depending
162456a5849SKalderon, Michal 	 * on whether the ep is the tcp connection active side or passive side
163456a5849SKalderon, Michal 	 * The cb_context is passed to the event_cb function.
164456a5849SKalderon, Michal 	 */
165456a5849SKalderon, Michal 	iwarp_event_handler event_cb;
166456a5849SKalderon, Michal 	void *cb_context;
167456a5849SKalderon, Michal };
168456a5849SKalderon, Michal 
16965a91a6cSKalderon, Michal struct qed_iwarp_listener {
17065a91a6cSKalderon, Michal 	struct list_head list_entry;
17165a91a6cSKalderon, Michal 
17265a91a6cSKalderon, Michal 	/* The event_cb function is called for connection requests.
17365a91a6cSKalderon, Michal 	 * The cb_context is passed to the event_cb function.
17465a91a6cSKalderon, Michal 	 */
17565a91a6cSKalderon, Michal 	iwarp_event_handler event_cb;
17665a91a6cSKalderon, Michal 	void *cb_context;
17765a91a6cSKalderon, Michal 	u32 max_backlog;
17865a91a6cSKalderon, Michal 	u32 ip_addr[4];
17965a91a6cSKalderon, Michal 	u16 port;
18065a91a6cSKalderon, Michal 	u16 vlan;
18165a91a6cSKalderon, Michal 	u8 ip_version;
18265a91a6cSKalderon, Michal };
18365a91a6cSKalderon, Michal 
18467b40dccSKalderon, Michal int qed_iwarp_alloc(struct qed_hwfn *p_hwfn);
18567b40dccSKalderon, Michal 
18679284adeSMichal Kalderon int qed_iwarp_setup(struct qed_hwfn *p_hwfn,
18767b40dccSKalderon, Michal 		    struct qed_rdma_start_in_params *params);
18867b40dccSKalderon, Michal 
189d1abfd0bSMichal Kalderon void qed_iwarp_init_fw_ramrod(struct qed_hwfn *p_hwfn,
190da090917STomer Tayar 			      struct iwarp_init_func_ramrod_data *p_ramrod);
191d1abfd0bSMichal Kalderon 
19279284adeSMichal Kalderon int qed_iwarp_stop(struct qed_hwfn *p_hwfn);
19367b40dccSKalderon, Michal 
19467b40dccSKalderon, Michal void qed_iwarp_resc_free(struct qed_hwfn *p_hwfn);
19567b40dccSKalderon, Michal 
19667b40dccSKalderon, Michal void qed_iwarp_init_devinfo(struct qed_hwfn *p_hwfn);
19767b40dccSKalderon, Michal 
19867b40dccSKalderon, Michal void qed_iwarp_init_hw(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
19967b40dccSKalderon, Michal 
20067b40dccSKalderon, Michal int qed_iwarp_create_qp(struct qed_hwfn *p_hwfn,
20167b40dccSKalderon, Michal 			struct qed_rdma_qp *qp,
20267b40dccSKalderon, Michal 			struct qed_rdma_create_qp_out_params *out_params);
20367b40dccSKalderon, Michal 
20467b40dccSKalderon, Michal int qed_iwarp_modify_qp(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp,
20567b40dccSKalderon, Michal 			enum qed_iwarp_qp_state new_state, bool internal);
20667b40dccSKalderon, Michal 
20767b40dccSKalderon, Michal int qed_iwarp_destroy_qp(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp);
20867b40dccSKalderon, Michal 
20967b40dccSKalderon, Michal int qed_iwarp_fw_destroy(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp);
21067b40dccSKalderon, Michal 
21167b40dccSKalderon, Michal void qed_iwarp_query_qp(struct qed_rdma_qp *qp,
21267b40dccSKalderon, Michal 			struct qed_rdma_query_qp_out_params *out_params);
21367b40dccSKalderon, Michal 
21465a91a6cSKalderon, Michal int
2154b0fdd7cSKalderon, Michal qed_iwarp_connect(void *rdma_cxt,
2164b0fdd7cSKalderon, Michal 		  struct qed_iwarp_connect_in *iparams,
2174b0fdd7cSKalderon, Michal 		  struct qed_iwarp_connect_out *oparams);
2184b0fdd7cSKalderon, Michal 
2194b0fdd7cSKalderon, Michal int
22065a91a6cSKalderon, Michal qed_iwarp_create_listen(void *rdma_cxt,
22165a91a6cSKalderon, Michal 			struct qed_iwarp_listen_in *iparams,
22265a91a6cSKalderon, Michal 			struct qed_iwarp_listen_out *oparams);
22365a91a6cSKalderon, Michal 
224456a5849SKalderon, Michal int qed_iwarp_accept(void *rdma_cxt, struct qed_iwarp_accept_in *iparams);
225456a5849SKalderon, Michal 
226456a5849SKalderon, Michal int qed_iwarp_reject(void *rdma_cxt, struct qed_iwarp_reject_in *iparams);
22765a91a6cSKalderon, Michal int qed_iwarp_destroy_listen(void *rdma_cxt, void *handle);
22865a91a6cSKalderon, Michal 
2294b0fdd7cSKalderon, Michal int qed_iwarp_send_rtr(void *rdma_cxt, struct qed_iwarp_send_rtr_in *iparams);
2304b0fdd7cSKalderon, Michal 
23167b40dccSKalderon, Michal #endif
232