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 
32 FILE_LICENCE ( BSD2 );
33 
34 #include <errno.h>
35 #include <stdio.h>
36 #include <unistd.h>
37 #include <byteswap.h>
38 #include <ipxe/pci.h>
39 #include "aqc1xx.h"
40 #include "atl_hw.h"
41 #include <compiler.h>
42 
43 
44 int atl_hw_reset_flb_ ( struct atl_nic *nic ) {
45  uint32_t val;
46  int k = 0;
47 
50 
51  /* Cleanup SPI */
54 
58 
59  /* Kickstart MAC */
63 
65 
66  /* Reset SPI again because of possible interrupted SPI burst */
70  /* Clear SPI reset state */
72 
73  /* MAC Kickstart */
75 
76  for (k = 0; k < 1000; k++) {
78 
79  flb_status = flb_status & FLB_LOAD_STS;
80  if ( flb_status )
81  break;
83  }
84  if ( k == 1000 ) {
85  DBGC (nic, "MAC kickstart failed\n" );
86  return -EIO;
87  }
88 
89  /* FW reset */
92 
94 
95  /* Global software reset*/
100 
103 
107 
108  for (k = 0; k < 1000; k++) {
109  u32 fw_state = ATL_READ_REG ( ATL_FW_VER );
110 
111  if ( fw_state )
112  break;
114  }
115  if ( k == 1000 ) {
116  DBGC ( nic, "FW kickstart failed\n" );
117  return -EIO;
118  }
119  /* Old FW requires fixed delay after init */
121 
122  return 0;
123 }
124 
125 int atl_hw_reset_rbl_ ( struct atl_nic *nic ) {
126  uint32_t val, rbl_status;
127  int k;
128 
133 
134  /* Alter RBL status */
136 
137  /* Cleanup SPI */
140 
141  /* Global software reset*/
143  ATL_RX_CTRL );
145  ATL_TX_CTRL );
148 
152 
154 
155  /* Wait for RBL boot */
156  for ( k = 0; k < 1000; k++ ) {
157  rbl_status = ATL_READ_REG ( ATL_MPI_BOOT_EXIT_CODE ) & 0xFFFF;
158  if ( rbl_status && rbl_status != POISON_SIGN )
159  break;
161  }
162  if ( !rbl_status || rbl_status == POISON_SIGN ) {
163  DBGC ( nic, "RBL Restart failed\n" );
164  return -EIO;
165  }
166 
167  if ( rbl_status == FW_NOT_SUPPORT )
168  return -ENOTSUP;
169 
170  for ( k = 0; k < 1000; k++ ) {
171  u32 fw_state = ATL_READ_REG ( ATL_FW_VER );
172 
173  if ( fw_state )
174  break;
176  }
177  if ( k == 1000 ) {
178  DBGC ( nic, "FW kickstart failed\n" );
179  return -EIO;
180  }
181  /* Old FW requires fixed delay after init */
183 
184  return 0;
185 }
186 
187 int atl_hw_reset ( struct atl_nic *nic ) {
188  uint32_t boot_exit_code = 0;
189  uint32_t k;
190  int rbl_enabled;
192  uint32_t sem_timeout;
193 
194  for ( k = 0; k < 1000; ++k ) {
196  boot_exit_code = ATL_READ_REG ( ATL_MPI_BOOT_EXIT_CODE );
197  if ( flb_status != ATL_MPI_DAISY_CHAIN_STS_ERROR_STATUS ||
198  boot_exit_code != 0 )
199  break;
200  }
201 
202  if ( k == 1000 ) {
203  DBGC ( nic, "Neither RBL nor FLB firmware started\n" );
204  return -ENOTSUP;
205  }
206 
207  rbl_enabled = ( boot_exit_code != 0 );
208 
210  if ( ( ( fw_ver >> 24 ) & 0xFF ) >= 4 ) {
211  sem_timeout = ATL_READ_REG ( ATL_SEM_TIMEOUT );
212  if ( sem_timeout > ATL_SEM_MAX_TIMEOUT )
213  sem_timeout = ATL_SEM_MAX_TIMEOUT;
214 
215  for ( k = 0; k < sem_timeout; ++k ) {
216  if ( ATL_READ_REG ( ATL_GLB_MCP_SEM4 ) )
217  break;
218 
220  }
221  for ( k = 0; k < sem_timeout; ++k ) {
222  if ( ATL_READ_REG ( ATL_GLB_MCP_SEM5 ) )
223  break;
224 
226  }
227  }
228 
229 
230  if ( rbl_enabled )
231  return atl_hw_reset_rbl_ ( nic );
232  else
233  return atl_hw_reset_flb_ ( nic );
234 }
235 
236 int atl_hw_start ( struct atl_nic *nic ) {
238  return 0;
239 }
240 
241 int atl_hw_stop ( struct atl_nic *nic ) {
243  return 0;
244 }
245 
246 int atl_hw_get_link ( struct atl_nic *nic ) {
247  return ( ATL_READ_REG ( ATL_LINK_ST) & ATL_LINK_ADV_AUTONEG ) != 0;
248 }
249 
251  uint32_t size ) {
252  uint32_t i;
253 
254  for ( i = 0; i < 100; ++i ) {
255  if ( ATL_READ_REG( ATL_SEM_RAM ) )
256  break;
258  }
259  if ( i == 100 ) {
260  DBGC ( nic, "Semaphore Register not set\n" );
261  return -EIO;
262  }
263 
265 
266  for ( i = 0; i < size; ++i, addr += 4 ) {
267  uint32_t j;
268 
270  for ( j = 0; j < 10000; ++j ) {
271  if ( ATL_READ_REG (ATL_MBOX_CTRL3 ) != addr )
272  break;
274  }
275  if ( j == 10000 ) {
276  DBGC ( nic, "Reading from CTRL3 Register Failed\n" );
277  return -EIO;
278  }
279 
281  }
282 
284 
285  return 0;
286 }
287 
288 int atl_hw_get_mac ( struct atl_nic *nic, uint8_t *mac ) {
289  uint32_t mac_addr[2] = {0};
290  int err = 0;
291  uint32_t efuse_addr = ATL_READ_REG ( ATL_GLB_MCP_SP26 );
292 
293  if ( efuse_addr != 0) {
294  uint32_t mac_efuse_addr = efuse_addr + 40 * sizeof ( uint32_t );
295  err = atl_hw_read_mem ( nic, mac_efuse_addr, mac_addr, 2 );
296  if ( err != 0 )
297  return err;
298 
299  mac_addr[0] = cpu_to_be32 ( mac_addr[0] );
300  mac_addr[1] = cpu_to_be32 ( mac_addr[1] );
301 
302  memcpy ( mac, ( uint8_t * )mac_addr, ATL_MAC_ADDRESS_SIZE );
303  }
304  return 0;
305 }
306 
307 struct atl_hw_ops atl_hw = {
308  .reset = atl_hw_reset,
309  .start = atl_hw_start,
310  .stop = atl_hw_stop,
311  .get_link = atl_hw_get_link,
312  .get_mac = atl_hw_get_mac,
313 };
#define ATL_GEN_PROV9
Definition: atl_hw.h:60
An aQuanita network card.
Definition: aqc1xx.h:248
#define ATL_SHUT_LINK
Definition: aqc1xx.h:159
Global compiler definitions.
#define ATL_MAC_PHY_CTRL_RST_DIS
Definition: atl_hw.h:63
#define ATL_MBOX_CTRL3
Definition: aqc1xx.h:173
void __asmcall int val
Definition: setjmp.h:12
#define ATL_MPI_BOOT_EXIT_CODE
Definition: atl_hw.h:42
#define FLB_LOAD_STS
Definition: atl_hw.h:40
Error codes.
#define ATL_MIF_PWR_GATING_EN_CTRL_RESET
Definition: atl_hw.h:65
#define ATL_GLB_MCP_SEM5
Definition: atl_hw.h:52
#define ATL_GLB_CTRL_RST_DIS
Definition: atl_hw.h:34
#define ATL_RX_CTRL_RST_DIS
Definition: aqc1xx.h:80
__be32 fw_ver
Definition: CIB_PRM.h:33
#define DBGC(...)
Definition: compiler.h:505
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition: netvsc.h:16
#define ATL_GLB_MCP_SEM4
Definition: atl_hw.h:51
uint8_t mac[ETH_ALEN]
MAC address.
Definition: ena.h:24
#define ATL_MAC_ADDRESS_SIZE
Definition: atl_hw.h:79
#define ATL_GEN_PROV9_ENABLE
Definition: atl_hw.h:66
#define ATL_DELAY_15_MNS
Definition: atl_hw.h:76
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
int(* reset)(struct atl_nic *nic)
Definition: aqc1xx.h:240
#define ATL_MIF_PWR_GATING_EN_CTRL
Definition: atl_hw.h:54
#define ATL_MBOX_CTRL1
Definition: aqc1xx.h:170
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define ATL_LINK_ADV_AUTONEG
Definition: aqc1xx.h:160
#define ATL_GLB_CTRL2_MBOX_ERR_UP_RUN_STALL
Definition: atl_hw.h:69
#define ATL_FW_VER
Definition: atl_hw.h:35
#define ATL_GLB_CTRL2_MAC_KICK_START
Definition: atl_hw.h:67
int atl_hw_reset_flb_(struct atl_nic *nic)
Definition: atl_hw.c:44
#define ATL_GBL_MCP_SEM1_RELEASE
Definition: atl_hw.h:49
#define ATL_SEM_MAX_TIMEOUT
Definition: atl_hw.h:45
#define ATL_LINK_ADV
Definition: aqc1xx.h:158
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition: timer.c:60
#define ATL_TX_CTRL
Definition: aqc1xx.h:81
#define FW_NOT_SUPPORT
Definition: atl_hw.h:81
int atl_hw_start(struct atl_nic *nic)
Definition: atl_hw.c:236
#define ATL_WRITE_REG(VAL, REG)
Definition: aqc1xx.h:180
#define ATL_DELAY_50_MNS
Definition: atl_hw.h:77
int atl_hw_get_link(struct atl_nic *nic)
Definition: atl_hw.c:246
#define ATL_DELAY_1_MNS
Definition: atl_hw.h:74
PCI bus.
#define ATL_MPI_DAISY_CHAIN_STS_ERROR_STATUS
Definition: atl_hw.h:72
#define ATL_GLB_CTRL2_FW_RESET
Definition: atl_hw.h:68
#define ATL_SEM_RAM_RESET
Definition: aqc1xx.h:166
unsigned char uint8_t
Definition: stdint.h:10
#define ATL_GLB_MCP_SEM1
Definition: atl_hw.h:48
#define ATL_RX_CTRL
Definition: aqc1xx.h:79
FILE_LICENCE(BSD2)
#define ATL_LINK_ST
Definition: aqc1xx.h:162
#define ATL_DELAY_10_MNS
Definition: atl_hw.h:75
#define ATL_READ_REG(REG)
Definition: aqc1xx.h:181
int atl_hw_get_mac(struct atl_nic *nic, uint8_t *mac)
Definition: atl_hw.c:288
static const uint32_t k[64]
MD5 constants.
Definition: md5.c:53
Definition: nic.h:49
unsigned int uint32_t
Definition: stdint.h:12
int atl_hw_reset(struct atl_nic *nic)
Definition: atl_hw.c:187
Marvell AQtion family network card driver definitions.
#define ATL_GLB_CTRL2
Definition: atl_hw.h:47
#define ATL_MBOX_CTRL5
Definition: aqc1xx.h:174
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define ATL_MPI_DAISY_CHAIN_STS
Definition: atl_hw.h:37
#define cpu_to_be32(value)
Definition: byteswap.h:110
int atl_hw_read_mem(struct atl_nic *nic, uint32_t addr, uint32_t *buffer, uint32_t size)
Definition: atl_hw.c:250
#define POISON_SIGN
Definition: atl_hw.h:80
u32 addr
Definition: sky2.h:8
#define EIO
Input/output error.
Definition: errno.h:433
#define ATL_SEM_RAM
Definition: aqc1xx.h:165
#define ATL_GLB_CTRL2_MBOX_ERR_UP_RUN_NORMAL
Definition: atl_hw.h:70
#define ATL_GLB_MCP_SP26
Definition: atl_hw.h:53
#define ATL_GBL_NVR_PROV4_RESET
Definition: atl_hw.h:57
uint8_t size
Entry size (in 32-bit words)
Definition: ena.h:16
#define ATL_TX_CTRL_RST_DIS
Definition: aqc1xx.h:82
#define ATL_MAC_PHY_CTRL
Definition: atl_hw.h:62
struct atl_hw_ops atl_hw
Definition: atl_hw.c:307
#define ATL_MBOX_CTRL1_START_MBOX_OPT
Definition: aqc1xx.h:171
int atl_hw_reset_rbl_(struct atl_nic *nic)
Definition: atl_hw.c:125
#define ATL_SEM_TIMEOUT
Definition: atl_hw.h:44
#define ATL_GLB_NVR_PROV4
Definition: atl_hw.h:56
#define ATL_GLB_STD_CTRL
Definition: atl_hw.h:33
int atl_hw_stop(struct atl_nic *nic)
Definition: atl_hw.c:241
uint32_t u32
Definition: stdint.h:23
#define ATL_GLB_STD_CTRL_RESET
Definition: atl_hw.h:71