xref: /freebsd/sys/dev/axgbe/xgbe-desc.c (revision 10ff414c)
1 /*
2  * AMD 10Gb Ethernet driver
3  *
4  * Copyright (c) 2014-2016,2020 Advanced Micro Devices, Inc.
5  *
6  * This file is available to you under your choice of the following two
7  * licenses:
8  *
9  * License 1: GPLv2
10  *
11  * This file is free software; you may copy, redistribute and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 2 of the License, or (at
14  * your option) any later version.
15  *
16  * This file is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  *
24  * This file incorporates work covered by the following copyright and
25  * permission notice:
26  *     The Synopsys DWC ETHER XGMAC Software Driver and documentation
27  *     (hereinafter "Software") is an unsupported proprietary work of Synopsys,
28  *     Inc. unless otherwise expressly agreed to in writing between Synopsys
29  *     and you.
30  *
31  *     The Software IS NOT an item of Licensed Software or Licensed Product
32  *     under any End User Software License Agreement or Agreement for Licensed
33  *     Product with Synopsys or any supplement thereto.  Permission is hereby
34  *     granted, free of charge, to any person obtaining a copy of this software
35  *     annotated with this license and the Software, to deal in the Software
36  *     without restriction, including without limitation the rights to use,
37  *     copy, modify, merge, publish, distribute, sublicense, and/or sell copies
38  *     of the Software, and to permit persons to whom the Software is furnished
39  *     to do so, subject to the following conditions:
40  *
41  *     The above copyright notice and this permission notice shall be included
42  *     in all copies or substantial portions of the Software.
43  *
44  *     THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
45  *     BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
46  *     TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
47  *     PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
48  *     BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
49  *     CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
50  *     SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
51  *     INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
52  *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53  *     ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
54  *     THE POSSIBILITY OF SUCH DAMAGE.
55  *
56  *
57  * License 2: Modified BSD
58  *
59  * Redistribution and use in source and binary forms, with or without
60  * modification, are permitted provided that the following conditions are met:
61  *     * Redistributions of source code must retain the above copyright
62  *       notice, this list of conditions and the following disclaimer.
63  *     * Redistributions in binary form must reproduce the above copyright
64  *       notice, this list of conditions and the following disclaimer in the
65  *       documentation and/or other materials provided with the distribution.
66  *     * Neither the name of Advanced Micro Devices, Inc. nor the
67  *       names of its contributors may be used to endorse or promote products
68  *       derived from this software without specific prior written permission.
69  *
70  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
71  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
72  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
73  * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
74  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
75  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
76  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
77  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
78  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
79  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
80  *
81  * This file incorporates work covered by the following copyright and
82  * permission notice:
83  *     The Synopsys DWC ETHER XGMAC Software Driver and documentation
84  *     (hereinafter "Software") is an unsupported proprietary work of Synopsys,
85  *     Inc. unless otherwise expressly agreed to in writing between Synopsys
86  *     and you.
87  *
88  *     The Software IS NOT an item of Licensed Software or Licensed Product
89  *     under any End User Software License Agreement or Agreement for Licensed
90  *     Product with Synopsys or any supplement thereto.  Permission is hereby
91  *     granted, free of charge, to any person obtaining a copy of this software
92  *     annotated with this license and the Software, to deal in the Software
93  *     without restriction, including without limitation the rights to use,
94  *     copy, modify, merge, publish, distribute, sublicense, and/or sell copies
95  *     of the Software, and to permit persons to whom the Software is furnished
96  *     to do so, subject to the following conditions:
97  *
98  *     The above copyright notice and this permission notice shall be included
99  *     in all copies or substantial portions of the Software.
100  *
101  *     THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
102  *     BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
103  *     TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
104  *     PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
105  *     BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
106  *     CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
107  *     SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
108  *     INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
109  *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
110  *     ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
111  *     THE POSSIBILITY OF SUCH DAMAGE.
112  */
113 
114 #include <sys/cdefs.h>
115 __FBSDID("$FreeBSD$");
116 
117 #include "xgbe.h"
118 #include "xgbe-common.h"
119 
120 static void
121 xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
122 {
123 	struct xgbe_hw_if *hw_if = &pdata->hw_if;
124 	struct xgbe_channel *channel;
125 	struct xgbe_ring *ring;
126 	struct xgbe_ring_data *rdata;
127 	struct xgbe_ring_desc *rdesc;
128 	bus_addr_t rdesc_paddr;
129 	unsigned int i, j;
130 
131 	DBGPR("-->xgbe_wrapper_tx_descriptor_init\n");
132 
133 	for (i = 0; i < pdata->channel_count; i++) {
134 
135 		channel = pdata->channel[i];
136 
137 		ring = channel->tx_ring;
138 		if (!ring)
139 			break;
140 
141 		rdesc = ring->rdesc;
142 		rdesc_paddr = ring->rdesc_paddr;
143 
144 		for (j = 0; j < ring->rdesc_count; j++) {
145 			rdata = XGBE_GET_DESC_DATA(ring, j);
146 
147 			rdata->rdesc = rdesc;
148 			rdata->rdata_paddr = rdesc_paddr;
149 
150 			rdesc++;
151 			rdesc_paddr += sizeof(struct xgbe_ring_desc);
152 		}
153 
154 		ring->cur = 0;
155 		ring->dirty = 0;
156 		memset(&ring->tx, 0, sizeof(ring->tx));
157 
158 		hw_if->tx_desc_init(channel);
159 	}
160 
161 	DBGPR("<--xgbe_wrapper_tx_descriptor_init\n");
162 }
163 
164 static void
165 xgbe_wrapper_rx_descriptor_init(struct xgbe_prv_data *pdata)
166 {
167 	struct xgbe_hw_if *hw_if = &pdata->hw_if;
168 	struct xgbe_channel *channel;
169 	struct xgbe_ring *ring;
170 	struct xgbe_ring_desc *rdesc;
171 	struct xgbe_ring_data *rdata;
172 	bus_addr_t rdesc_paddr;
173 	unsigned int i, j;
174 
175 	DBGPR("-->xgbe_wrapper_rx_descriptor_init\n");
176 
177 	for (i = 0; i < pdata->channel_count; i++) {
178 
179 		channel = pdata->channel[i];
180 
181 		ring = channel->rx_ring;
182 		if (!ring)
183 			break;
184 
185 		rdesc = ring->rdesc;
186 		rdesc_paddr = ring->rdesc_paddr;
187 
188 		for (j = 0; j < ring->rdesc_count; j++) {
189 			rdata = XGBE_GET_DESC_DATA(ring, j);
190 
191 			rdata->rdesc = rdesc;
192 			rdata->rdata_paddr = rdesc_paddr;
193 
194 			rdesc++;
195 			rdesc_paddr += sizeof(struct xgbe_ring_desc);
196 		}
197 
198 		ring->cur = 0;
199 		ring->dirty = 0;
200 
201 		hw_if->rx_desc_init(channel);
202 	}
203 }
204 
205 void
206 xgbe_init_function_ptrs_desc(struct xgbe_desc_if *desc_if)
207 {
208 
209 	desc_if->wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init;
210 	desc_if->wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init;
211 }
212