From owner-p4-projects@FreeBSD.ORG Sun Apr 1 14:52:40 2012 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id A9D971065670; Sun, 1 Apr 2012 14:52:40 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 6C257106566B for ; Sun, 1 Apr 2012 14:52:40 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id 535C18FC0C for ; Sun, 1 Apr 2012 14:52:40 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id q31EqeUe038649 for ; Sun, 1 Apr 2012 14:52:40 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id q31Eqd2L038646 for perforce@freebsd.org; Sun, 1 Apr 2012 14:52:39 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Sun, 1 Apr 2012 14:52:39 GMT Message-Id: <201204011452.q31Eqd2L038646@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 208918 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 Apr 2012 14:52:41 -0000 http://p4web.freebsd.org/@@208918?ac=10 Change 208918 by rwatson@rwatson_svr_ctsrd_mipsbuild on 2012/04/01 14:51:53 Implement first cut at reading the SD Card CSD register in the FreeBSD device driver for the Altera Univesity Program SD Card IP Core. Currently, support only v1 CSD structures; we'll see what turns up in the actual SD Cards shipped by Altera. Add support for "bad" cards whose insertion event is suppressed when we encounter unexpected configuration data. Work under the assumption that CSD data is immediately available via memory-mapped registers -- if this proves not to be true, we will need to add additional states in order to allow blocking reads of CSD/CID/etc from the card prior to starting I/O. Affected files ... .. //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard.c#2 edit .. //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard.h#4 edit .. //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard_disk.c#2 edit .. //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard_io.c#3 edit Differences ... ==== //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard.c#2 (text+ko) ==== @@ -174,12 +174,27 @@ } /* - * Handle card insertion. + * If there is no card insertion, remain in NOCARD. + */ + if (!(altera_sdcard_read_asr(sc) & ALTERA_SDCARD_ASR_CARDPRESENT)) + return; + + /* + * Read the CSD -- it may contain values that force the setting of + * ALTERA_SDCARD_FLAG_BADCARD, in which case we suppress detection of + * the card. For example, if there is an unrecognised CSD structure + * version, or if the IP Core doesn't support the returned sector + * size. + */ + altera_sdcard_read_csd(sc); + if (sc->as_flags & ALTERA_SDCARD_FLAG_BADCARD) + return; + + /* + * Process card insertion and upgrade to the IDLE state. */ - if (altera_sdcard_read_asr(sc) & ALTERA_SDCARD_ASR_CARDPRESENT) { - altera_sdcard_disk_insert(sc); - sc->as_state = ALTERA_SDCARD_STATE_IDLE; - } + altera_sdcard_disk_insert(sc); + sc->as_state = ALTERA_SDCARD_STATE_IDLE; } static void @@ -198,6 +213,9 @@ /* * Handle safe card removal. + * + * XXXRW: In the future, we may want to handle the run-time setting of + * ALTERA_SDCARD_FLAG_BADCARD. */ if (!(altera_sdcard_read_asr(sc) & ALTERA_SDCARD_ASR_CARDPRESENT)) { altera_sdcard_disk_remove(sc); @@ -217,6 +235,9 @@ /* * Check for unexpected card removal during an I/O. + * + * XXXRW: In the future, we may want to handle the run-time setting of + * ALTERA_SDCARD_FLAG_BADCARD. */ if (!(asr & ALTERA_SDCARD_ASR_CARDPRESENT)) { altera_sdcard_disk_remove(sc); ==== //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard.h#4 (text+ko) ==== @@ -31,6 +31,11 @@ #ifndef _DEV_ALTERA_SDCARD_H_ #define _DEV_ALTERA_SDCARD_H_ +#define ALTERA_SDCARD_CSD_SIZE 16 +struct altera_sdcard_csd { + uint8_t csd_data[ALTERA_SDCARD_CSD_SIZE]; +}; + struct altera_sdcard_softc { device_t as_dev; int as_unit; @@ -45,6 +50,12 @@ struct bio *as_currentbio; struct taskqueue *as_taskqueue; struct timeout_task as_task; + + /* + * Infrequently changing fields cached from the SD Card IP Core. + */ + struct altera_sdcard_csd as_csd; + uint64_t as_mediasize; }; #define ALTERA_SDCARD_LOCK(sc) mtx_lock(&(sc)->as_lock) @@ -81,6 +92,7 @@ * Driver status flags. */ #define ALTERA_SDCARD_FLAG_DETACHREQ 0x00000001 /* Detach requested. */ +#define ALTERA_SDCARD_FLAG_BADCARD 0x00000002 /* Unsupported card. */ /* * Functions for performing low-level register and memory I/O to/from the SD @@ -88,7 +100,7 @@ * hardware interface. */ uint16_t altera_sdcard_read_asr(struct altera_sdcard_softc *sc); -uint64_t altera_sdcard_read_csd_size(struct altera_sdcard_softc *sc); +void altera_sdcard_read_csd(struct altera_sdcard_softc *sc); void altera_sdcard_io_complete(struct altera_sdcard_softc *sc, uint16_t asr); @@ -96,6 +108,40 @@ struct bio *bp); /* + * Constants for interpreting the SD Card Card Specific Data (CSD) register. + */ +#define ALTERA_SDCARD_CSD_STRUCTURE_BYTE 15 +#define ALTERA_SDCARD_CSD_STRUCTURE_MASK 0xc0 /* 2 bits */ +#define ALTERA_SDCARD_CSD_STRUCTURE_RSHIFT 6 + +#define ALTERA_SDCARD_CSD_READ_BL_LEN_BYTE 10 +#define ALTERA_SDCARD_CSD_READ_BL_LEN_MASK 0x0f /* 4 bits */ + +/* + * C_SIZE is a 12-bit field helpfully split over three differe bytes of CSD + * data. Software ease of use was not a design consideration. + */ +#define ALTERA_SDCARD_CSD_C_SIZE_BYTE0 7 +#define ALTERA_SDCARD_CSD_C_SIZE_MASK0 0xc /* top 2 bits */ +#define ALTERA_SDCARD_CSD_C_SIZE_RSHIFT0 6 + +#define ALTERA_SDCARD_CSD_C_SIZE_BYTE1 8 +#define ALTERA_SDCARD_CSD_C_SIZE_MASK1 0xff /* 8 bits */ +#define ALTERA_SDCARD_CSD_C_SIZE_LSHIFT1 2 + +#define ALTERA_SDCARD_CSD_C_SIZE_BYTE2 9 +#define ALTERA_SDCARD_CSD_C_SIZE_MASK2 0x03 /* bottom 2 bits */ +#define ALTERA_SDCARD_CSD_C_SIZE_LSHIFT2 10 + +#define ALTERA_SDCARD_CSD_C_SIZE_MULT_BYTE0 5 +#define ALTERA_SDCARD_CSD_C_SIZE_MULT_MASK0 0x80 /* top 1 bit */ +#define ALTERA_SDCARD_CSD_C_SIZE_MULT_RSHIFT0 7 + +#define ALTERA_SDCARD_CSD_C_SIZE_MULT_BYTE1 6 +#define ALTERA_SDCARD_CSD_C_SIZE_MULT_MASK1 0x03 /* bottom 2 bits */ +#define ALTERA_SDCARD_CSD_C_SIZE_MULT_LSHIFT1 1 + +/* * I/O register/buffer offsets, from Table 4.1.1 in the Altera University * Program SD Card IP Core specification. */ ==== //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard_disk.c#2 (text+ko) ==== @@ -131,7 +131,7 @@ disk->d_dump = altera_sdcard_disk_dump; disk->d_ioctl = altera_sdcard_disk_ioctl; disk->d_sectorsize = ALTERA_SDCARD_SECTORSIZE; - disk->d_mediasize = altera_sdcard_read_csd_size(sc); + disk->d_mediasize = sc->as_mediasize; disk->d_maxsize = ALTERA_SDCARD_SECTORSIZE; sc->as_disk = disk; disk_create(disk, DISK_VERSION); ==== //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard_io.c#3 (text+ko) ==== @@ -55,6 +55,11 @@ /* * Low-level I/O routines for the Altera SD Card University IP Core driver. + * + * XXXRW: Throughout, it is assumed that the IP Core handles multibyte + * registers as little endian, as is the case for other Altera IP cores. + * However, the specification makes no reference to endianness, so this + * assumption might not always be correct. */ uint16_t altera_sdcard_read_asr(struct altera_sdcard_softc *sc) @@ -63,14 +68,96 @@ return (le16toh(bus_read_2(sc->as_res, ALTERA_SDCARD_OFF_ASR))); } -uint64_t -altera_sdcard_read_csd_size(struct altera_sdcard_softc *sc) +void +altera_sdcard_read_csd(struct altera_sdcard_softc *sc) { + uint64_t c_size, c_size_mult, read_bl_len; + uint8_t csd_structure, byte0, byte1, byte2; + + ALTERA_SDCARD_LOCK_ASSERT(sc); - panic("%s: not yet", __func__); + /* + * XXXRW: Assume for now that when the SD Card IP Core negotiates + * voltage/speed/etc, it must use the CSD register, and therefore + * populates the SD Card IP Core's cache of the register value. This + * means that we can read it without issuing further SD Card commands. + * If this assumption proves false, we will (a) get back garbage and + * (b) need to add additional states in the driver state machine in + * order to query card properties before I/O can start. + * + * XXXRW: Treating this as an array of bytes, so no byte swapping -- + * is that a safe assumption? + */ + bus_read_region_1(sc->as_res, ALTERA_SDCARD_OFF_CSD, + sc->as_csd.csd_data, sizeof(sc->as_csd)); + + /* + * Interpret the loaded CSD, extracting certain fields and copying + * them into the softc for easy software access. + * + * Currently, we support only CSD Version 1.0. If we detect a newer + * version, suppress card detection. + */ + csd_structure = sc->as_csd.csd_data[ALTERA_SDCARD_CSD_STRUCTURE_BYTE]; + csd_structure &= ALTERA_SDCARD_CSD_STRUCTURE_MASK; + csd_structure >>= ALTERA_SDCARD_CSD_STRUCTURE_RSHIFT; + if (csd_structure != 0) { + sc->as_flags |= ALTERA_SDCARD_FLAG_BADCARD; + return; + } + + /*- + * Compute card capacity per SD Card interface description as follows: + * + * Memory capacity = BLOCKNR * BLOCK_LEN + * + * Where: + * + * BLOCKNR = (C_SIZE + 1) * MULT + * MULT = C_SIZE_MULT << 8 + * BLOCK_LEN = READ_BL_LEN << 12 + */ + read_bl_len = sc->as_csd.csd_data[ALTERA_SDCARD_CSD_READ_BL_LEN_BYTE]; + read_bl_len &= ALTERA_SDCARD_CSD_READ_BL_LEN_MASK; + + byte0 = sc->as_csd.csd_data[ALTERA_SDCARD_CSD_C_SIZE_MULT_BYTE0]; + byte0 &= ALTERA_SDCARD_CSD_C_SIZE_MULT_MASK0; + byte1 = sc->as_csd.csd_data[ALTERA_SDCARD_CSD_C_SIZE_MULT_BYTE1]; + byte1 &= ALTERA_SDCARD_CSD_C_SIZE_MULT_MASK1; + c_size_mult = (byte0 >> ALTERA_SDCARD_CSD_C_SIZE_MULT_RSHIFT0) | + (byte0 << ALTERA_SDCARD_CSD_C_SIZE_MULT_LSHIFT1); + + byte0 = sc->as_csd.csd_data[ALTERA_SDCARD_CSD_C_SIZE_BYTE0]; + byte0 &= ALTERA_SDCARD_CSD_C_SIZE_MASK0; + byte1 = sc->as_csd.csd_data[ALTERA_SDCARD_CSD_C_SIZE_BYTE1]; + byte2 = sc->as_csd.csd_data[ALTERA_SDCARD_CSD_C_SIZE_BYTE2]; + byte2 &= ALTERA_SDCARD_CSD_C_SIZE_MASK2; + c_size = (byte0 >> ALTERA_SDCARD_CSD_C_SIZE_RSHIFT0) | + (byte1 << ALTERA_SDCARD_CSD_C_SIZE_LSHIFT1) | + (byte2 << ALTERA_SDCARD_CSD_C_SIZE_LSHIFT2); + + byte0 = sc->as_csd.csd_data[ALTERA_SDCARD_CSD_C_SIZE_MULT_BYTE0]; + byte0 &= ALTERA_SDCARD_CSD_C_SIZE_MULT_MASK0; + byte1 = sc->as_csd.csd_data[ALTERA_SDCARD_CSD_C_SIZE_MULT_BYTE1]; + byte1 &= ALTERA_SDCARD_CSD_C_SIZE_MULT_MASK1; + c_size_mult = (byte0 >> ALTERA_SDCARD_CSD_C_SIZE_MULT_RSHIFT0) | + (byte1 << ALTERA_SDCARD_CSD_C_SIZE_MULT_LSHIFT1); + + /* + * If we're just getting back zero's, mark the card as bad. + */ + sc->as_mediasize = (c_size + 1) * (c_size_mult << 8) * + (read_bl_len << 12); + if (sc->as_mediasize == 0) + sc->as_flags |= ALTERA_SDCARD_FLAG_BADCARD; } #if 0 +/* + * XXXRW: The Altera IP Core specification indicates that RR1 is a 16-bit + * register, but all bits it identifies are >16 bit. Most likely, RR1 is a + * 32-bit register? + */ uint16_t altera_sdcard_read_rr1(struct altera_sdcard_softc *sc) { From owner-p4-projects@FreeBSD.ORG Sun Apr 1 15:29:55 2012 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 55BE61065673; Sun, 1 Apr 2012 15:29:55 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 180A71065670 for ; Sun, 1 Apr 2012 15:29:55 +0000 (UTC) (envelope-from rene@FreeBSD.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id EDC7E8FC19 for ; Sun, 1 Apr 2012 15:29:54 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id q31FTs1j045428 for ; Sun, 1 Apr 2012 15:29:54 GMT (envelope-from rene@FreeBSD.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id q31FTsMP045425 for perforce@freebsd.org; Sun, 1 Apr 2012 15:29:54 GMT (envelope-from rene@FreeBSD.org) Date: Sun, 1 Apr 2012 15:29:54 GMT Message-Id: <201204011529.q31FTsMP045425@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to rene@FreeBSD.org using -f From: Rene Ladan To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 208919 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 Apr 2012 15:29:55 -0000 http://p4web.freebsd.org/@@208919?ac=10 Change 208919 by rene@rene_acer on 2012/04/01 15:29:46 MFen handbook/config 1.251 -> 1.254 Affected files ... .. //depot/projects/docproj_nl/nl_NL.ISO8859-1/books/handbook/config/chapter.sgml#39 edit Differences ... ==== //depot/projects/docproj_nl/nl_NL.ISO8859-1/books/handbook/config/chapter.sgml#39 (text+ko) ==== @@ -4,7 +4,7 @@ $FreeBSD: doc/nl_NL.ISO8859-1/books/handbook/config/chapter.sgml,v 1.32 2012/02/19 15:08:48 rene Exp $ %SOURCE% en_US.ISO8859-1/books/handbook/config/chapter.sgml - %SRCID% 1.251 + %SRCID% 1.254 --> @@ -526,14 +526,14 @@ gezette tijden. cron gebruikt twee verschillende soorten - instellingenbestanden: de systeemcrontab en gebruikerscrontabs. - Het enige verschil tussen deze twee formaten is het zesde veld. - In de systeemcrontab is dit de gebruikersnaam die het commando - uitvoert. Hierdoor kunnen met de systeemcrontab commando's als - iedere gebruiker uitgevoerd worden. In een gebruikerscrontab is - het zesde veld het uit te voeren commando en alle commando's - worden uitgevoerd als de gebruiker die de crontab heeft - aangemaakt. Dit is een belangrijke veiligheidsmaatregel. + instellingenbestanden: de systeemcrontab en gebruikerscrontabs. Deze + formaten verschillen alleen in het zesde en verdere velden. In de + systeemcrontab zal cron het commando draaien als de + gebruiker die in het zesde veld is opgegeven. In een gebruikerscrontab + draaien alle commando's onder de gebruiker die de crontab heeft + aangemaakt, dus is het zesde veld het laatste veld; dit is een belangrijk + beveiligingsaspect. Het laatste veld is altijd het commando dat gedraaid + wordt. Gebruikerscrontabs geven individuele gebruikers de @@ -543,11 +543,11 @@ uitgevoerd met de rechten van de eigenaar. root kan ook een gebruikerscrontab - aanleggen. Dit is niet dezelfde als - /etc/crontab (de systeemcrontab). Omdat er - al een systeemcrontab is, is het doorgaans niet nodig om een - gebruikerscrontab voor root te - maken. + aanleggen net als elke andere gebruiker. Dit is niet dezelfde als + /etc/crontab (de systeemcrontab). Omdat de + systeemcrontab in de praktijk de commando's als root uitvoert, is het + doorgaans niet nodig om een gebruikerscrontab voor + root te maken. /etc/crontab (de systeemcrontab) ziet er @@ -607,9 +607,7 @@ wdag geeft de dag van de week aan. Het veld wie is bijzonder en bestaat alleen in /etc/crontab. Het geeft aan als welke - gebruiker het commando uitgevoerd moet worden. Een gebruiker - die zijn eigen crontab installeert, - heeft deze optie niet. Het veld commando + gebruiker het commando uitgevoerd moet worden. Het laatste veld bevat het uit te voeren commando. @@ -644,10 +642,10 @@ De onderstaande procedure moet niet gebruikt worden om de - systeemcrontab te wijzigen of te installeren. Er kan een - gewone editor gebruikt worden. cron - ziet dat het bestand veranderd is en begint direct met het - gebruiken van de nieuwe versie. /etc/crontab te wijzigen of te + installeren. Er kan een gewone editor gebruikt worden. + cron ziet dat het bestand veranderd is en begint + direct met het gebruiken van de nieuwe versie. Deze FAQ vraag geeft verdere uitleg. @@ -2610,15 +2608,37 @@ handboek. - Wisselbestand (partitie) op een nieuwe harde schijf + Swap op een nieuwe of bestaande harde schijf + + Een nieuwe harde schijf voor swap toevoegen geeft betere prestaties + dan een partitie aan een bestaande schijf toevoegen. Het aanmaken van + partities en harde schijven wordt uitgelegd in . + bespreekt de overwegingen van partitie-indelingen en de grootte van + swap-partities. + + Gebruik &man.swapon.8; om een swap-partitie aan het systeem toe te + voegen, bijvoorbeeld: + + &prompt.root; swapon /dev/ada1s1p2 + + + Het is mogelijk om elke partitie te gebruiken die momenteel niet + aangekoppeld is, zelfs als deze al gegevens bevat. Het gebruik van + &man.swapon.8; op een partitie die gegevens bevat zal deze gegevens + overschrijven en vernietigen. Zorg ervoor dat de partitie die als + swap toegevoegd wordt echt de bedoelde partitie is voordat + &man.swapon.8; gebruikt wordt. + + + Voeg een regel toe aan /etc/fstab voor de + partitie om deze swap-partitie automatisch toe te voegen tijdens het + opstarten: + + /dev/ada1s1p1 none swap sw 0 0 - Dit is natuurlijk de beste manier om de wisselbestandsruimte - te vergroten en een goed excuus om een extra harde schijf toe te - voegen. Die komt immers altijd wel van pas. In dat geval kan - het beste de discussie over wisselbestandruimte in nog eens herlezen worden om - wat suggesties op te doen over hoe wisselbestandpartitie(s) het - beste ingedeeld kunnen worden. + Raadpleeg &man.fstab.5; voor een uitleg over de regels in + /etc/fstab. From owner-p4-projects@FreeBSD.ORG Tue Apr 3 19:13:15 2012 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 5E8591065674; Tue, 3 Apr 2012 19:13:15 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 20EF3106566C for ; Tue, 3 Apr 2012 19:13:15 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id 0935F8FC18 for ; Tue, 3 Apr 2012 19:13:15 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id q33JDEjP097396 for ; Tue, 3 Apr 2012 19:13:14 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id q33JDEZW097393 for perforce@freebsd.org; Tue, 3 Apr 2012 19:13:14 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Tue, 3 Apr 2012 19:13:14 GMT Message-Id: <201204031913.q33JDEZW097393@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 209029 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Apr 2012 19:13:15 -0000 http://p4web.freebsd.org/@@209029?ac=10 Change 209029 by rwatson@rwatson_svr_ctsrd_mipsbuild on 2012/04/03 19:12:10 Remove a KASSERT documenting a non-invariant of bp->bio_resid in the Altera SD Card IP core. An earlier iteration depended on this invariant but the current one doesn't, so functional change other than fewer assertion failures. Affected files ... .. //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard_io.c#4 edit Differences ... ==== //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard_io.c#4 (text+ko) ==== @@ -217,8 +217,6 @@ * SD Card IP Core sector size. Catch any attempts to not follow the * rules. */ - KASSERT(bp->bio_bcount == bp->bio_resid, - ("%s: bcount != resid", __func__)); KASSERT(bp->bio_bcount == ALTERA_SDCARD_SECTORSIZE, ("%s: I/O size not %d", __func__, ALTERA_SDCARD_SECTORSIZE)); From owner-p4-projects@FreeBSD.ORG Wed Apr 4 10:14:22 2012 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 06DA2106568C; Wed, 4 Apr 2012 10:14:22 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id B066E1065675 for ; Wed, 4 Apr 2012 10:14:21 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id 971A78FC0A for ; Wed, 4 Apr 2012 10:14:21 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id q34AELTS085618 for ; Wed, 4 Apr 2012 10:14:21 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id q34AELok085615 for perforce@freebsd.org; Wed, 4 Apr 2012 10:14:21 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Wed, 4 Apr 2012 10:14:21 GMT Message-Id: <201204041014.q34AELok085615@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 209055 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Apr 2012 10:14:22 -0000 http://p4web.freebsd.org/@@209055?ac=10 Change 209055 by rwatson@rwatson_svr_ctsrd_mipsbuild on 2012/04/04 10:13:58 Improve convergence of Altera SD Card IP Core with hardware as it becomes more accessible, as well as fixing a number of driver bugs and issues: - Properly initialise softc condition variable; destroy lock and condition variable on device detach (detach path unexercised as yet). - Have the driver name controllers "altera_sdcardc%d" so that they don't collide with disk instances, which are "altera_sdcard%d". It would be interesting to try this with multiple controllers to make sure this works as desired. - Introduce a new state, ALTERA_SDCARD_STATE_BADCARD to replace the softc flag ALTERA_SDCARD_FLAG_BADCARD. We now have a number of reasons we might transition a controller into the bad card state, not least unsupported CSD versions or unlikely disk sizes (e.g., all zeroes). This eliminates a number of XXX comments elsewhere in the driver about how to handle bad cards. - Extract and cache the CSD structure version in the softc. Restructure CSD processing code so that it can (a) return a failure and (b) in principle (although not yet in practice) handle multiple CSD versions more smoothly. Announce card insert, as well as card probe failures, more vocally. - Fix logic bugs in the handling of CSD fields -- I misread the SD Card physical layer specification for how certain fields are composed to calculate the actual disk size. Affected files ... .. //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard.c#3 edit .. //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard.h#5 edit .. //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard_disk.c#3 edit .. //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard_io.c#5 edit .. //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard_nexus.c#2 edit Differences ... ==== //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard.c#3 (text+ko) ==== @@ -76,14 +76,15 @@ { ALTERA_SDCARD_LOCK_INIT(sc); + ALTERA_SDCARD_CONDVAR_INIT(sc); sc->as_disk = NULL; bioq_init(&sc->as_bioq); sc->as_currentbio = NULL; sc->as_state = ALTERA_SDCARD_STATE_NOCARD; - sc->as_taskqueue = taskqueue_create("altera_sdcard taskq", M_WAITOK, + sc->as_taskqueue = taskqueue_create("altera_sdcardc taskq", M_WAITOK, taskqueue_thread_enqueue, &sc->as_taskqueue); taskqueue_start_threads(&sc->as_taskqueue, 1, PI_DISK, - "altera_sdcard%d taskqueue", sc->as_unit); + "altera_sdcardc%d taskqueue", sc->as_unit); TIMEOUT_TASK_INIT(sc->as_taskqueue, &sc->as_task, 0, altera_sdcard_task, sc); @@ -135,6 +136,8 @@ */ taskqueue_free(sc->as_taskqueue); sc->as_taskqueue = NULL; + ALTERA_SDCARD_CONDVAR_DESTROY(sc); + ALTERA_SDCARD_LOCK_DESTROY(sc); } /* @@ -180,15 +183,19 @@ return; /* - * Read the CSD -- it may contain values that force the setting of - * ALTERA_SDCARD_FLAG_BADCARD, in which case we suppress detection of - * the card. For example, if there is an unrecognised CSD structure - * version, or if the IP Core doesn't support the returned sector - * size. + * Read the CSD -- it may contain values that the driver can't handle, + * either because of an unsupported version/feature, or because the + * card is misbehaving. This triggers a transition to + * ALTERA_SDCARD_STATE_BADCARD. We rely on the CSD read to print a + * banner about how the card is problematic, since it has more + * information. The bad card state allows us to print that banner + * once rather than each time we notice the card is there, and still + * bad. */ - altera_sdcard_read_csd(sc); - if (sc->as_flags & ALTERA_SDCARD_FLAG_BADCARD) + if (altera_sdcard_read_csd(sc) != 0) { + sc->as_state = ALTERA_SDCARD_STATE_BADCARD; return; + } /* * Process card insertion and upgrade to the IDLE state. @@ -198,6 +205,28 @@ } static void +altera_sdcard_task_badcard(struct altera_sdcard_softc *sc) +{ + + ALTERA_SDCARD_LOCK_ASSERT(sc); + + /* + * Handle device driver detach. + */ + if (sc->as_flags & ALTERA_SDCARD_FLAG_DETACHREQ) { + sc->as_state = ALTERA_SDCARD_STATE_DETACHED; + return; + } + + /* + * Handle safe card removal -- no teardown is required, just a state + * transition. + */ + if (!(altera_sdcard_read_asr(sc) & ALTERA_SDCARD_ASR_CARDPRESENT)) + sc->as_state = ALTERA_SDCARD_STATE_NOCARD; +} + +static void altera_sdcard_task_idle(struct altera_sdcard_softc *sc) { @@ -213,9 +242,6 @@ /* * Handle safe card removal. - * - * XXXRW: In the future, we may want to handle the run-time setting of - * ALTERA_SDCARD_FLAG_BADCARD. */ if (!(altera_sdcard_read_asr(sc) & ALTERA_SDCARD_ASR_CARDPRESENT)) { altera_sdcard_disk_remove(sc); @@ -235,9 +261,6 @@ /* * Check for unexpected card removal during an I/O. - * - * XXXRW: In the future, we may want to handle the run-time setting of - * ALTERA_SDCARD_FLAG_BADCARD. */ if (!(asr & ALTERA_SDCARD_ASR_CARDPRESENT)) { altera_sdcard_disk_remove(sc); @@ -285,10 +308,11 @@ /* * Reschedule based on new state. Or not, if detaching the device - * driver. + * driver. Treat a bad card as though it were no card at all. */ switch (sc->as_state) { case ALTERA_SDCARD_STATE_NOCARD: + case ALTERA_SDCARD_STATE_BADCARD: interval = ALTERA_SDCARD_TIMEOUT_NOCARD; break; @@ -328,6 +352,10 @@ altera_sdcard_task_nocard(sc); break; + case ALTERA_SDCARD_STATE_BADCARD: + altera_sdcard_task_badcard(sc); + break; + case ALTERA_SDCARD_STATE_IDLE: altera_sdcard_task_idle(sc); break; ==== //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard.h#5 (text+ko) ==== @@ -55,6 +55,7 @@ * Infrequently changing fields cached from the SD Card IP Core. */ struct altera_sdcard_csd as_csd; + uint8_t as_csd_structure; /* CSD version. */ uint64_t as_mediasize; }; @@ -66,7 +67,8 @@ #define ALTERA_SDCARD_UNLOCK(sc) mtx_unlock(&(sc)->as_lock) #define ALTERA_SDCARD_CONDVAR_DESTROY(sc) cv_destroy(&(sc)->as_condvar) -#define ALTERA_SDCARD_CONDVAR_INIT(sc) cv_init(&(sc)->as_condvar) +#define ALTERA_SDCARD_CONDVAR_INIT(sc) cv_init(&(sc)->as_condvar, \ + "altera_sdcard_detach_wait") #define ALTERA_SDCARD_CONDVAR_SIGNAL(dc) cv_signal(&(sc)->as_condvar) #define ALTERA_SDCARD_CONDVAR_WAIT(sc) cv_wait(&(sc)->as_condvar, \ &(sc)->as_lock) @@ -75,9 +77,10 @@ * States an instance can be in at any given moment. */ #define ALTERA_SDCARD_STATE_NOCARD 1 /* No card inserted. */ -#define ALTERA_SDCARD_STATE_IDLE 2 /* Card present but idle. */ -#define ALTERA_SDCARD_STATE_IO 3 /* Card in I/O currently. */ -#define ALTERA_SDCARD_STATE_DETACHED 4 /* Driver is detaching. */ +#define ALTERA_SDCARD_STATE_BADCARD 2 /* Card bad/not supported. */ +#define ALTERA_SDCARD_STATE_IDLE 3 /* Card present but idle. */ +#define ALTERA_SDCARD_STATE_IO 4 /* Card in I/O currently. */ +#define ALTERA_SDCARD_STATE_DETACHED 5 /* Driver is detaching. */ /* * Different timeout intervals based on state. When just looking for a card @@ -92,7 +95,6 @@ * Driver status flags. */ #define ALTERA_SDCARD_FLAG_DETACHREQ 0x00000001 /* Detach requested. */ -#define ALTERA_SDCARD_FLAG_BADCARD 0x00000002 /* Unsupported card. */ /* * Functions for performing low-level register and memory I/O to/from the SD @@ -100,7 +102,7 @@ * hardware interface. */ uint16_t altera_sdcard_read_asr(struct altera_sdcard_softc *sc); -void altera_sdcard_read_csd(struct altera_sdcard_softc *sc); +int altera_sdcard_read_csd(struct altera_sdcard_softc *sc); void altera_sdcard_io_complete(struct altera_sdcard_softc *sc, uint16_t asr); ==== //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard_disk.c#3 (text+ko) ==== @@ -86,6 +86,12 @@ biofinish(bp, NULL, ENXIO); break; + case ALTERA_SDCARD_STATE_BADCARD: + device_printf(sc->as_dev, "%s: unexpected I/O on BADCARD", + __func__); + biofinish(bp, NULL, ENXIO); + break; + case ALTERA_SDCARD_STATE_DETACHED: device_printf(sc->as_dev, "%s: unexpected I/O on DETACHED", __func__); @@ -110,6 +116,8 @@ altera_sdcard_disk_insert(struct altera_sdcard_softc *sc) { struct disk *disk; + uint64_t size; + char scale; ALTERA_SDCARD_LOCK_ASSERT(sc); @@ -135,6 +143,24 @@ disk->d_maxsize = ALTERA_SDCARD_SECTORSIZE; sc->as_disk = disk; disk_create(disk, DISK_VERSION); + + /* + * Print a pretty-ish card insertion string. We could stand to + * decorate this further, e.g., with card vendor information. + */ + size = sc->as_mediasize; + if (size > 1024*1024*1024) { + scale = 'G'; + size /= 1024*1024*1024; + } else if (size > 1024*1024) { + scale = 'M'; + size /= 1024*1024; + } else { + scale = 'K'; + size /= 1024; + } + device_printf(sc->as_dev, "%ju%c SD Card inserted\n", (uintmax_t)size, + scale); } void ==== //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard_io.c#5 (text+ko) ==== @@ -68,44 +68,14 @@ return (le16toh(bus_read_2(sc->as_res, ALTERA_SDCARD_OFF_ASR))); } -void -altera_sdcard_read_csd(struct altera_sdcard_softc *sc) +static int +altera_sdcard_process_csd0(struct altera_sdcard_softc *sc) { uint64_t c_size, c_size_mult, read_bl_len; - uint8_t csd_structure, byte0, byte1, byte2; + uint8_t byte0, byte1, byte2; ALTERA_SDCARD_LOCK_ASSERT(sc); - /* - * XXXRW: Assume for now that when the SD Card IP Core negotiates - * voltage/speed/etc, it must use the CSD register, and therefore - * populates the SD Card IP Core's cache of the register value. This - * means that we can read it without issuing further SD Card commands. - * If this assumption proves false, we will (a) get back garbage and - * (b) need to add additional states in the driver state machine in - * order to query card properties before I/O can start. - * - * XXXRW: Treating this as an array of bytes, so no byte swapping -- - * is that a safe assumption? - */ - bus_read_region_1(sc->as_res, ALTERA_SDCARD_OFF_CSD, - sc->as_csd.csd_data, sizeof(sc->as_csd)); - - /* - * Interpret the loaded CSD, extracting certain fields and copying - * them into the softc for easy software access. - * - * Currently, we support only CSD Version 1.0. If we detect a newer - * version, suppress card detection. - */ - csd_structure = sc->as_csd.csd_data[ALTERA_SDCARD_CSD_STRUCTURE_BYTE]; - csd_structure &= ALTERA_SDCARD_CSD_STRUCTURE_MASK; - csd_structure >>= ALTERA_SDCARD_CSD_STRUCTURE_RSHIFT; - if (csd_structure != 0) { - sc->as_flags |= ALTERA_SDCARD_FLAG_BADCARD; - return; - } - /*- * Compute card capacity per SD Card interface description as follows: * @@ -114,8 +84,8 @@ * Where: * * BLOCKNR = (C_SIZE + 1) * MULT - * MULT = C_SIZE_MULT << 8 - * BLOCK_LEN = READ_BL_LEN << 12 + * MULT = 2^(C_SIZE_MULT+2) + * BLOCK_LEN = 2^READ_BL_LEN */ read_bl_len = sc->as_csd.csd_data[ALTERA_SDCARD_CSD_READ_BL_LEN_BYTE]; read_bl_len &= ALTERA_SDCARD_CSD_READ_BL_LEN_MASK; @@ -144,12 +114,73 @@ (byte1 << ALTERA_SDCARD_CSD_C_SIZE_MULT_LSHIFT1); /* - * If we're just getting back zero's, mark the card as bad. + * If we're just getting back zero's, mark the card as bad, even + * though it could just mean a Very Small Disk Indeed. + */ + if (c_size == 0 && c_size_mult == 0 && read_bl_len == 0) { + device_printf(sc->as_dev, "Ignored zero-size card\n"); + return (ENXIO); + } + sc->as_mediasize = (c_size + 1) * (1 << (c_size_mult + 2)) * + (1 << read_bl_len); + return (0); +} + +int +altera_sdcard_read_csd(struct altera_sdcard_softc *sc) +{ + uint8_t csd_structure; + int error; + + ALTERA_SDCARD_LOCK_ASSERT(sc); + + /* + * XXXRW: Assume for now that when the SD Card IP Core negotiates + * voltage/speed/etc, it must use the CSD register, and therefore + * populates the SD Card IP Core's cache of the register value. This + * means that we can read it without issuing further SD Card commands. + * If this assumption proves false, we will (a) get back garbage and + * (b) need to add additional states in the driver state machine in + * order to query card properties before I/O can start. + * + * XXXRW: Treating this as an array of bytes, so no byte swapping -- + * is that a safe assumption? + */ + bus_read_region_1(sc->as_res, ALTERA_SDCARD_OFF_CSD, + sc->as_csd.csd_data, sizeof(sc->as_csd)); + + /* + * Interpret the loaded CSD, extracting certain fields and copying + * them into the softc for easy software access. + * + * Currently, we support only CSD Version 1.0. If we detect a newer + * version, suppress card detection. + */ + csd_structure = sc->as_csd.csd_data[ALTERA_SDCARD_CSD_STRUCTURE_BYTE]; + csd_structure &= ALTERA_SDCARD_CSD_STRUCTURE_MASK; + csd_structure >>= ALTERA_SDCARD_CSD_STRUCTURE_RSHIFT; + sc->as_csd_structure = csd_structure; + + /* + * Interpret the CSD field based on its version. Extract fields, + * especially mediasize. + * + * XXXRW: Desirable to support further CSD versions here. */ - sc->as_mediasize = (c_size + 1) * (c_size_mult << 8) * - (read_bl_len << 12); - if (sc->as_mediasize == 0) - sc->as_flags |= ALTERA_SDCARD_FLAG_BADCARD; + switch (sc->as_csd_structure) { + case 0: + error = altera_sdcard_process_csd0(sc); + if (error) + return (error); + break; + + default: + device_printf(sc->as_dev, + "Ignored disk with unsupported CSD structure (%d)\n", + sc->as_csd_structure); + return (ENXIO); + } + return (0); } #if 0 ==== //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard_nexus.c#2 (text+ko) ==== @@ -105,7 +105,7 @@ }; static driver_t altera_sdcard_nexus_driver = { - "altera_sdcard", + "altera_sdcardc", altera_sdcard_nexus_methods, sizeof(struct altera_sdcard_softc), }; From owner-p4-projects@FreeBSD.ORG Wed Apr 4 14:22:18 2012 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 183451065674; Wed, 4 Apr 2012 14:22:18 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id C43E8106566B for ; Wed, 4 Apr 2012 14:22:17 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id AC2D48FC08 for ; Wed, 4 Apr 2012 14:22:17 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id q34EMH0x039785 for ; Wed, 4 Apr 2012 14:22:17 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id q34EMH8m039782 for perforce@freebsd.org; Wed, 4 Apr 2012 14:22:17 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Wed, 4 Apr 2012 14:22:17 GMT Message-Id: <201204041422.q34EMH8m039782@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 209065 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Apr 2012 14:22:18 -0000 http://p4web.freebsd.org/@@209065?ac=10 Change 209065 by rwatson@rwatson_svr_ctsrd_mipsbuild on 2012/04/04 14:21:52 Catch up BERI.hints from the Altera SD Card IP Core controller device name being changed to avoid collision with disk devices representing inserted cards. Affected files ... .. //depot/projects/ctsrd/beribsd/src/sys/mips/conf/BERI.hints#3 edit Differences ... ==== //depot/projects/ctsrd/beribsd/src/sys/mips/conf/BERI.hints#3 (text+ko) ==== @@ -1,5 +1,5 @@ # $FreeBSD$ -hint.altera_sdcard.0.at="nexus0" -hint.altera_sdcard.0.maddr=0x7f008000 -hint.altera_sdcard.0.msize=0x400 +hint.altera_sdcardc.0.at="nexus0" +hint.altera_sdcardc.0.maddr=0x7f008000 +hint.altera_sdcardc.0.msize=0x400 From owner-p4-projects@FreeBSD.ORG Wed Apr 4 14:58:27 2012 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id EC9211065673; Wed, 4 Apr 2012 14:58:26 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AF2421065670 for ; Wed, 4 Apr 2012 14:58:26 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id 96B838FC0C for ; Wed, 4 Apr 2012 14:58:26 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id q34EwQQ4045946 for ; Wed, 4 Apr 2012 14:58:26 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id q34EwQxH045943 for perforce@freebsd.org; Wed, 4 Apr 2012 14:58:26 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Wed, 4 Apr 2012 14:58:26 GMT Message-Id: <201204041458.q34EwQxH045943@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 209069 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Apr 2012 14:58:27 -0000 http://p4web.freebsd.org/@@209069?ac=10 Change 209069 by rwatson@rwatson_svr_ctsrd_mipsbuild on 2012/04/04 14:57:28 Fix two inverted assertions regarding block I/O sizes in the Altera SD Card IP Core driver. Fix an incorrect register offset that led commands to be written to the command argument register, causing block load/store operations to fail to occur. With these changes, it is now possibly to load blocks from FreeBSD on a CHERI MIPS processor using a 2G SD Card in the Terasic DE-4 board. I've not yet tried mounting a file system. Affected files ... .. //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard_io.c#6 edit Differences ... ==== //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard_io.c#6 (text+ko) ==== @@ -208,7 +208,7 @@ altera_sdcard_write_cmd(struct altera_sdcard_softc *sc, uint16_t cmd) { - bus_write_2(sc->as_res, ALTERA_SDCARD_OFF_CMD_ARG, htole16(cmd)); + bus_write_2(sc->as_res, ALTERA_SDCARD_OFF_CMD, htole16(cmd)); } static void @@ -216,7 +216,7 @@ size_t len) { - KASSERT(len > ALTERA_SDCARD_SECTORSIZE, + KASSERT(len <= ALTERA_SDCARD_SECTORSIZE, ("%s: invalid length %ju", __func__, len)); bus_read_region_1(sc->as_res, ALTERA_SDCARD_OFF_RXTX_BUFFER, data, @@ -228,7 +228,7 @@ size_t len) { - KASSERT(len > ALTERA_SDCARD_SECTORSIZE, + KASSERT(len <= ALTERA_SDCARD_SECTORSIZE, ("%s: invalid length %ju", __func__, len)); bus_write_region_1(sc->as_res, ALTERA_SDCARD_OFF_RXTX_BUFFER, data, From owner-p4-projects@FreeBSD.ORG Wed Apr 4 17:13:53 2012 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 040A61065670; Wed, 4 Apr 2012 17:13:53 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BACCA106564A for ; Wed, 4 Apr 2012 17:13:52 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id 8907B8FC0C for ; Wed, 4 Apr 2012 17:13:52 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id q34HDqni077697 for ; Wed, 4 Apr 2012 17:13:52 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id q34HDqOa077694 for perforce@freebsd.org; Wed, 4 Apr 2012 17:13:52 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Wed, 4 Apr 2012 17:13:52 GMT Message-Id: <201204041713.q34HDqOa077694@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 209073 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Apr 2012 17:13:53 -0000 http://p4web.freebsd.org/@@209073?ac=10 Change 209073 by rwatson@rwatson_svr_ctsrd_mipsbuild on 2012/04/04 17:13:10 Fix two bugs in the Altera SD Card IP Core: 1. More serious -- don't perform sleeping memory allocations while holding mutexes. Discovered by turning on WITNESS. 2. Less serious -- Simply print SD Card size in MB, don't try and do a GB calculation, as floor(MB) is less worrying than floor(GB) for a (very nearly) 2GB SD Card. Affected files ... .. //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard_disk.c#4 edit Differences ... ==== //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard_disk.c#4 (text+ko) ==== @@ -117,7 +117,6 @@ { struct disk *disk; uint64_t size; - char scale; ALTERA_SDCARD_LOCK_ASSERT(sc); @@ -131,7 +130,6 @@ */ ALTERA_SDCARD_UNLOCK(sc); disk = disk_alloc(); - ALTERA_SDCARD_LOCK(sc); disk->d_drv1 = sc; disk->d_name = "altera_sdcard"; disk->d_unit = sc->as_unit; @@ -143,24 +141,14 @@ disk->d_maxsize = ALTERA_SDCARD_SECTORSIZE; sc->as_disk = disk; disk_create(disk, DISK_VERSION); + ALTERA_SDCARD_LOCK(sc); /* * Print a pretty-ish card insertion string. We could stand to * decorate this further, e.g., with card vendor information. */ - size = sc->as_mediasize; - if (size > 1024*1024*1024) { - scale = 'G'; - size /= 1024*1024*1024; - } else if (size > 1024*1024) { - scale = 'M'; - size /= 1024*1024; - } else { - scale = 'K'; - size /= 1024; - } - device_printf(sc->as_dev, "%ju%c SD Card inserted\n", (uintmax_t)size, - scale); + size = sc->as_mediasize / (1000 * 1000); + device_printf(sc->as_dev, "%juM SD Card inserted\n", (uintmax_t)size); } void @@ -192,4 +180,5 @@ sc->as_currentbio = NULL; } bioq_flush(&sc->as_bioq, NULL, ENXIO); + device_printf(sc->as_dev, "SD Card removed\n"); } From owner-p4-projects@FreeBSD.ORG Thu Apr 5 18:24:55 2012 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 988AC1065673; Thu, 5 Apr 2012 18:24:55 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5AB751065670 for ; Thu, 5 Apr 2012 18:24:55 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id 435028FC14 for ; Thu, 5 Apr 2012 18:24:55 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id q35IOtvL097963 for ; Thu, 5 Apr 2012 18:24:55 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id q35IOtoC097960 for perforce@freebsd.org; Thu, 5 Apr 2012 18:24:55 GMT (envelope-from jhb@freebsd.org) Date: Thu, 5 Apr 2012 18:24:55 GMT Message-Id: <201204051824.q35IOtoC097960@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to jhb@freebsd.org using -f From: John Baldwin To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 209119 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Apr 2012 18:24:55 -0000 http://p4web.freebsd.org/@@209119?ac=10 Change 209119 by jhb@jhb_fiver on 2012/04/05 18:24:07 WIP to partially bring back fast eventhandlers. However, in this incarnation fast lists are in the set of named events, so the same API can be used for registering both fast and slow handlers. The result is that switching an eventhandler from slow to fast no longer requires changing all the callers. Affected files ... .. //depot/projects/smpng/share/man/man9/EVENTHANDLER.9#2 edit .. //depot/projects/smpng/share/man/man9/Makefile#29 edit .. //depot/projects/smpng/sys/kern/subr_eventhandler.c#26 edit .. //depot/projects/smpng/sys/sys/eventhandler.h#36 edit Differences ... ==== //depot/projects/smpng/share/man/man9/EVENTHANDLER.9#2 (text+ko) ==== @@ -33,6 +33,10 @@ .In sys/eventhandler.h .Fn EVENTHANDLER_DECLARE name type .Fn EVENTHANDLER_INVOKE name ... +.Fn EVENTHANDLER_FAST_DECLARE name type +.Fn EVENTHANDLER_FAST_DEFINE name type +.Fn EVENTHANDLER_FAST_INVOKE name ... +.Fn EVENTHANDLER_DEFINE name func arg priority .Ft eventhandler_tag .Fn EVENTHANDLER_REGISTER name func arg priority .Fn EVENTHANDLER_DEREGISTER name tag ==== //depot/projects/smpng/share/man/man9/Makefile#29 (text+ko) ==== @@ -629,8 +629,12 @@ drbr.9 drbr_inuse.9 \ drbr.9 drbr_stats_update.9 MLINKS+=EVENTHANDLER.9 EVENTHANDLER_DECLARE.9 \ + EVENTHANDLER.9 EVENTHANDLER_DEFINE.9 \ EVENTHANDLER.9 EVENTHANDLER_DEREGISTER.9 \ EVENTHANDLER.9 eventhandler_deregister.9 \ + EVENTHANDLER.9 EVENTHANDLER_FAST_DECLARE.9 \ + EVENTHANDLER.9 EVENTHANDLER_FAST_DEFINE.9 \ + EVENTHANDLER.9 EVENTHANDLER_FAST_INVOKE.9 \ EVENTHANDLER.9 eventhandler_find_list.9 \ EVENTHANDLER.9 EVENTHANDLER_INVOKE.9 \ EVENTHANDLER.9 eventhandler_prune_list.9 \ ==== //depot/projects/smpng/sys/kern/subr_eventhandler.c#26 (text+ko) ==== @@ -64,6 +64,28 @@ SYSINIT(eventhandlers, SI_SUB_EVENTHANDLER, SI_ORDER_FIRST, eventhandler_init, NULL); +/* + * Initialize a pre-allocated "fast" eventhandler list. The list's + * name is set in 'el_name', but the list is otherwise uninitialized. + */ +void +eventhandler_fast_list_init(void *arg) +{ + struct eventhandler_list *list; + + list = arg; + CTR2(KTR_EVH, "%s: initializing list \"%s\"", __func__, list->el_name); + TAILQ_INIT(&list->el_entries); + mtx_init(&list->el_lock, list->el_name, "eventhandler list", MTX_DEF); + atomic_store_rel_int(&list->el_flags, EHL_INITTED); + + mtx_lock(&eventhandler_mutex); + if (_eventhandler_find_list(list->el_name) != NULL) + panic("Duplicate fast eventhandler list: %s", list->el_name); + TAILQ_INSERT_HEAD(&eventhandler_lists, list, el_link); + mtx_unlock(&eventhandler_mutex); +} + /* * Insertion is O(n) due to the priority scan, but optimises to O(1) * if all priorities are identical. @@ -81,7 +103,7 @@ /* lock the eventhandler lists */ mtx_lock(&eventhandler_mutex); - /* Do we need to find/create the (slow) list? */ + /* Do we need to find/create the list? */ if (list == NULL) { /* look for a matching, existing list */ list = _eventhandler_find_list(name); @@ -91,7 +113,7 @@ mtx_unlock(&eventhandler_mutex); new_list = malloc(sizeof(struct eventhandler_list) + - strlen(name) + 1, M_EVENTHANDLER, M_WAITOK); + strlen(name) + 1, M_EVENTHANDLER, M_WAITOK | M_ZERO); /* If someone else created it already, then use that one. */ mtx_lock(&eventhandler_mutex); @@ -101,20 +123,15 @@ } else { CTR2(KTR_EVH, "%s: creating list \"%s\"", __func__, name); list = new_list; - list->el_flags = 0; - list->el_runcount = 0; - bzero(&list->el_lock, sizeof(list->el_lock)); list->el_name = (char *)list + sizeof(struct eventhandler_list); strcpy(list->el_name, name); + TAILQ_INIT(&list->el_entries); + mtx_init(&list->el_lock, name, "eventhandler list", MTX_DEF); TAILQ_INSERT_HEAD(&eventhandler_lists, list, el_link); + atomic_store_rel_int(&list->el_flags, EHL_INITTED); } } } - if (!(list->el_flags & EHL_INITTED)) { - TAILQ_INIT(&list->el_entries); - mtx_init(&list->el_lock, name, "eventhandler list", MTX_DEF); - atomic_store_rel_int(&list->el_flags, EHL_INITTED); - } mtx_unlock(&eventhandler_mutex); KASSERT(epn->ee_priority != EHE_DEAD_PRIORITY, @@ -244,8 +261,8 @@ { struct eventhandler_list *list; - if (!eventhandler_lists_initted) - return(NULL); + KASSERT(eventhandler_lists_initted, + ("eventhandler_find_list called too early")); /* scan looking for the requested list */ mtx_lock(&eventhandler_mutex); ==== //depot/projects/smpng/sys/sys/eventhandler.h#36 (text+ko) ==== @@ -98,12 +98,40 @@ } while (0) /* - * Slow handlers are entirely dynamic; lists are created - * when entries are added to them, and thus have no concept of "owner", + * Fast handler lists require the eventhandler list be present + * at link time. They don't allow addition of entries to + * unknown eventhandler lists, ie. each list must have an + * "owner". + * + * Fast handler lists must be defined once by the owner + * of the eventhandler list, and the declaration must be in + * scope at any point the list is manipulated. + */ + +/* + * Event handlers provide named lists of hooks to be invoked when a + * specific event occurs. Hooks are added and removed to lists that + * are identified by name. + * + * There are two types of event handler lists. + * + * Default, or "slow" lists allocate the list storage dynamically when + * the first hook is registered for an event. Invoking a default hook + * will always have some overhead as it uses an O(n) lookup to find + * the event handler list by name. + * + * "Fast" lists use statically allocated storage for the event handler + * list. As a result, they can avoid the O(n) lookup and should have + * very minimal overhead when no hooks are active. Fast lists can + * never be freed, so they cannot be used in kernel modules that + * support unloading. They must also be defined in addition to being + * declared. * - * Slow handlers need to be declared, but do not need to be defined. The - * declaration must be in scope wherever the handler is to be invoked. + * Registering a hook for an event or invoking an event requires that + * the declaration of the list is in scope. */ + +/* "Slow" list operations. */ #define EVENTHANDLER_DECLARE(name, type) \ struct eventhandler_entry_ ## name \ { \ @@ -112,6 +140,36 @@ }; \ struct __hack +#define EVENTHANDLER_INVOKE(name, ...) \ +do { \ + struct eventhandler_list *_el; \ + \ + if ((_el = eventhandler_find_list(#name)) != NULL) \ + _EVENTHANDLER_INVOKE(name, _el , ## __VA_ARGS__); \ +} while (0) + +/* "Fast" list operations. */ +#define EVENTHANDLER_FAST_DECLARE(name, type) \ +extern struct eventhandler_list Xeventhandler_list_ ## name; \ +EVENTHANDLER_DECLARE(name, type) + +#define EVENTHANDLER_FAST_DEFINE(name, type) \ +struct eventhandler_list Xeventhandler_list_ ## name = { #name }; \ +SYSINIT(eventhandler_list_ ##name, SI_SUB_EVENTHANDLER, SI_ORDER_SECOND, \ + eventhandler_fast_list_init, &Xeventhandler_list_ ## name) + +#define EVENTHANDLER_FAST_INVOKE(name, ...) do { \ + struct eventhandler_list *_el = &Xeventhandler_list_ ## name ; \ + \ + KASSERT(_el->el_flags & EHL_INITTED, \ + ("eventhandler_fast_invoke: too early")); \ + if (!TAILQ_EMPTY(&_el->el_entries) { \ + EHL_LOCK(_el); \ + _EVENTHANDLER_INVOKE(name, _el , ## __VA_ARGS__); \ + } \ +} while (0) + +/* Operations to add and remove hooks. */ #define EVENTHANDLER_DEFINE(name, func, arg, priority) \ static eventhandler_tag name ## _tag; \ static void name ## _evh_init(void *ctx) \ @@ -123,15 +181,7 @@ name ## _evh_init, arg); \ struct __hack -#define EVENTHANDLER_INVOKE(name, ...) \ -do { \ - struct eventhandler_list *_el; \ - \ - if ((_el = eventhandler_find_list(#name)) != NULL) \ - _EVENTHANDLER_INVOKE(name, _el , ## __VA_ARGS__); \ -} while (0) - -#define EVENTHANDLER_REGISTER(name, func, arg, priority) \ +#define EVENTHANDLER_REGISTER(name, func, arg, priority) \ eventhandler_register(NULL, #name, func, arg, priority) #define EVENTHANDLER_DEREGISTER(name, tag) \ @@ -141,12 +191,12 @@ if ((_el = eventhandler_find_list(#name)) != NULL) \ eventhandler_deregister(_el, tag); \ } while(0) - -eventhandler_tag eventhandler_register(struct eventhandler_list *list, +eventhandler_tag eventhandler_register(struct eventhandler_list *list, const char *name, void *func, void *arg, int priority); void eventhandler_deregister(struct eventhandler_list *list, eventhandler_tag tag); +void eventhandler_fast_list_init(void *arg); struct eventhandler_list *eventhandler_find_list(const char *name); void eventhandler_prune_list(struct eventhandler_list *list); From owner-p4-projects@FreeBSD.ORG Thu Apr 5 21:18:14 2012 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 8DB971065675; Thu, 5 Apr 2012 21:18:14 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 503511065670 for ; Thu, 5 Apr 2012 21:18:14 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id 3A6128FC18 for ; Thu, 5 Apr 2012 21:18:14 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id q35LIEcA033850 for ; Thu, 5 Apr 2012 21:18:14 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id q35LIDvm033847 for perforce@freebsd.org; Thu, 5 Apr 2012 21:18:13 GMT (envelope-from jhb@freebsd.org) Date: Thu, 5 Apr 2012 21:18:13 GMT Message-Id: <201204052118.q35LIDvm033847@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to jhb@freebsd.org using -f From: John Baldwin To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 209124 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Apr 2012 21:18:14 -0000 http://p4web.freebsd.org/@@209124?ac=10 Change 209124 by jhb@jhb_jhbbsd on 2012/04/05 21:17:14 - Add a test module to see if the "fast" lists really are better. - Compile. Affected files ... .. //depot/projects/smpng/sys/modules/evbench/Makefile#1 add .. //depot/projects/smpng/sys/modules/evbench/evbench.c#1 add .. //depot/projects/smpng/sys/sys/eventhandler.h#37 edit Differences ... ==== //depot/projects/smpng/sys/sys/eventhandler.h#37 (text+ko) ==== @@ -163,7 +163,7 @@ \ KASSERT(_el->el_flags & EHL_INITTED, \ ("eventhandler_fast_invoke: too early")); \ - if (!TAILQ_EMPTY(&_el->el_entries) { \ + if (!TAILQ_EMPTY(&_el->el_entries)) { \ EHL_LOCK(_el); \ _EVENTHANDLER_INVOKE(name, _el , ## __VA_ARGS__); \ } \ From owner-p4-projects@FreeBSD.ORG Fri Apr 6 18:08:33 2012 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 9FE031065674; Fri, 6 Apr 2012 18:08:33 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6289F106566C for ; Fri, 6 Apr 2012 18:08:33 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id 49D708FC08 for ; Fri, 6 Apr 2012 18:08:33 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id q36I8XMP097524 for ; Fri, 6 Apr 2012 18:08:33 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id q36I8X1o097521 for perforce@freebsd.org; Fri, 6 Apr 2012 18:08:33 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Fri, 6 Apr 2012 18:08:33 GMT Message-Id: <201204061808.q36I8X1o097521@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 209160 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Apr 2012 18:08:33 -0000 http://p4web.freebsd.org/@@209160?ac=10 Change 209160 by rwatson@rwatson_svr_ctsrd_mipsbuild on 2012/04/06 18:07:38 Hook up mysteriously un-hooked up single-byte bus I/O routines for generic MIPS bus space. This allows bus_write_region_1() to work, which previously panicked when used from the Altera SD Card IP Core driver. Affected files ... .. //depot/projects/ctsrd/beribsd/src/sys/mips/mips/bus_space_generic.c#3 edit Differences ... ==== //depot/projects/ctsrd/beribsd/src/sys/mips/mips/bus_space_generic.c#3 (text+ko) ==== @@ -136,7 +136,7 @@ NULL, /* write region */ - NULL, + generic_bs_wr_1, generic_bs_wr_2, generic_bs_wr_4, NULL, @@ -148,7 +148,7 @@ NULL, /* set region */ - NULL, + generic_bs_sr_1, generic_bs_sr_2, generic_bs_sr_4, NULL, @@ -190,7 +190,7 @@ NULL, /* write region stream */ - NULL, + generic_bs_wr_1, generic_bs_wr_2, generic_bs_wr_4, NULL, From owner-p4-projects@FreeBSD.ORG Fri Apr 6 18:15:07 2012 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 012CD1065670; Fri, 6 Apr 2012 18:15:07 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B8162106564A for ; Fri, 6 Apr 2012 18:15:06 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id 7F4658FC08 for ; Fri, 6 Apr 2012 18:15:06 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id q36IF6I8000326 for ; Fri, 6 Apr 2012 18:15:06 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id q36IF6Ij000323 for perforce@freebsd.org; Fri, 6 Apr 2012 18:15:06 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Fri, 6 Apr 2012 18:15:06 GMT Message-Id: <201204061815.q36IF6Ij000323@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 209161 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Apr 2012 18:15:07 -0000 http://p4web.freebsd.org/@@209161?ac=10 Change 209161 by rwatson@rwatson_svr_ctsrd_mipsbuild on 2012/04/06 18:14:42 Enable querying and printing of Altera SD Card IP Core register RR1 when an I/O error is reported. Leave XXX comments as it remains the case that the error-related bits are not properly documented in the specification. Do more generally print failure information when I/O bombs. There appear to be non-trivial reliability issues with I/O -- this evening I will investigate whether simply retrying the I/O request causes them to clear, and whether the data it returns, despite the error, might be correct. Affected files ... .. //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard.h#6 edit .. //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard_io.c#7 edit Differences ... ==== //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard.h#6 (text+ko) ==== @@ -103,6 +103,7 @@ */ uint16_t altera_sdcard_read_asr(struct altera_sdcard_softc *sc); int altera_sdcard_read_csd(struct altera_sdcard_softc *sc); +uint16_t altera_sdcard_read_rr1(struct altera_sdcard_softc *sc); void altera_sdcard_io_complete(struct altera_sdcard_softc *sc, uint16_t asr); ==== //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard_io.c#7 (text+ko) ==== @@ -183,7 +183,6 @@ return (0); } -#if 0 /* * XXXRW: The Altera IP Core specification indicates that RR1 is a 16-bit * register, but all bits it identifies are >16 bit. Most likely, RR1 is a @@ -195,7 +194,6 @@ return (le16toh(bus_read_2(sc->as_res, ALTERA_SDCARD_OFF_RR1))); } -#endif static void altera_sdcard_write_cmd_arg(struct altera_sdcard_softc *sc, uint32_t cmd_arg) @@ -277,9 +275,7 @@ altera_sdcard_io_complete(struct altera_sdcard_softc *sc, uint16_t asr) { struct bio *bp; -#if 0 uint16_t rr1; -#endif ALTERA_SDCARD_LOCK_ASSERT(sc); KASSERT(!(asr & ALTERA_SDCARD_ASR_CMDINPROGRESS), @@ -296,19 +292,19 @@ */ if (asr & (ALTERA_SDCARD_ASR_CMDTIMEOUT | ALTERA_SDCARD_ASR_CMDDATAERROR)) { + rr1 = altera_sdcard_read_rr1(sc); + device_printf(sc->as_dev, "%s: %s operation block %ju length " + "%ju failed; asr 0x%08x (rr1: 0x%04x)\n", + __func__, bp->bio_cmd == BIO_READ ? "BIO_READ" : + (bp->bio_cmd == BIO_WRITE ? "write" : "unknown"), + bp->bio_pblkno, bp->bio_bcount, asr, rr1); biofinish(bp, NULL, EIO); return; } -#if 0 /* - * XXXRW: We would like to use RR1 to check on the status of the last - * command handled by the unit. Unfortunately, the documentation on - * its use is inconsistent, so we don't do that yet. + * Successful I/O completion path. */ - rr1 = altera_sdcard_read_rr1(sc); -#endif - switch (bp->bio_cmd) { case BIO_READ: altera_sdcard_read_rxtx_buffer(sc, bp->bio_data, From owner-p4-projects@FreeBSD.ORG Sat Apr 7 11:03:26 2012 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id E03C41065672; Sat, 7 Apr 2012 11:03:25 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 94702106566B for ; Sat, 7 Apr 2012 11:03:25 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id 7AC928FC0A for ; Sat, 7 Apr 2012 11:03:25 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id q37B3Pp2013882 for ; Sat, 7 Apr 2012 11:03:25 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id q37B3Pl8013879 for perforce@freebsd.org; Sat, 7 Apr 2012 11:03:25 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Sat, 7 Apr 2012 11:03:25 GMT Message-Id: <201204071103.q37B3Pl8013879@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 209192 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Apr 2012 11:03:26 -0000 http://p4web.freebsd.org/@@209192?ac=10 Change 209192 by rwatson@rwatson_svr_ctsrd_mipsbuild on 2012/04/07 11:03:10 Implement support for retrying transactions when the Altera SD Card IP Core returns errors. It appears that a number of transient errors occur in our current configuration, and while many I/Os succeed on the first attempt, a moderate number require 2-4 retries before the IP core will return success. To this end, implement a flag indicating that the current transaction has experienced an error, and a retry counter with alternative retry delay. Generate console output only then an I/O finally succeeds or fails, following an error, rather than on each attempt. We aren't yet able to interpret the nature of the error in software due to inadequate documentation, so this seems reasonable. If and when we are able to interpret the errors, we might want to handle different failures differently -- for example, if the core is reinitialising following a serious error, we might be willing to wait much longer. Return EINVAL rather than panic() since fsck requires it. Affected files ... .. //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard.c#4 edit .. //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard.h#7 edit .. //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard_disk.c#5 edit .. //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard_io.c#8 edit Differences ... ==== //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard.c#4 (text+ko) ==== @@ -280,8 +280,11 @@ /* * Handle various forms of I/O completion, successful and otherwise. + * The I/O layer may restart the transaction if an error occurred, in + * which case remain in the IO state and reschedule. */ - altera_sdcard_io_complete(sc, asr); + if (!altera_sdcard_io_complete(sc, asr)) + return; /* * Now that I/O is complete, process detach requests in preference to @@ -321,7 +324,10 @@ break; case ALTERA_SDCARD_STATE_IO: - interval = ALTERA_SDCARD_TIMEOUT_IO; + if (sc->as_flags & ALTERA_SDCARD_FLAG_IOERROR) + interval = ALTERA_SDCARD_TIMEOUT_IOERROR; + else + interval = ALTERA_SDCARD_TIMEOUT_IO; break; default: ==== //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard.h#7 (text+ko) ==== @@ -46,10 +46,15 @@ int as_state; int as_flags; struct disk *as_disk; + struct taskqueue *as_taskqueue; + struct timeout_task as_task; + + /* + * Fields relating to in-progress and pending I/O, if any. + */ struct bio_queue_head as_bioq; struct bio *as_currentbio; - struct taskqueue *as_taskqueue; - struct timeout_task as_task; + u_int as_retriesleft; /* * Infrequently changing fields cached from the SD Card IP Core. @@ -90,11 +95,18 @@ #define ALTERA_SDCARD_TIMEOUT_NOCARD (hz/2) #define ALTERA_SDCARD_TIMEOUT_IDLE (hz/2) #define ALTERA_SDCARD_TIMEOUT_IO (hz/100) +#define ALTERA_SDCARD_TIMEOUT_IOERROR (hz/2) /* + * Maximum number of retries on an I/O. + */ +#define ALTERA_SDCARD_RETRY_LIMIT 10 + +/* * Driver status flags. */ #define ALTERA_SDCARD_FLAG_DETACHREQ 0x00000001 /* Detach requested. */ +#define ALTERA_SDCARD_FLAG_IOERROR 0x00000002 /* Error in progress. */ /* * Functions for performing low-level register and memory I/O to/from the SD @@ -105,7 +117,7 @@ int altera_sdcard_read_csd(struct altera_sdcard_softc *sc); uint16_t altera_sdcard_read_rr1(struct altera_sdcard_softc *sc); -void altera_sdcard_io_complete(struct altera_sdcard_softc *sc, +int altera_sdcard_io_complete(struct altera_sdcard_softc *sc, uint16_t asr); void altera_sdcard_io_start(struct altera_sdcard_softc *sc, struct bio *bp); ==== //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard_disk.c#5 (text+ko) ==== @@ -65,7 +65,8 @@ struct thread *td) { - panic("%s: not yet", __func__); + /* XXXRW: more here? */ + return (EINVAL); } static void ==== //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard_io.c#8 (text+ko) ==== @@ -233,22 +233,10 @@ len); } -void -altera_sdcard_io_start(struct altera_sdcard_softc *sc, struct bio *bp) +static void +altera_sdcard_io_start_internal(struct altera_sdcard_softc *sc, struct bio *bp) { - ALTERA_SDCARD_LOCK_ASSERT(sc); - KASSERT(sc->as_currentbio == NULL, - ("%s: bio already started", __func__)); - - /* - * We advertise a block size and maximum I/O size up the stack of the - * SD Card IP Core sector size. Catch any attempts to not follow the - * rules. - */ - KASSERT(bp->bio_bcount == ALTERA_SDCARD_SECTORSIZE, - ("%s: I/O size not %d", __func__, ALTERA_SDCARD_SECTORSIZE)); - switch (bp->bio_cmd) { case BIO_READ: altera_sdcard_write_cmd_arg(sc, bp->bio_pblkno * @@ -268,14 +256,39 @@ panic("%s: unsupported I/O operation %d", __func__, bp->bio_cmd); } +} + +void +altera_sdcard_io_start(struct altera_sdcard_softc *sc, struct bio *bp) +{ + + ALTERA_SDCARD_LOCK_ASSERT(sc); + KASSERT(sc->as_currentbio == NULL, + ("%s: bio already started", __func__)); + + /* + * We advertise a block size and maximum I/O size up the stack of the + * SD Card IP Core sector size. Catch any attempts to not follow the + * rules. + */ + KASSERT(bp->bio_bcount == ALTERA_SDCARD_SECTORSIZE, + ("%s: I/O size not %d", __func__, ALTERA_SDCARD_SECTORSIZE)); + altera_sdcard_io_start_internal(sc, bp); sc->as_currentbio = bp; + sc->as_retriesleft = ALTERA_SDCARD_RETRY_LIMIT; } -void +/* + * Handle completed I/O. ASR is passed in to avoid reading it more than once. + * Return 1 if the I/O is actually complete (success, or retry limit + * exceeded), or 0 if not. + */ +int altera_sdcard_io_complete(struct altera_sdcard_softc *sc, uint16_t asr) { struct bio *bp; uint16_t rr1; + int error; ALTERA_SDCARD_LOCK_ASSERT(sc); KASSERT(!(asr & ALTERA_SDCARD_ASR_CMDINPROGRESS), @@ -284,40 +297,57 @@ ("%s: card removed", __func__)); bp = sc->as_currentbio; - sc->as_currentbio = NULL; /* - * Handle I/O errors. Assume that the caller has already checked for - * unexpected removal. + * Handle I/O retries if an error is returned by the device. */ if (asr & (ALTERA_SDCARD_ASR_CMDTIMEOUT | ALTERA_SDCARD_ASR_CMDDATAERROR)) { rr1 = altera_sdcard_read_rr1(sc); + sc->as_retriesleft--; + if (sc->as_retriesleft != 0) { + sc->as_flags |= ALTERA_SDCARD_FLAG_IOERROR; + altera_sdcard_io_start_internal(sc, bp); + return (0); + } device_printf(sc->as_dev, "%s: %s operation block %ju length " - "%ju failed; asr 0x%08x (rr1: 0x%04x)\n", - __func__, bp->bio_cmd == BIO_READ ? "BIO_READ" : - (bp->bio_cmd == BIO_WRITE ? "write" : "unknown"), + "%ju failed; asr 0x%08x (rr1: 0x%04x)\n", __func__, + bp->bio_cmd == BIO_READ ? "BIO_READ" : + (bp->bio_cmd == BIO_WRITE ? "BIO_WRITE" : "unknown"), bp->bio_pblkno, bp->bio_bcount, asr, rr1); - biofinish(bp, NULL, EIO); - return; - } + sc->as_flags &= ~ALTERA_SDCARD_FLAG_IOERROR; + error = EIO; + } else { + if (sc->as_flags & ALTERA_SDCARD_FLAG_IOERROR) { + device_printf(sc->as_dev, "%s: %s operation block %ju" + " length %ju succeeded after %d retries\n", + __func__, bp->bio_cmd == BIO_READ ? "BIO_READ" : + (bp->bio_cmd == BIO_WRITE ? "write" : "unknown"), + bp->bio_pblkno, bp->bio_bcount, + ALTERA_SDCARD_RETRY_LIMIT - sc->as_retriesleft); + sc->as_flags &= ~ALTERA_SDCARD_FLAG_IOERROR; + } - /* - * Successful I/O completion path. - */ - switch (bp->bio_cmd) { - case BIO_READ: - altera_sdcard_read_rxtx_buffer(sc, bp->bio_data, - bp->bio_bcount); - break; + /* + * Successful I/O completion path. + */ + switch (bp->bio_cmd) { + case BIO_READ: + altera_sdcard_read_rxtx_buffer(sc, bp->bio_data, + bp->bio_bcount); + break; - case BIO_WRITE: - break; + case BIO_WRITE: + break; - default: - panic("%s: unsupported I/O operation %d", __func__, - bp->bio_cmd); + default: + panic("%s: unsupported I/O operation %d", __func__, + bp->bio_cmd); + } + bp->bio_resid = 0; + error = 0; } - bp->bio_resid = 0; - biofinish(bp, NULL, 0); + biofinish(bp, NULL, error); + sc->as_currentbio = NULL; + return (1); } From owner-p4-projects@FreeBSD.ORG Sat Apr 7 12:40:22 2012 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 78EC21065677; Sat, 7 Apr 2012 12:40:22 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3BD611065673 for ; Sat, 7 Apr 2012 12:40:22 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id 256548FC0A for ; Sat, 7 Apr 2012 12:40:22 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id q37CeMRJ033409 for ; Sat, 7 Apr 2012 12:40:22 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id q37CeM25033405 for perforce@freebsd.org; Sat, 7 Apr 2012 12:40:22 GMT (envelope-from jhb@freebsd.org) Date: Sat, 7 Apr 2012 12:40:22 GMT Message-Id: <201204071240.q37CeM25033405@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to jhb@freebsd.org using -f From: John Baldwin To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 209195 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Apr 2012 12:40:22 -0000 http://p4web.freebsd.org/@@209195?ac=10 Change 209195 by jhb@jhb_fiver on 2012/04/07 12:40:19 Fix style of EVENTHANDLER_DEFINE() and add a SYSUNINIT to remove the tag on unload. Affected files ... .. //depot/projects/smpng/sys/sys/eventhandler.h#38 edit Differences ... ==== //depot/projects/smpng/sys/sys/eventhandler.h#38 (text+ko) ==== @@ -171,15 +171,21 @@ /* Operations to add and remove hooks. */ #define EVENTHANDLER_DEFINE(name, func, arg, priority) \ - static eventhandler_tag name ## _tag; \ - static void name ## _evh_init(void *ctx) \ - { \ - name ## _tag = EVENTHANDLER_REGISTER(name, func, ctx, \ - priority); \ - } \ - SYSINIT(name ## _evh_init, SI_SUB_CONFIGURE, SI_ORDER_ANY, \ - name ## _evh_init, arg); \ - struct __hack +static eventhandler_tag name ## _tag; \ + \ +static void name ## _evh_init(void *ctx) \ +{ \ + name ## _tag = EVENTHANDLER_REGISTER(name, func, ctx, priority); \ +} \ +SYSINIT(name ## _evh_init, SI_SUB_CONFIGURE, SI_ORDER_ANY, \ + name ## _evh_init, arg); \ + \ +static void name ## _evh_fini(void *ctx __unused) \ +{ \ + EVENTHANDLER_DEREGISTER(name, name ## _tag); \ +} \ +SYSUNINIT(name ## _evh_fini, SI_SUB_CONFIGURE, SI_ORDER_ANY, \ + name ## _evh_fini, NULL) #define EVENTHANDLER_REGISTER(name, func, arg, priority) \ eventhandler_register(NULL, #name, func, arg, priority) From owner-p4-projects@FreeBSD.ORG Sat Apr 7 12:41:28 2012 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 9860E1065673; Sat, 7 Apr 2012 12:41:28 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 5AFE9106564A for ; Sat, 7 Apr 2012 12:41:28 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id 43CFC8FC15 for ; Sat, 7 Apr 2012 12:41:28 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id q37CfS1C034811 for ; Sat, 7 Apr 2012 12:41:28 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id q37CfSZN034808 for perforce@freebsd.org; Sat, 7 Apr 2012 12:41:28 GMT (envelope-from jhb@freebsd.org) Date: Sat, 7 Apr 2012 12:41:28 GMT Message-Id: <201204071241.q37CfSZN034808@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to jhb@freebsd.org using -f From: John Baldwin To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 209196 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Apr 2012 12:41:28 -0000 http://p4web.freebsd.org/@@209196?ac=10 Change 209196 by jhb@jhb_fiver on 2012/04/07 12:40:55 Update. Affected files ... .. //depot/projects/smpng/share/man/man9/EVENTHANDLER.9#3 edit Differences ... ==== //depot/projects/smpng/share/man/man9/EVENTHANDLER.9#3 (text+ko) ==== @@ -36,10 +36,10 @@ .Fn EVENTHANDLER_FAST_DECLARE name type .Fn EVENTHANDLER_FAST_DEFINE name type .Fn EVENTHANDLER_FAST_INVOKE name ... -.Fn EVENTHANDLER_DEFINE name func arg priority .Ft eventhandler_tag .Fn EVENTHANDLER_REGISTER name func arg priority .Fn EVENTHANDLER_DEREGISTER name tag +.Fn EVENTHANDLER_DEFINE name func arg priority .Ft eventhandler_tag .Fo eventhandler_register .Fa "struct eventhandler_list *list" @@ -64,15 +64,63 @@ kernel events and have their callback functions invoked when these events occur. .Pp -The normal way to use this subsystem is via the macro interface. +Each event is associated with a named event handler list which contains +the associated callback functions. +There are two types of event handler lists: +normal lists and fast lists. +.Pp +Normal lists are more flexible at the expense of additional overhead. +These lists are allocated dynamically when the first callback +function is registered. +Invoking a normal event list always requires a linear lookup of the +list by name, +even if there are no callback functions registered for the event. +.Pp +Fast lists use static allocation rather than dynamic allocation. +This allows fast list invocations to avoid the lookup operation +and to minimize overhead if no callback functions are registered for +an event. +However, +the storage for fast lists must always be valid, +so they cannot be used in a kernel module that supports unloading. +In addition, +fast lists must be defined in exactly one place. +.Pp +This subsystem should be used via the macro interface. The macros that can be used for working with event handlers and callback function lists are: .Bl -tag -width indent .It Fn EVENTHANDLER_DECLARE -This macro declares an event handler named by argument +This macro declares a normal event handler named by argument +.Fa name +with callback functions of type +.Fa type . +.It Fn EVENTHANDLER_INVOKE +This macro is used to invoke all the callbacks associated with the +event handler +.Fa name . +This macro is a variadic one. +Additional arguments to the macro after the +.Fa name +parameter are passed as the second and subsequent arguments to each +registered callback function. +.It Fn EVENTHANDLER_FAST_DECLARE +This macro declares a fast event handler named by argument .Fa name with callback functions of type .Fa type . +.It Fn EVENTHANDLER_FAST_DEFINE +This macro defines the storage for a fast event handler list and +registers the list with +.Fa name . +.It Fn EVENTHANDLER_FAST_INVOKE +This macro is used to invoke all the callbacks associated with the +fast event handler +.Fa name . +As with +.Fn EVENTHANDLER_INVOKE , +this macro is a variadic macro that passes additional arguments to +each registered callback function. .It Fn EVENTHANDLER_REGISTER This macro registers a callback function .Fa func @@ -82,10 +130,12 @@ .Fa func will be invoked with argument .Fa arg -as its first parameter along with any additional parameters passed in -via macro +as its first parameter along with any additional parameters passed to +the .Fn EVENTHANDLER_INVOKE -(see below). +or +.Fn EVENTHANDLER_FAST_INVOKE +macro. Callback functions are invoked in order of priority. The relative priority of each callback among other callbacks associated with an event is given by argument @@ -108,15 +158,17 @@ .Fa tag from the event handler named by argument .Fa name . -.It Fn EVENTHANDLER_INVOKE -This macro is used to invoke all the callbacks associated with event -handler -.Fa name . -This macro is a variadic one. -Additional arguments to the macro after the -.Fa name -parameter are passed as the second and subsequent arguments to each -registered callback function. +.It Fn EVENTHANDLER_DEFINE +This macro is used to manage a static callback. +It registers a callback function via the +.Fn EVENTHANDLER_REGISTER +macro at system boot or module load. +Its arguments have the same meaning as for the +.Fn EVENTHANDLER_REGISTER +macro. +Additionally, +the callback function will be removed from the named event handler +list on module unload. .El .Pp The macros are implemented using the following functions: From owner-p4-projects@FreeBSD.ORG Sat Apr 7 13:39:33 2012 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 50DD01065670; Sat, 7 Apr 2012 13:39:33 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1386A106564A for ; Sat, 7 Apr 2012 13:39:33 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id EF21D8FC08 for ; Sat, 7 Apr 2012 13:39:32 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id q37DdW3S045280 for ; Sat, 7 Apr 2012 13:39:32 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id q37DdUZY045277 for perforce@freebsd.org; Sat, 7 Apr 2012 13:39:30 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Sat, 7 Apr 2012 13:39:30 GMT Message-Id: <201204071339.q37DdUZY045277@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 209200 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Apr 2012 13:39:33 -0000 http://p4web.freebsd.org/@@209200?ac=10 Change 209200 by rwatson@rwatson_svr_ctsrd_mipsbuild on 2012/04/07 13:39:22 When performing an SD Card write, ignore the ASR bit described by the specification as "most recently received data contains errors"; this bit is apparently always set if a block write is performed, and only useful when looking at the results of a block read. With this change, many block writes using the SD Card slot on the Terasic DE-4 board often succeed. Affected files ... .. //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard_io.c#9 edit Differences ... ==== //depot/projects/ctsrd/beribsd/src/sys/dev/altera/sdcard/altera_sdcard_io.c#9 (text+ko) ==== @@ -301,8 +301,8 @@ /* * Handle I/O retries if an error is returned by the device. */ - if (asr & - (ALTERA_SDCARD_ASR_CMDTIMEOUT | ALTERA_SDCARD_ASR_CMDDATAERROR)) { + if ((asr & ALTERA_SDCARD_ASR_CMDTIMEOUT) || (bp->bio_cmd == BIO_READ + && (asr & ALTERA_SDCARD_ASR_CMDDATAERROR))) { rr1 = altera_sdcard_read_rr1(sc); sc->as_retriesleft--; if (sc->as_retriesleft != 0) { From owner-p4-projects@FreeBSD.ORG Sat Apr 7 17:27:02 2012 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id E8D771065674; Sat, 7 Apr 2012 17:27:01 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id AB56E1065672 for ; Sat, 7 Apr 2012 17:27:01 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id 9330C8FC12 for ; Sat, 7 Apr 2012 17:27:01 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id q37HR1wU092770 for ; Sat, 7 Apr 2012 17:27:01 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id q37HR1cX092767 for perforce@freebsd.org; Sat, 7 Apr 2012 17:27:01 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Sat, 7 Apr 2012 17:27:01 GMT Message-Id: <201204071727.q37HR1cX092767@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 209211 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Apr 2012 17:27:02 -0000 http://p4web.freebsd.org/@@209211?ac=10 Change 209211 by rwatson@rwatson_svr_ctsrd_mipsbuild on 2012/04/07 17:26:16 Adjust BERI configuration based on local documentation changes; it's a reference configuration for using a memory file system, so comment on that. Add a BERI_SDROOT configuration file that will be used for booting from the Altera SD Card IP Core. Affected files ... .. //depot/projects/ctsrd/beribsd/src/sys/mips/conf/BERI#7 edit .. //depot/projects/ctsrd/beribsd/src/sys/mips/conf/BERI_SDROOT#1 add Differences ... ==== //depot/projects/ctsrd/beribsd/src/sys/mips/conf/BERI#7 (text+ko) ==== @@ -31,8 +31,6 @@ options FFS #Berkeley Fast Filesystem -#options ROOTDEVNAME=\"ufs:ada0s1a\" - # Debugging for use in -current #options DEADLKRES #Enable the deadlock resolver options INVARIANTS #Enable calls of extra sanity checking @@ -40,9 +38,13 @@ #options WITNESS #Enable checks to detect deadlocks and cycles #options WITNESS_SKIPSPIN #Don't run witness on spinlocks for speed +# +# This kernel configuration uses an embedded 8MB memory root file system. +# Adjust the following path based on local requirements. +# options MD_ROOT # MD is a potential root device options MD_ROOT_SIZE=8192 -makeoptions MFS_IMAGE=/tmp/root.img +makeoptions MFS_IMAGE=/local/scratch/rnw24/root.img options ROOTDEVNAME=\"ufs:md0\" device altera_jtag_uart From owner-p4-projects@FreeBSD.ORG Sat Apr 7 17:28:08 2012 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 25E621065672; Sat, 7 Apr 2012 17:28:08 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id DC9B5106564A for ; Sat, 7 Apr 2012 17:28:07 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id C3D4E8FC08 for ; Sat, 7 Apr 2012 17:28:07 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id q37HS7Wl092809 for ; Sat, 7 Apr 2012 17:28:07 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id q37HS70s092806 for perforce@freebsd.org; Sat, 7 Apr 2012 17:28:07 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Sat, 7 Apr 2012 17:28:07 GMT Message-Id: <201204071728.q37HS70s092806@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 209212 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Apr 2012 17:28:08 -0000 http://p4web.freebsd.org/@@209212?ac=10 Change 209212 by rwatson@rwatson_svr_ctsrd_mipsbuild on 2012/04/07 17:27:50 Rename BERI to BERI_MDROOT to make the difference between our two BERI kernel configurations more obvious. Modify the BERI_SDROOT config file so that it knows its own name better. Affected files ... .. //depot/projects/ctsrd/beribsd/src/sys/mips/conf/BERI#8 delete .. //depot/projects/ctsrd/beribsd/src/sys/mips/conf/BERI_MDROOT#1 add .. //depot/projects/ctsrd/beribsd/src/sys/mips/conf/BERI_SDROOT#2 edit Differences ... ==== //depot/projects/ctsrd/beribsd/src/sys/mips/conf/BERI_SDROOT#2 (text+ko) ==== @@ -6,7 +6,7 @@ # $FreeBSD$ # -ident BERI +ident BERI_SDROOT machine mips mips64eb From owner-p4-projects@FreeBSD.ORG Sat Apr 7 19:52:50 2012 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 943031065673; Sat, 7 Apr 2012 19:52:50 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 56D231065670 for ; Sat, 7 Apr 2012 19:52:50 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id 3FA038FC0A for ; Sat, 7 Apr 2012 19:52:50 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id q37Jqoxf023156 for ; Sat, 7 Apr 2012 19:52:50 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id q37Jqnxb023153 for perforce@freebsd.org; Sat, 7 Apr 2012 19:52:50 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Sat, 7 Apr 2012 19:52:50 GMT Message-Id: <201204071952.q37Jqnxb023153@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 209217 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Apr 2012 19:52:50 -0000 http://p4web.freebsd.org/@@209217?ac=10 Change 209217 by rwatson@rwatson_svr_ctsrd_mipsbuild on 2012/04/07 19:51:48 Synchronise BERI_MDROOT kernel configuration to local name change for generated memory root file systems. Affected files ... .. //depot/projects/ctsrd/beribsd/src/sys/mips/conf/BERI_MDROOT#2 edit Differences ... ==== //depot/projects/ctsrd/beribsd/src/sys/mips/conf/BERI_MDROOT#2 (text+ko) ==== @@ -44,7 +44,7 @@ # options MD_ROOT # MD is a potential root device options MD_ROOT_SIZE=8192 -makeoptions MFS_IMAGE=/local/scratch/rnw24/root.img +makeoptions MFS_IMAGE=/local/scratch/rnw24/mdroot.img options ROOTDEVNAME=\"ufs:md0\" device altera_jtag_uart