From owner-svn-src-all@FreeBSD.ORG Thu Jul 31 16:54:55 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id CBDE9BCA; Thu, 31 Jul 2014 16:54:55 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B906229A4; Thu, 31 Jul 2014 16:54:55 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s6VGstwt090734; Thu, 31 Jul 2014 16:54:55 GMT (envelope-from ian@svn.freebsd.org) Received: (from ian@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s6VGstu4090731; Thu, 31 Jul 2014 16:54:55 GMT (envelope-from ian@svn.freebsd.org) Message-Id: <201407311654.s6VGstu4090731@svn.freebsd.org> From: Ian Lepore Date: Thu, 31 Jul 2014 16:54:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r269341 - head/sys/dev/mmc X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jul 2014 16:54:55 -0000 Author: ian Date: Thu Jul 31 16:54:54 2014 New Revision: 269341 URL: http://svnweb.freebsd.org/changeset/base/269341 Log: 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). Modified: head/sys/dev/mmc/mmc.c head/sys/dev/mmc/mmcsd.c head/sys/dev/mmc/mmcvar.h Modified: head/sys/dev/mmc/mmc.c ============================================================================== --- head/sys/dev/mmc/mmc.c Thu Jul 31 16:43:56 2014 (r269340) +++ head/sys/dev/mmc/mmc.c Thu Jul 31 16:54:54 2014 (r269341) @@ -102,6 +102,7 @@ struct mmc_ivars { uint32_t hs_tran_speed; /* Max speed in high speed mode */ uint32_t erase_sector; /* Card native erase sector size */ 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 @@ -887,6 +888,9 @@ mmc_format_card_id_string(struct mmc_iva * mmcsd0: 968MB at mmc0 * 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, * and our max formatted length is currently 55 bytes if every field * contains the largest value. @@ -900,8 +904,10 @@ mmc_format_card_id_string(struct mmc_iva snprintf(oidstr, sizeof(oidstr), "%c%c", c1, c2); else 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), - "%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->cid.pnm, ivar->cid.prv >> 4, ivar->cid.prv & 0x0f, ivar->cid.psn, ivar->cid.mdt_month, ivar->cid.mdt_year, @@ -1698,6 +1704,9 @@ mmc_read_ivar(device_t bus, device_t chi case MMC_IVAR_CARD_ID_STRING: *(char **)result = ivar->card_id_string; break; + case MMC_IVAR_CARD_SN_STRING: + *(char **)result = ivar->card_sn_string; + break; } return (0); } Modified: head/sys/dev/mmc/mmcsd.c ============================================================================== --- head/sys/dev/mmc/mmcsd.c Thu Jul 31 16:43:56 2014 (r269340) +++ head/sys/dev/mmc/mmcsd.c Thu Jul 31 16:54:54 2014 (r269341) @@ -163,6 +163,9 @@ mmcsd_attach(device_t dev) d->d_unit = device_get_unit(dev); d->d_flags = DISKFLAG_CANDELETE; 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 * 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)); maxblocks = mmc_get_max_data(dev); 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)" : "", device_get_nameunit(device_get_parent(dev)), speed / 1000000, (speed / 100000) % 10, Modified: head/sys/dev/mmc/mmcvar.h ============================================================================== --- head/sys/dev/mmc/mmcvar.h Thu Jul 31 16:43:56 2014 (r269340) +++ head/sys/dev/mmc/mmcvar.h Thu Jul 31 16:54:54 2014 (r269341) @@ -69,11 +69,12 @@ enum mmc_device_ivars { MMC_IVAR_BUS_WIDTH, MMC_IVAR_ERASE_SECTOR, 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) \ __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(max_data, MAX_DATA, int) 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 */