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
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 "atl2_hw.h"
42
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
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
92int atl2_hw_fw_init_ ( struct atl_nic *nic ) {
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
112int 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
129 ( status != 0xFFFFFFFFu ) ) )
130 break;
131
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
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
178err_exit:
179 return err;
180}
181
182int atl2_hw_start ( struct atl_nic *nic ) {
184
186 val = 0x4B00FFE1;
188
189 return atl2_hw_finish_ack_ ( nic, 100000 );
190}
191
192int atl2_hw_stop ( struct atl_nic *nic ) {
194
196 val = 0;
198
199 return atl2_hw_finish_ack_ ( nic, 100000 );
200}
201
202int atl2_hw_get_link ( struct atl_nic *nic ) {
204
206
207 return ( ( val & 0xf ) != 0 ) && ( ( val & 0xF0 ) != 0 );
208}
209
211 uint32_t mac_addr[2] = {0};
212
214
215 memcpy ( mac, ( uint8_t * )mac_addr, 6 );
216
217 return 0;
218}
219
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};
struct atl_hw_ops atl2_hw
Definition atl2_hw.c:220
Marvell AQtion family network card driver definitions.
#define ATL_READ_REG(REG)
Definition aqc1xx.h:181
#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
void atl2_hw_write_shared_in_(struct atl_nic *nic, uint32_t offset, uint32_t *data, uint32_t len)
Definition atl2_hw.c:61
int atl2_hw_finish_ack_(struct atl_nic *nic, uint32_t ms)
Definition atl2_hw.c:71
void atl2_hw_read_shared_in_(struct atl_nic *nic, uint32_t offset, uint32_t *data, uint32_t len)
Definition atl2_hw.c:51
static int atl2_hw_boot_completed_(struct atl_nic *nic)
Definition atl2_hw.c:43
int atl2_hw_reset(struct atl_nic *nic)
Definition atl2_hw.c:112
int atl2_hw_start(struct atl_nic *nic)
Definition atl2_hw.c:182
int atl2_hw_fw_init_(struct atl_nic *nic)
Definition atl2_hw.c:92
int atl2_hw_get_mac(struct atl_nic *nic, uint8_t *mac)
Definition atl2_hw.c:210
int atl2_hw_stop(struct atl_nic *nic)
Definition atl2_hw.c:192
int atl2_hw_get_link(struct atl_nic *nic)
Definition atl2_hw.c:202
#define ATL2_RESET_STATUS_BC_STARTED
Definition atl2_hw.h:47
#define ATL2_LINK_CTRL_IN_OFF
Definition atl2_hw.h:85
#define ATL2_MIF_SHARED_BUF_IN
Definition atl2_hw.h:80
#define ATL2_GLB_RST_CTRL2
Definition atl2_hw.h:34
#define ATL2_HOST_FINISHED_WRITE
Definition atl2_hw.h:35
#define ATL2_MCP_BUSY_WRITE
Definition atl2_hw.h:36
#define ATL2_MIF_SHARED_BUF_OUT
Definition atl2_hw.h:81
#define ATL2_RESET_STATUS_BOOT_FAILED_MASK
Definition atl2_hw.h:53
#define ATL2_RESET_STATUS_BOOT_COMPLETED_MASK
Definition atl2_hw.h:54
#define ATL2_MAC_ADDR_IN_OFF
Definition atl2_hw.h:84
#define ATL2_MTU_IN_OFF
Definition atl2_hw.h:83
#define ATL2_LINK_OPTS_IN_OFF
Definition atl2_hw.h:86
#define ATL2_HOST_ITR_REQ
Definition atl2_hw.h:37
#define ATL2_LINK_STS_OUT_OFF
Definition atl2_hw.h:89
#define ATL2_DELAY_100
Definition atl2_hw.h:92
#define ATL2_DELAY_10
Definition atl2_hw.h:91
#define ATL2_RESET_STATUS_REQ_GSR
Definition atl2_hw.h:40
#define ATL2_HOST_MODE_ACTIVE
Definition atl2_hw.h:75
#define ATL2_FW_HOST_INTERRUPT_REQUEST_READY
Definition atl2_hw.h:56
uint16_t offset
Offset to command line.
Definition bzimage.h:3
ring len
Length.
Definition dwmac.h:226
uint8_t data[48]
Additional event data.
Definition ena.h:11
uint8_t status
Status.
Definition ena.h:5
uint8_t mac[ETH_ALEN]
MAC address.
Definition ena.h:13
Error codes.
#define DBGC(...)
Definition compiler.h:505
#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 ETIME
Timer expired.
Definition errno.h:665
u8 request[0]
List of IEs requested.
Definition ieee80211.h:2
void __asmcall int val
Definition setjmp.h:12
String functions.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
PCI bus.
An aQuanita network card.
Definition aqc1xx.h:248
Definition nic.h:49
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition timer.c:61