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 <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 "atl2_hw.h"
41 
42 static int atl2_hw_boot_completed_ ( struct atl_nic *nic ) {
43  uint32_t reset_status = ATL_READ_REG ( ATL2_GLB_RST_CTRL2 );
44 
45  return ( reset_status & ATL2_RESET_STATUS_BOOT_COMPLETED_MASK ) ||
48 }
49 
52  uint32_t i;
53 
54  for (i = 0; i < len; ++i )
55  {
57  }
58 }
59 
62  uint32_t i;
63 
64  for ( i = 0; i < len; ++i )
65  {
67  }
68 }
69 
70 int atl2_hw_finish_ack_ ( struct atl_nic *nic, uint32_t ms ) {
71  uint32_t i;
72  int err = 0;
73 
76 
77  for ( i = 0; i < ( ms / 100 ); ++i )
78  {
79  if ( ( ATL_READ_REG ( ATL2_MCP_BUSY_WRITE ) & 1 ) == 0 )
80  {
81  break;
82  }
84  }
85  if (i == ( ms / 100 ) )
86  err = -ETIME;
87 
88  return err;
89 }
90 
91 int atl2_hw_fw_init_ ( struct atl_nic *nic ) {
92  uint32_t val;
93  int err = 0;
94 
96  val |= ( ATL2_HOST_MODE_ACTIVE | ( 1U << 13 ) );
98 
100  val = 16352;
102 
104  val = 0;
106  err = atl2_hw_finish_ack_ ( nic, 50000000 );
107 
108  return err;
109 }
110 
111 int atl2_hw_reset ( struct atl_nic *nic ) {
112  int completed = 0;
113  uint32_t status = 0;
115  int err = 0;
116  int i;
117 
119 
121 
122  /* Wait for boot code started every 10us, 200 ms */
123  for ( i = 0; i < 20000; ++i )
124  {
126 
127  if ( ( ( status & ATL2_RESET_STATUS_BC_STARTED ) &&
128  ( status != 0xFFFFFFFFu ) ) )
129  break;
130 
131  udelay ( ATL2_DELAY_10 );
132  }
133  if ( i == 20000 )
134  {
135  DBGC ( nic, "Boot code hanged" );
136  err = -EIO;
137  goto err_exit;
138  }
139 
140  /* Wait for boot succeed, failed or host request every 10us, 480ms */
141  for ( i = 0; i < 48000; ++i )
142  {
143  completed = atl2_hw_boot_completed_ ( nic );
144  if ( completed )
145  break;
146 
147  udelay ( ATL2_DELAY_10 );
148  }
149 
150  if ( !completed )
151  {
152  DBGC ( nic, "FW Restart timed out" );
153  err = -ETIME;
154  goto err_exit;
155  }
156 
158 
160  {
161  err = -EIO;
162  DBGC ( nic, "FW Restart failed" );
163  DBGC ( nic, "status = 0x%x", status );
164  goto err_exit;
165  }
166 
169  {
170  err = -ENOTSUP;
171  DBGC ( nic, "Dynamic FW load not implemented" );
172  goto err_exit;
173  }
174 
175  err = atl2_hw_fw_init_ ( nic );
176 
177 err_exit:
178  return err;
179 }
180 
181 int atl2_hw_start ( struct atl_nic *nic ) {
182  uint32_t val;
183 
185  val = 0x4B00FFE1;
187 
188  return atl2_hw_finish_ack_ ( nic, 100000 );
189 }
190 
191 int atl2_hw_stop ( struct atl_nic *nic ) {
192  uint32_t val;
193 
195  val = 0;
197 
198  return atl2_hw_finish_ack_ ( nic, 100000 );
199 }
200 
201 int atl2_hw_get_link ( struct atl_nic *nic ) {
202  uint32_t val;
203 
205 
206  return ( ( val & 0xf ) != 0 ) && ( ( val & 0xF0 ) != 0 );
207 }
208 
209 int atl2_hw_get_mac ( struct atl_nic *nic, uint8_t *mac ) {
210  uint32_t mac_addr[2] = {0};
211 
213 
214  memcpy ( mac, ( uint8_t * )mac_addr, 6 );
215 
216  return 0;
217 }
218 
219 struct atl_hw_ops atl2_hw = {
220  .reset = atl2_hw_reset,
221  .start = atl2_hw_start,
222  .stop = atl2_hw_stop,
223  .get_link = atl2_hw_get_link,
224  .get_mac = atl2_hw_get_mac,
225 };
int atl2_hw_reset(struct atl_nic *nic)
Definition: atl2_hw.c:111
#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:91
#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:209
#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:60
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:70
#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
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:50
int atl2_hw_stop(struct atl_nic *nic)
Definition: atl2_hw.c:191
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:42
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:201
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:181
struct atl_hw_ops atl2_hw
Definition: atl2_hw.c:219
#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
uint32_t len
Length.
Definition: ena.h:14
#define ATL2_LINK_CTRL_IN_OFF
Definition: atl2_hw.h:85