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