|
| 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 | +}; |
0 commit comments