xref: /freebsd/sys/dev/axgbe/xgbe-desc.c (revision 02e9120893770924227138ba49df1edb3896112a)
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 #include "xgbe.h"
116 #include "xgbe-common.h"
117 
118 static void
119 xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
120 {
121 	struct xgbe_hw_if *hw_if = &pdata->hw_if;
122 	struct xgbe_channel *channel;
123 	struct xgbe_ring *ring;
124 	struct xgbe_ring_data *rdata;
125 	struct xgbe_ring_desc *rdesc;
126 	bus_addr_t rdesc_paddr;
127 	unsigned int i, j;
128 
129 	DBGPR("-->xgbe_wrapper_tx_descriptor_init\n");
130 
131 	for (i = 0; i < pdata->channel_count; i++) {
132 
133 		channel = pdata->channel[i];
134 
135 		ring = channel->tx_ring;
136 		if (!ring)
137 			break;
138 
139 		rdesc = ring->rdesc;
140 		rdesc_paddr = ring->rdesc_paddr;
141 
142 		for (j = 0; j < ring->rdesc_count; j++) {
143 			rdata = XGBE_GET_DESC_DATA(ring, j);
144 
145 			rdata->rdesc = rdesc;
146 			rdata->rdata_paddr = rdesc_paddr;
147 
148 			rdesc++;
149 			rdesc_paddr += sizeof(struct xgbe_ring_desc);
150 		}
151 
152 		ring->cur = 0;
153 		ring->dirty = 0;
154 		memset(&ring->tx, 0, sizeof(ring->tx));
155 
156 		hw_if->tx_desc_init(channel);
157 	}
158 
159 	DBGPR("<--xgbe_wrapper_tx_descriptor_init\n");
160 }
161 
162 static void
163 xgbe_wrapper_rx_descriptor_init(struct xgbe_prv_data *pdata)
164 {
165 	struct xgbe_hw_if *hw_if = &pdata->hw_if;
166 	struct xgbe_channel *channel;
167 	struct xgbe_ring *ring;
168 	struct xgbe_ring_desc *rdesc;
169 	struct xgbe_ring_data *rdata;
170 	bus_addr_t rdesc_paddr;
171 	unsigned int i, j;
172 
173 	DBGPR("-->xgbe_wrapper_rx_descriptor_init\n");
174 
175 	for (i = 0; i < pdata->channel_count; i++) {
176 
177 		channel = pdata->channel[i];
178 
179 		ring = channel->rx_ring;
180 		if (!ring)
181 			break;
182 
183 		rdesc = ring->rdesc;
184 		rdesc_paddr = ring->rdesc_paddr;
185 
186 		for (j = 0; j < ring->rdesc_count; j++) {
187 			rdata = XGBE_GET_DESC_DATA(ring, j);
188 
189 			rdata->rdesc = rdesc;
190 			rdata->rdata_paddr = rdesc_paddr;
191 
192 			rdesc++;
193 			rdesc_paddr += sizeof(struct xgbe_ring_desc);
194 		}
195 
196 		ring->cur = 0;
197 		ring->dirty = 0;
198 
199 		hw_if->rx_desc_init(channel);
200 	}
201 }
202 
203 void
204 xgbe_init_function_ptrs_desc(struct xgbe_desc_if *desc_if)
205 {
206 
207 	desc_if->wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init;
208 	desc_if->wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init;
209 }
210