From: Peter Stuge Date: Mon, 23 Jul 2012 23:08:54 +0200 Subject: [ath9k-devel] [PATCH] qca-swiss-army-knife: Add a tool to dump EEPROM In-Reply-To: <20492.53272.943747.11705@gargle.gargle.HOWL> References: <20492.53272.943747.11705@gargle.gargle.HOWL> Message-ID: <20120723210854.28601.qmail@stuge.se> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: ath9k-devel@lists.ath9k.org Sujith Manoharan wrote: > +static int is_supported_chipset(struct pci_device *pdev) > +{ > + if (pdev->vendor_id != ATHEROS_VENDOR_ID) > + return 0; > + > + if ((pdev->device_id != AR5416_DEVID_PCI) && > + (pdev->device_id != AR5416_DEVID_PCIE) && > + (pdev->device_id != AR9160_DEVID_PCI) && > + (pdev->device_id != AR9280_DEVID_PCI) && > + (pdev->device_id != AR9280_DEVID_PCIE) && > + (pdev->device_id != AR9285_DEVID_PCIE) && > + (pdev->device_id != AR9287_DEVID_PCI) && > + (pdev->device_id != AR9287_DEVID_PCIE)) { > + fprintf(stderr, "Device ID: 0x%x not supported\n", pdev->device_id); > + return 0; > + } Perhaps a switch () would be more suitable here. > +++ b/tools/edump/src/eep_4k.c .. > +static bool fill_eeprom_4k(struct edump *edump) > +{ > +#define SIZE_EEPROM_4K (sizeof(struct ar5416_eeprom_4k) / sizeof(uint16_t)) > + > + uint16_t *eep_data = (uint16_t *)&edump->eeprom.map4k; > + int addr, eep_start_loc = 0; > + > + eep_start_loc = 64; > + > + for (addr = 0; addr < SIZE_EEPROM_4K; addr++) { > + if (!pci_eeprom_read(edump, addr + eep_start_loc, eep_data)) { > + fprintf(stderr, "Unable to read eeprom region\n"); > + return false; > + } > + eep_data++; > + } > + > + return true; > + > +#undef SIZE_EEPROM_4K > +} What is the define+undef about in each of these fill functions? I guess there could be a better solution for these sizes? Even writing out sizeof(struct ar5416_eeprom_4k) / sizeof(uint16_t) in the loop condition would be an improvement IMO. > +static void modal_eeprom_4k(struct edump *edump) > +{ > +#define PR(_token, _p, _val_fmt, _val) \ > + do { \ > + printf("%-23s %-2s", (_token), ":"); \ > + printf("%s%"_val_fmt, _p, (_val)); \ > + printf("\n"); \ > + } while(0) Several lovely two-letter macros which get undefined again. Not super awesome for code readability, which is really a shame, since the rest of the code looks rather good. > + PR("Ant Chain 0", "0x", "X", pModal->antCtrlChain[0]); > + PR("Antenna Common", "0x", "X", pModal->antCtrlCommon); > + PR("Antenna Gain Chain 0", "", "d", pModal->antennaGainCh[0]); ..followed by 44 more lines with second and third parameter identical. What do you think about having two macros instead? > +++ b/tools/edump/src/eep_9287.c .. > +static void modal_eeprom_9287(struct edump *edump) > +{ > +#define PR(_token, _p, _val_fmt, _val) \ > + do { \ > + printf("%-23s %-2s", (_token), ":"); \ > + printf("%s%"_val_fmt, _p, (_val)); \ > + printf("\n"); \ > + } while(0) ..oh - is this an identical macro - with same lovely two letter name and same parameters? > +++ b/tools/edump/src/eep_def.c .. > +static bool fill_eeprom_def(struct edump *edump) > +{ > +#define SIZE_EEPROM_DEF (sizeof(struct ar5416_eeprom_def) / sizeof(uint16_t)) I don't see why these size defines aren't at least next to the structs. > +static void modal_eeprom_def(struct edump *edump) > +{ > +#define PR(_token, _p, _val_fmt, _val) \ > + do { \ > + printf("%-23s %-8s", (_token), ":"); \ > + if (pBase->opCapFlags & AR5416_OPFLAGS_11G) { \ > + pModal = &(ar5416Eep->modalHeader[1]); \ > + printf("%s%-6"_val_fmt, _p, (_val)); \ > + } \ > + if (pBase->opCapFlags & AR5416_OPFLAGS_11A) { \ > + pModal = &(ar5416Eep->modalHeader[0]); \ > + printf("%8s%"_val_fmt"\n", _p, (_val)); \ > + } else { \ > + printf("\n"); \ > + } \ > + } while(0) Yeah baby. Got another one! Other than these handful points I think the code looks very good and it will certainly be helpful for many. Is a commit to also do EEPROM writes likely to be accepted into qca-swiss-army-knife.git? //Peter