Skip to content

Commit d178e35

Browse files
committed
Add stub QCA6174 support
Add very basic QCA6174 chips calibration (board) data support. At the moment utility support only blob (file) loading, basic checking and very basic base header dumping.
1 parent bca6ff4 commit d178e35

File tree

6 files changed

+164
-0
lines changed

6 files changed

+164
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ OBJ=\
77
con_stub.o \
88
eep_5211.o \
99
eep_5416.o \
10+
eep_6174.o \
1011
eep_9285.o \
1112
eep_9287.o \
1213
eep_9300.o \

atheepmgr.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ static struct atheepmgr __aem;
2525
static const struct eepmap * const eepmaps[] = {
2626
&eepmap_5211,
2727
&eepmap_5416,
28+
&eepmap_6174,
2829
&eepmap_9285,
2930
&eepmap_9287,
3031
&eepmap_9300,
@@ -38,6 +39,8 @@ static const struct eepmap * const eepmaps[] = {
3839
AEM_CHIP(__name, &eepmap_5211)
3940
#define AEM_CHIP_EEP5416(__name) \
4041
AEM_CHIP(__name, &eepmap_5416)
42+
#define AEM_CHIP_EEP6174(__name) \
43+
AEM_CHIP(__name, &eepmap_6174)
4144
#define AEM_CHIP_EEP9285(__name) \
4245
AEM_CHIP(__name, &eepmap_9285)
4346
#define AEM_CHIP_EEP9287(__name) \
@@ -132,6 +135,10 @@ static const struct chip chips[] = {
132135
{ AEM_CHIP_EEP9880("QCA9890"), .pciids = {{ .dev_id = 0x003c }} },
133136
{ AEM_CHIP_EEP9880("QCA9892"), .pciids = {{ .dev_id = 0x003c }} },
134137

138+
/* QCA6174 EEPROM map PCIe chip(s) */
139+
{ AEM_CHIP_EEP6174("QCA6164"), .pciids = {{ .dev_id = 0x0041 }} }, /* Check PCI Id */
140+
{ AEM_CHIP_EEP6174("QCA6174"), .pciids = {{ .dev_id = 0x003e }} },
141+
135142
/* QCA9888 EEPROM map PCIe chip(s) */
136143
{ AEM_CHIP_EEP9888("QCA9886"), .pciids = {{ .dev_id = 0x0056 }} },
137144
{ AEM_CHIP_EEP9888("QCA9888"), .pciids = {{ .dev_id = 0x0056 }} },

atheepmgr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ extern const struct connector con_stub;
282282

283283
extern const struct eepmap eepmap_5211;
284284
extern const struct eepmap eepmap_5416;
285+
extern const struct eepmap eepmap_6174;
285286
extern const struct eepmap eepmap_9285;
286287
extern const struct eepmap eepmap_9287;
287288
extern const struct eepmap eepmap_9300;

eep_6174.c

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Copyright (c) 2021 Sergey Ryazanov <[email protected]>
3+
*
4+
* Permission to use, copy, modify, and/or distribute this software for any
5+
* purpose with or without fee is hereby granted, provided that the above
6+
* copyright notice and this permission notice appear in all copies.
7+
*
8+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15+
*/
16+
17+
#include "atheepmgr.h"
18+
#include "utils.h"
19+
#include "eep_common.h"
20+
#include "eep_6174.h"
21+
22+
struct eep_6174_priv {
23+
int curr_ref_tpl; /* Current reference EEPROM template */
24+
struct qca6174_eeprom eep;
25+
};
26+
27+
static bool eep_6174_load_blob(struct atheepmgr *aem)
28+
{
29+
const int data_size = sizeof(struct qca6174_eeprom);
30+
struct eep_6174_priv *emp = aem->eepmap_priv;
31+
int res;
32+
33+
if (aem->con->blob->getsize(aem) < data_size)
34+
return false;
35+
res = aem->con->blob->read(aem, aem->eep_buf, data_size);
36+
if (res != data_size) {
37+
fprintf(stderr, "Unable to read calibration data blob\n");
38+
return false;
39+
}
40+
41+
memcpy(&emp->eep, aem->eep_buf, sizeof(emp->eep));
42+
43+
aem->eep_len = (data_size + 1) / 2;
44+
45+
return true;
46+
}
47+
48+
static int eep_6174_check(struct atheepmgr *aem)
49+
{
50+
struct eep_6174_priv *emp = aem->eepmap_priv;
51+
struct qca6174_eeprom *eep = &emp->eep;
52+
struct qca6174_base_eep_hdr *pBase = &eep->baseEepHeader;
53+
uint16_t sum;
54+
55+
if (pBase->length != sizeof(*eep) &&
56+
bswap_16(pBase->length) != sizeof(*eep)) {
57+
fprintf(stderr, "Bad EEPROM length 0x%04x/0x%04x (expect 0x%04x)\n",
58+
pBase->length, bswap_16(pBase->length),
59+
(unsigned int)sizeof(*eep));
60+
return false;
61+
}
62+
63+
/**
64+
* NB: take pointer another one time from container to avoid warning
65+
* about a *possible* unaligned access
66+
*/
67+
sum = eep_calc_csum((uint16_t *)&emp->eep,
68+
sizeof(emp->eep) / sizeof(uint16_t));
69+
if (sum != 0xffff) {
70+
fprintf(stderr, "Bad EEPROM checksum 0x%04x\n", sum);
71+
return false;
72+
}
73+
74+
return true;
75+
}
76+
77+
static void eep_6174_dump_base_header(struct atheepmgr *aem)
78+
{
79+
const struct eep_6174_priv *emp = aem->eepmap_priv;
80+
const struct qca6174_eeprom *eep = &emp->eep;
81+
const struct qca6174_base_eep_hdr *pBase = &eep->baseEepHeader;
82+
83+
EEP_PRINT_SECT_NAME("EEPROM Base Header");
84+
85+
printf("%-30s : 0x%04X\n", "Length", pBase->length);
86+
printf("%-30s : 0x%04X\n", "Checksum", pBase->checksum);
87+
printf("%-30s : %d\n", "EEP Version", pBase->eepromVersion);
88+
printf("%-30s : %d\n", "Template Version", pBase->templateVersion);
89+
printf("%-30s : %02X:%02X:%02X:%02X:%02X:%02X\n",
90+
"MacAddress",
91+
pBase->macAddr[0], pBase->macAddr[1], pBase->macAddr[2],
92+
pBase->macAddr[3], pBase->macAddr[4], pBase->macAddr[5]);
93+
94+
printf("\nCustomer Data in hex:\n");
95+
hexdump_print(pBase->custData, sizeof(pBase->custData));
96+
97+
printf("\n");
98+
}
99+
100+
const struct eepmap eepmap_6174 = {
101+
.name = "6174",
102+
.desc = "EEPROM map for .11ac chips (QCA6174)",
103+
.chip_regs = {
104+
.srev = 0x08f0,
105+
},
106+
.priv_data_sz = sizeof(struct eep_6174_priv),
107+
.eep_buf_sz = sizeof(struct qca6174_eeprom) / sizeof(uint16_t),
108+
.load_blob = eep_6174_load_blob,
109+
.check_eeprom = eep_6174_check,
110+
.dump = {
111+
[EEP_SECT_BASE] = eep_6174_dump_base_header,
112+
},
113+
};

eep_6174.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2021 Sergey Ryazanov <[email protected]>
3+
*
4+
* Permission to use, copy, modify, and/or distribute this software for any
5+
* purpose with or without fee is hereby granted, provided that the above
6+
* copyright notice and this permission notice appear in all copies.
7+
*
8+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15+
*/
16+
17+
#ifndef EEP_6174_H
18+
#define EEP_6174_H
19+
20+
#define QCA6174_CUSTOMER_DATA_SIZE 20
21+
22+
struct qca6174_base_eep_hdr {
23+
uint16_t length;
24+
uint16_t checksum;
25+
uint8_t eepromVersion;
26+
uint8_t templateVersion;
27+
uint8_t macAddr[6];
28+
uint8_t __unkn_0c[32];
29+
uint8_t custData[QCA6174_CUSTOMER_DATA_SIZE];
30+
} __attribute__ ((packed));
31+
32+
struct qca6174_eeprom {
33+
struct qca6174_base_eep_hdr baseEepHeader;
34+
35+
uint8_t __unkn_0040[8060]; /* to match structure size to the EEPROM data size */
36+
} __attribute__ ((packed));
37+
38+
/* Structure size watchdog */
39+
_Static_assert(sizeof(struct qca6174_eeprom) == 8124, "Invalid QCA6174 EEPROM structure size");
40+
41+
#endif

hw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define HW_H
2020

2121
#define AR5211_SREV 0x4020
22+
#define QCA6174_SREV 0x08f0
2223
#define QCA988X_SREV 0x40ec
2324
#define QCA9888_SREV 0x800ec
2425
#define AR_SREV_ID 0x000000FF

0 commit comments

Comments
 (0)