Skip to content

Commit 0af69a4

Browse files
committed
Allow connector to detect a EEPROM map type
Connectors that interact with real card via PnP bus (e.g. PCI) are able to determine a chip model and via it determine a EEPROM map type. Add a new connector capabilities flag (CON_CAP_PNP) that indicates connector ability to determine EEPROM map type. Assign the new flag to PCI connector and assign map type in the PCI connector if chip was detected. Old utility behaviour is preserved too. User specified EEPROM type overrides autodetected type, but now all these are done in more explicit way. If autodetection failed or autodetected type differs from user input than utility will print coresponding message in the verbose output mode. Also if EEPROM type was not provided by a user or autodetected by a connector, then as earlier the utility will fallback to SREV register based autodetection. All this gives us a reliable source of chip type information before any access to the chip registers.
1 parent f30be4c commit 0af69a4

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

atheepmgr.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,7 @@ int main(int argc, char *argv[])
859859
{
860860
struct atheepmgr *aem = &__aem;
861861
const struct action *act = NULL;
862+
const struct eepmap *user_eepmap = NULL;
862863
char *con_arg = NULL;
863864
int print_usage = 0;
864865
int i, opt;
@@ -891,10 +892,10 @@ int main(int argc, char *argv[])
891892
break;
892893
#endif
893894
case 't':
894-
aem->eepmap = eepmap_find_by_name(optarg);
895-
if (!aem->eepmap)
896-
aem->eepmap = eepmap_find_by_chip(optarg);
897-
if (!aem->eepmap) {
895+
user_eepmap = eepmap_find_by_name(optarg);
896+
if (!user_eepmap)
897+
user_eepmap = eepmap_find_by_chip(optarg);
898+
if (!user_eepmap) {
898899
fprintf(stderr, "Unknown EEPROM map type or chip name: %s\n",
899900
optarg);
900901
goto exit;
@@ -948,7 +949,7 @@ int main(int argc, char *argv[])
948949
goto exit;
949950
}
950951

951-
if ((act->flags & ACT_F_DATA) && !aem->eepmap &&
952+
if ((act->flags & ACT_F_DATA) && !user_eepmap &&
952953
!(aem->con->caps & CON_CAP_HW)) {
953954
fprintf(stderr, "EEPROM map type option is mandatory for connectors without direct HW access\n");
954955
goto exit;
@@ -965,6 +966,25 @@ int main(int argc, char *argv[])
965966
if (ret)
966967
goto exit;
967968

969+
if (!aem->eepmap && !user_eepmap) {
970+
if ((aem->con->caps & CON_CAP_PNP) && aem->verbose)
971+
printf("Connector failed to autodetect EEPROM type, fallback to SREV register based autodetection\n");
972+
} else if (!aem->eepmap && user_eepmap) {
973+
if ((aem->con->caps & CON_CAP_PNP) && aem->verbose)
974+
printf("Connector failed to autodetect EEPROM type, use manually configured %s type\n",
975+
user_eepmap->name);
976+
aem->eepmap = user_eepmap;
977+
} else if (aem->eepmap && !user_eepmap) {
978+
if (aem->verbose)
979+
printf("Autodetected EEPROM map type is %s\n",
980+
aem->eepmap->name);
981+
} else if (aem->eepmap != user_eepmap) {
982+
if (aem->verbose)
983+
printf("Override autodetected %s EEPROM type with manually configured %s type\n",
984+
aem->eepmap->name, user_eepmap->name);
985+
aem->eepmap = user_eepmap;
986+
}
987+
968988
if (aem->con->caps & CON_CAP_HW) {
969989
ret = hw_init(aem);
970990
if (ret)

atheepmgr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ typedef int bool;
138138
#define AH_TIME_QUANTUM 10
139139

140140
#define CON_CAP_HW 1 /* Con. is able to interact with HW */
141+
#define CON_CAP_PNP 2 /* Con. is able to detect EEP layout */
141142

142143
#define EEP_WP_GPIO_AUTO -1 /* Use autodetection */
143144
#define EEP_WP_GPIO_NONE -2 /* Do not use GPIO for unlocking */

con_pci.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ static int is_supported_chipset(struct atheepmgr *aem, struct pci_device *pdev)
5454
printf(")\n");
5555
}
5656

57+
aem->eepmap = chips[0]->eepmap;
58+
5759
return 1;
5860

5961
not_supported:
@@ -249,7 +251,7 @@ static void pci_clean(struct atheepmgr *aem)
249251
const struct connector con_pci = {
250252
.name = "PCI",
251253
.priv_data_sz = sizeof(struct pci_priv),
252-
.caps = CON_CAP_HW,
254+
.caps = CON_CAP_HW | CON_CAP_PNP,
253255
.init = pci_init,
254256
.clean = pci_clean,
255257
.reg_read = pci_reg_read,

0 commit comments

Comments
 (0)