xref: /freebsd/sys/dev/qlnx/qlnxe/ecore_ll2.h (revision d93a896e)
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  * $FreeBSD$
28  *
29  */
30 
31 #ifndef __ECORE_LL2_H__
32 #define __ECORE_LL2_H__
33 
34 #include "ecore.h"
35 #include "ecore_hsi_eth.h"
36 #include "ecore_chain.h"
37 #include "ecore_hsi_common.h"
38 #include "ecore_ll2_api.h"
39 #include "ecore_sp_api.h"
40 
41 /* ECORE LL2: internal structures and functions*/
42 #define ECORE_MAX_NUM_OF_LL2_CONNECTIONS                    (4)
43 
44 static OSAL_INLINE u8 ecore_ll2_handle_to_queue_id(struct ecore_hwfn *p_hwfn,
45 					      u8 handle)
46 {
47 	return p_hwfn->hw_info.resc_start[ECORE_LL2_QUEUE] + handle;
48 }
49 
50 struct ecore_ll2_rx_packet
51 {
52 	osal_list_entry_t   list_entry;
53 	struct core_rx_bd_with_buff_len   *rxq_bd;
54 	dma_addr_t          rx_buf_addr;
55 	u16                 buf_length;
56 	void                *cookie;
57 	u8                  placement_offset;
58 	u16                 parse_flags;
59 	u16                 packet_length;
60 	u16                 vlan;
61 	u32                 opaque_data[2];
62 };
63 
64 struct ecore_ll2_tx_packet
65 {
66 	osal_list_entry_t       list_entry;
67 	u16                     bd_used;
68 	bool                    notify_fw;
69 	void                    *cookie;
70 	struct {
71 		struct core_tx_bd       *txq_bd;
72 		dma_addr_t              tx_frag;
73 		u16                     frag_len;
74 	}   bds_set[1];
75 	/* Flexible Array of bds_set determined by max_bds_per_packet */
76 };
77 
78 struct ecore_ll2_rx_queue {
79 	osal_spinlock_t		lock;
80 	struct ecore_chain	rxq_chain;
81 	struct ecore_chain	rcq_chain;
82 	u8			rx_sb_index;
83 	bool			b_cb_registred;
84 	__le16			*p_fw_cons;
85 	osal_list_t		active_descq;
86 	osal_list_t		free_descq;
87 	osal_list_t		posting_descq;
88 	struct ecore_ll2_rx_packet	*descq_array;
89 	void OSAL_IOMEM		*set_prod_addr;
90 };
91 
92 struct ecore_ll2_tx_queue {
93 	osal_spinlock_t			lock;
94 	struct ecore_chain		txq_chain;
95 	u8				tx_sb_index;
96 	bool				b_cb_registred;
97 	__le16				*p_fw_cons;
98 	osal_list_t			active_descq;
99 	osal_list_t			free_descq;
100 	osal_list_t			sending_descq;
101 	struct ecore_ll2_tx_packet	*descq_array;
102 	struct ecore_ll2_tx_packet	*cur_send_packet;
103 	struct ecore_ll2_tx_packet	cur_completing_packet;
104 	u16				cur_completing_bd_idx;
105 	void OSAL_IOMEM			*doorbell_addr;
106 	u16				bds_idx;
107 	u16				cur_send_frag_num;
108 	u16				cur_completing_frag_num;
109 	bool				b_completing_packet;
110 };
111 
112 struct ecore_ll2_info {
113 	osal_mutex_t			mutex;
114 
115 	struct ecore_ll2_acquire_data_inputs input;
116 	u32				cid;
117 	u8				my_id;
118 	u8				queue_id;
119 	u8				tx_stats_id;
120 	bool				b_active;
121 	enum core_tx_dest		tx_dest;
122 	u8				tx_stats_en;
123 	u8				main_func_queue;
124 	struct ecore_ll2_rx_queue	rx_queue;
125 	struct ecore_ll2_tx_queue	tx_queue;
126 	struct ecore_ll2_cbs		cbs;
127 };
128 
129 /**
130 * @brief ecore_ll2_alloc - Allocates LL2 connections set
131 *
132 * @param p_hwfn
133 *
134 * @return enum _ecore_status_t
135 */
136 enum _ecore_status_t ecore_ll2_alloc(struct ecore_hwfn *p_hwfn);
137 
138 /**
139 * @brief ecore_ll2_setup - Inits LL2 connections set
140 *
141 * @param p_hwfn
142 *
143 */
144 void ecore_ll2_setup(struct ecore_hwfn *p_hwfn);
145 
146 /**
147 * @brief ecore_ll2_free - Releases LL2 connections set
148 *
149 * @param p_hwfn
150 *
151 */
152 void ecore_ll2_free(struct ecore_hwfn *p_hwfn);
153 
154 /**
155  * @brief ecore_ll2_get_fragment_of_tx_packet
156  *
157  * @param p_hwfn
158  * @param connection_handle    LL2 connection's handle
159  *                              obtained from
160  *                              ecore_ll2_require_connection
161  * @param addr
162  * @param last_fragment)
163  *
164  * @return enum _ecore_status_t
165  */
166 enum _ecore_status_t
167 ecore_ll2_get_fragment_of_tx_packet(struct ecore_hwfn *p_hwfn,
168 				    u8 connection_handle,
169 				    dma_addr_t *addr,
170 				    bool *last_fragment);
171 
172 #endif /*__ECORE_LL2_H__*/
173