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)
49b5c29ca7SKalderon, Michal #define QED_IWARP_MAX_SYN_PKT_SIZE      (128)
50d1abfd0bSMichal Kalderon 
51d1abfd0bSMichal Kalderon #define QED_IWARP_LL2_OOO_DEF_TX_SIZE   (256)
52d1abfd0bSMichal Kalderon #define QED_IWARP_MAX_OOO		(16)
53d1abfd0bSMichal Kalderon #define QED_IWARP_LL2_OOO_MAX_RX_SIZE   (16384)
54d1abfd0bSMichal Kalderon 
55b5c29ca7SKalderon, Michal #define QED_IWARP_HANDLE_INVAL		(0xff)
56b5c29ca7SKalderon, Michal 
57b5c29ca7SKalderon, Michal struct qed_iwarp_ll2_buff {
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 
71469981b1SMichal Kalderon struct qed_iwarp_fpdu {
72469981b1SMichal Kalderon 	struct qed_iwarp_ll2_buff *mpa_buf;
73469981b1SMichal Kalderon 	void *mpa_frag_virt;
74469981b1SMichal Kalderon 	dma_addr_t mpa_frag;
75469981b1SMichal Kalderon 	dma_addr_t pkt_hdr;
76469981b1SMichal Kalderon 	u16 mpa_frag_len;
77469981b1SMichal Kalderon 	u16 fpdu_length;
78469981b1SMichal Kalderon 	u16 incomplete_bytes;
79469981b1SMichal Kalderon 	u8 pkt_hdr_size;
80469981b1SMichal Kalderon };
81469981b1SMichal Kalderon 
8267b40dccSKalderon, Michal struct qed_iwarp_info {
8365a91a6cSKalderon, Michal 	struct list_head listen_list;	/* qed_iwarp_listener */
84456a5849SKalderon, Michal 	struct list_head ep_list;	/* qed_iwarp_ep */
85456a5849SKalderon, Michal 	struct list_head ep_free_list;	/* pre-allocated ep's */
86fcb39f6cSMichal Kalderon 	struct list_head mpa_buf_list;	/* list of mpa_bufs */
87fcb39f6cSMichal Kalderon 	struct list_head mpa_buf_pending_list;
8867b40dccSKalderon, Michal 	spinlock_t iw_lock;	/* for iwarp resources */
8967b40dccSKalderon, Michal 	spinlock_t qp_lock;	/* for teardown races */
9067b40dccSKalderon, Michal 	u32 rcv_wnd_scale;
9167b40dccSKalderon, Michal 	u16 max_mtu;
9267b40dccSKalderon, Michal 	u8 mac_addr[ETH_ALEN];
9367b40dccSKalderon, Michal 	u8 crc_needed;
9467b40dccSKalderon, Michal 	u8 tcp_flags;
95b5c29ca7SKalderon, Michal 	u8 ll2_syn_handle;
96d1abfd0bSMichal Kalderon 	u8 ll2_ooo_handle;
97ae3488ffSMichal Kalderon 	u8 ll2_mpa_handle;
9867b40dccSKalderon, Michal 	u8 peer2peer;
9967b40dccSKalderon, Michal 	enum mpa_negotiation_mode mpa_rev;
10067b40dccSKalderon, Michal 	enum mpa_rtr_type rtr_type;
101469981b1SMichal Kalderon 	struct qed_iwarp_fpdu *partial_fpdus;
102fcb39f6cSMichal Kalderon 	struct qed_iwarp_ll2_mpa_buf *mpa_bufs;
103469981b1SMichal Kalderon 	u16 max_num_partial_fpdus;
10467b40dccSKalderon, Michal };
10567b40dccSKalderon, Michal 
106456a5849SKalderon, Michal enum qed_iwarp_ep_state {
107456a5849SKalderon, Michal 	QED_IWARP_EP_INIT,
108456a5849SKalderon, Michal 	QED_IWARP_EP_MPA_REQ_RCVD,
109456a5849SKalderon, Michal 	QED_IWARP_EP_MPA_OFFLOADED,
110456a5849SKalderon, Michal 	QED_IWARP_EP_ESTABLISHED,
111456a5849SKalderon, Michal 	QED_IWARP_EP_CLOSED
112456a5849SKalderon, Michal };
113456a5849SKalderon, Michal 
114456a5849SKalderon, Michal union async_output {
115456a5849SKalderon, Michal 	struct iwarp_eqe_data_mpa_async_completion mpa_response;
116456a5849SKalderon, Michal 	struct iwarp_eqe_data_tcp_async_completion mpa_request;
117456a5849SKalderon, Michal };
118456a5849SKalderon, Michal 
119456a5849SKalderon, Michal #define QED_MAX_PRIV_DATA_LEN (512)
120456a5849SKalderon, Michal struct qed_iwarp_ep_memory {
121456a5849SKalderon, Michal 	u8 in_pdata[QED_MAX_PRIV_DATA_LEN];
122456a5849SKalderon, Michal 	u8 out_pdata[QED_MAX_PRIV_DATA_LEN];
123456a5849SKalderon, Michal 	union async_output async_output;
124456a5849SKalderon, Michal };
125456a5849SKalderon, Michal 
126456a5849SKalderon, Michal /* Endpoint structure represents a TCP connection. This connection can be
127456a5849SKalderon, Michal  * associated with a QP or not (in which case QP==NULL)
128456a5849SKalderon, Michal  */
129456a5849SKalderon, Michal struct qed_iwarp_ep {
130456a5849SKalderon, Michal 	struct list_head list_entry;
131456a5849SKalderon, Michal 	struct qed_rdma_qp *qp;
132456a5849SKalderon, Michal 	struct qed_iwarp_ep_memory *ep_buffer_virt;
133456a5849SKalderon, Michal 	dma_addr_t ep_buffer_phys;
134456a5849SKalderon, Michal 	enum qed_iwarp_ep_state state;
135456a5849SKalderon, Michal 	int sig;
136456a5849SKalderon, Michal 	struct qed_iwarp_cm_info cm_info;
137456a5849SKalderon, Michal 	enum tcp_connect_mode connect_mode;
138456a5849SKalderon, Michal 	enum mpa_rtr_type rtr_type;
139456a5849SKalderon, Michal 	enum mpa_negotiation_mode mpa_rev;
140456a5849SKalderon, Michal 	u32 tcp_cid;
141456a5849SKalderon, Michal 	u32 cid;
142456a5849SKalderon, Michal 	u16 mss;
143456a5849SKalderon, Michal 	u8 remote_mac_addr[6];
144456a5849SKalderon, Michal 	u8 local_mac_addr[6];
145456a5849SKalderon, Michal 	bool mpa_reply_processed;
146456a5849SKalderon, Michal 
147456a5849SKalderon, Michal 	/* For Passive side - syn packet related data */
148456a5849SKalderon, Michal 	u16 syn_ip_payload_length;
149456a5849SKalderon, Michal 	struct qed_iwarp_ll2_buff *syn;
150456a5849SKalderon, Michal 	dma_addr_t syn_phy_addr;
151456a5849SKalderon, Michal 
152456a5849SKalderon, Michal 	/* The event_cb function is called for asynchrounous events associated
153456a5849SKalderon, Michal 	 * with the ep. It is initialized at different entry points depending
154456a5849SKalderon, Michal 	 * on whether the ep is the tcp connection active side or passive side
155456a5849SKalderon, Michal 	 * The cb_context is passed to the event_cb function.
156456a5849SKalderon, Michal 	 */
157456a5849SKalderon, Michal 	iwarp_event_handler event_cb;
158456a5849SKalderon, Michal 	void *cb_context;
159456a5849SKalderon, Michal };
160456a5849SKalderon, Michal 
16165a91a6cSKalderon, Michal struct qed_iwarp_listener {
16265a91a6cSKalderon, Michal 	struct list_head list_entry;
16365a91a6cSKalderon, Michal 
16465a91a6cSKalderon, Michal 	/* The event_cb function is called for connection requests.
16565a91a6cSKalderon, Michal 	 * The cb_context is passed to the event_cb function.
16665a91a6cSKalderon, Michal 	 */
16765a91a6cSKalderon, Michal 	iwarp_event_handler event_cb;
16865a91a6cSKalderon, Michal 	void *cb_context;
16965a91a6cSKalderon, Michal 	u32 max_backlog;
17065a91a6cSKalderon, Michal 	u32 ip_addr[4];
17165a91a6cSKalderon, Michal 	u16 port;
17265a91a6cSKalderon, Michal 	u16 vlan;
17365a91a6cSKalderon, Michal 	u8 ip_version;
17465a91a6cSKalderon, Michal };
17565a91a6cSKalderon, Michal 
17667b40dccSKalderon, Michal int qed_iwarp_alloc(struct qed_hwfn *p_hwfn);
17767b40dccSKalderon, Michal 
17867b40dccSKalderon, Michal int qed_iwarp_setup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
17967b40dccSKalderon, Michal 		    struct qed_rdma_start_in_params *params);
18067b40dccSKalderon, Michal 
181d1abfd0bSMichal Kalderon void qed_iwarp_init_fw_ramrod(struct qed_hwfn *p_hwfn,
182d1abfd0bSMichal Kalderon 			      struct iwarp_init_func_params *p_ramrod);
183d1abfd0bSMichal Kalderon 
18467b40dccSKalderon, Michal int qed_iwarp_stop(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
18567b40dccSKalderon, Michal 
18667b40dccSKalderon, Michal void qed_iwarp_resc_free(struct qed_hwfn *p_hwfn);
18767b40dccSKalderon, Michal 
18867b40dccSKalderon, Michal void qed_iwarp_init_devinfo(struct qed_hwfn *p_hwfn);
18967b40dccSKalderon, Michal 
19067b40dccSKalderon, Michal void qed_iwarp_init_hw(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
19167b40dccSKalderon, Michal 
19267b40dccSKalderon, Michal int qed_iwarp_create_qp(struct qed_hwfn *p_hwfn,
19367b40dccSKalderon, Michal 			struct qed_rdma_qp *qp,
19467b40dccSKalderon, Michal 			struct qed_rdma_create_qp_out_params *out_params);
19567b40dccSKalderon, Michal 
19667b40dccSKalderon, Michal int qed_iwarp_modify_qp(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp,
19767b40dccSKalderon, Michal 			enum qed_iwarp_qp_state new_state, bool internal);
19867b40dccSKalderon, Michal 
19967b40dccSKalderon, Michal int qed_iwarp_destroy_qp(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp);
20067b40dccSKalderon, Michal 
20167b40dccSKalderon, Michal int qed_iwarp_fw_destroy(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp);
20267b40dccSKalderon, Michal 
20367b40dccSKalderon, Michal void qed_iwarp_query_qp(struct qed_rdma_qp *qp,
20467b40dccSKalderon, Michal 			struct qed_rdma_query_qp_out_params *out_params);
20567b40dccSKalderon, Michal 
20665a91a6cSKalderon, Michal int
2074b0fdd7cSKalderon, Michal qed_iwarp_connect(void *rdma_cxt,
2084b0fdd7cSKalderon, Michal 		  struct qed_iwarp_connect_in *iparams,
2094b0fdd7cSKalderon, Michal 		  struct qed_iwarp_connect_out *oparams);
2104b0fdd7cSKalderon, Michal 
2114b0fdd7cSKalderon, Michal int
21265a91a6cSKalderon, Michal qed_iwarp_create_listen(void *rdma_cxt,
21365a91a6cSKalderon, Michal 			struct qed_iwarp_listen_in *iparams,
21465a91a6cSKalderon, Michal 			struct qed_iwarp_listen_out *oparams);
21565a91a6cSKalderon, Michal 
216456a5849SKalderon, Michal int qed_iwarp_accept(void *rdma_cxt, struct qed_iwarp_accept_in *iparams);
217456a5849SKalderon, Michal 
218456a5849SKalderon, Michal int qed_iwarp_reject(void *rdma_cxt, struct qed_iwarp_reject_in *iparams);
21965a91a6cSKalderon, Michal int qed_iwarp_destroy_listen(void *rdma_cxt, void *handle);
22065a91a6cSKalderon, Michal 
2214b0fdd7cSKalderon, Michal int qed_iwarp_send_rtr(void *rdma_cxt, struct qed_iwarp_send_rtr_in *iparams);
2224b0fdd7cSKalderon, Michal 
22367b40dccSKalderon, Michal #endif
224