Export an mmc or sd card's serial number from the mmc layer as an ivar.

In the mmcsd layer use this value to populate disk->d_ident.  Also set
disk->d_descr to the full set of card identification info (includes vendor,
model, manufacturing date, etc).
This commit is contained in:
Ian Lepore 2014-07-31 16:54:54 +00:00
parent 5af464bbe0
commit f3a4b7f73b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=269341
3 changed files with 18 additions and 4 deletions

View file

@ -102,6 +102,7 @@ struct mmc_ivars {
uint32_t hs_tran_speed; /* Max speed in high speed mode */ uint32_t hs_tran_speed; /* Max speed in high speed mode */
uint32_t erase_sector; /* Card native erase sector size */ uint32_t erase_sector; /* Card native erase sector size */
char card_id_string[64];/* Formatted CID info (serial, MFG, etc) */ char card_id_string[64];/* Formatted CID info (serial, MFG, etc) */
char card_sn_string[16];/* Formatted serial # for disk->d_ident */
}; };
#define CMD_RETRIES 3 #define CMD_RETRIES 3
@ -887,6 +888,9 @@ mmc_format_card_id_string(struct mmc_ivars *ivar)
* mmcsd0: 968MB <SD SD01G 8.0 SN 2686905 Mfg 08/2008 by 3 TN> at mmc0 * mmcsd0: 968MB <SD SD01G 8.0 SN 2686905 Mfg 08/2008 by 3 TN> at mmc0
* 22.5MHz/4bit/128-block * 22.5MHz/4bit/128-block
* *
* Also format just the card serial number, which the mmcsd driver will
* use as the disk->d_ident string.
*
* The card_id_string in mmc_ivars is currently allocated as 64 bytes, * The card_id_string in mmc_ivars is currently allocated as 64 bytes,
* and our max formatted length is currently 55 bytes if every field * and our max formatted length is currently 55 bytes if every field
* contains the largest value. * contains the largest value.
@ -900,8 +904,10 @@ mmc_format_card_id_string(struct mmc_ivars *ivar)
snprintf(oidstr, sizeof(oidstr), "%c%c", c1, c2); snprintf(oidstr, sizeof(oidstr), "%c%c", c1, c2);
else else
snprintf(oidstr, sizeof(oidstr), "0x%04x", ivar->cid.oid); snprintf(oidstr, sizeof(oidstr), "0x%04x", ivar->cid.oid);
snprintf(ivar->card_sn_string, sizeof(ivar->card_sn_string),
"%08X", ivar->cid.psn);
snprintf(ivar->card_id_string, sizeof(ivar->card_id_string), snprintf(ivar->card_id_string, sizeof(ivar->card_id_string),
"%s%s %s %d.%d SN %u MFG %02d/%04d by %d %s", "%s%s %s %d.%d SN %08X MFG %02d/%04d by %d %s",
ivar->mode == mode_sd ? "SD" : "MMC", ivar->high_cap ? "HC" : "", ivar->mode == mode_sd ? "SD" : "MMC", ivar->high_cap ? "HC" : "",
ivar->cid.pnm, ivar->cid.prv >> 4, ivar->cid.prv & 0x0f, ivar->cid.pnm, ivar->cid.prv >> 4, ivar->cid.prv & 0x0f,
ivar->cid.psn, ivar->cid.mdt_month, ivar->cid.mdt_year, ivar->cid.psn, ivar->cid.mdt_month, ivar->cid.mdt_year,
@ -1698,6 +1704,9 @@ mmc_read_ivar(device_t bus, device_t child, int which, uintptr_t *result)
case MMC_IVAR_CARD_ID_STRING: case MMC_IVAR_CARD_ID_STRING:
*(char **)result = ivar->card_id_string; *(char **)result = ivar->card_id_string;
break; break;
case MMC_IVAR_CARD_SN_STRING:
*(char **)result = ivar->card_sn_string;
break;
} }
return (0); return (0);
} }

View file

@ -163,6 +163,9 @@ mmcsd_attach(device_t dev)
d->d_unit = device_get_unit(dev); d->d_unit = device_get_unit(dev);
d->d_flags = DISKFLAG_CANDELETE; d->d_flags = DISKFLAG_CANDELETE;
d->d_delmaxsize = mmc_get_erase_sector(dev) * d->d_sectorsize * 1; /* conservative */ d->d_delmaxsize = mmc_get_erase_sector(dev) * d->d_sectorsize * 1; /* conservative */
strlcpy(d->d_ident, mmc_get_card_sn_string(dev), sizeof(d->d_ident));
strlcpy(d->d_descr, mmc_get_card_id_string(dev), sizeof(d->d_descr));
/* /*
* Display in most natural units. There's no cards < 1MB. The SD * Display in most natural units. There's no cards < 1MB. The SD
* standard goes to 2GiB due to its reliance on FAT, but the data * standard goes to 2GiB due to its reliance on FAT, but the data
@ -188,7 +191,7 @@ mmcsd_attach(device_t dev)
speed = mmcbr_get_clock(device_get_parent(dev)); speed = mmcbr_get_clock(device_get_parent(dev));
maxblocks = mmc_get_max_data(dev); maxblocks = mmc_get_max_data(dev);
device_printf(dev, "%ju%cB <%s>%s at %s %d.%01dMHz/%dbit/%d-block\n", device_printf(dev, "%ju%cB <%s>%s at %s %d.%01dMHz/%dbit/%d-block\n",
mb, unit, mmc_get_card_id_string(dev), mb, unit, d->d_descr,
mmc_get_read_only(dev) ? " (read-only)" : "", mmc_get_read_only(dev) ? " (read-only)" : "",
device_get_nameunit(device_get_parent(dev)), device_get_nameunit(device_get_parent(dev)),
speed / 1000000, (speed / 100000) % 10, speed / 1000000, (speed / 100000) % 10,

View file

@ -69,11 +69,12 @@ enum mmc_device_ivars {
MMC_IVAR_BUS_WIDTH, MMC_IVAR_BUS_WIDTH,
MMC_IVAR_ERASE_SECTOR, MMC_IVAR_ERASE_SECTOR,
MMC_IVAR_MAX_DATA, MMC_IVAR_MAX_DATA,
MMC_IVAR_CARD_ID_STRING MMC_IVAR_CARD_ID_STRING,
MMC_IVAR_CARD_SN_STRING,
}; };
/* /*
* Simplified accessors for pci devices * Simplified accessors for mmc devices
*/ */
#define MMC_ACCESSOR(var, ivar, type) \ #define MMC_ACCESSOR(var, ivar, type) \
__BUS_ACCESSOR(mmc, var, MMC, ivar, type) __BUS_ACCESSOR(mmc, var, MMC, ivar, type)
@ -90,5 +91,6 @@ MMC_ACCESSOR(bus_width, BUS_WIDTH, int)
MMC_ACCESSOR(erase_sector, ERASE_SECTOR, int) MMC_ACCESSOR(erase_sector, ERASE_SECTOR, int)
MMC_ACCESSOR(max_data, MAX_DATA, int) MMC_ACCESSOR(max_data, MAX_DATA, int)
MMC_ACCESSOR(card_id_string, CARD_ID_STRING, const char *) MMC_ACCESSOR(card_id_string, CARD_ID_STRING, const char *)
MMC_ACCESSOR(card_sn_string, CARD_SN_STRING, const char *)
#endif /* DEV_MMC_MMCVAR_H */ #endif /* DEV_MMC_MMCVAR_H */