xref: /freebsd/sys/dev/qlnx/qlnxe/ecore_l2.h (revision eb69d1f144a6fcc765d1b9d44a5ae8082353e70b)
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 	/* VFs queues are mapped differently, so we need to know the
90 	 * relative queue associated with them [0-based].
91 	 * Notice this is relevant on the *PF* queue-cid of its VF's queues,
92 	 * and not on the VF itself.
93 	 */
94 	u8 vfid;
95 	u8 vf_qid;
96 
97 	/* We need an additional index to diffrentiate between queues opened
98 	 * for same queue-zone, as VFs would have to communicate the info
99 	 * to the PF [otherwise PF has no way to diffrentiate].
100 	 */
101 	u8 qid_usage_idx;
102 
103 	/* Legacy VFs might have Rx producer located elsewhere */
104 	u8 vf_legacy;
105 #define ECORE_QCID_LEGACY_VF_RX_PROD	(1 << 0)
106 #define ECORE_QCID_LEGACY_VF_CID	(1 << 1)
107 
108 	struct ecore_hwfn *p_owner;
109 };
110 
111 enum _ecore_status_t ecore_l2_alloc(struct ecore_hwfn *p_hwfn);
112 void ecore_l2_setup(struct ecore_hwfn *p_hwfn);
113 void ecore_l2_free(struct ecore_hwfn *p_hwfn);
114 
115 void ecore_eth_queue_cid_release(struct ecore_hwfn *p_hwfn,
116 				 struct ecore_queue_cid *p_cid);
117 
118 struct ecore_queue_cid *
119 ecore_eth_queue_to_cid(struct ecore_hwfn *p_hwfn, u16 opaque_fid,
120 		       struct ecore_queue_start_common_params *p_params,
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 #endif
166