18
18
#include "utils.h"
19
19
#include "eep_common.h"
20
20
#include "eep_9880.h"
21
+ #include "eep_9880_templates.h"
21
22
22
23
static const uint8_t eep_9880_otp_magic [2 ] = {0xaa , 0x55 };
23
24
24
25
struct eep_9880_priv {
26
+ int curr_ref_tpl ; /* Current reference EEPROM template */
25
27
struct qca9880_eeprom eep ;
26
- } __attribute__((aligned (4 ))); /* Force alignment to make gcc happy */
28
+ };
29
+
30
+ #define QCA9880_TEMPLATE_DESC (__name , __tpl ) \
31
+ { qca9880_tpl_ver_ ## __tpl, __name, &qca9880_ ## __tpl }
32
+
33
+ static const struct eeptemplate eep_9880_templates [] = {
34
+ QCA9880_TEMPLATE_DESC ("CUS223" , cus223 ),
35
+ QCA9880_TEMPLATE_DESC ("XB140" , xb140 ),
36
+ { 0 , NULL }
37
+ };
38
+
39
+ static const uint8_t * qca9880_template_find_by_id (int id )
40
+ {
41
+ const struct eeptemplate * tpl ;
42
+
43
+ for (tpl = eep_9880_templates ; tpl -> name ; ++ tpl )
44
+ if (tpl -> id == id )
45
+ break ;
46
+
47
+ return tpl -> data ;
48
+ }
49
+
50
+ static void eep_9880_proc_otp_caldata (struct atheepmgr * aem ,
51
+ const uint8_t * data , int len )
52
+ {
53
+ struct eep_9880_priv * emp = aem -> eepmap_priv ;
54
+ struct ar9300_comp_hdr hdr ;
55
+ uint16_t cksum , _cksum ;
56
+
57
+ ar9300_comp_hdr_unpack (data , & hdr );
58
+ if (aem -> verbose )
59
+ printf ("Found block at %x: comp=%d ref=%d length=%d major=%d minor=%d\n" ,
60
+ 0 , hdr .comp , hdr .ref , hdr .len , hdr .maj , hdr .min );
61
+
62
+ data += sizeof (AR9300_COMP_HDR_LEN );
63
+ len -= AR9300_COMP_HDR_LEN + sizeof (cksum );
64
+ if (hdr .len > len ) {
65
+ if (aem -> verbose )
66
+ printf ("Caldata block length greater then OTP stream length\n" );
67
+ return ;
68
+ }
69
+
70
+ cksum = ar9300_comp_cksum (data , hdr .len );
71
+ _cksum = data [hdr .len + 0 ] | (data [hdr .len + 1 ] << 8 );
72
+ if (cksum != _cksum ) {
73
+ if (aem -> verbose )
74
+ printf ("Bad caldata block checksum (got 0x%04x, expect 0x%04x)\n" ,
75
+ cksum , _cksum );
76
+ return ;
77
+ }
78
+
79
+ ar9300_compress_decision (aem , 0 , & hdr , aem -> unpacked_buf , data ,
80
+ sizeof (emp -> eep ), & emp -> curr_ref_tpl ,
81
+ qca9880_template_find_by_id );
82
+ }
27
83
28
84
static struct eep_9880_otp_str_desc {
29
85
const char * name ;
30
86
void (* proc )(struct atheepmgr * aem , const uint8_t * data , int len );
31
87
} eep_9880_otp_streams [] = {
88
+ [QCA9880_OTP_STR_TYPE_CALDATA ] = {
89
+ "calibration data" , eep_9880_proc_otp_caldata
90
+ },
32
91
};
33
92
34
93
static bool eep_9880_load_blob (struct atheepmgr * aem )
@@ -54,6 +113,8 @@ static bool eep_9880_load_blob(struct atheepmgr *aem)
54
113
55
114
static bool eep_9880_load_otp (struct atheepmgr * aem )
56
115
{
116
+ struct eep_9880_priv * emp = aem -> eepmap_priv ;
117
+ struct qca9880_eeprom * eep ;
57
118
uint8_t * buf = (uint8_t * )aem -> eep_buf ; /* Use as an array of bytes */
58
119
unsigned int addr , end_mark_seen ;
59
120
uint8_t strcode ;
@@ -80,6 +141,8 @@ static bool eep_9880_load_otp(struct atheepmgr *aem)
80
141
goto exit ;
81
142
}
82
143
144
+ emp -> curr_ref_tpl = -1 ; /* Reset reference template */
145
+
83
146
/**
84
147
* Now we are ready to parse OTP memory content.
85
148
*
@@ -155,7 +218,19 @@ static bool eep_9880_load_otp(struct atheepmgr *aem)
155
218
}
156
219
}
157
220
221
+ /**
222
+ * OTP does not contain a checksum correction, so update unpacked
223
+ * caldata checksum manually.
224
+ */
225
+ eep = (void * )aem -> unpacked_buf ;
226
+ eep -> baseEepHeader .checksum = 0xffff ;
227
+ eep -> baseEepHeader .checksum =
228
+ eep_calc_csum ((uint16_t * )aem -> unpacked_buf ,
229
+ sizeof (* eep ) / sizeof (uint16_t ));
230
+
158
231
aem -> eep_len = QCA9880_OTP_SIZE / sizeof (uint16_t );
232
+ aem -> unpacked_len = sizeof (struct qca9880_eeprom );
233
+ memcpy (& emp -> eep , aem -> unpacked_buf , sizeof (emp -> eep ));
159
234
160
235
exit :
161
236
return aem -> eep_len != 0 ;
@@ -487,6 +562,8 @@ const struct eepmap eepmap_9880 = {
487
562
.desc = "EEPROM map for earlier .11ac chips (QCA9880/QCA9882/QCA9892/etc.)" ,
488
563
.priv_data_sz = sizeof (struct eep_9880_priv ),
489
564
.eep_buf_sz = QCA9880_EEPROM_SIZE / sizeof (uint16_t ),
565
+ .unpacked_buf_sz = sizeof (struct qca9880_eeprom ),
566
+ .templates = eep_9880_templates ,
490
567
.load_blob = eep_9880_load_blob ,
491
568
.load_otp = eep_9880_load_otp ,
492
569
.check_eeprom = eep_9880_check ,
0 commit comments