]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - sys/dev/qlnx/qlnxe/ecore_ll2.h
MFC r316485
[FreeBSD/stable/10.git] / sys / dev / qlnx / qlnxe / ecore_ll2.h
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         enum ecore_ll2_conn_type        conn_type;
115         u32                             cid;
116         u8                              my_id;
117         u8                              queue_id;
118         u8                              tx_stats_id;
119         bool                            b_active;
120         u16                             mtu;
121         u8                              rx_drop_ttl0_flg;
122         u8                              rx_vlan_removal_en;
123         u8                              tx_tc;
124         u8                              tx_max_bds_per_packet;
125         enum core_tx_dest               tx_dest;
126         enum core_error_handle          ai_err_packet_too_big;
127         enum core_error_handle          ai_err_no_buf;
128         u8                              gsi_enable;
129         u8                              tx_stats_en;
130         u8                              main_func_queue;
131         struct ecore_ll2_rx_queue       rx_queue;
132         struct ecore_ll2_tx_queue       tx_queue;
133         struct ecore_ll2_cbs            cbs;
134 };
135
136 /**
137 * @brief ecore_ll2_alloc - Allocates LL2 connections set
138 *
139 * @param p_hwfn
140 *
141 * @return enum _ecore_status_t
142 */
143 enum _ecore_status_t ecore_ll2_alloc(struct ecore_hwfn *p_hwfn);
144
145 /**
146 * @brief ecore_ll2_setup - Inits LL2 connections set
147 *
148 * @param p_hwfn
149 *
150 */
151 void ecore_ll2_setup(struct ecore_hwfn *p_hwfn);
152
153 /**
154 * @brief ecore_ll2_free - Releases LL2 connections set
155 *
156 * @param p_hwfn
157 *
158 */
159 void ecore_ll2_free(struct ecore_hwfn *p_hwfn);
160
161 /**
162  * @brief ecore_ll2_get_fragment_of_tx_packet
163  *
164  * @param p_hwfn
165  * @param connection_handle    LL2 connection's handle
166  *                              obtained from
167  *                              ecore_ll2_require_connection
168  * @param addr
169  * @param last_fragment)
170  *
171  * @return enum _ecore_status_t
172  */
173 enum _ecore_status_t
174 ecore_ll2_get_fragment_of_tx_packet(struct ecore_hwfn *p_hwfn,
175                                     u8 connection_handle,
176                                     dma_addr_t *addr,
177                                     bool *last_fragment);
178
179 #endif /*__ECORE_LL2_H__*/