Browse Source

Plan 9 from Bell Labs 2007-06-07

David du Colombier 13 years ago
parent
commit
69a89d3067

+ 7 - 8
dist/replica/_plan9.db

@@ -71,7 +71,7 @@
 386/bin/auth/rsafill - 775 sys sys 1168402273 143968
 386/bin/auth/rsagen - 775 sys sys 1178568249 151953
 386/bin/auth/secretpem - 775 sys sys 1045537944 118526
-386/bin/auth/secstore - 775 sys sys 1180468712 195983
+386/bin/auth/secstore - 775 sys sys 1181100215 195887
 386/bin/auth/secstored - 775 sys sys 1180468713 197571
 386/bin/auth/secuser - 775 sys sys 1180468714 152765
 386/bin/auth/status - 775 sys sys 1020319060 738
@@ -5821,7 +5821,7 @@ sys/games - 20000000775 sys sys 1117225532 0
 sys/games/lib - 20000000775 sys sys 1165337608 0
 sys/games/lib/4scores - 10000000666 sys sys 1118680448 0
 sys/games/lib/5scores - 10000000666 sys sys 1118680453 0
-sys/games/lib/fortunes - 664 sys sys 1181057665 265556
+sys/games/lib/fortunes - 664 sys sys 1181172615 265729
 sys/games/lib/mahjongg - 20000000775 sys sys 1095792278 0
 sys/games/lib/mahjongg/backgrounds - 20000000775 sys sys 1095792293 0
 sys/games/lib/mahjongg/backgrounds/default.bit - 664 sys sys 1095792293 346803
@@ -7621,7 +7621,7 @@ sys/man/2/string - 664 sys sys 1055701090 5306
 sys/man/2/stringsize - 664 sys sys 952627482 1409
 sys/man/2/subfont - 664 sys sys 956345937 5140
 sys/man/2/symbol - 664 sys sys 950892874 9423
-sys/man/2/thread - 664 sys sys 1175868879 11642
+sys/man/2/thread - 664 sys sys 1181168564 11712
 sys/man/2/time - 664 sys sys 1015091527 739
 sys/man/2/tmpfile - 664 sys sys 1048637161 1157
 sys/man/2/wait - 664 sys sys 1163004064 2525
@@ -7810,7 +7810,7 @@ sys/man/8/nfsserver - 664 sys sys 1163208425 3587
 sys/man/8/pcmcia - 664 sys sys 944959679 408
 sys/man/8/pem - 664 sys sys 1060263669 1189
 sys/man/8/ping - 664 sys sys 1169105315 3650
-sys/man/8/plan9.ini - 664 sys sys 1173993823 22729
+sys/man/8/plan9.ini - 664 sys sys 1181169193 23242
 sys/man/8/pop3 - 664 sys sys 1063854676 2720
 sys/man/8/ppp - 664 sys sys 1125530075 4414
 sys/man/8/prep - 664 sys sys 1152729153 14013
@@ -8017,7 +8017,7 @@ sys/src/9/mtx/trap.c - 664 sys sys 1105030157 15882
 sys/src/9/mtx/uarti8250.c - 664 sys sys 1018721288 11590
 sys/src/9/pc - 20000000775 sys sys 1161233143 0
 sys/src/9/pc/a100p.cp - 444 sys sys 1159735144 21984
-sys/src/9/pc/ahci.h - 664 sys sys 1178833481 6297
+sys/src/9/pc/ahci.h - 664 sys sys 1181155864 6287
 sys/src/9/pc/apbootstrap.s - 664 sys sys 1131293655 3037
 sys/src/9/pc/apic.c - 664 sys sys 1174415344 8991
 sys/src/9/pc/apm.c - 664 sys sys 1131290210 3723
@@ -8064,7 +8064,7 @@ sys/src/9/pc/etherigbe.c - 664 sys sys 1168306113 44967
 sys/src/9/pc/etherm10g.c - 664 sys sys 1174595240 27681
 sys/src/9/pc/etherm10g2k.i - 664 sys sys 1174590427 957485
 sys/src/9/pc/etherm10g4k.i - 664 sys sys 1174590430 926959
-sys/src/9/pc/ethermii.c - 664 sys sys 1168306129 4651
+sys/src/9/pc/ethermii.c - 664 sys sys 1181160689 4668
 sys/src/9/pc/ethermii.h - 664 sys sys 1086873891 3258
 sys/src/9/pc/etherrhine.c - 664 sys sys 1081706478 13799
 sys/src/9/pc/ethersink.c - 664 sys sys 1048644103 1076
@@ -8114,7 +8114,7 @@ sys/src/9/pc/screen.c - 664 sys sys 1136336092 13971
 sys/src/9/pc/screen.h - 664 sys sys 1147023549 4256
 sys/src/9/pc/sd53c8xx.c - 664 sys sys 1170456695 55276
 sys/src/9/pc/sd53c8xx.n - 664 sys sys 1131290556 12657
-sys/src/9/pc/sd63xxesb.c - 664 sys sys 1178836359 35774
+sys/src/9/pc/sd63xxesb.c - 664 sys sys 1181160430 35976
 sys/src/9/pc/sdata.c - 664 sys sys 1175564140 52809
 sys/src/9/pc/sdmv50xx.c - 664 sys sys 1177393607 33810
 sys/src/9/pc/sdmylex.c - 664 sys sys 1171321627 28237
@@ -15840,4 +15840,3 @@ usr/glenda/lib/profile - 664 glenda glenda 1105128663 890
 usr/glenda/readme.acme - 664 glenda glenda 1019860628 4753
 usr/glenda/readme.rio - 664 glenda glenda 1019860628 6370
 usr/glenda/tmp - 20000000775 glenda glenda 1018802620 0
-386/bin/auth/secstore - 775 sys sys 1181100215 195887

+ 6 - 6
dist/replica/plan9.db

@@ -5821,7 +5821,7 @@ sys/games - 20000000775 sys sys 1117225532 0
 sys/games/lib - 20000000775 sys sys 1165337608 0
 sys/games/lib/4scores - 10000000666 sys sys 1118680448 0
 sys/games/lib/5scores - 10000000666 sys sys 1118680453 0
-sys/games/lib/fortunes - 664 sys sys 1181057665 265556
+sys/games/lib/fortunes - 664 sys sys 1181172615 265729
 sys/games/lib/mahjongg - 20000000775 sys sys 1095792278 0
 sys/games/lib/mahjongg/backgrounds - 20000000775 sys sys 1095792293 0
 sys/games/lib/mahjongg/backgrounds/default.bit - 664 sys sys 1095792293 346803
@@ -7621,7 +7621,7 @@ sys/man/2/string - 664 sys sys 1055701090 5306
 sys/man/2/stringsize - 664 sys sys 952627482 1409
 sys/man/2/subfont - 664 sys sys 956345937 5140
 sys/man/2/symbol - 664 sys sys 950892874 9423
-sys/man/2/thread - 664 sys sys 1175868879 11642
+sys/man/2/thread - 664 sys sys 1181168564 11712
 sys/man/2/time - 664 sys sys 1015091527 739
 sys/man/2/tmpfile - 664 sys sys 1048637161 1157
 sys/man/2/wait - 664 sys sys 1163004064 2525
@@ -7810,7 +7810,7 @@ sys/man/8/nfsserver - 664 sys sys 1163208425 3587
 sys/man/8/pcmcia - 664 sys sys 944959679 408
 sys/man/8/pem - 664 sys sys 1060263669 1189
 sys/man/8/ping - 664 sys sys 1169105315 3650
-sys/man/8/plan9.ini - 664 sys sys 1173993823 22729
+sys/man/8/plan9.ini - 664 sys sys 1181169193 23242
 sys/man/8/pop3 - 664 sys sys 1063854676 2720
 sys/man/8/ppp - 664 sys sys 1125530075 4414
 sys/man/8/prep - 664 sys sys 1152729153 14013
@@ -8017,7 +8017,7 @@ sys/src/9/mtx/trap.c - 664 sys sys 1105030157 15882
 sys/src/9/mtx/uarti8250.c - 664 sys sys 1018721288 11590
 sys/src/9/pc - 20000000775 sys sys 1161233143 0
 sys/src/9/pc/a100p.cp - 444 sys sys 1159735144 21984
-sys/src/9/pc/ahci.h - 664 sys sys 1178833481 6297
+sys/src/9/pc/ahci.h - 664 sys sys 1181155864 6287
 sys/src/9/pc/apbootstrap.s - 664 sys sys 1131293655 3037
 sys/src/9/pc/apic.c - 664 sys sys 1174415344 8991
 sys/src/9/pc/apm.c - 664 sys sys 1131290210 3723
@@ -8064,7 +8064,7 @@ sys/src/9/pc/etherigbe.c - 664 sys sys 1168306113 44967
 sys/src/9/pc/etherm10g.c - 664 sys sys 1174595240 27681
 sys/src/9/pc/etherm10g2k.i - 664 sys sys 1174590427 957485
 sys/src/9/pc/etherm10g4k.i - 664 sys sys 1174590430 926959
-sys/src/9/pc/ethermii.c - 664 sys sys 1168306129 4651
+sys/src/9/pc/ethermii.c - 664 sys sys 1181160689 4668
 sys/src/9/pc/ethermii.h - 664 sys sys 1086873891 3258
 sys/src/9/pc/etherrhine.c - 664 sys sys 1081706478 13799
 sys/src/9/pc/ethersink.c - 664 sys sys 1048644103 1076
@@ -8114,7 +8114,7 @@ sys/src/9/pc/screen.c - 664 sys sys 1136336092 13971
 sys/src/9/pc/screen.h - 664 sys sys 1147023549 4256
 sys/src/9/pc/sd53c8xx.c - 664 sys sys 1170456695 55276
 sys/src/9/pc/sd53c8xx.n - 664 sys sys 1131290556 12657
-sys/src/9/pc/sd63xxesb.c - 664 sys sys 1178836359 35774
+sys/src/9/pc/sd63xxesb.c - 664 sys sys 1181160430 35976
 sys/src/9/pc/sdata.c - 664 sys sys 1175564140 52809
 sys/src/9/pc/sdmv50xx.c - 664 sys sys 1177393607 33810
 sys/src/9/pc/sdmylex.c - 664 sys sys 1171321627 28237

+ 8 - 0
dist/replica/plan9.log

@@ -49137,3 +49137,11 @@
 1181071824 1 c sys/src/cmd/ip/6in4.c - 664 sys sys 1181070455 7744
 1181084422 0 c sys/src/9/pc/devvga.c - 664 sys sys 1181083003 9334
 1181100623 0 c 386/bin/auth/secstore - 775 sys sys 1181100215 195887
+1181156423 0 c sys/src/9/pc/ahci.h - 664 sys sys 1181155864 6287
+1181161823 0 c sys/src/9/pc/ethermii.c - 664 sys sys 1181160689 4668
+1181161823 1 c sys/src/9/pc/sd63xxesb.c - 664 sys sys 1181160430 35976
+1181167223 0 c sys/man/8/plan9.ini - 664 sys sys 1181166067 23043
+1181169023 0 c sys/man/2/thread - 664 sys sys 1181168564 11712
+1181169023 1 c sys/man/8/plan9.ini - 664 sys sys 1181167491 23243
+1181170824 0 c sys/man/8/plan9.ini - 664 sys sys 1181169193 23242
+1181172622 0 c sys/games/lib/fortunes - 664 sys sys 1181172615 265729

+ 1 - 0
sys/games/lib/fortunes

@@ -4183,3 +4183,4 @@ Subject: Re: [9fans] speaking of kenc... can you imagine a c compiler that does
 I expect to be quite wealthy once the dust from the Linux IPOs has settled.  - Eric Raymond, "Doing It For the Cause", December 1999
 A handful of characteristics of Unix are responsible for its resilience. First, Unix is simple: whereas some operating systems implement thousands of system calls and have unclear design goals, Unix systems typically implement only hundreds of system calls and have a very clear design. -- Linux Kernel Development, 2nd Ed. by Robert Love
 IF YOU CAN HEAR THUNDER...YOU ARE CLOSE ENOUGH TO BE STRUCK BY LIGHTNING.
+If you go and talk to our people and ask why they are doing something, they will give you a good reason why they are doing it.  - Ravi Sethi, President, Avaya Labs Research

+ 4 - 0
sys/man/2/thread

@@ -569,6 +569,10 @@ functions for debugging threaded programs.
 .PP
 .B /sys/src/libthread/example.c
 contains a full example program.
+.PP
+.B /mnt/temp
+is used as a place to create pipes by
+.IR procexec .
 .SH SOURCE
 .B /sys/src/libthread
 .SH SEE ALSO

+ 42 - 20
sys/man/8/plan9.ini

@@ -66,7 +66,7 @@ Probing stops when a card is found or there is no line for
 .BR etherX+1 .
 After probing as directed by the
 .BI ether X
-lines, any remaining ethernet cards that can be automatically
+lines, any remaining Ethernet cards that can be automatically
 detected are added.
 Almost all cards can be automatically detected.
 For debugging purposes, automatic probing can
@@ -74,27 +74,34 @@ be disabled by specifying the line
 .BR *noetherprobe= .
 This automatic probing is only done by the kernel, not by
 .IR 9load (8).
-Thus, if you want to load a kernel over the ethernet, you need
+Thus, if you want to load a kernel over the Ethernet, you need
 to specify an
 .B ether0
 line so that
 .I 9load
-can find the ethernet card, even if the kernel would
+can find the Ethernet card, even if the kernel would
 have automatically detected it.
 .PP
 Some cards are software configurable and do not require all options.
 Unspecified options default to the factory defaults.
 .PP
 Known types are
-.TF ga620
+.\" .TF ga620
+.TF vt6102
 .PD
 .TP
 .B igbe
 The Intel 8254X Gigabit Ethernet controllers,
 as found on the Intel PRO/1000 adapters for copper (not fiber).
+Completely configurable.
+.TP
+.B i82563
+The Intel 82563 Gigabit Ethernet controller.
+Completely configurable.
 .TP
 .B rtl8169
 The Realtek 8169 Gigabit Ethernet controller.
+Completely configurable.
 .TP
 .B ga620
 Netgear GA620 and GA620T Gigabit Ethernet cards,
@@ -103,9 +110,20 @@ Alteon Acenic fiber and copper cards,
 the DEC DEGPA-SA and the SGI Acenic.
 Completely configurable.
 .TP
-.B 83820
-National Semiconductor DP83820-based gigabit ethernet adapters, notably
+.B dp83820
+National Semiconductor DP83820-based Gigabit Ethernet adapters, notably
 the D-Link DGE-500T.
+Completely configurable.
+.TP
+.B vt6102
+The VIA VT6102 Fast Ethernet Controller (Rhine II).
+.TP
+.B vgbe
+The VIA Velocity Gigabit Ethernet controller.
+Known to drive the VIA8237 (ABIT AV8), but at 100Mb/s full-duplex only.
+.TP
+.B m10g
+The Myricom 10-Gigabit Ethernet controllers.
 .TP
 .B i82557
 Cards using the Intel 8255[789] Fast Ethernet PCI Bus LAN Controller such as the
@@ -123,6 +141,7 @@ one of the options (no value)
 .BR 100BASE-FX ,
 or
 .BR 100BASE-FXFD .
+Completely configurable.
 .TP
 .B 2114x
 Cards using the Digital Equipment (now Intel) 2114x PCI Fast Ethernet Adapter Controller,
@@ -140,13 +159,15 @@ near-clone chips may also work.
 National Semiconductor DP83815-based adapters, notably
 the Netgear FA311, Netgear FA312, and various SiS built-in
 controllers such as the SiS900.
-On the SiS controllers, the ethernet address is not detected properly;
+On the SiS controllers, the Ethernet address is not detected properly;
 specify it with an
 .B ea=
 attribute.
+Completely configurable.
 .TP
 .B rtl8139
 The Realtek 8139 Fast Ethernet controller.
+Completely configurable.
 .TP
 .B smc91cxx
 SMC 91cXX chip-based PCMCIA adapters, notably the SMC EtherEZ card.
@@ -229,7 +250,7 @@ is needed on some (near) clones to turn off a dummy remote read in the driver.
 .TP
 .B amd79c970
 The AMD PCnet PCI Ethernet Adapter (AM79C970).
-(This is the ethernet adapter used by VMware.)
+(This is the Ethernet adapter used by VMware.)
 Completely configurable, no options need be given.
 .TP
 .B wd8003
@@ -244,10 +265,10 @@ BUG: On many machines only the 16 bit card works.
 .B sink
 A
 .B /dev/null
-for ethernet packets \(em the interface discards sent
+for Ethernet packets \(em the interface discards sent
 packets and never receives any.
 This is used to provide a test bed for
-some experimental ethernet bridging software.
+some experimental Ethernet bridging software.
 .TP
 .B wavelan
 Lucent Wavelan (Orinoco) IEEE 802.11b
@@ -255,7 +276,7 @@ and compatible PCMCIA cards.
 Compatible cards include the Dell TrueMobile 1150
 and the Linksys Instant Wireless Network PC Card.
 Port and IRQ defaults are 0x180 and 3 respectively.
-
+.IP
 These cards take a number of unique options to aid in
 identifying the card correctly on the 802.11b network.
 The network may be
@@ -293,7 +314,7 @@ where
 .I number
 lies in the range 1 to 16 inclusive;
 the channel is normally negotiated automatically.
-
+.IP
 If the card is capable of encryption,
 the following options may be used:
 .EX
@@ -333,7 +354,7 @@ If it is desired to exclude or include unencrypted packets
 	clear=[off, on]
 .EE
 configures reception and defaults to inclusion.
-
+.IP
 The defaults are intended to match the common case of
 a managed network with encryption and a typical entry would
 only require, for example
@@ -345,28 +366,29 @@ These options may be set after boot by writing to the device's
 .I ctl
 file using a space as the separator between option and value, e.g.
 .EX
-	echo 'key2 1d8f65c9a52d83c8e4b43f94af' > /net/ether0/0/ctl
+	echo 'key2 1d8f65c9a52d83c8e4b43f94af' >/net/ether0/0/ctl
 .EE
-
+.IP
 Card-specific power management may be enabled/disabled by
 .EX
 	pm=[on, off]
 .EE
 .TP
 .B wavelanpci
-PCI ethernet adapters that use the same Wavelan
+PCI Ethernet adapters that use the same Wavelan
 programming interface.
 Currently the only tested cards are those based on the
 Intersil Prism 2.5 chipset.
+.
 .SS \fLusbX=type=uhci port=xxx irq=xxx\fP
 This specifies the settings for a USB UHCI controller.
-Like the ethernet controllers, USB controllers are autodetected
+Like the Ethernet controllers, USB controllers are autodetected
 after scanning for the ones listed in
 .IR plan9.ini .
 Thus, most systems will not need a
 .B usbX
 line.
-Also like the ethernet controllers, USB autoprobing can be
+Also like the Ethernet controllers, USB autoprobing can be
 disabled by specifying the line
 .BR *nousbprobe= .
 .SS \fLscsiX=value\fP
@@ -376,14 +398,14 @@ by the kernel.
 Known types are
 .TP
 .B aha1542
-The Adaptec 154x series of controllers (and clones).
+Adaptec 154x series of controllers (and clones).
 Almost completely configurable, only the
 .EX
 	port=0x300
 .EE
 option need be given.
 .PP
-NCR/Symbios/LSI Logic 53c8xx-based adapters
+NCR/Symbios/LSI-Logic 53c8xx-based adapters
 and Mylex MultiMaster (Buslogic BT-*) adapters are
 automatically detected and need no entries.
 .PP

+ 15 - 15
sys/src/9/pc/ahci.h

@@ -15,7 +15,7 @@ enum{
 	Ewp	= 1<<6,		/* write protect */
 	Eicrc	= 1<<7,		/* interface crc error */
 
-	Efatal	= Eidnf|Eicrc,	/* must sw reset. */
+	Efatal	= Eidnf|Eicrc,	/* must sw reset */
 };
 
 /* ata status */
@@ -55,7 +55,7 @@ enum{
 	Hsalp	= 1<<26,	/* aggressive link pm */
 	Hsal	= 1<<25,	/* activity led */
 	Hsclo	= 1<<24,	/* command-list override */
-	Hiss	= 1<<20,	/* for interface speed. */
+	Hiss	= 1<<20,	/* for interface speed */
 //	Hsnzo	= 1<<19,
 	Hsam	= 1<<18,	/* ahci-mode only */
 	Hspm	= 1<<17,	/* port multiplier */
@@ -66,7 +66,7 @@ enum{
 	Hncs	= 1<<8,		/* n command slots */
 	Hcccs	= 1<<7,		/* coal */
 	Hems	= 1<<6,		/* enclosure mgmt. */
-	Hsxs	= 1<<5,		/* external sata. */
+	Hsxs	= 1<<5,		/* external sata */
 	Hnp	= 1<<0,		/* n ports */
 };
 
@@ -81,9 +81,9 @@ typedef struct{
 	u32int	cap;
 	u32int	ghc;
 	u32int	isr;
-	u32int	pi;	/* ports implemented */
+	u32int	pi;		/* ports implemented */
 	u32int	ver;
-	u32int	ccc;	/* coaleasing control */
+	u32int	ccc;		/* coaleasing control */
 	u32int	cccports;
 	u32int	emloc;
 	u32int	emctl;
@@ -96,7 +96,7 @@ enum{
 	Ahbds	= 1<<28,	/* hba error (parity error) */
 	Aifs	= 1<<27,	/* interface fatal  §6.1.2 */
 	Ainfs	= 1<<26,	/* interface error (recovered) */
-	Aofs	= 1<<24,	/* too many bytes from disk. */
+	Aofs	= 1<<24,	/* too many bytes from disk */
 	Aipms	= 1<<23,	/* incorrect prt mul status */
 	Aprcs	= 1<<22,	/* PhyRdy change status Pxserr.diag.n */
 	Adpms	= 1<<7,		/* mechanical presence status */
@@ -106,10 +106,10 @@ enum{
 	Asdbs	= 1<<3,		/* set device bits fis received w/ i bit set */
 	Adss	= 1<<2,		/* dma setup */
 	Apio	= 1<<1,		/* pio setup fis */
-	Adhrs	= 1<<0,		/* device to host register fis. */
+	Adhrs	= 1<<0,		/* device to host register fis */
 
 	IEM	= Acpds|Atfes|Ahbds|Ahbfs|Ahbds|Aifs|Ainfs|Aprcs|Apcs|Adps|
-		  Aufs|Asdbs|Adss|Adhrs,
+			Aufs|Asdbs|Adss|Adhrs,
 	Ifatal	= Atfes|Ahbfs|Ahbds|Aifs,
 };
 
@@ -135,8 +135,8 @@ enum{
 	ErrI	= 1<<0,		/* recovered data integrety */
 
 	ErrAll	= ErrE|ErrP|ErrC|ErrT|ErrM|ErrI,
-	SerrAll	= SerrX|SerrF|SerrT|SerrS|SerrH|SerrC|SerrD|SerrB|SerrW|SerrI|
-		  SerrN|ErrAll,
+	SerrAll	= SerrX|SerrF|SerrT|SerrS|SerrH|SerrC|SerrD|SerrB|SerrW|
+			SerrI|SerrN|ErrAll,
 	SerrBad	= 0x7f<<19,
 };
 
@@ -157,10 +157,10 @@ enum{
 	Afr	= 1<<14,	/* fis running */
 	Ampss	= 1<<13,	/* mechanical presence switch state */
 	Accs	= 1<<8,		/* current command slot 12:08 */
-	Afre	= 1<<4,		/* fis enable receive. */
+	Afre	= 1<<4,		/* fis enable receive */
 	Aclo	= 1<<3,		/* command list override */
-	Apod	= 1<<2,		/* power on device (needs cold-pres. detect) */
-	Asud	= 1<<1,		/* spin-up device;  requires ss capability. */
+	Apod	= 1<<2,		/* power on dev (requires cold-pres. detect) */
+	Asud	= 1<<1,		/* spin-up device;  requires ss capability */
 	Ast	= 1<<0,		/* start */
 
 	Arun	= Ast|Acr|Afre|Afr,
@@ -170,7 +170,7 @@ enum{
 enum{
 	Aipm	= 1<<8,		/* interface power mgmt. 3=off */
 	Aspd	= 1<<4,
-	Adet	= 1<<0,		/* device detcection. */
+	Adet	= 1<<0,		/* device detection */
 };
 
 #define	sstatus	scr0
@@ -181,7 +181,7 @@ enum{
 typedef struct{
 	u32int	list;		/* PxCLB must be 1kb aligned. */
 	u32int	listhi;
-	u32int	fis;		/* 256-byte aligned. */
+	u32int	fis;		/* 256-byte aligned */
 	u32int	fishi;
 	u32int	isr;
 	u32int	ie;		/* interrupt enable */

+ 7 - 9
sys/src/9/pc/ethermii.c

@@ -174,15 +174,14 @@ miistatus(Mii* mii)
 	 * (Read status twice as the Ls bit is sticky).
 	 */
 	bmsr = mii->mir(mii, phyno, Bmsr);
-	if(!(bmsr & (BmsrAnc|BmsrAna)))
-{
-print("miistatus: auto-neg incomplete\n");
+	if(!(bmsr & (BmsrAnc|BmsrAna))) {
+		// print("miistatus: auto-neg incomplete\n");
 		return -1;
-}
+	}
 
 	bmsr = mii->mir(mii, phyno, Bmsr);
 	if(!(bmsr & BmsrLs)){
-print("miistatus: link down\n");
+		// print("miistatus: link down\n");
 		phy->link = 0;
 		return -1;
 	}
@@ -214,11 +213,10 @@ print("miistatus: link down\n");
 		else if(r & Ana10HD)
 			phy->speed = 10;
 	}
-	if(phy->speed == 0)
-{
-print("miistatus: phy speed 0\n");
+	if(phy->speed == 0) {
+		// print("miistatus: phy speed 0\n");
 		return -1;
-}
+	}
 
 	if(phy->fd){
 		p = phy->fc;

+ 135 - 131
sys/src/9/pc/sd63xxesb.c

@@ -15,7 +15,7 @@
 
 #define	dprint(...)	if(debug == 1)	iprint(__VA_ARGS__); else USED(debug)
 #define	idprint(...)	if(prid == 1)	print(__VA_ARGS__); else USED(prid)
-#define	aprint(...)	if(datapi == 1)	iprint(__VA_ARGS__); else USED(datapi);
+#define	aprint(...)	if(datapi == 1)	iprint(__VA_ARGS__); else USED(datapi)
 
 enum{
 	NCtlr	= 4,
@@ -26,7 +26,7 @@ enum{
 	Write,
 };
 
-/* pci space configurtion */
+/* pci space configuration */
 enum{
 	Pmap	= 0x90,
 	Ppcs	= 0x91,
@@ -88,7 +88,7 @@ typedef struct{
 	char	name[10];
 	Aport	*port;
 	Aportm	portm;
-	Aportc	portc;		/* redundant ptr to port and portm. */
+	Aportc	portc;	/* redundant ptr to port and portm. */
 
 	uchar	mediachange;
 	uchar	state;
@@ -97,7 +97,7 @@ typedef struct{
 	uvlong	sectors;
 	ulong	intick;
 	int	wait;
-	uchar	mode;		/* DMautoneg, satai or sataii. */
+	uchar	mode;	/* DMautoneg, satai or sataii. */
 	uchar	active;
 
 	char	serial[20+1];
@@ -107,7 +107,7 @@ typedef struct{
 	ushort	info[0x200];
 
 	int	driveno;	/* ctlr*NCtlrdrv + unit */
-	/* ctlr port # != driveno when not all ports are enabled */
+	/* controller port # != driveno when not all ports are enabled */
 	int	portno;
 }Drive;
 
@@ -138,7 +138,7 @@ static	int	niadrive;
 
 static	int	debug;
 static	int	prid = 1;
-static	int	datapi = 1;
+static	int	datapi = 0;
 
 static char stab[] = {
 [0]	'i', 'm',
@@ -153,7 +153,7 @@ serrstr(ulong r, char *s, char *e)
 
 	e -= 3;
 	for(i = 0; i < nelem(stab) && s < e; i++)
-		if((r & (1<<i)) && stab[i]){
+		if(r & (1<<i) && stab[i]){
 			*s++ = stab[i];
 			if(SerrBad & (1<<i))
 				*s++ = '*';
@@ -207,7 +207,7 @@ ahciclear(void *v)
 	Asleep *s;
 
 	s = v;
-	return (s->p->ci & s->i) == 0;
+	return (s->p->ci&s->i) == 0;
 }
 
 static void
@@ -256,7 +256,7 @@ nop(Aportc *pc)
 	c[7] = 0xa0;		/* obsolete device bits */
 
 	l = pc->m->list;
-	l->flags = Lwrite|0x5;
+	l->flags = Lwrite | 0x5;
 	l->len = 0;
 	l->ctab = PCIWADDR(t);
 	l->ctabhi = 0;
@@ -282,7 +282,7 @@ setfeatures(Aportc *pc, uchar f)
 	c[7] = 0xa0;		/* obsolete device bits */
 
 	l = pc->m->list;
-	l->flags = Lwrite|0x5;
+	l->flags = Lwrite | 0x5;
 	l->len = 0;
 	l->ctab = PCIWADDR(t);
 	l->ctabhi = 0;
@@ -306,10 +306,10 @@ setudmamode(Aportc *pc, uchar f)
 	c[2] = 0xef;
 	c[3] = 3;		/* set transfer mode */
 	c[7] = 0xa0;		/* obsolete device bits */
-	c[12] = 0x40|f;		/* sector count */
+	c[12] = 0x40 | f;	/* sector count */
 
 	l = pc->m->list;
-	l->flags = Lwrite|0x5;
+	l->flags = Lwrite | 0x5;
 	l->len = 0;
 	l->ctab = PCIWADDR(t);
 	l->ctabhi = 0;
@@ -336,12 +336,11 @@ ahciportreset(Aportc *c)
 	cmd = &p->cmd;
 	*cmd &= ~(Afre|Ast);
 	for(i = 0; i < 500; i += 25){
-		if((*cmd & Acr) == 0)
+		if((*cmd&Acr) == 0)
 			break;
 		asleep(25);
 	}
-
-	p->sctl = 1 | (p->sctl & ~7);
+	p->sctl = 1|(p->sctl&~7);
 	delay(1);
 	p->sctl &= ~7;
 	return 0;
@@ -364,7 +363,7 @@ smart(Aportc *pc, int n)
 	c[0] = 0x27;
 	c[1] = 0x80;
 	c[2] = 0xb0;
-	c[3] = 0xd8+n;		/* able smart */
+	c[3] = 0xd8 + n;	/* able smart */
 	c[5] = 0x4f;
 	c[6] = 0xc2;
 	c[7] = 0xa0;
@@ -429,7 +428,7 @@ flushcache(Aportc *pc)
 	Alist *l;
 	static uchar tab[2] = {0xe7, 0xea};
 
-	llba = pc->m->feat & Dllba? 1: 0;
+	llba = pc->m->feat&Dllba? 1: 0;
 	t = pc->m->ctab;
 	c = t->cfis;
 
@@ -468,8 +467,8 @@ gbit16(void *a)
 static u32int
 gbit32(void *a)
 {
-	uchar *i;
 	u32int j;
+	uchar *i;
 
 	i = a;
 	j  = i[3] << 24;
@@ -495,7 +494,7 @@ ahciidentify0(Aportc *pc, void *id, int atapi)
 	Actab *t;
 	Alist *l;
 	Aprdt *p;
-	static uchar tab[] = {0xec, 0xa1};
+	static uchar tab[] = { 0xec, 0xa1, };
 
 	t = pc->m->ctab;
 	c = t->cfis;
@@ -533,7 +532,7 @@ ahciidentify(Aportc *pc, ushort *id)
 	m->smart = 0;
 	i = 0;
 	sig = pc->p->sig >> 16;
-	if(sig == 0xeb14 || sig == 0x9669){
+	if(sig == 0xeb14){
 		m->feat |= Datapi;
 		i = 1;
 	}
@@ -604,9 +603,9 @@ stop1:
 static int
 ahcicomreset(Aportc *pc)
 {
+	uchar *c;
 	Actab *t;
 	Alist *l;
-	uchar *c;
 
 	dprint("ahcicomreset\n");
 	dreg("comreset ", pc->p);
@@ -663,7 +662,7 @@ ahciidle(Aport *port)
 	u32int *p, i, r;
 
 	p = &port->cmd;
-	if((*p&Arun) == 0)
+	if((*p & Arun) == 0)
 		return 0;
 	*p &= ~Ast;
 	r = 0;
@@ -752,7 +751,7 @@ ahciconfigdrive(Ahba *h, Aportc *c, int mode)
 
 	if(p->sstatus & 3 && h->cap & Hsss){
 		dprint("configdrive:  spinning up ... [%ux]\n", p->sstatus);
-		p->cmd |= Apod | Asud;
+		p->cmd |= Apod|Asud;
 		asleep(1400);
 	}
 
@@ -762,13 +761,14 @@ ahciconfigdrive(Ahba *h, Aportc *c, int mode)
 	p->listhi = 0;
 	p->fis = PCIWADDR(m->fis.base);
 	p->fishi = 0;
-	p->cmd |= Afre | Ast;
+	p->cmd |= Afre|Ast;
 
 	/* disable power managment sequence from book. */
 	p->sctl = (3*Aipm) | (mode*Aspd) | 0*Adet;
 	p->cmd &= ~Aalpe;
 
 	p->ie = IEM;
+
 	return 0;
 }
 
@@ -871,18 +871,18 @@ identify(Drive *d)
 	d->sectors = s;
 	d->smartrs = 0;
 
-	idmove(d->serial, id + 10, 20);
-	idmove(d->firmware, id + 23, 8);
-	idmove(d->model, id + 27, 40);
+	idmove(d->serial, id+10, 20);
+	idmove(d->firmware, id+23, 8);
+	idmove(d->model, id+27, 40);
 
 	u = d->unit;
 	memset(u->inquiry, 0, sizeof u->inquiry);
 	u->inquiry[2] = 2;
 	u->inquiry[3] = 2;
-	u->inquiry[4] = sizeof u->inquiry-4;
+	u->inquiry[4] = sizeof u->inquiry - 4;
 	memmove(u->inquiry+8, d->model, 40);
 
-	if ((osectors == 0 || osectors != s) &&
+	if((osectors == 0 || osectors != s) &&
 	    memcmp(oserial, d->serial, sizeof oserial) != 0){
 		d->mediachange = 1;
 		u->sectors = 0;
@@ -893,10 +893,10 @@ identify(Drive *d)
 static void
 clearci(Aport *p)
 {
-	if((p->cmd & Ast) == 0)
-		return;
-	p->cmd &= ~Ast;
-	p->cmd |=  Ast;
+	if(p->cmd & Ast) {
+		p->cmd &= ~Ast;
+		p->cmd |=  Ast;
+	}
 }
 
 static void
@@ -921,14 +921,14 @@ updatedrive(Drive *d)
 		d->portm.flag |= Fdone;
 		wakeup(&d->portm);
 		pr = 0;
-	}else if(cause&Adps)
+	}else if(cause & Adps)
 		pr = 0;
-	if(cause&Ifatal){
+	if(cause & Ifatal){
 		ewake = 1;
 		dprint("Fatal\n");
 	}
-	if(cause&Adhrs){
-		if(p->task&33){
+	if(cause & Adhrs){
+		if(p->task & 33){
 			dprint("Adhrs cause = %ux; serr = %ux; task=%ux\n",
 				cause, serr, p->task);
 			d->portm.flag |= Ferror;
@@ -953,7 +953,7 @@ updatedrive(Drive *d)
 			break;
 		case 3:
 			/* power mgnt crap for suprise removal */
-			p->ie |= Aprcs | Apcs;	/* is this required? */
+			p->ie |= Aprcs|Apcs;	/* is this required? */
 			d->state = Dreset;
 			break;
 		case 4:
@@ -963,6 +963,8 @@ updatedrive(Drive *d)
 		dprint("%s: %s → %s [Apcrs] %ux\n", name, diskstates[s0],
 			diskstates[d->state], p->sstatus);
 		/* print pulled message here. */
+		if(s0 == Dready && d->state != Dready)
+			idprint("%s: pulled\n", name);
 		if(d->state != Dready)
 			d->portm.flag |= Ferror;
 		ewake = 1;
@@ -980,7 +982,7 @@ pstatus(Drive *d, ulong s)
 {
 	/*
 	 * bogus code because the first interrupt is currently dropped.
-	 * likely my fault.  serror is may be cleared at the wrong time.
+	 * likely my fault.  serror is maybe cleared at the wrong time.
 	 */
 	switch(s){
 	case 0:
@@ -988,7 +990,7 @@ pstatus(Drive *d, ulong s)
 		break;
 	case 2:			/* should this be missing?  need testcase. */
 		dprint("pstatus 2\n");
-		/* FALLTHROUGH */
+		/* fallthrough */
 	case 3:
 		d->wait = 0;
 		d->state = Dnew;
@@ -1019,7 +1021,7 @@ resetdisk(Drive *d)
 	p = d->port;
 	det = p->sctl & 7;
 	stat = p->sstatus & 7;
-	state = (p->cmd >> 28) & 0xf;
+	state = (p->cmd>>28) & 0xf;
 	dprint("resetdisk: icc %ux  det %d sdet %d\n", state, det, stat);
 	if(stat != 3){
 		ilock(d);
@@ -1031,15 +1033,15 @@ resetdisk(Drive *d)
 	state = d->state;
 	if(d->state != Dready || d->state != Dnew)
 		d->portm.flag |= Ferror;
-	clearci(p);			/* satisfy sleep condition */
+	clearci(p);			/* satisfy sleep condition. */
 	wakeup(&d->portm);
 	iunlock(d);
 
 	qlock(&d->portm);
 
-	if(p->cmd & Ast && ahciswreset(&d->portc) == -1){
+	if(p->cmd&Ast && ahciswreset(&d->portc) == -1){
 		ilock(d);
-		d->state = Dportreset;	/* get a bigger stick */
+		d->state = Dportreset;	/* get a bigger stick. */
 		iunlock(d);
 	} else {
 		ilock(d);
@@ -1071,16 +1073,16 @@ newdrive(Drive *d)
 	qlock(c->m);
 	if(setudmamode(c, 5) == -1){
 		dprint("%s: can't set udma mode\n", name);
-		goto loose;
+		goto lose;
 	}
 	if(identify(d) == -1){
 		dprint("%s: identify failure\n", name);
-		goto loose;
+		goto lose;
 	}
-	if(m->feat &Dpower && setfeatures(c, 0x85) == -1){
+	if(m->feat & Dpower && setfeatures(c, 0x85) == -1){
 		m->feat &= ~Dpower;
 		if(ahcirecover(c) == -1)
-			goto loose;
+			goto lose;
 	}
 
 	ilock(d);
@@ -1096,8 +1098,10 @@ newdrive(Drive *d)
 	idprint("  %s %s %s %s\n", d->model, d->firmware, d->serial,
 		d->mediachange?"[mediachange]":"");
 	return 0;
-loose:
-	qunlock(&d->portm);
+
+lose:
+//	qunlock(&d->portm);		/* shurely shome mishtake */
+	qunlock(c->m);
 	return -1;
 }
 
@@ -1111,7 +1115,7 @@ enum{
 static void
 westerndigitalhung(Drive *d)
 {
-	if ((d->portm.feat & Datapi) == 0 && d->active &&
+	if((d->portm.feat&Datapi) == 0 && d->active &&
 	    TK2MS(MACHP(0)->ticks-d->intick) > 5000){
 		dprint("%s: drive hung; resetting [%ux] ci=%x\n",
 			d->unit->name, d->port->task, d->port->ci);
@@ -1133,8 +1137,8 @@ doportreset(Drive *d)
 	else
 		i = 0;
 	qunlock(&d->portm);
-	dprint("portreset → %s  [task %ux]\n", diskstates[d->state],
-		d->port->task);
+	dprint("portreset → %s  [task %ux]\n",
+		diskstates[d->state], d->port->task);
 	return i;
 }
 
@@ -1148,14 +1152,15 @@ checkdrive(Drive *d, int i)
 	name = d->unit->name;
 	s = d->port->sstatus;
 	if(s != olds[i]){
-		dprint("%s: status: %04ux -> %04ux: %s\n", name, olds[i], s,
-			diskstates[d->state]);
+		dprint("%s: status: %04ux -> %04ux: %s\n",
+			name, olds[i], s, diskstates[d->state]);
 		olds[i] = s;
 		d->wait = 0;
 	}
 	westerndigitalhung(d);
 	switch(d->state){
 	case Dnull:
+	case Dready:
 		break;
 	case Dmissing:
 	case Dnew:
@@ -1166,7 +1171,7 @@ checkdrive(Drive *d, int i)
 		default:
 			dprint("%s: unknown status %04ux\n", name, s);
 		case 0x100:
-			if(++d->wait & Mphywait)
+			if(++d->wait&Mphywait)
 				break;
 reset:
 			if(++d->mode > DMsataii)
@@ -1182,36 +1187,39 @@ reset:
 			ilock(d);
 			break;
 		case 0x103:
-			if((++d->wait & Midwait) == 0){
+			if((++d->wait&Midwait) == 0){
 				dprint("%s: slow reset %04ux task=%ux; %d\n",
 					name, s, d->port->task, d->wait);
 				goto reset;
 			}
-			s = d->port->task & 0xff;
-			if(s == 0x7f || (s & ~0x17) != (1<<6))
+			s = d->port->task&0xff;
+			if(s == 0x7f || ((d->port->sig >> 16) != 0xeb14 &&
+			    (s & ~0x17) != (1<<6)))
 				break;
 			iunlock(d);
 			newdrive(d);
 			ilock(d);
+			break;
 		}
 		break;
-	case Dready:
-		break;
 	case Doffline:
 		if(d->wait++ & Mcomrwait)
 			break;
+		/* fallthrough */
 	case Derror:
 	case Dreset:
-		dprint("%s: reset [%s]: mode %d; status %04ux\n", name,
-			diskstates[d->state], d->mode, s);
+		dprint("%s: reset [%s]: mode %d; status %04ux\n",
+			name, diskstates[d->state], d->mode, s);
 		iunlock(d);
 		resetdisk(d);
 		ilock(d);
 		break;
 	case Dportreset:
 portreset:
-		dprint("%s: portreset [%s]: mode %d; status %04ux\n", name, 
-			diskstates[d->state], d->mode, s);
+		if(d->wait++ & 0xff && (s & 0x100) == 0)
+			break;
+		dprint("%s: portreset [%s]: mode %d; status %04ux\n",
+			name, diskstates[d->state], d->mode, s);
 		d->portm.flag |= Ferror;
 		clearci(d->port);
 		wakeup(&d->portm);
@@ -1233,7 +1241,7 @@ satakproc(void*)
 	int i;
 
 	memset(olds, 0xff, sizeof olds);
-	for (; ; ){
+	for(;;){
 		tsleep(&up->sleep, return0, 0, Nms);
 		for(i = 0; i < niadrive; i++)
 			checkdrive(iadrive[i], i);
@@ -1252,10 +1260,10 @@ iainterrupt(Ureg*, void *a)
 	ilock(c);
 	cause = c->hba->isr;
 	for(i = 0; i < c->ndrive; i++){
-		m = 1<<i;
+		m = 1 << i;
 		if((cause & m) == 0)
 			continue;
-		d = c->rawdrive+i;
+		d = c->rawdrive + i;
 		ilock(d);
 		if(d->port->isr && c->hba->pi & m)
 			updatedrive(d);
@@ -1285,8 +1293,8 @@ static int
 iaenable(SDev *s)
 {
 	char name[32];
-	Ctlr *c;
 	static int once;
+	Ctlr *c;
 
 	c = s->ctlr;
 	ilock(c);
@@ -1323,7 +1331,7 @@ iadisable(SDev *s)
 static int
 iaonline(SDunit *unit)
 {
-	ulong r;
+	int r;
 	Ctlr *c;
 	Drive *d;
 
@@ -1331,7 +1339,7 @@ iaonline(SDunit *unit)
 	d = c->drive[unit->subno];
 	r = 0;
 
-	if((d->portm.feat & Datapi) && d->mediachange){
+	if(d->portm.feat & Datapi && d->mediachange){
 		r = scsionline(unit);
 		if(r > 0)
 			d->mediachange = 0;
@@ -1348,7 +1356,6 @@ iaonline(SDunit *unit)
 	} else if(d->state == Dready)
 		r = 1;
 	iunlock(d);
-
 	return r;
 }
 
@@ -1357,15 +1364,14 @@ static Alist*
 ahcibuild(Aportm *m, uchar *cmd, void *data, int n, vlong lba)
 {
 	uchar *c, acmd, dir, llba;
-	Actab *t;
 	Alist *l;
+	Actab *t;
 	Aprdt *p;
-	static uchar tab[2][2] = {0xc8, 0x25, 0xca, 0x35};
+	static uchar tab[2][2] = { 0xc8, 0x25, 0xca, 0x35, };
 
 	dir = *cmd != 0x28;
-	llba = m->feat & Dllba? 1: 0;
+	llba = m->feat&Dllba? 1: 0;
 	acmd = tab[dir][llba];
-
 	qlock(m);
 	l = m->list;
 	t = m->ctab;
@@ -1381,10 +1387,10 @@ ahcibuild(Aportm *m, uchar *cmd, void *data, int n, vlong lba)
 	c[6] = lba >> 16;	/* cylinder hi		lba hi	23:16 */
 	c[7] = 0xa0 | 0x40;	/* obsolete device bits + lba */
 	if(llba == 0)
-		c[7] |= (lba >> 24) & 7;
+		c[7] |= (lba>>24) & 7;
 
-	c[8]  = lba >> 24;	/* sector (exp)		lba 	31:24 */
-	c[9]  = lba >> 32;	/* cylinder low (exp)	lba	39:32 */
+	c[8] = lba >> 24;	/* sector (exp)		lba 	31:24 */
+	c[9] = lba >> 32;	/* cylinder low (exp)	lba	39:32 */
 	c[10] = lba >> 48;	/* cylinder hi (exp)	lba	48:40 */
 	c[11] = 0;		/* features (exp); */
 
@@ -1415,8 +1421,8 @@ ahcibuildpkt(Aportm *m, SDreq *r, void *data, int n)
 {
 	int fill, len;
 	uchar *c;
-	Actab *t;
 	Alist *l;
+	Actab *t;
 	Aprdt *p;
 
 	qlock(m);
@@ -1424,7 +1430,7 @@ ahcibuildpkt(Aportm *m, SDreq *r, void *data, int n)
 	t = m->ctab;
 	c = t->cfis;
 
-	fill = m->feat & Datapi16? 16: 12;
+	fill = m->feat&Datapi16? 16: 12;
 	if((len = r->clen) > fill)
 		len = fill;
 	memmove(t->atapi, r->cmd, len);
@@ -1434,9 +1440,9 @@ ahcibuildpkt(Aportm *m, SDreq *r, void *data, int n)
 	c[1] = 0x80;
 	c[2] = 0xa0;
 	if(n != 0)
-		c[3] = 1;		/* dma */
+		c[3] = 1;	/* dma */
 	else
-		c[3] = 0;		/* features (exp); */
+		c[3] = 0;	/* features (exp); */
 
 	c[4] = 0;		/* sector		lba low	7:0 */
 	c[5] = n;		/* cylinder low		lba mid	15:8 */
@@ -1444,25 +1450,23 @@ ahcibuildpkt(Aportm *m, SDreq *r, void *data, int n)
 	c[7] = 0xa0;		/* obsolete device bits */
 
 	*(ulong*)(c + 8) = 0;
-//	c[8] =  lba >> 24;	/* sector (exp)		lba 	31:24 */
-//	c[9] =  lba >> 32;	/* cylinder low (exp)	lba	39:32 */
-//	c[10] = lba >> 48;	/* cylinder hi (exp)	lba	48:40 */
-//	c[11] = 0;
-
 	*(ulong*)(c + 12) = 0;
 	*(ulong*)(c + 16) = 0;
 
 	l->flags = 1<<16 | Lpref | Latapi | 0x5;
-	if(r->write != 0)
+	if(r->write != 0 && data)
 		l->flags |= Lwrite;
 	l->len = 0;
 	l->ctab = PCIWADDR(t);
 	l->ctabhi = 0;
 
+	if(data == 0)
+		return l;
+
 	p = &t->prdt;
 	p->dba = PCIWADDR(data);
 	p->dbahi = 0;
-	p->count = 1<<31 | (n-2) | 1;
+	p->count = 1<<31 | (n - 2) | 1;
 
 	return l;
 }
@@ -1506,7 +1510,8 @@ iariopkt(SDreq *r, Drive *d)
 	name = d->unit->name;
 	p = d->port;
 
-	aprint("%02ux %02ux\n", cmd[0], cmd[2]);
+	aprint("%02ux %02ux %c %d %p\n", cmd[0], cmd[2], "rw"[r->write],
+		r->dlen, r->data);
 	if(cmd[0] == 0x5a && (cmd[2] & 0x3f) == 0x3f)
 		return sdmodesense(r, cmd, d->info, sizeof d->info);
 	r->rlen = 0;
@@ -1559,7 +1564,7 @@ retry:
 		esleep(1000);
 		goto retry;
 	}
-	if(flag&Ferror){
+	if(flag & Ferror){
 		iprint("%s: i/o error %ux\n", name, task);
 		r->status = SDcheck;
 		return SDcheck;
@@ -1594,7 +1599,7 @@ iario(SDreq *r)
 	name = d->unit->name;
 	p = d->port;
 
-	if(r->cmd[0] == 0x35){
+	if(r->cmd[0] == 0x35 || r->cmd[0] == 0x91){
 		qlock(&d->portm);
 		i = flushcache(&d->portc);
 		qunlock(&d->portm);
@@ -1614,12 +1619,12 @@ iario(SDreq *r)
 		return SDcheck;
 	}
 
-	lba =   cmd[2]<<24 | cmd[3]<<16 | cmd[4]<<8 | cmd[5];
-	count = cmd[7]<<8  | cmd[8];
+	lba   = cmd[2]<<24 | cmd[3]<<16 | cmd[4]<<8 | cmd[5];
+	count = cmd[7]<<8 | cmd[8];
 	if(r->data == nil)
 		return SDok;
-	if(r->dlen < count*unit->secsize)
-		count = r->dlen/unit->secsize;
+	if(r->dlen < count * unit->secsize)
+		count = r->dlen / unit->secsize;
 	max = 128;
 
 	try = 0;
@@ -1652,8 +1657,8 @@ retry:
 		task = d->port->task;
 		iunlock(d);
 
-		if (task & (Efatal<<8) || task & (ASbsy|ASdrq) &&
-		    d->state == Dready){
+		if(task & (Efatal<<8) ||
+		    task & (ASbsy|ASdrq) && d->state == Dready){
 			d->port->ci = 0;	/* @? */
 			ahcirecover(&d->portc);
 			task = d->port->task;
@@ -1677,7 +1682,7 @@ retry:
 		}
 
 		count -= n;
-		lba += n;
+		lba   += n;
 		data += n * unit->secsize;
 	}
 	r->rlen = data - (uchar*)r->data;
@@ -1694,9 +1699,8 @@ iaahcimode(Pcidev *p)
 	dprint("iaahcimode %ux %ux %ux\n", pcicfgr8(p, 0x91), pcicfgr8(p, 92),
 		pcicfgr8(p, 93));
 	pcicfgw16(p, 0x92, pcicfgr32(p, 0x92) | 0xf);	/* ports 0-3 */
-//	pcicfgw8(p, 0x93,  pcicfgr32(p, 9x93) | 3);	/* ports 4-5 */
+//	pcicfgw8(p, 0x93, pcicfgr32(p, 9x93) | 3);	/* ports 4-5 */
 	return 0;
-
 }
 
 static void
@@ -1706,12 +1710,13 @@ iasetupahci(Ctlr *c)
 	pcicfgw16(c->pci, 0x40, pcicfgr16(c->pci, 0x40) & ~(1<<15));
 	pcicfgw16(c->pci, 0x42, pcicfgr16(c->pci, 0x42) & ~(1<<15));
 
-	c->lmmio[0x4/4] |=  1<<31;	/* enable ahci mode (ghc register) */
-	c->lmmio[0xc/4]  = (1<<6)-1;	/* 5 ports (supposedly ro pi reg) */
+	c->lmmio[0x4/4] |= 1<<31;	/* enable ahci mode (ghc register) */
+	c->lmmio[0xc/4] = (1<<6) - 1;	/* 5 ports. (supposedly ro pi reg.) */
 
 	/* enable ahci mode. */
 //	pcicfgw8(c->pci, 0x90, 0x40);
-	pcicfgw16(c->pci, 0x90, 1<<6 | 1<<5);	/* pedanticly proper for ich9 */
+//	pcicfgw16(c->pci, 0x90, 1<<6 | 1<<5); /* pedantically proper for ich9 */
+	pcicfgw8(c->pci, 0x90, 1<<6 | 1<<5);  /* pedantically proper for ich9 */
 }
 
 static SDev*
@@ -1729,13 +1734,11 @@ iapnp(void)
 		return nil;
 
 	p = nil;
-	head = nil;
-	tail = nil;
+	head = tail = nil;
 loop:
 	while((p = pcimatch(p, 0x8086, 0)) != nil){
-		if ((p->did&0xfffc) != 0x2680 &&	/* esb */
-		    (p->did&0xfffe) != 0x27c4)		/* 82801g[bh]m */
-			continue;
+		if((p->did & 0xfffc) != 0x2680 && (p->did & 0xfffe) != 0x27c4)
+			continue;		/* !esb && !82801g[bh]m */
 		if(niactlr == NCtlr){
 			print("iapnp: too many controllers\n");
 			break;
@@ -1747,8 +1750,8 @@ loop:
 		io = p->mem[Abar].bar & ~0xf;
 		c->mmio = vmap(io, p->mem[0].size);
 		if(c->mmio == 0){
-			print("iapnp: address 0x%luX in use did=%x\n", io,
-				p->did);
+			print("iapnp: address 0x%luX in use did=%x\n",
+				io, p->did);
 			continue;
 		}
 		c->lmmio = (ulong*)c->mmio;
@@ -1756,14 +1759,15 @@ loop:
 		if(p->did != 0x2681)
 			iasetupahci(c);
 		nunit = ahciconf(c);
-		/* ahcihbareset((Ahba*)c->mmio); */
+		// ahcihbareset((Ahba*)c->mmio);
 		if(iaahcimode(p) == -1)
 			break;
 		if(nunit < 1){
 			vunmap(c->mmio, p->mem[0].size);
 			continue;
 		}
-		i = (c->hba->cap >> 21) & 1;
+
+		i = (c->hba->cap>>21) & 1;
 		print("intel 63[12]xesb: sata-%s ports with %d ports\n",
 			"I\0II" + i*2, nunit);
 		s->ifc = &sd63xxesbifc;
@@ -1779,12 +1783,12 @@ loop:
 		memset(c->rawdrive, 0, sizeof c->rawdrive);
 		n = 0;
 		for(i = 0; i < NCtlrdrv; i++) {
-			d = c->rawdrive+i;
+			d = c->rawdrive + i;
 			d->portno = i;
 			d->driveno = -1;
 			d->sectors = 0;
 			d->ctlr = c;
-			if((c->hba->pi & (1 << i)) == 0)
+			if((c->hba->pi & (1<<i)) == 0)
 				continue;
 			d->port = (Aport*)(c->mmio + 0x80*i + 0x100);
 			d->portc.p = d->port;
@@ -1795,8 +1799,7 @@ loop:
 		}
 		for(i = 0; i < n; i++)
 			if(ahciidle(c->drive[i]->port) == -1){
-				dprint("intel 63[12]xesb: port %d wedged; abort\n",
-					i);
+				dprint("intel 63[12]xesb: port %d wedged; abort\n", i);
 				goto loop;
 			}
 		for(i = 0; i < n; i++){
@@ -1828,7 +1831,7 @@ pflag(char *s, char *e, uchar f)
 
 	for(i = 0; i < 8; i++){
 		m = 1 << i;
-		if(f & m)
+		if(f&m)
 			s = seprint(s, e, "%s ", flagname[i]);
 	}
 	return seprint(s, e, "\n");
@@ -1837,8 +1840,8 @@ pflag(char *s, char *e, uchar f)
 static int
 iarctl(SDunit *u, char *p, int l)
 {
-	char *e, *op;
 	char buf[32];
+	char *e, *op;
 	Aport *o;
 	Ctlr *c;
 	Drive *d;
@@ -1866,11 +1869,11 @@ iarctl(SDunit *u, char *p, int l)
 	}else
 		p = seprint(p, e, "no disk present [%s]\n", diskstates[d->state]);
 	serrstr(o->serror, buf, buf + sizeof buf - 1);
-	p = seprint(p, e, "reg\ttask %ux cmd %ux serr %ux %s ci %ux is %ux; sig %ux\n",
-		o->task, o->cmd, o->serror, buf, o->ci, o->isr, o->sig);
+	p = seprint(p, e, "reg\ttask %ux cmd %ux serr %ux %s ci %ux is %ux; "
+		"sig %ux sstatus %04x\n", o->task, o->cmd, o->serror, buf,
+		o->ci, o->isr, o->sig, o->sstatus);
 	p = seprint(p, e, "geometry %llud 512\n", d->sectors);
-
-	return p-op;
+	return p - op;
 }
 
 static void
@@ -1882,7 +1885,7 @@ runflushcache(Drive *d)
 	qlock(&d->portm);
 	flushcache(&d->portc);
 	qunlock(&d->portm);
-	dprint("flush in %ldms\n", TK2MS(MACHP(0)->ticks - t0));
+	dprint("flush in %ldms\n", TK2MS(MACHP(0)->ticks-t0));
 }
 
 static void
@@ -1929,11 +1932,12 @@ forcestate(Drive *d, char *state)
 	d->state = i;
 	if(i == Dnull){
 		d->mediachange = 1;
-		d->unit->sectors = 0;	/* force disk to disappear */
+		d->unit->sectors = 0;		/* force disk to disappear. */
 	}
 	iunlock(d);
 }
 
+
 static int
 iawctl(SDunit *u, Cmdbuf *cmd)
 {
@@ -2006,7 +2010,7 @@ portr(char *p, char *e, uint x)
 	p[0] = 0;
 	a = -1;
 	for(i = 0; i < 32; i++){
-		if((x & (1 << i)) == 0){
+		if((x & (1<<i)) == 0){
 			if(a != -1 && i - 1 != a)
 				p = seprint(p, e, "-%d", i - 1);
 			a = -1;
@@ -2055,10 +2059,10 @@ iartopctl(SDev *s, char *p, char *e)
 	has(Hsxs, "sxs ");
 	p = seprint(p, e, "\n");
 
-	p = seprint(p, e, "%s iss %d ncs %d np %d\n", name, (u >> 20) & 0xf,
-		(u >> 8) & 0x1f, 1 + (u & 0x1f));
+	p = seprint(p, e, "%s iss %d ncs %d np %d\n", name, (u>>20) & 0xf,
+		(u>>8) & 0x1f, 1 + (u & 0x1f));
 	h = c->hba;
-	portr(pr, pr+sizeof pr, h->pi);
+	portr(pr, pr + sizeof pr, h->pi);
 	p = seprint(p, e, "%s ghc %ux isr %ux pi %ux %s ver %ux\n",
 		name, h->ghc, h->isr, h->pi, pr, h->ver);
 	return p;
@@ -2067,8 +2071,8 @@ iartopctl(SDev *s, char *p, char *e)
 static int
 iawtopctl(SDev *, Cmdbuf *cmd)
 {
-	char **f;
 	int *v;
+	char **f;
 
 	f = cmd->f;
 	v = 0;