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 {
58d531038eSMichal Kalderon 	struct qed_iwarp_ll2_buff *piggy_buf;
59b5c29ca7SKalderon, Michal 	void *data;
60b5c29ca7SKalderon, Michal 	dma_addr_t data_phys_addr;
61b5c29ca7SKalderon, Michal 	u32 buff_size;
62b5c29ca7SKalderon, Michal };
63b5c29ca7SKalderon, Michal 
64fcb39f6cSMichal Kalderon struct qed_iwarp_ll2_mpa_buf {
65fcb39f6cSMichal Kalderon 	struct list_head list_entry;
66fcb39f6cSMichal Kalderon 	struct qed_iwarp_ll2_buff *ll2_buf;
67fcb39f6cSMichal Kalderon 	struct unaligned_opaque_data data;
68fcb39f6cSMichal Kalderon 	u16 tcp_payload_len;
69fcb39f6cSMichal Kalderon 	u8 placement_offset;
70fcb39f6cSMichal Kalderon };
71fcb39f6cSMichal Kalderon 
72c7d1d839SMichal Kalderon /* In some cases a fpdu will arrive with only one byte of the header, in this
73c7d1d839SMichal Kalderon  * case the fpdu_length will be partial (contain only higher byte and
74c7d1d839SMichal Kalderon  * incomplete bytes will contain the invalid value
75c7d1d839SMichal Kalderon  */
76c7d1d839SMichal Kalderon #define QED_IWARP_INVALID_INCOMPLETE_BYTES 0xffff
77c7d1d839SMichal Kalderon 
78469981b1SMichal Kalderon struct qed_iwarp_fpdu {
79469981b1SMichal Kalderon 	struct qed_iwarp_ll2_buff *mpa_buf;
80469981b1SMichal Kalderon 	void *mpa_frag_virt;
81469981b1SMichal Kalderon 	dma_addr_t mpa_frag;
82469981b1SMichal Kalderon 	dma_addr_t pkt_hdr;
83469981b1SMichal Kalderon 	u16 mpa_frag_len;
84469981b1SMichal Kalderon 	u16 fpdu_length;
85469981b1SMichal Kalderon 	u16 incomplete_bytes;
86469981b1SMichal Kalderon 	u8 pkt_hdr_size;
87469981b1SMichal Kalderon };
88469981b1SMichal Kalderon 
8967b40dccSKalderon, Michal struct qed_iwarp_info {
9065a91a6cSKalderon, Michal 	struct list_head listen_list;	/* qed_iwarp_listener */
91456a5849SKalderon, Michal 	struct list_head ep_list;	/* qed_iwarp_ep */
92456a5849SKalderon, Michal 	struct list_head ep_free_list;	/* pre-allocated ep's */
93fcb39f6cSMichal Kalderon 	struct list_head mpa_buf_list;	/* list of mpa_bufs */
94fcb39f6cSMichal Kalderon 	struct list_head mpa_buf_pending_list;
9567b40dccSKalderon, Michal 	spinlock_t iw_lock;	/* for iwarp resources */
9667b40dccSKalderon, Michal 	spinlock_t qp_lock;	/* for teardown races */
9767b40dccSKalderon, Michal 	u32 rcv_wnd_scale;
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;
110469981b1SMichal Kalderon 	u16 max_num_partial_fpdus;
11167b40dccSKalderon, Michal };
11267b40dccSKalderon, Michal 
113456a5849SKalderon, Michal enum qed_iwarp_ep_state {
114456a5849SKalderon, Michal 	QED_IWARP_EP_INIT,
115456a5849SKalderon, Michal 	QED_IWARP_EP_MPA_REQ_RCVD,
116456a5849SKalderon, Michal 	QED_IWARP_EP_MPA_OFFLOADED,
117456a5849SKalderon, Michal 	QED_IWARP_EP_ESTABLISHED,
118456a5849SKalderon, Michal 	QED_IWARP_EP_CLOSED
119456a5849SKalderon, Michal };
120456a5849SKalderon, Michal 
121456a5849SKalderon, Michal union async_output {
122456a5849SKalderon, Michal 	struct iwarp_eqe_data_mpa_async_completion mpa_response;
123456a5849SKalderon, Michal 	struct iwarp_eqe_data_tcp_async_completion mpa_request;
124456a5849SKalderon, Michal };
125456a5849SKalderon, Michal 
126456a5849SKalderon, Michal #define QED_MAX_PRIV_DATA_LEN (512)
127456a5849SKalderon, Michal struct qed_iwarp_ep_memory {
128456a5849SKalderon, Michal 	u8 in_pdata[QED_MAX_PRIV_DATA_LEN];
129456a5849SKalderon, Michal 	u8 out_pdata[QED_MAX_PRIV_DATA_LEN];
130456a5849SKalderon, Michal 	union async_output async_output;
131456a5849SKalderon, Michal };
132456a5849SKalderon, Michal 
133456a5849SKalderon, Michal /* Endpoint structure represents a TCP connection. This connection can be
134456a5849SKalderon, Michal  * associated with a QP or not (in which case QP==NULL)
135456a5849SKalderon, Michal  */
136456a5849SKalderon, Michal struct qed_iwarp_ep {
137456a5849SKalderon, Michal 	struct list_head list_entry;
138456a5849SKalderon, Michal 	struct qed_rdma_qp *qp;
139456a5849SKalderon, Michal 	struct qed_iwarp_ep_memory *ep_buffer_virt;
140456a5849SKalderon, Michal 	dma_addr_t ep_buffer_phys;
141456a5849SKalderon, Michal 	enum qed_iwarp_ep_state state;
142456a5849SKalderon, Michal 	int sig;
143456a5849SKalderon, Michal 	struct qed_iwarp_cm_info cm_info;
144456a5849SKalderon, Michal 	enum tcp_connect_mode connect_mode;
145456a5849SKalderon, Michal 	enum mpa_rtr_type rtr_type;
146456a5849SKalderon, Michal 	enum mpa_negotiation_mode mpa_rev;
147456a5849SKalderon, Michal 	u32 tcp_cid;
148456a5849SKalderon, Michal 	u32 cid;
149456a5849SKalderon, Michal 	u16 mss;
150456a5849SKalderon, Michal 	u8 remote_mac_addr[6];
151456a5849SKalderon, Michal 	u8 local_mac_addr[6];
152456a5849SKalderon, Michal 	bool mpa_reply_processed;
153456a5849SKalderon, Michal 
154456a5849SKalderon, Michal 	/* For Passive side - syn packet related data */
155456a5849SKalderon, Michal 	u16 syn_ip_payload_length;
156456a5849SKalderon, Michal 	struct qed_iwarp_ll2_buff *syn;
157456a5849SKalderon, Michal 	dma_addr_t syn_phy_addr;
158456a5849SKalderon, Michal 
159456a5849SKalderon, Michal 	/* The event_cb function is called for asynchrounous events associated
160456a5849SKalderon, Michal 	 * with the ep. It is initialized at different entry points depending
161456a5849SKalderon, Michal 	 * on whether the ep is the tcp connection active side or passive side
162456a5849SKalderon, Michal 	 * The cb_context is passed to the event_cb function.
163456a5849SKalderon, Michal 	 */
164456a5849SKalderon, Michal 	iwarp_event_handler event_cb;
165456a5849SKalderon, Michal 	void *cb_context;
166456a5849SKalderon, Michal };
167456a5849SKalderon, Michal 
16865a91a6cSKalderon, Michal struct qed_iwarp_listener {
16965a91a6cSKalderon, Michal 	struct list_head list_entry;
17065a91a6cSKalderon, Michal 
17165a91a6cSKalderon, Michal 	/* The event_cb function is called for connection requests.
17265a91a6cSKalderon, Michal 	 * The cb_context is passed to the event_cb function.
17365a91a6cSKalderon, Michal 	 */
17465a91a6cSKalderon, Michal 	iwarp_event_handler event_cb;
17565a91a6cSKalderon, Michal 	void *cb_context;
17665a91a6cSKalderon, Michal 	u32 max_backlog;
17765a91a6cSKalderon, Michal 	u32 ip_addr[4];
17865a91a6cSKalderon, Michal 	u16 port;
17965a91a6cSKalderon, Michal 	u16 vlan;
18065a91a6cSKalderon, Michal 	u8 ip_version;
18165a91a6cSKalderon, Michal };
18265a91a6cSKalderon, Michal 
18367b40dccSKalderon, Michal int qed_iwarp_alloc(struct qed_hwfn *p_hwfn);
18467b40dccSKalderon, Michal 
18567b40dccSKalderon, Michal int qed_iwarp_setup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
18667b40dccSKalderon, Michal 		    struct qed_rdma_start_in_params *params);
18767b40dccSKalderon, Michal 
188d1abfd0bSMichal Kalderon void qed_iwarp_init_fw_ramrod(struct qed_hwfn *p_hwfn,
189d1abfd0bSMichal Kalderon 			      struct iwarp_init_func_params *p_ramrod);
190d1abfd0bSMichal Kalderon 
19167b40dccSKalderon, Michal int qed_iwarp_stop(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
19267b40dccSKalderon, Michal 
19367b40dccSKalderon, Michal void qed_iwarp_resc_free(struct qed_hwfn *p_hwfn);
19467b40dccSKalderon, Michal 
19567b40dccSKalderon, Michal void qed_iwarp_init_devinfo(struct qed_hwfn *p_hwfn);
19667b40dccSKalderon, Michal 
19767b40dccSKalderon, Michal void qed_iwarp_init_hw(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
19867b40dccSKalderon, Michal 
19967b40dccSKalderon, Michal int qed_iwarp_create_qp(struct qed_hwfn *p_hwfn,
20067b40dccSKalderon, Michal 			struct qed_rdma_qp *qp,
20167b40dccSKalderon, Michal 			struct qed_rdma_create_qp_out_params *out_params);
20267b40dccSKalderon, Michal 
20367b40dccSKalderon, Michal int qed_iwarp_modify_qp(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp,
20467b40dccSKalderon, Michal 			enum qed_iwarp_qp_state new_state, bool internal);
20567b40dccSKalderon, Michal 
20667b40dccSKalderon, Michal int qed_iwarp_destroy_qp(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp);
20767b40dccSKalderon, Michal 
20867b40dccSKalderon, Michal int qed_iwarp_fw_destroy(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp);
20967b40dccSKalderon, Michal 
21067b40dccSKalderon, Michal void qed_iwarp_query_qp(struct qed_rdma_qp *qp,
21167b40dccSKalderon, Michal 			struct qed_rdma_query_qp_out_params *out_params);
21267b40dccSKalderon, Michal 
21365a91a6cSKalderon, Michal int
2144b0fdd7cSKalderon, Michal qed_iwarp_connect(void *rdma_cxt,
2154b0fdd7cSKalderon, Michal 		  struct qed_iwarp_connect_in *iparams,
2164b0fdd7cSKalderon, Michal 		  struct qed_iwarp_connect_out *oparams);
2174b0fdd7cSKalderon, Michal 
2184b0fdd7cSKalderon, Michal int
21965a91a6cSKalderon, Michal qed_iwarp_create_listen(void *rdma_cxt,
22065a91a6cSKalderon, Michal 			struct qed_iwarp_listen_in *iparams,
22165a91a6cSKalderon, Michal 			struct qed_iwarp_listen_out *oparams);
22265a91a6cSKalderon, Michal 
223456a5849SKalderon, Michal int qed_iwarp_accept(void *rdma_cxt, struct qed_iwarp_accept_in *iparams);
224456a5849SKalderon, Michal 
225456a5849SKalderon, Michal int qed_iwarp_reject(void *rdma_cxt, struct qed_iwarp_reject_in *iparams);
22665a91a6cSKalderon, Michal int qed_iwarp_destroy_listen(void *rdma_cxt, void *handle);
22765a91a6cSKalderon, Michal 
2284b0fdd7cSKalderon, Michal int qed_iwarp_send_rtr(void *rdma_cxt, struct qed_iwarp_send_rtr_in *iparams);
2294b0fdd7cSKalderon, Michal 
23067b40dccSKalderon, Michal #endif
231