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