xref: /freebsd/sys/dev/qlnx/qlnxe/ecore_l2.h (revision 36712a94975f5bd0d26c85377283b49a2369c82f)
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_L2_H__
32 #define __ECORE_L2_H__
33 
34 
35 #include "ecore.h"
36 #include "ecore_hw.h"
37 #include "ecore_spq.h"
38 #include "ecore_l2_api.h"
39 
40 #define MAX_QUEUES_PER_QZONE	(sizeof(unsigned long) * 8)
41 #define ECORE_QUEUE_CID_PF	(0xff)
42 
43 /* Almost identical to the ecore_queue_start_common_params,
44  * but here we maintain the SB index in IGU CAM.
45  */
46 struct ecore_queue_cid_params {
47 	u8 vport_id;
48 	u16 queue_id;
49 	u8 stats_id;
50 };
51 
52  /* Additional parameters required for initialization of the queue_cid
53  * and are relevant only for a PF initializing one for its VFs.
54  */
55 struct ecore_queue_cid_vf_params {
56 	/* Should match the VF's relative index */
57 	u8 vfid;
58 
59 	/* 0-based queue index. Should reflect the relative qzone the
60 	 * VF thinks is associated with it [in its range].
61 	 */
62 	u8 vf_qid;
63 
64 	/* Indicates a VF is legacy, making it differ in several things:
65 	 *  - Producers would be placed in a different place.
66 	 *  - Makes assumptions regarding the CIDs.
67 	 */
68 	u8 vf_legacy;
69 
70 	/* For VFs, this index arrives via TLV to diffrentiate between
71 	 * different queues opened on the same qzone, and is passed
72 	 * [where the PF would have allocated it internally for its own].
73 	 */
74 	u8 qid_usage_idx;
75 };
76 
77 struct ecore_queue_cid {
78 	/* For stats-id, the `rel' is actually absolute as well */
79 	struct ecore_queue_cid_params rel;
80 	struct ecore_queue_cid_params abs;
81 
82 	/* These have no 'relative' meaning */
83 	u16 sb_igu_id;
84 	u8 sb_idx;
85 
86 	u32 cid;
87 	u16 opaque_fid;
88 
89 	bool b_is_rx;
90 
91 	/* VFs queues are mapped differently, so we need to know the
92 	 * relative queue associated with them [0-based].
93 	 * Notice this is relevant on the *PF* queue-cid of its VF's queues,
94 	 * and not on the VF itself.
95 	 */
96 	u8 vfid;
97 	u8 vf_qid;
98 
99 	/* We need an additional index to diffrentiate between queues opened
100 	 * for same queue-zone, as VFs would have to communicate the info
101 	 * to the PF [otherwise PF has no way to diffrentiate].
102 	 */
103 	u8 qid_usage_idx;
104 
105 	/* Legacy VFs might have Rx producer located elsewhere */
106 	u8 vf_legacy;
107 #define ECORE_QCID_LEGACY_VF_RX_PROD	(1 << 0)
108 #define ECORE_QCID_LEGACY_VF_CID	(1 << 1)
109 
110 	struct ecore_hwfn *p_owner;
111 };
112 
113 enum _ecore_status_t ecore_l2_alloc(struct ecore_hwfn *p_hwfn);
114 void ecore_l2_setup(struct ecore_hwfn *p_hwfn);
115 void ecore_l2_free(struct ecore_hwfn *p_hwfn);
116 
117 void ecore_eth_queue_cid_release(struct ecore_hwfn *p_hwfn,
118 				 struct ecore_queue_cid *p_cid);
119 
120 struct ecore_queue_cid *
121 ecore_eth_queue_to_cid(struct ecore_hwfn *p_hwfn, u16 opaque_fid,
122 		       struct ecore_queue_start_common_params *p_params,
123 		       bool b_is_rx,
124 		       struct ecore_queue_cid_vf_params *p_vf_params);
125 
126 enum _ecore_status_t
127 ecore_sp_eth_vport_start(struct ecore_hwfn *p_hwfn,
128 			 struct ecore_sp_vport_start_params *p_params);
129 
130 /**
131  * @brief - Starts an Rx queue, when queue_cid is already prepared
132  *
133  * @param p_hwfn
134  * @param p_cid
135  * @param bd_max_bytes
136  * @param bd_chain_phys_addr
137  * @param cqe_pbl_addr
138  * @param cqe_pbl_size
139  *
140  * @return enum _ecore_status_t
141  */
142 enum _ecore_status_t
143 ecore_eth_rxq_start_ramrod(struct ecore_hwfn *p_hwfn,
144 			   struct ecore_queue_cid *p_cid,
145 			   u16 bd_max_bytes,
146 			   dma_addr_t bd_chain_phys_addr,
147 			   dma_addr_t cqe_pbl_addr,
148 			   u16 cqe_pbl_size);
149 
150 /**
151  * @brief - Starts a Tx queue, where queue_cid is already prepared
152  *
153  * @param p_hwfn
154  * @param p_cid
155  * @param pbl_addr
156  * @param pbl_size
157  * @param p_pq_params - parameters for choosing the PQ for this Tx queue
158  *
159  * @return enum _ecore_status_t
160  */
161 enum _ecore_status_t
162 ecore_eth_txq_start_ramrod(struct ecore_hwfn *p_hwfn,
163 			   struct ecore_queue_cid *p_cid,
164 			   dma_addr_t pbl_addr, u16 pbl_size,
165 			   u16 pq_id);
166 
167 u8 ecore_mcast_bin_from_mac(u8 *mac);
168 
169 enum _ecore_status_t ecore_set_rxq_coalesce(struct ecore_hwfn *p_hwfn,
170 					    struct ecore_ptt *p_ptt,
171 					    u16 coalesce,
172 					    struct ecore_queue_cid *p_cid);
173 
174 enum _ecore_status_t ecore_set_txq_coalesce(struct ecore_hwfn *p_hwfn,
175 					    struct ecore_ptt *p_ptt,
176 					    u16 coalesce,
177 					    struct ecore_queue_cid *p_cid);
178 
179 enum _ecore_status_t ecore_get_rxq_coalesce(struct ecore_hwfn *p_hwfn,
180 					    struct ecore_ptt *p_ptt,
181 					    struct ecore_queue_cid *p_cid,
182 					    u16 *p_hw_coal);
183 
184 enum _ecore_status_t ecore_get_txq_coalesce(struct ecore_hwfn *p_hwfn,
185 					    struct ecore_ptt *p_ptt,
186 					    struct ecore_queue_cid *p_cid,
187 					    u16 *p_hw_coal);
188 
189 #endif
190