11f4d4ed6SAlexander Lobakin /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
267b40dccSKalderon, Michal /* QLogic qed NIC Driver
367b40dccSKalderon, Michal  * Copyright (c) 2015-2017  QLogic Corporation
4663eacd8SAlexander Lobakin  * Copyright (c) 2019-2020 Marvell International Ltd.
567b40dccSKalderon, Michal  */
61f4d4ed6SAlexander Lobakin 
767b40dccSKalderon, Michal #ifndef _QED_IWARP_H
867b40dccSKalderon, Michal #define _QED_IWARP_H
967b40dccSKalderon, Michal 
1067b40dccSKalderon, Michal enum qed_iwarp_qp_state {
1167b40dccSKalderon, Michal 	QED_IWARP_QP_STATE_IDLE,
1267b40dccSKalderon, Michal 	QED_IWARP_QP_STATE_RTS,
1367b40dccSKalderon, Michal 	QED_IWARP_QP_STATE_TERMINATE,
1467b40dccSKalderon, Michal 	QED_IWARP_QP_STATE_CLOSING,
1567b40dccSKalderon, Michal 	QED_IWARP_QP_STATE_ERROR,
1667b40dccSKalderon, Michal };
1767b40dccSKalderon, Michal 
1867b40dccSKalderon, Michal enum qed_iwarp_qp_state qed_roce2iwarp_state(enum qed_roce_qp_state state);
1967b40dccSKalderon, Michal 
20456a5849SKalderon, Michal #define QED_IWARP_PREALLOC_CNT  (256)
21456a5849SKalderon, Michal 
22b5c29ca7SKalderon, Michal #define QED_IWARP_LL2_SYN_TX_SIZE       (128)
23b5c29ca7SKalderon, Michal #define QED_IWARP_LL2_SYN_RX_SIZE       (256)
24d1abfd0bSMichal Kalderon 
25d1abfd0bSMichal Kalderon #define QED_IWARP_LL2_OOO_DEF_TX_SIZE   (256)
26d1abfd0bSMichal Kalderon #define QED_IWARP_MAX_OOO		(16)
27d1abfd0bSMichal Kalderon #define QED_IWARP_LL2_OOO_MAX_RX_SIZE   (16384)
28d1abfd0bSMichal Kalderon 
29b5c29ca7SKalderon, Michal #define QED_IWARP_HANDLE_INVAL		(0xff)
30b5c29ca7SKalderon, Michal 
31b5c29ca7SKalderon, Michal struct qed_iwarp_ll2_buff {
32d531038eSMichal Kalderon 	struct qed_iwarp_ll2_buff *piggy_buf;
33b5c29ca7SKalderon, Michal 	void *data;
34b5c29ca7SKalderon, Michal 	dma_addr_t data_phys_addr;
35b5c29ca7SKalderon, Michal 	u32 buff_size;
36b5c29ca7SKalderon, Michal };
37b5c29ca7SKalderon, Michal 
38fcb39f6cSMichal Kalderon struct qed_iwarp_ll2_mpa_buf {
39fcb39f6cSMichal Kalderon 	struct list_head list_entry;
40fcb39f6cSMichal Kalderon 	struct qed_iwarp_ll2_buff *ll2_buf;
41fcb39f6cSMichal Kalderon 	struct unaligned_opaque_data data;
42fcb39f6cSMichal Kalderon 	u16 tcp_payload_len;
43fcb39f6cSMichal Kalderon 	u8 placement_offset;
44fcb39f6cSMichal Kalderon };
45fcb39f6cSMichal Kalderon 
46c7d1d839SMichal Kalderon /* In some cases a fpdu will arrive with only one byte of the header, in this
47c7d1d839SMichal Kalderon  * case the fpdu_length will be partial (contain only higher byte and
48c7d1d839SMichal Kalderon  * incomplete bytes will contain the invalid value
49c7d1d839SMichal Kalderon  */
50c7d1d839SMichal Kalderon #define QED_IWARP_INVALID_INCOMPLETE_BYTES 0xffff
51c7d1d839SMichal Kalderon 
52469981b1SMichal Kalderon struct qed_iwarp_fpdu {
53469981b1SMichal Kalderon 	struct qed_iwarp_ll2_buff *mpa_buf;
54469981b1SMichal Kalderon 	void *mpa_frag_virt;
55469981b1SMichal Kalderon 	dma_addr_t mpa_frag;
56469981b1SMichal Kalderon 	dma_addr_t pkt_hdr;
57469981b1SMichal Kalderon 	u16 mpa_frag_len;
58469981b1SMichal Kalderon 	u16 fpdu_length;
59469981b1SMichal Kalderon 	u16 incomplete_bytes;
60469981b1SMichal Kalderon 	u8 pkt_hdr_size;
61469981b1SMichal Kalderon };
62469981b1SMichal Kalderon 
6367b40dccSKalderon, Michal struct qed_iwarp_info {
6465a91a6cSKalderon, Michal 	struct list_head listen_list;	/* qed_iwarp_listener */
65456a5849SKalderon, Michal 	struct list_head ep_list;	/* qed_iwarp_ep */
66456a5849SKalderon, Michal 	struct list_head ep_free_list;	/* pre-allocated ep's */
67fcb39f6cSMichal Kalderon 	struct list_head mpa_buf_list;	/* list of mpa_bufs */
68fcb39f6cSMichal Kalderon 	struct list_head mpa_buf_pending_list;
6967b40dccSKalderon, Michal 	spinlock_t iw_lock;	/* for iwarp resources */
7067b40dccSKalderon, Michal 	spinlock_t qp_lock;	/* for teardown races */
7167b40dccSKalderon, Michal 	u32 rcv_wnd_scale;
72da090917STomer Tayar 	u16 rcv_wnd_size;
7367b40dccSKalderon, Michal 	u16 max_mtu;
7467b40dccSKalderon, Michal 	u8 mac_addr[ETH_ALEN];
7567b40dccSKalderon, Michal 	u8 crc_needed;
7667b40dccSKalderon, Michal 	u8 tcp_flags;
77b5c29ca7SKalderon, Michal 	u8 ll2_syn_handle;
78d1abfd0bSMichal Kalderon 	u8 ll2_ooo_handle;
79ae3488ffSMichal Kalderon 	u8 ll2_mpa_handle;
8067b40dccSKalderon, Michal 	u8 peer2peer;
8167b40dccSKalderon, Michal 	enum mpa_negotiation_mode mpa_rev;
8267b40dccSKalderon, Michal 	enum mpa_rtr_type rtr_type;
83469981b1SMichal Kalderon 	struct qed_iwarp_fpdu *partial_fpdus;
84fcb39f6cSMichal Kalderon 	struct qed_iwarp_ll2_mpa_buf *mpa_bufs;
851e28eaadSMichal Kalderon 	u8 *mpa_intermediate_buf;
86469981b1SMichal Kalderon 	u16 max_num_partial_fpdus;
8767b40dccSKalderon, Michal };
8867b40dccSKalderon, Michal 
89456a5849SKalderon, Michal enum qed_iwarp_ep_state {
90456a5849SKalderon, Michal 	QED_IWARP_EP_INIT,
91456a5849SKalderon, Michal 	QED_IWARP_EP_MPA_REQ_RCVD,
92456a5849SKalderon, Michal 	QED_IWARP_EP_MPA_OFFLOADED,
93456a5849SKalderon, Michal 	QED_IWARP_EP_ESTABLISHED,
94456a5849SKalderon, Michal 	QED_IWARP_EP_CLOSED
95456a5849SKalderon, Michal };
96456a5849SKalderon, Michal 
97456a5849SKalderon, Michal union async_output {
98456a5849SKalderon, Michal 	struct iwarp_eqe_data_mpa_async_completion mpa_response;
99456a5849SKalderon, Michal 	struct iwarp_eqe_data_tcp_async_completion mpa_request;
100456a5849SKalderon, Michal };
101456a5849SKalderon, Michal 
102456a5849SKalderon, Michal #define QED_MAX_PRIV_DATA_LEN (512)
103456a5849SKalderon, Michal struct qed_iwarp_ep_memory {
104456a5849SKalderon, Michal 	u8 in_pdata[QED_MAX_PRIV_DATA_LEN];
105456a5849SKalderon, Michal 	u8 out_pdata[QED_MAX_PRIV_DATA_LEN];
106456a5849SKalderon, Michal 	union async_output async_output;
107456a5849SKalderon, Michal };
108456a5849SKalderon, Michal 
109456a5849SKalderon, Michal /* Endpoint structure represents a TCP connection. This connection can be
110456a5849SKalderon, Michal  * associated with a QP or not (in which case QP==NULL)
111456a5849SKalderon, Michal  */
112456a5849SKalderon, Michal struct qed_iwarp_ep {
113456a5849SKalderon, Michal 	struct list_head list_entry;
114456a5849SKalderon, Michal 	struct qed_rdma_qp *qp;
115456a5849SKalderon, Michal 	struct qed_iwarp_ep_memory *ep_buffer_virt;
116456a5849SKalderon, Michal 	dma_addr_t ep_buffer_phys;
117456a5849SKalderon, Michal 	enum qed_iwarp_ep_state state;
118456a5849SKalderon, Michal 	int sig;
119456a5849SKalderon, Michal 	struct qed_iwarp_cm_info cm_info;
120456a5849SKalderon, Michal 	enum tcp_connect_mode connect_mode;
121456a5849SKalderon, Michal 	enum mpa_rtr_type rtr_type;
122456a5849SKalderon, Michal 	enum mpa_negotiation_mode mpa_rev;
123456a5849SKalderon, Michal 	u32 tcp_cid;
124456a5849SKalderon, Michal 	u32 cid;
125456a5849SKalderon, Michal 	u16 mss;
126456a5849SKalderon, Michal 	u8 remote_mac_addr[6];
127456a5849SKalderon, Michal 	u8 local_mac_addr[6];
128456a5849SKalderon, Michal 	bool mpa_reply_processed;
129456a5849SKalderon, Michal 
130456a5849SKalderon, Michal 	/* For Passive side - syn packet related data */
131456a5849SKalderon, Michal 	u16 syn_ip_payload_length;
132456a5849SKalderon, Michal 	struct qed_iwarp_ll2_buff *syn;
133456a5849SKalderon, Michal 	dma_addr_t syn_phy_addr;
134456a5849SKalderon, Michal 
135456a5849SKalderon, Michal 	/* The event_cb function is called for asynchrounous events associated
136456a5849SKalderon, Michal 	 * with the ep. It is initialized at different entry points depending
137456a5849SKalderon, Michal 	 * on whether the ep is the tcp connection active side or passive side
138456a5849SKalderon, Michal 	 * The cb_context is passed to the event_cb function.
139456a5849SKalderon, Michal 	 */
140456a5849SKalderon, Michal 	iwarp_event_handler event_cb;
141456a5849SKalderon, Michal 	void *cb_context;
142456a5849SKalderon, Michal };
143456a5849SKalderon, Michal 
14465a91a6cSKalderon, Michal struct qed_iwarp_listener {
14565a91a6cSKalderon, Michal 	struct list_head list_entry;
14665a91a6cSKalderon, Michal 
14765a91a6cSKalderon, Michal 	/* The event_cb function is called for connection requests.
14865a91a6cSKalderon, Michal 	 * The cb_context is passed to the event_cb function.
14965a91a6cSKalderon, Michal 	 */
15065a91a6cSKalderon, Michal 	iwarp_event_handler event_cb;
15165a91a6cSKalderon, Michal 	void *cb_context;
15265a91a6cSKalderon, Michal 	u32 max_backlog;
15365a91a6cSKalderon, Michal 	u32 ip_addr[4];
15465a91a6cSKalderon, Michal 	u16 port;
15565a91a6cSKalderon, Michal 	u16 vlan;
15665a91a6cSKalderon, Michal 	u8 ip_version;
15765a91a6cSKalderon, Michal };
15865a91a6cSKalderon, Michal 
15967b40dccSKalderon, Michal int qed_iwarp_alloc(struct qed_hwfn *p_hwfn);
16067b40dccSKalderon, Michal 
16179284adeSMichal Kalderon int qed_iwarp_setup(struct qed_hwfn *p_hwfn,
16267b40dccSKalderon, Michal 		    struct qed_rdma_start_in_params *params);
16367b40dccSKalderon, Michal 
164d1abfd0bSMichal Kalderon void qed_iwarp_init_fw_ramrod(struct qed_hwfn *p_hwfn,
165da090917STomer Tayar 			      struct iwarp_init_func_ramrod_data *p_ramrod);
166d1abfd0bSMichal Kalderon 
16779284adeSMichal Kalderon int qed_iwarp_stop(struct qed_hwfn *p_hwfn);
16867b40dccSKalderon, Michal 
16967b40dccSKalderon, Michal void qed_iwarp_resc_free(struct qed_hwfn *p_hwfn);
17067b40dccSKalderon, Michal 
17167b40dccSKalderon, Michal void qed_iwarp_init_devinfo(struct qed_hwfn *p_hwfn);
17267b40dccSKalderon, Michal 
17367b40dccSKalderon, Michal void qed_iwarp_init_hw(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
17467b40dccSKalderon, Michal 
17567b40dccSKalderon, Michal int qed_iwarp_create_qp(struct qed_hwfn *p_hwfn,
17667b40dccSKalderon, Michal 			struct qed_rdma_qp *qp,
17767b40dccSKalderon, Michal 			struct qed_rdma_create_qp_out_params *out_params);
17867b40dccSKalderon, Michal 
17967b40dccSKalderon, Michal int qed_iwarp_modify_qp(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp,
18067b40dccSKalderon, Michal 			enum qed_iwarp_qp_state new_state, bool internal);
18167b40dccSKalderon, Michal 
18267b40dccSKalderon, Michal int qed_iwarp_destroy_qp(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp);
18367b40dccSKalderon, Michal 
18467b40dccSKalderon, Michal int qed_iwarp_fw_destroy(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp);
18567b40dccSKalderon, Michal 
18667b40dccSKalderon, Michal void qed_iwarp_query_qp(struct qed_rdma_qp *qp,
18767b40dccSKalderon, Michal 			struct qed_rdma_query_qp_out_params *out_params);
18867b40dccSKalderon, Michal 
18965a91a6cSKalderon, Michal int
1904b0fdd7cSKalderon, Michal qed_iwarp_connect(void *rdma_cxt,
1914b0fdd7cSKalderon, Michal 		  struct qed_iwarp_connect_in *iparams,
1924b0fdd7cSKalderon, Michal 		  struct qed_iwarp_connect_out *oparams);
1934b0fdd7cSKalderon, Michal 
1944b0fdd7cSKalderon, Michal int
19565a91a6cSKalderon, Michal qed_iwarp_create_listen(void *rdma_cxt,
19665a91a6cSKalderon, Michal 			struct qed_iwarp_listen_in *iparams,
19765a91a6cSKalderon, Michal 			struct qed_iwarp_listen_out *oparams);
19865a91a6cSKalderon, Michal 
199456a5849SKalderon, Michal int qed_iwarp_accept(void *rdma_cxt, struct qed_iwarp_accept_in *iparams);
200456a5849SKalderon, Michal 
201456a5849SKalderon, Michal int qed_iwarp_reject(void *rdma_cxt, struct qed_iwarp_reject_in *iparams);
20265a91a6cSKalderon, Michal int qed_iwarp_destroy_listen(void *rdma_cxt, void *handle);
20365a91a6cSKalderon, Michal 
2044b0fdd7cSKalderon, Michal int qed_iwarp_send_rtr(void *rdma_cxt, struct qed_iwarp_send_rtr_in *iparams);
2054b0fdd7cSKalderon, Michal 
20667b40dccSKalderon, Michal #endif
207