iPXE
atl2_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 <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 "atl2_hw.h"
42 
43 static int atl2_hw_boot_completed_ ( struct atl_nic *nic ) {
44  uint32_t reset_status = ATL_READ_REG ( ATL2_GLB_RST_CTRL2 );
45 
46  return ( reset_status & ATL2_RESET_STATUS_BOOT_COMPLETED_MASK ) ||
49 }
50 
53  uint32_t i;
54 
55  for (i = 0; i < len; ++i )
56  {
58  }
59 }
60 
63  uint32_t i;
64 
65  for ( i = 0; i < len; ++i )
66  {
68  }
69 }
70 
71 int atl2_hw_finish_ack_ ( struct atl_nic *nic, uint32_t ms ) {
72  uint32_t i;
73  int err = 0;
74 
77 
78  for ( i = 0; i < ( ms / 100 ); ++i )
79  {
80  if ( ( ATL_READ_REG ( ATL2_MCP_BUSY_WRITE ) & 1 ) == 0 )
81  {
82  break;
83  }
85  }
86  if (i == ( ms / 100 ) )
87  err = -ETIME;
88 
89  return err;
90 }
91 
92 int atl2_hw_fw_init_ ( struct atl_nic *nic ) {
93  uint32_t val;
94  int err = 0;
95 
97  val |= ( ATL2_HOST_MODE_ACTIVE | ( 1U << 13 ) );
99 
101  val = 16352;
103 
105  val = 0;
107  err = atl2_hw_finish_ack_ ( nic, 50000000 );
108 
109  return err;
110 }
111 
112 int atl2_hw_reset ( struct atl_nic *nic ) {
113  int completed = 0;
114  uint32_t status = 0;
116  int err = 0;
117  int i;
118 
120 
122 
123  /* Wait for boot code started every 10us, 200 ms */
124  for ( i = 0; i < 20000; ++i )
125  {
127 
128  if ( ( ( status & ATL2_RESET_STATUS_BC_STARTED ) &&
129  ( status != 0xFFFFFFFFu ) ) )
130  break;
131 
132  udelay ( ATL2_DELAY_10 );
133  }
134  if ( i == 20000 )
135  {
136  DBGC ( nic, "Boot code hanged" );
137  err = -EIO;
138  goto err_exit;
139  }
140 
141  /* Wait for boot succeed, failed or host request every 10us, 480ms */
142  for ( i = 0; i < 48000; ++i )
143  {
144  completed = atl2_hw_boot_completed_ ( nic );
145  if ( completed )
146  break;
147 
148  udelay ( ATL2_DELAY_10 );
149  }
150 
151  if ( !completed )
152  {
153  DBGC ( nic, "FW Restart timed out" );
154  err = -ETIME;
155  goto err_exit;
156  }
157 
159 
161  {
162  err = -EIO;
163  DBGC ( nic, "FW Restart failed" );
164  DBGC ( nic, "status = 0x%x", status );
165  goto err_exit;
166  }
167 
170  {
171  err = -ENOTSUP;
172  DBGC ( nic, "Dynamic FW load not implemented" );
173  goto err_exit;
174  }
175 
176  err = atl2_hw_fw_init_ ( nic );
177 
178 err_exit:
179  return err;
180 }
181 
182 int atl2_hw_start ( struct atl_nic *nic ) {
183  uint32_t val;
184 
186  val = 0x4B00FFE1;
188 
189  return atl2_hw_finish_ack_ ( nic, 100000 );
190 }
191 
192 int atl2_hw_stop ( struct atl_nic *nic ) {
193  uint32_t val;
194 
196  val = 0;
198 
199  return atl2_hw_finish_ack_ ( nic, 100000 );
200 }
201 
202 int atl2_hw_get_link ( struct atl_nic *nic ) {
203  uint32_t val;
204 
206 
207  return ( ( val & 0xf ) != 0 ) && ( ( val & 0xF0 ) != 0 );
208 }
209 
210 int atl2_hw_get_mac ( struct atl_nic *nic, uint8_t *mac ) {
211  uint32_t mac_addr[2] = {0};
212 
214 
215  memcpy ( mac, ( uint8_t * )mac_addr, 6 );
216 
217  return 0;
218 }
219 
220 struct atl_hw_ops atl2_hw = {
221  .reset = atl2_hw_reset,
222  .start = atl2_hw_start,
223  .stop = atl2_hw_stop,
224  .get_link = atl2_hw_get_link,
225  .get_mac = atl2_hw_get_mac,
226 };
int atl2_hw_reset(struct atl_nic *nic)
Definition: atl2_hw.c:112
#define ATL2_RESET_STATUS_BOOT_FAILED_MASK
Definition: atl2_hw.h:53
FILE_LICENCE(BSD2)
An aQuanita network card.
Definition: aqc1xx.h:248
int atl2_hw_fw_init_(struct atl_nic *nic)
Definition: atl2_hw.c:92
#define ATL2_RESET_STATUS_REQ_GSR
Definition: atl2_hw.h:40
void __asmcall int val
Definition: setjmp.h:12
Error codes.
#define ATL2_LINK_STS_OUT_OFF
Definition: atl2_hw.h:89
#define ATL2_MIF_SHARED_BUF_OUT
Definition: atl2_hw.h:81
#define ATL2_DELAY_100
Definition: atl2_hw.h:92
int atl2_hw_get_mac(struct atl_nic *nic, uint8_t *mac)
Definition: atl2_hw.c:210
#define DBGC(...)
Definition: compiler.h:505
#define ATL2_MIF_SHARED_BUF_IN
Definition: atl2_hw.h:80
void atl2_hw_write_shared_in_(struct atl_nic *nic, uint32_t offset, uint32_t *data, uint32_t len)
Definition: atl2_hw.c:61
uint8_t mac[ETH_ALEN]
MAC address.
Definition: ena.h:24
int atl2_hw_finish_ack_(struct atl_nic *nic, uint32_t ms)
Definition: atl2_hw.c:71
#define ATL2_HOST_FINISHED_WRITE
Definition: atl2_hw.h:35
#define ATL2_MCP_BUSY_WRITE
Definition: atl2_hw.h:36
#define ATL2_HOST_MODE_ACTIVE
Definition: atl2_hw.h:75
#define ATL2_LINK_OPTS_IN_OFF
Definition: atl2_hw.h:86
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
int(* reset)(struct atl_nic *nic)
Definition: aqc1xx.h:240
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define ATL2_GLB_RST_CTRL2
Definition: atl2_hw.h:34
#define ATL2_HOST_ITR_REQ
Definition: atl2_hw.h:37
ring len
Length.
Definition: dwmac.h:231
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition: timer.c:60
#define ATL_WRITE_REG(VAL, REG)
Definition: aqc1xx.h:180
void atl2_hw_read_shared_in_(struct atl_nic *nic, uint32_t offset, uint32_t *data, uint32_t len)
Definition: atl2_hw.c:51
int atl2_hw_stop(struct atl_nic *nic)
Definition: atl2_hw.c:192
PCI bus.
#define ATL2_MAC_ADDR_IN_OFF
Definition: atl2_hw.h:84
static int atl2_hw_boot_completed_(struct atl_nic *nic)
Definition: atl2_hw.c:43
unsigned char uint8_t
Definition: stdint.h:10
#define ATL2_MTU_IN_OFF
Definition: atl2_hw.h:83
#define ATL_READ_REG(REG)
Definition: aqc1xx.h:181
#define ETIME
Timer expired.
Definition: errno.h:664
int atl2_hw_get_link(struct atl_nic *nic)
Definition: atl2_hw.c:202
Definition: nic.h:49
unsigned int uint32_t
Definition: stdint.h:12
uint8_t status
Status.
Definition: ena.h:16
Marvell AQtion family network card driver definitions.
#define ATL2_RESET_STATUS_BC_STARTED
Definition: atl2_hw.h:47
int atl2_hw_start(struct atl_nic *nic)
Definition: atl2_hw.c:182
struct atl_hw_ops atl2_hw
Definition: atl2_hw.c:220
#define EIO
Input/output error.
Definition: errno.h:433
#define ATL2_FW_HOST_INTERRUPT_REQUEST_READY
Definition: atl2_hw.h:56
u8 request[0]
List of IEs requested.
Definition: ieee80211.h:16
#define ATL2_DELAY_10
Definition: atl2_hw.h:91
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
#define ATL2_RESET_STATUS_BOOT_COMPLETED_MASK
Definition: atl2_hw.h:54
String functions.
#define ATL2_LINK_CTRL_IN_OFF
Definition: atl2_hw.h:85