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