iPXE
atl_hw.c
Go to the documentation of this file.
1/** @file
2 *
3 * Marvell AQtion family network card driver, hardware-specific functions.
4 *
5 * Copyright(C) 2017-2024 Marvell
6 *
7 * SPDX-License-Identifier: BSD-2-Clause
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11
12 * 1. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 * TO,THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR HOLDER OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 */
31
32FILE_LICENCE ( BSD2 );
33
34#include <string.h>
35#include <errno.h>
36#include <stdio.h>
37#include <unistd.h>
38#include <byteswap.h>
39#include <ipxe/pci.h>
40#include "aqc1xx.h"
41#include "atl_hw.h"
42#include <compiler.h>
43
44
45int atl_hw_reset_flb_ ( struct atl_nic *nic ) {
47 int k = 0;
48
51
52 /* Cleanup SPI */
55
59
60 /* Kickstart MAC */
64
66
67 /* Reset SPI again because of possible interrupted SPI burst */
71 /* Clear SPI reset state */
73
74 /* MAC Kickstart */
76
77 for (k = 0; k < 1000; k++) {
79
80 flb_status = flb_status & FLB_LOAD_STS;
81 if ( flb_status )
82 break;
84 }
85 if ( k == 1000 ) {
86 DBGC (nic, "MAC kickstart failed\n" );
87 return -EIO;
88 }
89
90 /* FW reset */
93
95
96 /* Global software reset*/
101
104
108
109 for (k = 0; k < 1000; k++) {
110 u32 fw_state = ATL_READ_REG ( ATL_FW_VER );
111
112 if ( fw_state )
113 break;
115 }
116 if ( k == 1000 ) {
117 DBGC ( nic, "FW kickstart failed\n" );
118 return -EIO;
119 }
120 /* Old FW requires fixed delay after init */
122
123 return 0;
124}
125
127 uint32_t val, rbl_status;
128 int k;
129
134
135 /* Alter RBL status */
137
138 /* Cleanup SPI */
141
142 /* Global software reset*/
144 ATL_RX_CTRL );
146 ATL_TX_CTRL );
149
153
155
156 /* Wait for RBL boot */
157 for ( k = 0; k < 1000; k++ ) {
158 rbl_status = ATL_READ_REG ( ATL_MPI_BOOT_EXIT_CODE ) & 0xFFFF;
159 if ( rbl_status && rbl_status != POISON_SIGN )
160 break;
162 }
163 if ( !rbl_status || rbl_status == POISON_SIGN ) {
164 DBGC ( nic, "RBL Restart failed\n" );
165 return -EIO;
166 }
167
168 if ( rbl_status == FW_NOT_SUPPORT )
169 return -ENOTSUP;
170
171 for ( k = 0; k < 1000; k++ ) {
172 u32 fw_state = ATL_READ_REG ( ATL_FW_VER );
173
174 if ( fw_state )
175 break;
177 }
178 if ( k == 1000 ) {
179 DBGC ( nic, "FW kickstart failed\n" );
180 return -EIO;
181 }
182 /* Old FW requires fixed delay after init */
184
185 return 0;
186}
187
188int atl_hw_reset ( struct atl_nic *nic ) {
189 uint32_t boot_exit_code = 0;
190 uint32_t k;
191 int rbl_enabled;
193 uint32_t sem_timeout;
194
195 for ( k = 0; k < 1000; ++k ) {
197 boot_exit_code = ATL_READ_REG ( ATL_MPI_BOOT_EXIT_CODE );
198 if ( flb_status != ATL_MPI_DAISY_CHAIN_STS_ERROR_STATUS ||
199 boot_exit_code != 0 )
200 break;
201 }
202
203 if ( k == 1000 ) {
204 DBGC ( nic, "Neither RBL nor FLB firmware started\n" );
205 return -ENOTSUP;
206 }
207
208 rbl_enabled = ( boot_exit_code != 0 );
209
211 if ( ( ( fw_ver >> 24 ) & 0xFF ) >= 4 ) {
212 sem_timeout = ATL_READ_REG ( ATL_SEM_TIMEOUT );
213 if ( sem_timeout > ATL_SEM_MAX_TIMEOUT )
214 sem_timeout = ATL_SEM_MAX_TIMEOUT;
215
216 for ( k = 0; k < sem_timeout; ++k ) {
218 break;
219
221 }
222 for ( k = 0; k < sem_timeout; ++k ) {
224 break;
225
227 }
228 }
229
230
231 if ( rbl_enabled )
232 return atl_hw_reset_rbl_ ( nic );
233 else
234 return atl_hw_reset_flb_ ( nic );
235}
236
237int atl_hw_start ( struct atl_nic *nic ) {
239 return 0;
240}
241
242int atl_hw_stop ( struct atl_nic *nic ) {
244 return 0;
245}
246
247int atl_hw_get_link ( struct atl_nic *nic ) {
248 return ( ATL_READ_REG ( ATL_LINK_ST) & ATL_LINK_ADV_AUTONEG ) != 0;
249}
250
252 uint32_t size ) {
253 uint32_t i;
254
255 for ( i = 0; i < 100; ++i ) {
256 if ( ATL_READ_REG( ATL_SEM_RAM ) )
257 break;
259 }
260 if ( i == 100 ) {
261 DBGC ( nic, "Semaphore Register not set\n" );
262 return -EIO;
263 }
264
266
267 for ( i = 0; i < size; ++i, addr += 4 ) {
268 uint32_t j;
269
271 for ( j = 0; j < 10000; ++j ) {
272 if ( ATL_READ_REG (ATL_MBOX_CTRL3 ) != addr )
273 break;
275 }
276 if ( j == 10000 ) {
277 DBGC ( nic, "Reading from CTRL3 Register Failed\n" );
278 return -EIO;
279 }
280
282 }
283
285
286 return 0;
287}
288
290 uint32_t mac_addr[2] = {0};
291 int err = 0;
292 uint32_t efuse_addr = ATL_READ_REG ( ATL_GLB_MCP_SP26 );
293
294 if ( efuse_addr != 0) {
295 uint32_t mac_efuse_addr = efuse_addr + 40 * sizeof ( uint32_t );
296 err = atl_hw_read_mem ( nic, mac_efuse_addr, mac_addr, 2 );
297 if ( err != 0 )
298 return err;
299
300 mac_addr[0] = cpu_to_be32 ( mac_addr[0] );
301 mac_addr[1] = cpu_to_be32 ( mac_addr[1] );
302
303 memcpy ( mac, ( uint8_t * )mac_addr, ATL_MAC_ADDRESS_SIZE );
304 }
305 return 0;
306}
307
309 .reset = atl_hw_reset,
310 .start = atl_hw_start,
311 .stop = atl_hw_stop,
312 .get_link = atl_hw_get_link,
313 .get_mac = atl_hw_get_mac,
314};
__be32 fw_ver
Definition CIB_PRM.h:5
struct atl_hw_ops atl_hw
Definition atl_hw.c:308
Marvell AQtion family network card driver definitions.
#define ATL_MBOX_CTRL1_START_MBOX_OPT
Definition aqc1xx.h:171
#define ATL_SEM_RAM
Definition aqc1xx.h:165
#define ATL_TX_CTRL
Definition aqc1xx.h:81
#define ATL_LINK_ADV
Definition aqc1xx.h:158
#define ATL_MBOX_CTRL3
Definition aqc1xx.h:173
#define ATL_RX_CTRL
Definition aqc1xx.h:79
#define ATL_SEM_RAM_RESET
Definition aqc1xx.h:166
#define ATL_LINK_ADV_AUTONEG
Definition aqc1xx.h:160
#define ATL_MBOX_CTRL1
Definition aqc1xx.h:170
#define ATL_SHUT_LINK
Definition aqc1xx.h:159
#define ATL_MBOX_CTRL5
Definition aqc1xx.h:174
#define ATL_LINK_ST
Definition aqc1xx.h:162
#define ATL_READ_REG(REG)
Definition aqc1xx.h:181
#define ATL_RX_CTRL_RST_DIS
Definition aqc1xx.h:80
#define ATL_TX_CTRL_RST_DIS
Definition aqc1xx.h:82
#define ATL_WRITE_REG(VAL, REG)
Definition aqc1xx.h:180
unsigned int uint32_t
Definition stdint.h:12
unsigned char uint8_t
Definition stdint.h:10
int atl_hw_get_mac(struct atl_nic *nic, uint8_t *mac)
Definition atl_hw.c:289
int atl_hw_reset_rbl_(struct atl_nic *nic)
Definition atl_hw.c:126
int atl_hw_stop(struct atl_nic *nic)
Definition atl_hw.c:242
int atl_hw_reset(struct atl_nic *nic)
Definition atl_hw.c:188
int atl_hw_start(struct atl_nic *nic)
Definition atl_hw.c:237
int atl_hw_get_link(struct atl_nic *nic)
Definition atl_hw.c:247
int atl_hw_reset_flb_(struct atl_nic *nic)
Definition atl_hw.c:45
int atl_hw_read_mem(struct atl_nic *nic, uint32_t addr, uint32_t *buffer, uint32_t size)
Definition atl_hw.c:251
#define ATL_MIF_PWR_GATING_EN_CTRL
Definition atl_hw.h:54
#define ATL_GLB_CTRL2_FW_RESET
Definition atl_hw.h:68
#define ATL_GLB_MCP_SEM5
Definition atl_hw.h:52
#define POISON_SIGN
Definition atl_hw.h:80
#define ATL_MPI_DAISY_CHAIN_STS
Definition atl_hw.h:37
#define FLB_LOAD_STS
Definition atl_hw.h:40
#define ATL_GLB_MCP_SEM1
Definition atl_hw.h:48
#define ATL_GLB_CTRL2_MBOX_ERR_UP_RUN_STALL
Definition atl_hw.h:69
#define ATL_GLB_NVR_PROV4
Definition atl_hw.h:56
#define ATL_GBL_NVR_PROV4_RESET
Definition atl_hw.h:57
#define ATL_SEM_MAX_TIMEOUT
Definition atl_hw.h:45
#define ATL_DELAY_10_MNS
Definition atl_hw.h:75
#define ATL_DELAY_50_MNS
Definition atl_hw.h:77
#define ATL_GLB_STD_CTRL_RESET
Definition atl_hw.h:71
#define ATL_GLB_CTRL2_MAC_KICK_START
Definition atl_hw.h:67
#define ATL_MAC_PHY_CTRL
Definition atl_hw.h:62
#define ATL_GLB_MCP_SP26
Definition atl_hw.h:53
#define ATL_GLB_CTRL2
Definition atl_hw.h:47
#define ATL_MAC_ADDRESS_SIZE
Definition atl_hw.h:79
#define ATL_SEM_TIMEOUT
Definition atl_hw.h:44
#define ATL_GLB_MCP_SEM4
Definition atl_hw.h:51
#define ATL_GLB_STD_CTRL
Definition atl_hw.h:33
#define ATL_GLB_CTRL_RST_DIS
Definition atl_hw.h:34
#define ATL_GEN_PROV9
Definition atl_hw.h:60
#define ATL_MPI_DAISY_CHAIN_STS_ERROR_STATUS
Definition atl_hw.h:72
#define ATL_DELAY_1_MNS
Definition atl_hw.h:74
#define ATL_MAC_PHY_CTRL_RST_DIS
Definition atl_hw.h:63
#define FW_NOT_SUPPORT
Definition atl_hw.h:81
#define ATL_GLB_CTRL2_MBOX_ERR_UP_RUN_NORMAL
Definition atl_hw.h:70
#define ATL_GBL_MCP_SEM1_RELEASE
Definition atl_hw.h:49
#define ATL_FW_VER
Definition atl_hw.h:35
#define ATL_DELAY_15_MNS
Definition atl_hw.h:76
#define ATL_MIF_PWR_GATING_EN_CTRL_RESET
Definition atl_hw.h:65
#define ATL_GEN_PROV9_ENABLE
Definition atl_hw.h:66
#define ATL_MPI_BOOT_EXIT_CODE
Definition atl_hw.h:42
uint32_t addr
Buffer address.
Definition dwmac.h:9
uint8_t mac[ETH_ALEN]
MAC address.
Definition ena.h:13
Error codes.
#define DBGC(...)
Definition compiler.h:505
uint16_t size
Buffer size.
Definition dwmac.h:3
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition netvsc.h:5
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define EIO
Input/output error.
Definition errno.h:434
#define ENOTSUP
Operation not supported.
Definition errno.h:590
#define cpu_to_be32(value)
Definition byteswap.h:111
Global compiler definitions.
void __asmcall int val
Definition setjmp.h:12
String functions.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static const uint32_t k[64]
MD5 constants.
Definition md5.c:54
PCI bus.
An aQuanita network card.
Definition aqc1xx.h:248
Definition nic.h:49
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition timer.c:79
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition timer.c:61
#define u32
Definition vga.h:21