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: stable/11/sys/dev/qlnx/qlnxe/ecore_ll2.h 337517 2018-08-09 01:17:35Z davidcs $
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
44static 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
50struct 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
64struct 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
78struct 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
92struct 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	struct core_db_data		db_msg;
107	u16				bds_idx;
108	u16				cur_send_frag_num;
109	u16				cur_completing_frag_num;
110	bool				b_completing_packet;
111};
112
113struct ecore_ll2_info {
114	osal_mutex_t			mutex;
115
116	struct ecore_ll2_acquire_data_inputs input;
117	u32				cid;
118	u8				my_id;
119	u8				queue_id;
120	u8				tx_stats_id;
121	bool				b_active;
122	enum core_tx_dest		tx_dest;
123	u8				tx_stats_en;
124	u8				main_func_queue;
125	struct ecore_ll2_rx_queue	rx_queue;
126	struct ecore_ll2_tx_queue	tx_queue;
127	struct ecore_ll2_cbs		cbs;
128};
129
130/**
131* @brief ecore_ll2_alloc - Allocates LL2 connections set
132*
133* @param p_hwfn
134*
135* @return enum _ecore_status_t
136*/
137enum _ecore_status_t ecore_ll2_alloc(struct ecore_hwfn *p_hwfn);
138
139/**
140* @brief ecore_ll2_setup - Inits LL2 connections set
141*
142* @param p_hwfn
143*
144*/
145void ecore_ll2_setup(struct ecore_hwfn *p_hwfn);
146
147/**
148* @brief ecore_ll2_free - Releases LL2 connections set
149*
150* @param p_hwfn
151*
152*/
153void ecore_ll2_free(struct ecore_hwfn *p_hwfn);
154
155#ifndef LINUX_REMOVE
156/**
157 * @brief ecore_ll2_get_fragment_of_tx_packet
158 *
159 * @param p_hwfn
160 * @param connection_handle    LL2 connection's handle
161 *                              obtained from
162 *                              ecore_ll2_require_connection
163 * @param addr
164 * @param last_fragment)
165 *
166 * @return enum _ecore_status_t
167 */
168enum _ecore_status_t
169ecore_ll2_get_fragment_of_tx_packet(struct ecore_hwfn *p_hwfn,
170				    u8 connection_handle,
171				    dma_addr_t *addr,
172				    bool *last_fragment);
173#endif
174
175#endif /*__ECORE_LL2_H__*/
176