Skip to content

Commit a57d392

Browse files
caildavem330
authored andcommitted
net: aquantia: Introduce support for new firmware on AQC cards
This defines fw2x operations table and corresponding methods. Some of the functions are being shared with 1.x firmware Signed-off-by: Igor Russkikh <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 0c58c35 commit a57d392

File tree

5 files changed

+257
-4
lines changed

5 files changed

+257
-4
lines changed

drivers/net/ethernet/aquantia/atlantic/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ atlantic-objs := aq_main.o \
3939
hw_atl/hw_atl_a0.o \
4040
hw_atl/hw_atl_b0.o \
4141
hw_atl/hw_atl_utils.o \
42+
hw_atl/hw_atl_utils_fw2x.o \
4243
hw_atl/hw_atl_llh.o

drivers/net/ethernet/aquantia/atlantic/aq_hw.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ struct aq_hw_caps_s {
4242
u8 rx_rings;
4343
bool flow_control;
4444
bool is_64_dma;
45-
u32 fw_ver_expected;
4645
};
4746

4847
struct aq_hw_link_status_s {

drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#define HW_ATL_MPI_SPEED_SHIFT 16U
3333

3434
#define HW_ATL_FW_VER_1X 0x01050006U
35+
#define HW_ATL_FW_VER_2X 0x02000000U
36+
#define HW_ATL_FW_VER_3X 0x03000000U
3537

3638
static int hw_atl_utils_ver_match(u32 ver_expected, u32 ver_actual);
3739

@@ -46,6 +48,12 @@ int hw_atl_utils_initfw(struct aq_hw_s *self, const struct aq_fw_ops **fw_ops)
4648

4749
if (hw_atl_utils_ver_match(HW_ATL_FW_VER_1X, self->fw_ver_actual) == 0)
4850
*fw_ops = &aq_fw_1x_ops;
51+
else if (hw_atl_utils_ver_match(HW_ATL_FW_VER_2X,
52+
self->fw_ver_actual) == 0)
53+
*fw_ops = &aq_fw_2x_ops;
54+
else if (hw_atl_utils_ver_match(HW_ATL_FW_VER_3X,
55+
self->fw_ver_actual) == 0)
56+
*fw_ops = &aq_fw_2x_ops;
4957
else {
5058
aq_pr_err("Bad FW version detected: %x\n",
5159
self->fw_ver_actual);
@@ -56,8 +64,8 @@ int hw_atl_utils_initfw(struct aq_hw_s *self, const struct aq_fw_ops **fw_ops)
5664
return err;
5765
}
5866

59-
static int hw_atl_utils_fw_downld_dwords(struct aq_hw_s *self, u32 a,
60-
u32 *p, u32 cnt)
67+
int hw_atl_utils_fw_downld_dwords(struct aq_hw_s *self, u32 a,
68+
u32 *p, u32 cnt)
6169
{
6270
int err = 0;
6371

drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.h

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ struct __packed hw_aq_atl_utils_mbox {
163163
#define HAL_ATLANTIC_UTILS_CHIP_REVISION_B0 0x02000000U
164164

165165
#define IS_CHIP_FEATURE(_F_) (HAL_ATLANTIC_UTILS_CHIP_##_F_ & \
166-
self->chip_features)
166+
self->chip_features)
167167

168168
enum hal_atl_utils_fw_state_e {
169169
MPI_DEINIT = 0,
@@ -180,6 +180,64 @@ enum hal_atl_utils_fw_state_e {
180180
#define HAL_ATLANTIC_RATE_100M BIT(5)
181181
#define HAL_ATLANTIC_RATE_INVALID BIT(6)
182182

183+
enum hw_atl_fw2x_rate {
184+
FW2X_RATE_100M = 0x20,
185+
FW2X_RATE_1G = 0x100,
186+
FW2X_RATE_2G5 = 0x200,
187+
FW2X_RATE_5G = 0x400,
188+
FW2X_RATE_10G = 0x800,
189+
};
190+
191+
enum hw_atl_fw2x_caps_lo {
192+
CAPS_LO_10BASET_HD = 0x00,
193+
CAPS_LO_10BASET_FD,
194+
CAPS_LO_100BASETX_HD,
195+
CAPS_LO_100BASET4_HD,
196+
CAPS_LO_100BASET2_HD,
197+
CAPS_LO_100BASETX_FD,
198+
CAPS_LO_100BASET2_FD,
199+
CAPS_LO_1000BASET_HD,
200+
CAPS_LO_1000BASET_FD,
201+
CAPS_LO_2P5GBASET_FD,
202+
CAPS_LO_5GBASET_FD,
203+
CAPS_LO_10GBASET_FD,
204+
};
205+
206+
enum hw_atl_fw2x_caps_hi {
207+
CAPS_HI_RESERVED1 = 0x00,
208+
CAPS_HI_10BASET_EEE,
209+
CAPS_HI_RESERVED2,
210+
CAPS_HI_PAUSE,
211+
CAPS_HI_ASYMMETRIC_PAUSE,
212+
CAPS_HI_100BASETX_EEE,
213+
CAPS_HI_RESERVED3,
214+
CAPS_HI_RESERVED4,
215+
CAPS_HI_1000BASET_FD_EEE,
216+
CAPS_HI_2P5GBASET_FD_EEE,
217+
CAPS_HI_5GBASET_FD_EEE,
218+
CAPS_HI_10GBASET_FD_EEE,
219+
CAPS_HI_RESERVED5,
220+
CAPS_HI_RESERVED6,
221+
CAPS_HI_RESERVED7,
222+
CAPS_HI_RESERVED8,
223+
CAPS_HI_RESERVED9,
224+
CAPS_HI_CABLE_DIAG,
225+
CAPS_HI_TEMPERATURE,
226+
CAPS_HI_DOWNSHIFT,
227+
CAPS_HI_PTP_AVB_EN,
228+
CAPS_HI_MEDIA_DETECT,
229+
CAPS_HI_LINK_DROP,
230+
CAPS_HI_SLEEP_PROXY,
231+
CAPS_HI_WOL,
232+
CAPS_HI_MAC_STOP,
233+
CAPS_HI_EXT_LOOPBACK,
234+
CAPS_HI_INT_LOOPBACK,
235+
CAPS_HI_EFUSE_AGENT,
236+
CAPS_HI_WOL_TIMER,
237+
CAPS_HI_STATISTICS,
238+
CAPS_HI_TRANSACTION_ID,
239+
};
240+
183241
struct aq_hw_s;
184242
struct aq_fw_ops;
185243
struct aq_hw_caps_s;
@@ -222,7 +280,10 @@ int hw_atl_utils_get_fw_version(struct aq_hw_s *self, u32 *fw_version);
222280
int hw_atl_utils_update_stats(struct aq_hw_s *self);
223281

224282
struct aq_stats_s *hw_atl_utils_get_hw_stats(struct aq_hw_s *self);
283+
int hw_atl_utils_fw_downld_dwords(struct aq_hw_s *self, u32 a,
284+
u32 *p, u32 cnt);
225285

226286
extern const struct aq_fw_ops aq_fw_1x_ops;
287+
extern const struct aq_fw_ops aq_fw_2x_ops;
227288

228289
#endif /* HW_ATL_UTILS_H */
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
/*
2+
* aQuantia Corporation Network Driver
3+
* Copyright (C) 2014-2017 aQuantia Corporation. All rights reserved
4+
*
5+
* This program is free software; you can redistribute it and/or modify it
6+
* under the terms and conditions of the GNU General Public License,
7+
* version 2, as published by the Free Software Foundation.
8+
*/
9+
10+
/* File hw_atl_utils_fw2x.c: Definition of firmware 2.x functions for
11+
* Atlantic hardware abstraction layer.
12+
*/
13+
14+
#include "../aq_hw.h"
15+
#include "../aq_hw_utils.h"
16+
#include "../aq_pci_func.h"
17+
#include "../aq_ring.h"
18+
#include "../aq_vec.h"
19+
#include "hw_atl_utils.h"
20+
#include "hw_atl_llh.h"
21+
22+
#define HW_ATL_FW2X_MPI_EFUSE_ADDR 0x364
23+
#define HW_ATL_FW2X_MPI_MBOX_ADDR 0x360
24+
25+
#define HW_ATL_FW2X_MPI_CONTROL_ADDR 0x368
26+
#define HW_ATL_FW2X_MPI_CONTROL2_ADDR 0x36C
27+
28+
#define HW_ATL_FW2X_MPI_STATE_ADDR 0x370
29+
#define HW_ATL_FW2X_MPI_STATE2_ADDR 0x374
30+
31+
static int aq_fw2x_init(struct aq_hw_s *self)
32+
{
33+
int err = 0;
34+
35+
/* check 10 times by 1ms */
36+
AQ_HW_WAIT_FOR(0U != (self->mbox_addr =
37+
aq_hw_read_reg(self, HW_ATL_FW2X_MPI_MBOX_ADDR)),
38+
1000U, 10U);
39+
return err;
40+
}
41+
42+
static enum hw_atl_fw2x_rate link_speed_mask_2fw2x_ratemask(u32 speed)
43+
{
44+
enum hw_atl_fw2x_rate rate = 0;
45+
46+
if (speed & AQ_NIC_RATE_10G)
47+
rate |= FW2X_RATE_10G;
48+
49+
if (speed & AQ_NIC_RATE_5G)
50+
rate |= FW2X_RATE_5G;
51+
52+
if (speed & AQ_NIC_RATE_5GSR)
53+
rate |= FW2X_RATE_5G;
54+
55+
if (speed & AQ_NIC_RATE_2GS)
56+
rate |= FW2X_RATE_2G5;
57+
58+
if (speed & AQ_NIC_RATE_1G)
59+
rate |= FW2X_RATE_1G;
60+
61+
if (speed & AQ_NIC_RATE_100M)
62+
rate |= FW2X_RATE_100M;
63+
64+
return rate;
65+
}
66+
67+
static int aq_fw2x_set_link_speed(struct aq_hw_s *self, u32 speed)
68+
{
69+
u32 val = link_speed_mask_2fw2x_ratemask(speed);
70+
71+
aq_hw_write_reg(self, HW_ATL_FW2X_MPI_CONTROL_ADDR, val);
72+
73+
return 0;
74+
}
75+
76+
static int aq_fw2x_set_state(struct aq_hw_s *self,
77+
enum hal_atl_utils_fw_state_e state)
78+
{
79+
/* No explicit state in 2x fw */
80+
return 0;
81+
}
82+
83+
static int aq_fw2x_update_link_status(struct aq_hw_s *self)
84+
{
85+
u32 mpi_state = aq_hw_read_reg(self, HW_ATL_FW2X_MPI_STATE_ADDR);
86+
u32 speed = mpi_state & (FW2X_RATE_100M | FW2X_RATE_1G |
87+
FW2X_RATE_2G5 | FW2X_RATE_5G | FW2X_RATE_10G);
88+
struct aq_hw_link_status_s *link_status = &self->aq_link_status;
89+
90+
if (speed) {
91+
if (speed & FW2X_RATE_10G)
92+
link_status->mbps = 10000;
93+
else if (speed & FW2X_RATE_5G)
94+
link_status->mbps = 5000;
95+
else if (speed & FW2X_RATE_2G5)
96+
link_status->mbps = 2500;
97+
else if (speed & FW2X_RATE_1G)
98+
link_status->mbps = 1000;
99+
else if (speed & FW2X_RATE_100M)
100+
link_status->mbps = 100;
101+
else
102+
link_status->mbps = 10000;
103+
} else {
104+
link_status->mbps = 0;
105+
}
106+
107+
return 0;
108+
}
109+
110+
int aq_fw2x_get_mac_permanent(struct aq_hw_s *self, u8 *mac)
111+
{
112+
int err = 0;
113+
u32 h = 0U;
114+
u32 l = 0U;
115+
u32 mac_addr[2] = { 0 };
116+
u32 efuse_addr = aq_hw_read_reg(self, HW_ATL_FW2X_MPI_EFUSE_ADDR);
117+
118+
if (efuse_addr != 0) {
119+
err = hw_atl_utils_fw_downld_dwords(self,
120+
efuse_addr + (40U * 4U),
121+
mac_addr,
122+
ARRAY_SIZE(mac_addr));
123+
if (err)
124+
return err;
125+
mac_addr[0] = __swab32(mac_addr[0]);
126+
mac_addr[1] = __swab32(mac_addr[1]);
127+
}
128+
129+
ether_addr_copy(mac, (u8 *)mac_addr);
130+
131+
if ((mac[0] & 0x01U) || ((mac[0] | mac[1] | mac[2]) == 0x00U)) {
132+
unsigned int rnd = 0;
133+
134+
get_random_bytes(&rnd, sizeof(unsigned int));
135+
136+
l = 0xE3000000U
137+
| (0xFFFFU & rnd)
138+
| (0x00 << 16);
139+
h = 0x8001300EU;
140+
141+
mac[5] = (u8)(0xFFU & l);
142+
l >>= 8;
143+
mac[4] = (u8)(0xFFU & l);
144+
l >>= 8;
145+
mac[3] = (u8)(0xFFU & l);
146+
l >>= 8;
147+
mac[2] = (u8)(0xFFU & l);
148+
mac[1] = (u8)(0xFFU & h);
149+
h >>= 8;
150+
mac[0] = (u8)(0xFFU & h);
151+
}
152+
return err;
153+
}
154+
155+
static int aq_fw2x_update_stats(struct aq_hw_s *self)
156+
{
157+
int err = 0;
158+
u32 mpi_opts = aq_hw_read_reg(self, HW_ATL_FW2X_MPI_CONTROL2_ADDR);
159+
u32 orig_stats_val = mpi_opts & BIT(CAPS_HI_STATISTICS);
160+
161+
/* Toggle statistics bit for FW to update */
162+
mpi_opts = mpi_opts ^ BIT(CAPS_HI_STATISTICS);
163+
aq_hw_write_reg(self, HW_ATL_FW2X_MPI_CONTROL2_ADDR, mpi_opts);
164+
165+
/* Wait FW to report back */
166+
AQ_HW_WAIT_FOR(orig_stats_val !=
167+
(aq_hw_read_reg(self, HW_ATL_FW2X_MPI_STATE2_ADDR) &
168+
BIT(CAPS_HI_STATISTICS)),
169+
1U, 10000U);
170+
if (err)
171+
return err;
172+
173+
return hw_atl_utils_update_stats(self);
174+
}
175+
176+
const struct aq_fw_ops aq_fw_2x_ops = {
177+
.init = aq_fw2x_init,
178+
.reset = NULL,
179+
.get_mac_permanent = aq_fw2x_get_mac_permanent,
180+
.set_link_speed = aq_fw2x_set_link_speed,
181+
.set_state = aq_fw2x_set_state,
182+
.update_link_status = aq_fw2x_update_link_status,
183+
.update_stats = aq_fw2x_update_stats,
184+
};

0 commit comments

Comments
 (0)