Re: hme: incorrect register endian for PCI sun hme devices?

2017-08-13 Thread Mark Cave-Ayland
On 13/08/17 16:52, Kaashif Hymabaccus wrote:

> Hello Mark,
> 
> I have a Sun Ultra 5 with the following dmesg:
> 
> console is /pci@1f,0/pci@1,1/ebus@1/se@14,40:a
> Copyright (c) 1982, 1986, 1989, 1991, 1993
>   The Regents of the University of California.  All rights reserved.
> Copyright (c) 1995-2017 OpenBSD. All rights reserved.  https://www.OpenBSD.org
> 
> OpenBSD 6.1-current (GENERIC) #225: Fri Aug 11 19:58:43 MDT 2017
> dera...@sparc64.openbsd.org:/usr/src/sys/arch/sparc64/compile/GENERIC
> real mem = 536870912 (512MB)
> avail mem = 512393216 (488MB)
> mpath0 at root
> scsibus0 at mpath0: 256 targets
> mainbus0 at root: Sun Ultra 5/10 UPA/PCI (UltraSPARC-IIi 270MHz)
> cpu0 at mainbus0: SUNW,UltraSPARC-IIi (rev 1.3) @ 269.802 MHz
> cpu0: physical 16K instruction (32 b/l), 16K data (32 b/l), 256K external (64 
> b/l)
> psycho0 at mainbus0 addr 0xfffc4000: SUNW,sabre, impl 0, version 0, ign 7c0
> psycho0: bus range 0-2, PCI bus 0
> psycho0: dvma map c000-dfff
> pci0 at psycho0
> ppb0 at pci0 dev 1 function 1 "Sun Simba" rev 0x11
> pci1 at ppb0 bus 1
> ebus0 at pci1 dev 1 function 0 "Sun PCIO EBus2" rev 0x01
> auxio0 at ebus0 addr 726000-726003, 728000-728003, 72a000-72a003, 
> 72c000-72c003, 72f000-72f003
> power0 at ebus0 addr 724000-724003 ivec 0x25
> "SUNW,pll" at ebus0 addr 504000-504002 not configured
> sab0 at ebus0 addr 40-40007f ivec 0x2b: rev 3.2
> sabtty0 at sab0 port 0: console
> sabtty1 at sab0 port 1
> comkbd0 at ebus0 addr 3083f8-3083ff ivec 0x29: no keyboard
> comms0 at ebus0 addr 3062f8-3062ff ivec 0x2a
> wsmouse0 at comms0 mux 0
> lpt0 at ebus0 addr 3043bc-3043cb, 30015c-30015d, 70-7f ivec 0x22: 
> polled
> "fdthree" at ebus0 addr 3023f0-3023f7, 706000-70600f, 72-720003 ivec 0x27 
> not configured
> clock1 at ebus0 addr 0-1fff: mk48t59
> "flashprom" at ebus0 addr 0-f not configured
> audioce0 at ebus0 addr 20-2000ff, 702000-70200f, 704000-70400f, 
> 722000-722003 ivec 0x23 ivec 0x24: nvaddrs 0
> audio0 at audioce0
> hme0 at pci1 dev 1 function 1 "Sun HME" rev 0x01: ivec 0x7e1, address 
> 08:00:20:19:39:20
> nsphy0 at hme0 phy 1: DP83840 10/100 PHY, rev. 1
> machfb0 at pci1 dev 2 function 0 "ATI Mach64" rev 0x9a
> machfb0: ATY,GT-B, 1152x900
> wsdisplay0 at machfb0 mux 1
> wsdisplay0: screen 0 added (std, sun emulation)
> pciide0 at pci1 dev 3 function 0 "CMD Technology PCI0646" rev 0x03: DMA, 
> channel 0 configured to native-PCI, channel 1 configured to native-PCI
> pciide0: using ivec 0x7e0 for native-PCI interrupt
> wd0 at pciide0 channel 0 drive 0: 
> wd0: 16-sector PIO, LBA48, 117800MB, 241254720 sectors
> wd0(pciide0:0:0): using PIO mode 4, DMA mode 2
> atapiscsi0 at pciide0 channel 1 drive 0
> scsibus1 at atapiscsi0: 2 targets
> cd0 at scsibus1 targ 0 lun 0:  ATAPI 5/cdrom 
> removable
> wd1 at pciide0 channel 1 drive 1: 
> wd1: 16-sector PIO, LBA, 19546MB, 40031712 sectors
> cd0(pciide0:1:0): using PIO mode 4, DMA mode 2
> wd1(pciide0:1:1): using PIO mode 4, DMA mode 2
> ppb1 at pci0 dev 1 function 0 "Sun Simba" rev 0x11
> pci2 at ppb1 bus 2
> vscsi0 at root
> scsibus2 at vscsi0: 256 targets
> softraid0 at root
> scsibus3 at softraid0: 256 targets
> bootpath: /pci@1f,0/pci@1,1/ide@3,0/disk@0,0
> root on wd0a (f52f0bbc65e53556.a) swap on wd0b dump on wd0b
> 
> It has a PCI hme card and it works great.
> 
> I would be happy to help if you want to test some diff or program, but
> I am not knowledgeable enough to comment on the inner workings of the
> hme driver.

Great, thanks for the information - the fact that the nsphy0 has been
detected correctly means that the access still works. Looks like I'll
have to go digging deeper.


ATB,

Mark.



Re: rtadvd: no longer decrement lifetimes in real time

2017-08-13 Thread Florian Obser
*prod*, while t2k17 is still on...

On Sat, Aug 12, 2017 at 06:26:44PM +, Florian Obser wrote:
> 
> Stop supporting prefix lifetimes that decrement in real time.
> It complicates the code, it's off by default and RFC 4861 section
> 6.2.1 lists it as MAY.
> After this we can stop regenerating the RA packets everytime we send
> them.
> 
> Also I'm not convinced that this has a use case. I think it
> comes from a fairy tale where renumbering is easy.
> Considering the two hour rule in RFC 4862 this might not actually
> work to begin with...
> 
> OK?
> 
> diff --git config.c config.c
> index 497fedbf562..62ce62c58d3 100644
> --- config.c
> +++ config.c
> @@ -212,14 +212,6 @@ getconfig(char *intface)
>  
>   /* prefix information */
>  
> - /*
> -  * This is an implementation specific parameter to consider
> -  * link propagation delays and poorly synchronized clocks when
> -  * checking consistency of advertised lifetimes.
> -  */
> - MAYHAVE(val, "clockskew", 0);
> - tmp->clockskew = val;
> -
>   tmp->pfxs = 0;
>   for (i = -1; i < MAXPREFIX; i++) {
>   struct prefix *pfx;
> @@ -278,14 +270,6 @@ getconfig(char *intface)
>  
>   pfx->validlifetime = (u_int32_t)val64;
>  
> - makeentry(entbuf, sizeof(entbuf), i, "vltimedecr");
> - if (agetflag(entbuf)) {
> - struct timeval now;
> - gettimeofday(, 0);
> - pfx->vltimeexpire =
> - now.tv_sec + pfx->validlifetime;
> - }
> -
>   makeentry(entbuf, sizeof(entbuf), i, "pltime");
>   MAYHAVE(val64, entbuf, DEF_ADVPREFERREDLIFETIME);
>   if (val64 < 0 || val64 > 0x)
> @@ -296,13 +280,6 @@ getconfig(char *intface)
>  
>   pfx->preflifetime = (u_int32_t)val64;
>  
> - makeentry(entbuf, sizeof(entbuf), i, "pltimedecr");
> - if (agetflag(entbuf)) {
> - struct timeval now;
> - gettimeofday(, 0);
> - pfx->pltimeexpire =
> - now.tv_sec + pfx->preflifetime;
> - }
>   }
>   if (tmp->pfxs == 0 && !agetflag("noifprefix"))
>   get_prefix(tmp);
> @@ -748,9 +725,6 @@ make_packet(struct rainfo *rainfo)
>   }
>  
>   TAILQ_FOREACH(pfx, >prefixes, entry) {
> - u_int32_t vltime, pltime;
> - struct timeval now;
> -
>   ndopt_pi = (struct nd_opt_prefix_info *)buf;
>   ndopt_pi->nd_opt_pi_type = ND_OPT_PREFIX_INFORMATION;
>   ndopt_pi->nd_opt_pi_len = 4;
> @@ -762,27 +736,9 @@ make_packet(struct rainfo *rainfo)
>   if (pfx->autoconfflg)
>   ndopt_pi->nd_opt_pi_flags_reserved |=
>   ND_OPT_PI_FLAG_AUTO;
> - if (pfx->vltimeexpire || pfx->pltimeexpire)
> - gettimeofday(, NULL);
> - if (pfx->vltimeexpire == 0)
> - vltime = pfx->validlifetime;
> - else
> - vltime = (u_int32_t)(pfx->vltimeexpire > now.tv_sec ?
> - pfx->vltimeexpire - now.tv_sec : 0);
> - if (pfx->pltimeexpire == 0)
> - pltime = pfx->preflifetime;
> - else
> - pltime = (u_int32_t)(pfx->pltimeexpire > now.tv_sec ?
> - pfx->pltimeexpire - now.tv_sec : 0);
> - if (vltime < pltime) {
> - /*
> -  * this can happen if vltime is decremented but pltime
> -  * is not.
> -  */
> - pltime = vltime;
> - }
> - ndopt_pi->nd_opt_pi_valid_time = htonl(vltime);
> - ndopt_pi->nd_opt_pi_preferred_time = htonl(pltime);
> +
> + ndopt_pi->nd_opt_pi_valid_time = htonl(pfx->validlifetime);
> + ndopt_pi->nd_opt_pi_preferred_time = htonl(pfx->preflifetime);
>   ndopt_pi->nd_opt_pi_reserved2 = 0;
>   ndopt_pi->nd_opt_pi_prefix = pfx->prefix;
>  
> diff --git dump.c dump.c
> index bccfad7a3fb..f4a7bd4b2cf 100644
> --- dump.c
> +++ dump.c
> @@ -113,7 +113,6 @@ rtadvd_dump(void)
>   int first;
>   struct timeval now, next;
>   char *origin, *vltime, *pltime, *flags;
> - char *vltimexpire, *pltimexpire;
>   char ctimebuf[26];
>  
>   gettimeofday(, NULL);
> @@ -164,9 +163,7 @@ rtadvd_dump(void)
>   log_info("  ReachableTime: %d, RetransTimer: %d, "
>   "CurHopLimit: %d", rai->reachabletime,
>   rai->retranstimer, rai->hoplimit);
> - if (rai->clockskew)
> - log_info("  Clock skew: %ldsec",
> - rai->clockskew);
> +
>   first = 1;
>   TAILQ_FOREACH(pfx, >prefixes, entry) {
>   if 

Re: no seqpacket in nfs

2017-08-13 Thread Ted Unangst
Alexander Bluhm wrote:
> On Sun, Aug 13, 2017 at 05:20:05PM -0400, Ted Unangst wrote:
> > -   if (nmp->nm_sotype != SOCK_STREAM)
> > -   panic("nfscon sotype");
> > +   } else {
> > +   panic("nfscon sotype");
> 
> This panic can be reached from user land with a manipulated mount_nfs
> program.  This happens without you diff.

here's a new version that pulls the check higher.


Index: nfs_socket.c
===
RCS file: /cvs/src/sys/nfs/nfs_socket.c,v
retrieving revision 1.123
diff -u -p -r1.123 nfs_socket.c
--- nfs_socket.c11 Aug 2017 21:24:20 -  1.123
+++ nfs_socket.c14 Aug 2017 03:01:48 -
@@ -240,6 +240,11 @@ nfs_connect(struct nfsmount *nmp, struct
struct sockaddr_in *sin;
struct mbuf *m;
 
+   if (!(nmp->nm_sotype == SOCK_DGRAM || nmp->nm_sotype == SOCK_STREAM)) {
+   error = EINVAL;
+   goto bad;
+   }
+
nmp->nm_so = NULL;
saddr = mtod(nmp->nm_nam, struct sockaddr *);
error = socreate(saddr->sa_family, >nm_so, nmp->nm_sotype, 
@@ -347,13 +352,7 @@ nfs_connect(struct nfsmount *nmp, struct
sndreserve = nmp->nm_wsize + NFS_MAXPKTHDR;
rcvreserve = (max(nmp->nm_rsize, nmp->nm_readdirsize) +
NFS_MAXPKTHDR) * 2;
-   } else if (nmp->nm_sotype == SOCK_SEQPACKET) {
-   sndreserve = (nmp->nm_wsize + NFS_MAXPKTHDR) * 2;
-   rcvreserve = (max(nmp->nm_rsize, nmp->nm_readdirsize) +
-   NFS_MAXPKTHDR) * 2;
-   } else {
-   if (nmp->nm_sotype != SOCK_STREAM)
-   panic("nfscon sotype");
+   } else if (nmp->nm_sotype == SOCK_STREAM) {
if (so->so_proto->pr_flags & PR_CONNREQUIRED) {
MGET(m, M_WAIT, MT_SOOPTS);
*mtod(m, int32_t *) = 1;
@@ -478,10 +477,7 @@ nfs_send(struct socket *so, struct mbuf 
sendnam = NULL;
else
sendnam = nam;
-   if (so->so_type == SOCK_SEQPACKET)
-   flags = MSG_EOR;
-   else
-   flags = 0;
+   flags = 0;
 
error = sosend(so, sendnam, NULL, top, NULL, flags);
if (error) {



Re: no seqpacket in nfs

2017-08-13 Thread Alexander Bluhm
On Sun, Aug 13, 2017 at 05:20:05PM -0400, Ted Unangst wrote:
> - if (nmp->nm_sotype != SOCK_STREAM)
> - panic("nfscon sotype");
> + } else {
> + panic("nfscon sotype");

This panic can be reached from user land with a manipulated mount_nfs
program.  This happens without you diff.

panic: nfscon sotype
Stopped at  db_enter+0x5:   popq%rbp
TIDPIDUID PRFLAGS PFLAGS  CPU  COMMAND
* 39774  67297  0 0x3  00  mount_nfs
db_enter(10,83b18890,202,8,81251c35,0) at db_enter+0x5
panic(ff00020b1648,803b9698,803b9600,0,0,83b188a0) a
t panic+0x128
nfs_connect(0,3,803b9600,83b18a48,ff00060e3010,ff00
) at nfs_connect+0x557
nfs_receive(ff00060e3010,803b9600,83b18b90,83b18a38
,803b9640,284bfabeb69b780e) at nfs_receive+0x2c5
nfs_reply(32,ff00060e3010,83b18b90,803b9600,803b964
0,284bfabeb69b780e) at nfs_reply+0x7f
nfs_request(83b12028,803b9600,83b18b90,ff00077cab40
,ff00058c5d28,284bfabeb69b780e) at nfs_request+0x327
nfs_fsinfo(0,83b12028,ff00058c5d28,803b9600,200,284bfabeb69
b780e) at nfs_fsinfo+0x6f
nfs_statfs(803bf000,ff00051c7718,803bf000,83b12028,
0,284bfabeb69b780e) at nfs_statfs+0xae
sys_mount(83b18f20,150,83b12028,15,81a9a2d0,284bfabeb69
b780e) at sys_mount+0x468
syscall() at syscall+0x1e4
--- syscall (number 21) ---

We should return an EPROTONOSUPPORT error here or should do propper
input validation in the nfs mount system call.

bluhm



counter-clockwise rasops rotation

2017-08-13 Thread Mark Kettenis
Because I have a laptop that needs it.

ok?

Index: dev/rasops/rasops.c
===
RCS file: /cvs/src/sys/dev/rasops/rasops.c,v
retrieving revision 1.46
diff -u -p -r1.46 rasops.c
--- dev/rasops/rasops.c 13 Aug 2017 22:28:23 -  1.46
+++ dev/rasops/rasops.c 13 Aug 2017 23:37:31 -
@@ -150,7 +150,7 @@ int rasops_copyrows_rotated(void *, int,
 intrasops_erasecols_rotated(void *, int, int, int, long);
 intrasops_eraserows_rotated(void *, int, int, long);
 intrasops_putchar_rotated(void *, int, int, u_int, long);
-void   rasops_rotate_font(int *);
+void   rasops_rotate_font(int *, int);
 
 /*
  * List of all rotated fonts
@@ -218,8 +218,9 @@ rasops_init(struct rasops_info *ri, int 
 * Pick the rotated version of this font. This will create it
 * if necessary.
 */
-   if (ri->ri_flg & RI_ROTATE_CW)
-   rasops_rotate_font();
+   if (ri->ri_flg & (RI_ROTATE_CW | RI_ROTATE_CCW))
+   rasops_rotate_font(,
+   ISSET(ri->ri_flg, RI_ROTATE_CCW));
 #endif
 
if (wsfont_lock(cookie, >ri_font,
@@ -341,7 +342,7 @@ rasops_reconfig(struct rasops_info *ri, 
ri->ri_emuwidth--;
 
 #if NRASOPS_ROTATION > 0
-   if (ri->ri_flg & RI_ROTATE_CW) {
+   if (ri->ri_flg & (RI_ROTATE_CW | RI_ROTATE_CCW)) {
ri->ri_rows = ri->ri_emuwidth / ri->ri_font->fontwidth;
ri->ri_cols = ri->ri_emuheight / ri->ri_font->fontheight;
} else
@@ -460,7 +461,7 @@ rasops_reconfig(struct rasops_info *ri, 
}
 
 #if NRASOPS_ROTATION > 0
-   if (ri->ri_flg & RI_ROTATE_CW) {
+   if (ri->ri_flg & (RI_ROTATE_CW | RI_ROTATE_CCW)) {
ri->ri_real_ops = ri->ri_ops;
ri->ri_ops.copycols = rasops_copycols_rotated;
ri->ri_ops.copyrows = rasops_copyrows_rotated;
@@ -958,7 +959,11 @@ rasops_do_cursor(struct rasops_info *ri)
/* Rotate rows/columns */
row = ri->ri_ccol;
col = ri->ri_rows - ri->ri_crow - 1;
-   } else
+   } else if (ri->ri_flg & RI_ROTATE_CCW) {
+   /* Rotate rows/columns */
+   row = ri->ri_cols - ri->ri_ccol - 1;
+   col = ri->ri_crow;
+   } else  
 #endif
{
row = ri->ri_crow;
@@ -1153,7 +1158,7 @@ rasops_erasecols(void *cookie, int row, 
 #include 
 
 void
-rasops_rotate_font(int *cookie)
+rasops_rotate_font(int *cookie, int ccw)
 {
struct rotatedfont *f;
int ncookie;
@@ -1169,7 +1174,7 @@ rasops_rotate_font(int *cookie)
 * We did not find a rotated version of this font. Ask the wsfont
 * code to compute one for us.
 */
-   if ((ncookie = wsfont_rotate(*cookie)) == -1)
+   if ((ncookie = wsfont_rotate(*cookie, ccw)) == -1)
return;
 
f = malloc(sizeof(struct rotatedfont), M_DEVBUF, M_WAITOK);
@@ -1230,15 +1235,18 @@ rasops_putchar_rotated(void *cookie, int
 
ri = (struct rasops_info *)cookie;
 
+   if (ri->ri_flg & RI_ROTATE_CW)
+   row = ri->ri_rows - row - 1;
+   else
+   col = ri->ri_cols - col - 1;
+
/* Do rotated char sans (side)underline */
-   rc = ri->ri_real_ops.putchar(cookie, col, ri->ri_rows - row - 1, uc,
-   attr & ~1);
+   rc = ri->ri_real_ops.putchar(cookie, col, row, uc, attr & ~1);
if (rc != 0)
return rc;
 
/* Do rotated underline */
-   rp = ri->ri_bits + col * ri->ri_yscale + (ri->ri_rows - row - 1) * 
-   ri->ri_xscale;
+   rp = ri->ri_bits + col * ri->ri_yscale + row * ri->ri_xscale;
height = ri->ri_font->fontheight;
 
/* XXX this assumes 16-bit color depth */
Index: dev/rasops/rasops.h
===
RCS file: /cvs/src/sys/dev/rasops/rasops.h,v
retrieving revision 1.18
diff -u -p -r1.18 rasops.h
--- dev/rasops/rasops.h 15 Dec 2016 19:18:41 -  1.18
+++ dev/rasops/rasops.h 13 Aug 2017 23:37:31 -
@@ -52,10 +52,11 @@ struct wsdisplay_font;
 #defineRI_CLEARMARGINS 0x0020  /* clear display margins on startup */
 #define RI_CENTER  0x0040  /* center onscreen output */
 #define RI_CURSORCLIP  0x0080  /* cursor is currently clipped */
-#defineRI_ROTATE_CW0x0100  /* display is rotated, quarter 
clockwise */
-#define RI_CFGDONE 0x0200  /* rasops_reconfig() completed successfully */
-#define RI_VCONS   0x0400  /* virtual consoles */
-#define RI_WRONLY  0x0800  /* avoid framebuffer reads */
+#define RI_ROTATE_CW   0x0100  /* display is rotated, 90 deg clockwise */
+#define RI_ROTATE_CCW  0x0200  /* display is rotated, 90 deg anti-clockwise */
+#define RI_CFGDONE 0x0400  /* rasops_reconfig() completed successfully */
+#define RI_VCONS   0x0800  /* virtual consoles */

no seqpacket in nfs

2017-08-13 Thread Ted Unangst
discovered this looking at something else. we don't and won't support
seqpacket for nfs sockets.

perhaps a bit more can be cleaned up too. i don't think we support any stream
sockets that don't require connections, etc...


Index: nfs_socket.c
===
RCS file: /cvs/src/sys/nfs/nfs_socket.c,v
retrieving revision 1.123
diff -u -p -r1.123 nfs_socket.c
--- nfs_socket.c11 Aug 2017 21:24:20 -  1.123
+++ nfs_socket.c13 Aug 2017 21:16:18 -
@@ -347,13 +347,7 @@ nfs_connect(struct nfsmount *nmp, struct
sndreserve = nmp->nm_wsize + NFS_MAXPKTHDR;
rcvreserve = (max(nmp->nm_rsize, nmp->nm_readdirsize) +
NFS_MAXPKTHDR) * 2;
-   } else if (nmp->nm_sotype == SOCK_SEQPACKET) {
-   sndreserve = (nmp->nm_wsize + NFS_MAXPKTHDR) * 2;
-   rcvreserve = (max(nmp->nm_rsize, nmp->nm_readdirsize) +
-   NFS_MAXPKTHDR) * 2;
-   } else {
-   if (nmp->nm_sotype != SOCK_STREAM)
-   panic("nfscon sotype");
+   } else if (nmp->nm_sotype == SOCK_STREAM) {
if (so->so_proto->pr_flags & PR_CONNREQUIRED) {
MGET(m, M_WAIT, MT_SOOPTS);
*mtod(m, int32_t *) = 1;
@@ -370,6 +364,8 @@ nfs_connect(struct nfsmount *nmp, struct
sizeof (u_int32_t)) * 2;
rcvreserve = (nmp->nm_rsize + NFS_MAXPKTHDR +
sizeof (u_int32_t)) * 2;
+   } else {
+   panic("nfscon sotype");
}
error = soreserve(so, sndreserve, rcvreserve);
sounlock(s);
@@ -478,10 +474,7 @@ nfs_send(struct socket *so, struct mbuf 
sendnam = NULL;
else
sendnam = nam;
-   if (so->so_type == SOCK_SEQPACKET)
-   flags = MSG_EOR;
-   else
-   flags = 0;
+   flags = 0;
 
error = sosend(so, sendnam, NULL, top, NULL, flags);
if (error) {



amdgpu support

2017-08-13 Thread Андрей Болконский
When do you plan to port amdgpu to openbsd?


Looking for testers with a floppy drive

2017-08-13 Thread Stefan Fritsch
Hi,

is anyone still using floppies? If yes, it would be nice if they could 
give the diff below a test. It defers probing of the drives which reduces 
boot time quite a bit. If floppy does not work with the diff, please also 
test if it works without it. On qemu, floppy access seems to be broken (or 
I did something wrong).

Cheers,
Stefan


diff --git a/sys/dev/isa/fd.c b/sys/dev/isa/fd.c
index 3e16d054428..460830a97cc 100644
--- a/sys/dev/isa/fd.c
+++ b/sys/dev/isa/fd.c
@@ -210,11 +210,11 @@ fdprobe(struct device *parent, void *match, void *aux)
/* select drive and turn on motor */
bus_space_write_1(iot, ioh, fdout, drive | FDO_FRST | FDO_MOEN(drive));
/* wait for motor to spin up */
-   delay(25);
+   tsleep(fdc, 0, "fdprobe", 250 * hz / 1000);
out_fdc(iot, ioh, NE7CMD_RECAL);
out_fdc(iot, ioh, drive);
/* wait for recalibrate */
-   delay(200);
+   tsleep(fdc, 0, "fdprobe", 2000 * hz / 1000);
out_fdc(iot, ioh, NE7CMD_SENSEI);
n = fdcresult(fdc);
 #ifdef FD_DEBUG
@@ -228,7 +228,7 @@ fdprobe(struct device *parent, void *match, void *aux)
 #endif
 
/* turn off motor */
-   delay(25);
+   tsleep(fdc, 0, "fdprobe", 250 * hz / 1000);
bus_space_write_1(iot, ioh, fdout, FDO_FRST);
 
/* flags & 0x20 forces the drive to be found even if it won't probe */
diff --git a/sys/dev/isa/fdc.c b/sys/dev/isa/fdc.c
index c7b7ae4562c..ee195367322 100644
--- a/sys/dev/isa/fdc.c
+++ b/sys/dev/isa/fdc.c
@@ -57,6 +57,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -79,6 +80,8 @@
 /* controller driver configuration */
 int fdcprobe(struct device *, void *, void *);
 void fdcattach(struct device *, struct device *, void *);
+void fdcattach_deferred(void *);
+void fdc_create_kthread(void *);
 
 struct cfattach fdc_ca = {
sizeof(struct fdc_softc), fdcprobe, fdcattach
@@ -139,8 +142,6 @@ fdcattach(struct device *parent, struct device *self, void 
*aux)
bus_space_handle_t ioh;
bus_space_handle_t ioh_ctl;
struct isa_attach_args *ia = aux;
-   struct fdc_attach_args fa;
-   int type;
 
iot = ia->ia_iot;
 
@@ -163,6 +164,22 @@ fdcattach(struct device *parent, struct device *self, void 
*aux)
fdc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
IPL_BIO, fdcintr, fdc, fdc->sc_dev.dv_xname);
 
+   kthread_create_deferred(fdc_create_kthread, fdc);
+}
+
+void
+fdc_create_kthread(void *arg)
+{
+   kthread_create(fdcattach_deferred, arg, NULL, "fdcattach");
+}
+
+void
+fdcattach_deferred(void *arg)
+{
+   struct fdc_softc *fdc = arg;
+   struct fdc_attach_args fa;
+   int type;
+
 #if defined(__i386__) || defined(__amd64__)
/*
 * The NVRAM info only tells us about the first two disks on the
@@ -187,8 +204,9 @@ fdcattach(struct device *parent, struct device *self, void 
*aux)
else
 #endif
fa.fa_deftype = NULL;   /* unknown */
-   (void)config_found(self, (void *), fddprint);
+   (void)config_found(>sc_dev, (void *), fddprint);
}
+   kthread_exit(0);
 }
 
 /*



Re: iwm: eliminate redundant calls to iwm_stop/iwm_init

2017-08-13 Thread Stefan Sperling
Sorry, please ignore this diff. ifmedia_ioctl() does not propagate ENETRESET,
so this actually breaks things :(

On Sun, Aug 13, 2017 at 07:28:24PM +0200, Stefan Sperling wrote:
> When media is changed with ifconfig, the media change request passes
> through the following kernel function call chain:
> 
>  1 iwm_ioctl()
>  2 iee80211_ioctl()
>  3 ifmedia_ioctl()
>  4 iwm_media_change() via ifm->ifm_change pointer
>  5 ieee80211_media_change()
>  
> If ieee80211_media_change() returns ENETRESET, iwm resets the interface
> directly in iwm_media_change(). But iwm_ioctl() handles ENETRESET in the
> same way, so we can just pass the error up there and avoid redundant code.
> 
> ok?
> 
> Index: if_iwm.c
> ===
> RCS file: /cvs/src/sys/dev/pci/if_iwm.c,v
> retrieving revision 1.210
> diff -u -p -r1.210 if_iwm.c
> --- if_iwm.c  13 Aug 2017 15:34:54 -  1.210
> +++ if_iwm.c  13 Aug 2017 17:18:30 -
> @@ -5908,11 +5908,6 @@ iwm_media_change(struct ifnet *ifp)
>   sc->sc_fixed_ridx = ridx;
>   }
>  
> - if ((ifp->if_flags & (IFF_UP | IFF_RUNNING)) ==
> - (IFF_UP | IFF_RUNNING)) {
> - iwm_stop(ifp, 0);
> - err = iwm_init(ifp);
> - }
>   return err;
>  }
>  



iwm: eliminate redundant calls to iwm_stop/iwm_init

2017-08-13 Thread Stefan Sperling
When media is changed with ifconfig, the media change request passes
through the following kernel function call chain:

 1 iwm_ioctl()
 2 iee80211_ioctl()
 3 ifmedia_ioctl()
 4 iwm_media_change() via ifm->ifm_change pointer
 5 ieee80211_media_change()
 
If ieee80211_media_change() returns ENETRESET, iwm resets the interface
directly in iwm_media_change(). But iwm_ioctl() handles ENETRESET in the
same way, so we can just pass the error up there and avoid redundant code.

ok?

Index: if_iwm.c
===
RCS file: /cvs/src/sys/dev/pci/if_iwm.c,v
retrieving revision 1.210
diff -u -p -r1.210 if_iwm.c
--- if_iwm.c13 Aug 2017 15:34:54 -  1.210
+++ if_iwm.c13 Aug 2017 17:18:30 -
@@ -5908,11 +5908,6 @@ iwm_media_change(struct ifnet *ifp)
sc->sc_fixed_ridx = ridx;
}
 
-   if ((ifp->if_flags & (IFF_UP | IFF_RUNNING)) ==
-   (IFF_UP | IFF_RUNNING)) {
-   iwm_stop(ifp, 0);
-   err = iwm_init(ifp);
-   }
return err;
 }
 



Re: arm64 setregs

2017-08-13 Thread Philip Guenther
On Sun, Aug 13, 2017 at 9:13 AM, Mark Kettenis  wrote:
> Other architectures have this assignment in their setregs()
> implementation.  I don't fully understand why though.  Diff below
> makes arm64 consistent with the rest, but I don't think it fixes
> anything.

It does, but I think there's a better way to fix it.  As I read it,
we're currently preserving %rdx across execve() because syscall()
restores %rdx from retval[1].

Arguably, the better way is for LP64 archs to stop touching retval[1]
at all, as it's completely unnecessary there.  We eliminated the use
of retval[1] in *fork making its only use for lseek()'s long long
return value on ILP32 archs.

Philip Guenther



arm64 setregs

2017-08-13 Thread Mark Kettenis
Other architectures have this assignment in their setregs()
implementation.  I don't fully understand why though.  Diff below
makes arm64 consistent with the rest, but I don't think it fixes
anything.

Index: arch/arm64/arm64/machdep.c
===
RCS file: /cvs/src/sys/arch/arm64/arm64/machdep.c,v
retrieving revision 1.19
diff -u -p -r1.19 machdep.c
--- arch/arm64/arm64/machdep.c  9 Aug 2017 03:44:33 -   1.19
+++ arch/arm64/arm64/machdep.c  13 Aug 2017 16:08:27 -
@@ -398,6 +398,8 @@ setregs(struct proc *p, struct exec_pack
tf->tf_lr = pack->ep_entry;
tf->tf_elr = pack->ep_entry; /* ??? */
tf->tf_spsr = PSR_M_EL0t;
+
+   retval[1] = 0;
 }
 
 void



Re: DisplayPort MST changes from linux 4.4.79

2017-08-13 Thread Mark Kettenis
> Date: Sun, 13 Aug 2017 22:32:47 +1000
> From: Jonathan Gray 
> 
> Bring in some DisplayPort MST changes from linux-4.4.y/4.4.79

Sure.

> --
> 
> commit 4ca0f3730e2734f67e648b2b4f12b66673e995e1
> Author: Imre Deak 
> Date:   Wed Jul 19 16:46:32 2017 +0300
> 
> drm/mst: Avoid processing partially received up/down message transactions
> 
> commit 636c4c3e762b62aa93632c645ca65879285b16e3 upstream.
> 
> Currently we may process up/down message transactions containing
> uninitialized data. This can happen if there was an error during the
> reception of any message in the transaction, but we happened to receive
> the last message correctly with the end-of-message flag set.
> 
> To avoid this abort the reception of the transaction when the first
> error is detected, rejecting any messages until a message with the
> start-of-message flag is received (which will start a new transaction).
> This is also what the DP 1.4 spec 2.11.8.2 calls for in this case.
> 
> In addtion this also prevents receiving bogus transactions without the
> first message with the the start-of-message flag set.
> 
> v2:
> - unchanged
> v3:
> - git add the part that actually skips messages after an error in
>   drm_dp_sideband_msg_build()
> 
> Cc: Dave Airlie 
> Cc: Lyude 
> Cc: Daniel Vetter 
> Signed-off-by: Imre Deak 
> Reviewed-by: Lyude 
> Signed-off-by: Daniel Vetter 
> Link: 
> https://patchwork.freedesktop.org/patch/msgid/20170719134632.13366-1-imre.d...@intel.com
> Signed-off-by: Greg Kroah-Hartman 
> 
>  drivers/gpu/drm/drm_dp_mst_topology.c | 31 ---
>  1 file changed, 24 insertions(+), 7 deletions(-)
> 
> commit 3d26e2ed7c8b4b1a0d9406fef7f3b5d6309fba49
> Author: Imre Deak 
> Date:   Wed Jul 19 14:43:29 2017 +0300
> 
> drm/mst: Avoid dereferencing a NULL mstb in drm_dp_mst_handle_up_req()
> 
> commit 7f8b3987da54cb4d41ad2545cd4d7958b9a36bdf upstream.
> 
> In case of an unknown broadcast message is sent mstb will remain unset,
> so check for this.
> 
> Cc: Dave Airlie 
> Cc: Lyude 
> Cc: Daniel Vetter 
> Signed-off-by: Imre Deak 
> Reviewed-by: Lyude 
> Signed-off-by: Daniel Vetter 
> Link: 
> https://patchwork.freedesktop.org/patch/msgid/20170719114330.26540-3-imre.d...@intel.com
> Signed-off-by: Greg Kroah-Hartman 
> 
>  drivers/gpu/drm/drm_dp_mst_topology.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> commit 3383334a6cf38af6843793e343c95081b02773f1
> Author: Imre Deak 
> Date:   Wed Jul 19 14:43:28 2017 +0300
> 
> drm/mst: Fix error handling during MST sideband message reception
> 
> commit 448421b5e93b9177c5698f0cf6f5e72d2995eeca upstream.
> 
> Handle any error due to partial reads, timeouts etc. to avoid parsing
> uninitialized data subsequently. Also bail out if the parsing itself
> fails.
> 
> Cc: Dave Airlie 
> Cc: Lyude 
> Cc: Daniel Vetter 
> Signed-off-by: Imre Deak 
> Reviewed-by: Lyude 
> Signed-off-by: Daniel Vetter 
> Link: 
> https://patchwork.freedesktop.org/patch/msgid/20170719114330.26540-2-imre.d...@intel.com
> Signed-off-by: Greg Kroah-Hartman 
> 
>  drivers/gpu/drm/drm_dp_mst_topology.c | 10 --
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> Index: drm_dp_mst_topology.c
> ===
> RCS file: /cvs/src/sys/dev/pci/drm/drm_dp_mst_topology.c,v
> retrieving revision 1.2
> diff -u -p -r1.2 drm_dp_mst_topology.c
> --- drm_dp_mst_topology.c 14 Jul 2017 11:18:04 -  1.2
> +++ drm_dp_mst_topology.c 13 Aug 2017 12:04:47 -
> @@ -334,6 +334,13 @@ static bool drm_dp_sideband_msg_build(st
>   return false;
>   }
>  
> + /*
> +  * ignore out-of-order messages or messages that are part of a
> +  * failed transaction
> +  */
> + if (!recv_hdr.somt && !msg->have_somt)
> + return false;
> +
>   /* get length contained in this portion */
>   msg->curchunk_len = recv_hdr.msg_len;
>   msg->curchunk_hdrlen = hdrlen;
> @@ -2167,7 +2174,7 @@ out_unlock:
>  }
>  EXPORT_SYMBOL(drm_dp_mst_topology_mgr_resume);
>  
> -static void drm_dp_get_one_sb_msg(struct drm_dp_mst_topology_mgr 

Re: hme: incorrect register endian for PCI sun hme devices?

2017-08-13 Thread Kaashif Hymabaccus
On Sun, Aug 13, 2017 at 01:31:45PM +0100, Mark Cave-Ayland wrote:
> Hi all,
> 
> Does anyone have any real Sun hardware containing a PCI hme card running
> OpenBSD, and if so does it work with the current 6.1 release?
> 

Hello Mark,

I have a Sun Ultra 5 with the following dmesg:

console is /pci@1f,0/pci@1,1/ebus@1/se@14,40:a
Copyright (c) 1982, 1986, 1989, 1991, 1993
The Regents of the University of California.  All rights reserved.
Copyright (c) 1995-2017 OpenBSD. All rights reserved.  https://www.OpenBSD.org

OpenBSD 6.1-current (GENERIC) #225: Fri Aug 11 19:58:43 MDT 2017
dera...@sparc64.openbsd.org:/usr/src/sys/arch/sparc64/compile/GENERIC
real mem = 536870912 (512MB)
avail mem = 512393216 (488MB)
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root: Sun Ultra 5/10 UPA/PCI (UltraSPARC-IIi 270MHz)
cpu0 at mainbus0: SUNW,UltraSPARC-IIi (rev 1.3) @ 269.802 MHz
cpu0: physical 16K instruction (32 b/l), 16K data (32 b/l), 256K external (64 
b/l)
psycho0 at mainbus0 addr 0xfffc4000: SUNW,sabre, impl 0, version 0, ign 7c0
psycho0: bus range 0-2, PCI bus 0
psycho0: dvma map c000-dfff
pci0 at psycho0
ppb0 at pci0 dev 1 function 1 "Sun Simba" rev 0x11
pci1 at ppb0 bus 1
ebus0 at pci1 dev 1 function 0 "Sun PCIO EBus2" rev 0x01
auxio0 at ebus0 addr 726000-726003, 728000-728003, 72a000-72a003, 
72c000-72c003, 72f000-72f003
power0 at ebus0 addr 724000-724003 ivec 0x25
"SUNW,pll" at ebus0 addr 504000-504002 not configured
sab0 at ebus0 addr 40-40007f ivec 0x2b: rev 3.2
sabtty0 at sab0 port 0: console
sabtty1 at sab0 port 1
comkbd0 at ebus0 addr 3083f8-3083ff ivec 0x29: no keyboard
comms0 at ebus0 addr 3062f8-3062ff ivec 0x2a
wsmouse0 at comms0 mux 0
lpt0 at ebus0 addr 3043bc-3043cb, 30015c-30015d, 70-7f ivec 0x22: polled
"fdthree" at ebus0 addr 3023f0-3023f7, 706000-70600f, 72-720003 ivec 0x27 
not configured
clock1 at ebus0 addr 0-1fff: mk48t59
"flashprom" at ebus0 addr 0-f not configured
audioce0 at ebus0 addr 20-2000ff, 702000-70200f, 704000-70400f, 
722000-722003 ivec 0x23 ivec 0x24: nvaddrs 0
audio0 at audioce0
hme0 at pci1 dev 1 function 1 "Sun HME" rev 0x01: ivec 0x7e1, address 
08:00:20:19:39:20
nsphy0 at hme0 phy 1: DP83840 10/100 PHY, rev. 1
machfb0 at pci1 dev 2 function 0 "ATI Mach64" rev 0x9a
machfb0: ATY,GT-B, 1152x900
wsdisplay0 at machfb0 mux 1
wsdisplay0: screen 0 added (std, sun emulation)
pciide0 at pci1 dev 3 function 0 "CMD Technology PCI0646" rev 0x03: DMA, 
channel 0 configured to native-PCI, channel 1 configured to native-PCI
pciide0: using ivec 0x7e0 for native-PCI interrupt
wd0 at pciide0 channel 0 drive 0: 
wd0: 16-sector PIO, LBA48, 117800MB, 241254720 sectors
wd0(pciide0:0:0): using PIO mode 4, DMA mode 2
atapiscsi0 at pciide0 channel 1 drive 0
scsibus1 at atapiscsi0: 2 targets
cd0 at scsibus1 targ 0 lun 0:  ATAPI 5/cdrom 
removable
wd1 at pciide0 channel 1 drive 1: 
wd1: 16-sector PIO, LBA, 19546MB, 40031712 sectors
cd0(pciide0:1:0): using PIO mode 4, DMA mode 2
wd1(pciide0:1:1): using PIO mode 4, DMA mode 2
ppb1 at pci0 dev 1 function 0 "Sun Simba" rev 0x11
pci2 at ppb1 bus 2
vscsi0 at root
scsibus2 at vscsi0: 256 targets
softraid0 at root
scsibus3 at softraid0: 256 targets
bootpath: /pci@1f,0/pci@1,1/ide@3,0/disk@0,0
root on wd0a (f52f0bbc65e53556.a) swap on wd0b dump on wd0b

It has a PCI hme card and it works great.

I would be happy to help if you want to test some diff or program, but
I am not knowledgeable enough to comment on the inner workings of the
hme driver.

-- 
Kaashif Hymabaccus
GPG: 3E810B04



Re: attach ahci faster

2017-08-13 Thread Christian Weisgerber
Jonathan Matthew:

> Better version that actually preserves the port command register state across
> resets, rather than throwing it away and replacing it with garbage:

This appears to break ahci on the OverDrive 1000:

...
ahci0 at simplebus0: AHCI 1.3
scsibus0 at ahci0: 32 targets
ahci0: stopping the port, softreset slot 31 was still active.
ahci0: failed to reset port during timeout handling, disabling it
...
bootfile: sd0a:/bsd
boot device: lookup sd0a:/bsd failed 
root device: 

(There's still a long pause after the "ahci0 at simplebus0" line, too.)
-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



httpd: remove unused media_encoding field

2017-08-13 Thread Hiltjo Posthuma
Hi,

This patch removes the unused media_encoding field, it was probably intended to
be used to add text-encoding information.

However: forcing a text-encoding can be useful in some cases.
Currently in httpd.conf the text-encoding can be set with a hack for example:

types { "text"/"plain; charset=utf-8" txt c h }

This works because in parse.y the mediaoptsl grammar is defined as:
STRING '/' STRING.
However this might be incompatible with the mime.types format.

Anyway, patch below:


diff --git a/usr.sbin/httpd/httpd.c b/usr.sbin/httpd/httpd.c
index 6d1d1ff34fe..ef3f95a649d 100644
--- a/usr.sbin/httpd/httpd.c
+++ b/usr.sbin/httpd/httpd.c
@@ -1199,11 +1199,6 @@ media_add(struct mediatypes *types, struct media_type 
*media)
return (NULL);
 
memcpy(entry, media, sizeof(*entry));
-   if (media->media_encoding != NULL &&
-   (entry->media_encoding = strdup(media->media_encoding)) == NULL) {
-   free(entry);
-   return (NULL);
-   }
RB_INSERT(mediatypes, types, entry);
 
return (entry);
@@ -1214,7 +1209,6 @@ media_delete(struct mediatypes *types, struct media_type 
*media)
 {
RB_REMOVE(mediatypes, types, media);
 
-   free(media->media_encoding);
free(media);
 }
 
diff --git a/usr.sbin/httpd/httpd.h b/usr.sbin/httpd/httpd.h
index 05cbb8e3550..9a6530715c7 100644
--- a/usr.sbin/httpd/httpd.h
+++ b/usr.sbin/httpd/httpd.h
@@ -53,7 +53,7 @@
 #define HTTPD_LOGROOT  "/logs"
 #define HTTPD_ACCESS_LOG   "access.log"
 #define HTTPD_ERROR_LOG"error.log"
-#define HTTPD_DEFAULT_TYPE { "bin", "application", "octet-stream", NULL }
+#define HTTPD_DEFAULT_TYPE { "bin", "application", "octet-stream" }
 #define HTTPD_LOGVIS   VIS_NL|VIS_TAB|VIS_CSTYLE
 #define HTTPD_TLS_CERT "/etc/ssl/server.crt"
 #define HTTPD_TLS_KEY  "/etc/ssl/private/server.key"
@@ -438,7 +438,6 @@ struct media_type {
char media_name[MEDIATYPE_NAMEMAX];
char media_type[MEDIATYPE_TYPEMAX];
char media_subtype[MEDIATYPE_TYPEMAX];
-   char*media_encoding;
RB_ENTRY(media_type) media_entry;
 };
 RB_HEAD(mediatypes, media_type);
diff --git a/usr.sbin/httpd/parse.y b/usr.sbin/httpd/parse.y
index 203ddd1b0bb..2fc50b1a1da 100644
--- a/usr.sbin/httpd/parse.y
+++ b/usr.sbin/httpd/parse.y
@@ -1695,7 +1695,6 @@ load_config(const char *filename, struct httpd *x_conf)
(void)strlcpy(m.media_subtype,
mediatypes[i].media_subtype,
sizeof(m.media_subtype));
-   m.media_encoding = NULL;
 
if (media_add(conf->sc_mediatypes, ) == NULL) {
log_warnx("failed to add default media \"%s\"",

-- 
Kind regards,
Hiltjo



DisplayPort MST changes from linux 4.4.79

2017-08-13 Thread Jonathan Gray
Bring in some DisplayPort MST changes from linux-4.4.y/4.4.79

--

commit 4ca0f3730e2734f67e648b2b4f12b66673e995e1
Author: Imre Deak 
Date:   Wed Jul 19 16:46:32 2017 +0300

drm/mst: Avoid processing partially received up/down message transactions

commit 636c4c3e762b62aa93632c645ca65879285b16e3 upstream.

Currently we may process up/down message transactions containing
uninitialized data. This can happen if there was an error during the
reception of any message in the transaction, but we happened to receive
the last message correctly with the end-of-message flag set.

To avoid this abort the reception of the transaction when the first
error is detected, rejecting any messages until a message with the
start-of-message flag is received (which will start a new transaction).
This is also what the DP 1.4 spec 2.11.8.2 calls for in this case.

In addtion this also prevents receiving bogus transactions without the
first message with the the start-of-message flag set.

v2:
- unchanged
v3:
- git add the part that actually skips messages after an error in
  drm_dp_sideband_msg_build()

Cc: Dave Airlie 
Cc: Lyude 
Cc: Daniel Vetter 
Signed-off-by: Imre Deak 
Reviewed-by: Lyude 
Signed-off-by: Daniel Vetter 
Link: 
https://patchwork.freedesktop.org/patch/msgid/20170719134632.13366-1-imre.d...@intel.com
Signed-off-by: Greg Kroah-Hartman 

 drivers/gpu/drm/drm_dp_mst_topology.c | 31 ---
 1 file changed, 24 insertions(+), 7 deletions(-)

commit 3d26e2ed7c8b4b1a0d9406fef7f3b5d6309fba49
Author: Imre Deak 
Date:   Wed Jul 19 14:43:29 2017 +0300

drm/mst: Avoid dereferencing a NULL mstb in drm_dp_mst_handle_up_req()

commit 7f8b3987da54cb4d41ad2545cd4d7958b9a36bdf upstream.

In case of an unknown broadcast message is sent mstb will remain unset,
so check for this.

Cc: Dave Airlie 
Cc: Lyude 
Cc: Daniel Vetter 
Signed-off-by: Imre Deak 
Reviewed-by: Lyude 
Signed-off-by: Daniel Vetter 
Link: 
https://patchwork.freedesktop.org/patch/msgid/20170719114330.26540-3-imre.d...@intel.com
Signed-off-by: Greg Kroah-Hartman 

 drivers/gpu/drm/drm_dp_mst_topology.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

commit 3383334a6cf38af6843793e343c95081b02773f1
Author: Imre Deak 
Date:   Wed Jul 19 14:43:28 2017 +0300

drm/mst: Fix error handling during MST sideband message reception

commit 448421b5e93b9177c5698f0cf6f5e72d2995eeca upstream.

Handle any error due to partial reads, timeouts etc. to avoid parsing
uninitialized data subsequently. Also bail out if the parsing itself
fails.

Cc: Dave Airlie 
Cc: Lyude 
Cc: Daniel Vetter 
Signed-off-by: Imre Deak 
Reviewed-by: Lyude 
Signed-off-by: Daniel Vetter 
Link: 
https://patchwork.freedesktop.org/patch/msgid/20170719114330.26540-2-imre.d...@intel.com
Signed-off-by: Greg Kroah-Hartman 

 drivers/gpu/drm/drm_dp_mst_topology.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

Index: drm_dp_mst_topology.c
===
RCS file: /cvs/src/sys/dev/pci/drm/drm_dp_mst_topology.c,v
retrieving revision 1.2
diff -u -p -r1.2 drm_dp_mst_topology.c
--- drm_dp_mst_topology.c   14 Jul 2017 11:18:04 -  1.2
+++ drm_dp_mst_topology.c   13 Aug 2017 12:04:47 -
@@ -334,6 +334,13 @@ static bool drm_dp_sideband_msg_build(st
return false;
}
 
+   /*
+* ignore out-of-order messages or messages that are part of a
+* failed transaction
+*/
+   if (!recv_hdr.somt && !msg->have_somt)
+   return false;
+
/* get length contained in this portion */
msg->curchunk_len = recv_hdr.msg_len;
msg->curchunk_hdrlen = hdrlen;
@@ -2167,7 +2174,7 @@ out_unlock:
 }
 EXPORT_SYMBOL(drm_dp_mst_topology_mgr_resume);
 
-static void drm_dp_get_one_sb_msg(struct drm_dp_mst_topology_mgr *mgr, bool up)
+static bool drm_dp_get_one_sb_msg(struct drm_dp_mst_topology_mgr *mgr, bool up)
 {
int len;
u8 replyblock[32];
@@ -2182,12 +2189,12 @@ static void drm_dp_get_one_sb_msg(struct
   replyblock, len);
if (ret != len) {

hme: incorrect register endian for PCI sun hme devices?

2017-08-13 Thread Mark Cave-Ayland
Hi all,

Does anyone have any real Sun hardware containing a PCI hme card running
OpenBSD, and if so does it work with the current 6.1 release?

I've been working on a virtual hme device for qemu-system-sparc64 in the
hope of getting working networking on *BSD images and I have a driver
that now works well for pretty much all OSs... except OpenBSD.

Looking at the hme driver register accesses on OpenBSD, the issue
appears to be that all accesses to the hme register blocks defined in
if_hme_pci.c (SEB, ETX, ERX, MAC, MIF) are done using big endian
accesses, whereas for PCI devices these need to be done using little
endian accesses.

Is there something I've missed in the hme device emulation or is there
something amiss with the hme driver? I see that it is shared between PCI
and SBus so perhaps that is part of the puzzle?


ATB,

Mark.



Re: [patch] Add -z and -Z to apmd for automatic suspend/hibernate

2017-08-13 Thread Jesper Wallin
On Sun, Aug 13, 2017 at 09:52:22AM +0200, Martijn van Duren wrote:
> I've also been bitten by this a couple of times, but you can also solve
> this via the sensorsd framework, which is how I've done it.

Yeah, someone on IRC also suggested sensorsd or even ksh and a cronjob.
I personally find it a bit too ducttapey though, especially for a
feature one would expect on a laptop. This also saves me from running an
extra daemon just in case my battery runs out.

> I'm no expert in this area and I'm not going to make any statements on
> whether we should add this or not, but two (non functionality) nits
> inline for future reference.

Thanks for the feedback, greatly appreciated! I've done a few changes
and also rewrote some of the manual, as my previous patch was lying.


Jesper Wallin


Index: usr.sbin/apmd/apmd.8
===
RCS file: /cvs/src/usr.sbin/apmd/apmd.8,v
retrieving revision 1.47
diff -u -p -r1.47 apmd.8
--- usr.sbin/apmd/apmd.812 Feb 2015 14:03:49 -  1.47
+++ usr.sbin/apmd/apmd.813 Aug 2017 11:50:16 -
@@ -113,6 +113,20 @@ The polling rate defaults to
 once per 10 minutes, but may be specified using the
 .Fl t
 command-line flag.
+.It Fl z Ar percent
+Automatically suspend the system if no AC is connected and the
+estimated battery life is equal or below
+.Ar percent .
+.It Fl Z Ar percent
+Automatically hibernate the system if no AC is connected and the
+estimated battery life is equal or below
+.Ar percent .
+.Pp
+If both 
+.Fl Z
+and
+.Fl z
+are specified, the first one will supersede the other.
 .El
 .Pp
 When a client requests a suspend or stand-by state,
Index: usr.sbin/apmd/apmd.c
===
RCS file: /cvs/src/usr.sbin/apmd/apmd.c,v
retrieving revision 1.79
diff -u -p -r1.79 apmd.c
--- usr.sbin/apmd/apmd.c16 Nov 2015 17:35:05 -  1.79
+++ usr.sbin/apmd/apmd.c13 Aug 2017 11:50:16 -
@@ -56,6 +56,9 @@
 #define TRUE 1
 #define FALSE 0
 
+#define AUTO_SUSPEND 1
+#define AUTO_HIBERNATE 2
+
 const char apmdev[] = _PATH_APM_CTLDEV;
 const char sockfile[] = _PATH_APM_SOCKET;
 
@@ -94,8 +97,8 @@ void
 usage(void)
 {
fprintf(stderr,
-   "usage: %s [-AadHLs] [-f devname] [-S sockname] [-t seconds]\n",
-   __progname);
+   "usage: %s [-AadHLs] [-f devname] [-S sockname] [-t seconds] "
+   "[-z percent] [-Z percent]\n", __progname);
exit(1);
 }
 
@@ -348,6 +351,8 @@ main(int argc, char *argv[])
 {
const char *fname = apmdev;
int ctl_fd, sock_fd, ch, suspends, standbys, hibernates, resumes;
+   int autoaction = 0;
+   int autolimit = 0;
int statonly = 0;
int powerstatus = 0, powerbak = 0, powerchange = 0;
int noacsleep = 0;
@@ -355,13 +360,14 @@ main(int argc, char *argv[])
struct apm_power_info pinfo;
time_t apmtimeout = 0;
const char *sockname = sockfile;
+   const char *errstr;
int kq, nchanges;
struct kevent ev[2];
int ncpu_mib[2] = { CTL_HW, HW_NCPU };
int ncpu;
size_t ncpu_sz = sizeof(ncpu);
 
-   while ((ch = getopt(argc, argv, "aACdHLsf:t:S:")) != -1)
+   while ((ch = getopt(argc, argv, "aACdHLsf:t:S:z:Z:")) != -1)
switch(ch) {
case 'a':
noacsleep = 1;
@@ -402,6 +408,18 @@ main(int argc, char *argv[])
doperf = PERF_MANUAL;
setperfpolicy("high");
break;
+   case 'z':
+   autoaction = AUTO_SUSPEND;
+   autolimit = strtonum(optarg, 1, 100, );
+   if (errstr != NULL)
+   error("invalid percent: %s", errstr);
+   break;
+   case 'Z':
+   autoaction = AUTO_HIBERNATE;
+   autolimit = strtonum(optarg, 1, 100, );
+   if (errstr != NULL)
+   error("invalid percent: %s", errstr);
+   break;
case '?':
default:
usage();
@@ -479,6 +497,20 @@ main(int argc, char *argv[])
if (powerstatus != powerbak) {
powerstatus = powerbak;
powerchange = 1;
+   }
+
+   if (!powerstatus && autoaction &&
+   autolimit > (int)pinfo.battery_life) {
+   syslog(LOG_NOTICE, "estimated battery life 
%d%%, "
+   "autoaction limit set to %d%% .",
+   pinfo.battery_life,
+   autolimit
+   );
+
+   if (autoaction == AUTO_SUSPEND)
+  

Re: smtpd: simplify table parser

2017-08-13 Thread Gilles Chehade
On Sun, Aug 13, 2017 at 01:45:48PM +0200, Eric Faurot wrote:
> Remove the table_static_parse() indirection for parsing the file content.
> The "type" parameter is useless since the "(t->t_type & type)" test is always
> true.  I think this is a left-over from the old design when table parsing was
> done in context of its intended use in the global config.
> 

this is a leftover from when tables were called maps and used to be
declared with a type

ok gilles@


> Index: table_static.c
> ===
> RCS file: /cvs/src/usr.sbin/smtpd/table_static.c,v
> retrieving revision 1.15
> diff -u -p -r1.15 table_static.c
> --- table_static.c22 Jan 2016 13:08:44 -  1.15
> +++ table_static.c13 Aug 2017 11:28:50 -
> @@ -47,7 +47,6 @@ static int table_static_lookup(void *, s
>  static int table_static_fetch(void *, struct dict *, enum table_service,
>  union lookup *);
>  static void  table_static_close(void *);
> -static int table_static_parse(struct table *, const char *, enum table_type);
>  
>  struct table_backend table_backend_static = {
>   K_ALIAS|K_CREDENTIALS|K_DOMAIN|K_NETADDR|K_USERINFO|
> @@ -71,17 +70,7 @@ static struct keycmp {
>  
>  
>  static int
> -table_static_config(struct table *table)
> -{
> - /* no config ? ok */
> - if (*table->t_config == '\0')
> - return 1;
> -
> - return table_static_parse(table, table->t_config, T_LIST|T_HASH);
> -}
> -
> -static int
> -table_static_parse(struct table *t, const char *config, enum table_type type)
> +table_static_config(struct table *t)
>  {
>   FILE*fp;
>   char*buf = NULL;
> @@ -91,10 +80,14 @@ table_static_parse(struct table *t, cons
>   char*valp;
>   size_t   ret = 0;
>  
> -if ((fp = fopen(config, "r")) == NULL) {
> -log_warn("warn: Table \"%s\"", config);
> -return 0;
> -}
> + /* no config ? ok */
> + if (*t->t_config == '\0')
> + return 1;
> +
> + if ((fp = fopen(t->t_config, "r")) == NULL) {
> + log_warn("warn: Table \"%s\"", t->t_config);
> + return 0;
> + }
>  
>   while ((flen = getline(, , fp)) != -1) {
>   if (buf[flen - 1] == '\n')
> @@ -122,9 +115,6 @@ table_static_parse(struct table *t, cons
>   if (t->t_type == 0)
>   t->t_type = (valp == keyp || valp == NULL) ? T_LIST :
>   T_HASH;
> -
> - if (!(t->t_type & type))
> - goto end;
>  
>   if ((valp == keyp || valp == NULL) && t->t_type == T_LIST)
>   table_add(t, keyp, NULL);
> 

-- 
Gilles Chehade

https://www.poolp.org  @poolpOrg



smtpd: simplify table parser

2017-08-13 Thread Eric Faurot
Remove the table_static_parse() indirection for parsing the file content.
The "type" parameter is useless since the "(t->t_type & type)" test is always
true.  I think this is a left-over from the old design when table parsing was
done in context of its intended use in the global config.

Eric.


Index: table_static.c
===
RCS file: /cvs/src/usr.sbin/smtpd/table_static.c,v
retrieving revision 1.15
diff -u -p -r1.15 table_static.c
--- table_static.c  22 Jan 2016 13:08:44 -  1.15
+++ table_static.c  13 Aug 2017 11:28:50 -
@@ -47,7 +47,6 @@ static int table_static_lookup(void *, s
 static int table_static_fetch(void *, struct dict *, enum table_service,
 union lookup *);
 static void  table_static_close(void *);
-static int table_static_parse(struct table *, const char *, enum table_type);
 
 struct table_backend table_backend_static = {
K_ALIAS|K_CREDENTIALS|K_DOMAIN|K_NETADDR|K_USERINFO|
@@ -71,17 +70,7 @@ static struct keycmp {
 
 
 static int
-table_static_config(struct table *table)
-{
-   /* no config ? ok */
-   if (*table->t_config == '\0')
-   return 1;
-
-   return table_static_parse(table, table->t_config, T_LIST|T_HASH);
-}
-
-static int
-table_static_parse(struct table *t, const char *config, enum table_type type)
+table_static_config(struct table *t)
 {
FILE*fp;
char*buf = NULL;
@@ -91,10 +80,14 @@ table_static_parse(struct table *t, cons
char*valp;
size_t   ret = 0;
 
-if ((fp = fopen(config, "r")) == NULL) {
-log_warn("warn: Table \"%s\"", config);
-return 0;
-}
+   /* no config ? ok */
+   if (*t->t_config == '\0')
+   return 1;
+
+   if ((fp = fopen(t->t_config, "r")) == NULL) {
+   log_warn("warn: Table \"%s\"", t->t_config);
+   return 0;
+   }
 
while ((flen = getline(, , fp)) != -1) {
if (buf[flen - 1] == '\n')
@@ -122,9 +115,6 @@ table_static_parse(struct table *t, cons
if (t->t_type == 0)
t->t_type = (valp == keyp || valp == NULL) ? T_LIST :
T_HASH;
-
-   if (!(t->t_type & type))
-   goto end;
 
if ((valp == keyp || valp == NULL) && t->t_type == T_LIST)
table_add(t, keyp, NULL);



Re: attach ahci faster

2017-08-13 Thread Jonathan Matthew
On Sun, Aug 13, 2017 at 02:09:49PM +1000, Jonathan Matthew wrote:
> On some systems, attaching ahci(4) is one of the most noticeably slow parts
> of the boot process, since each port with no device attached takes a whole
> second to probe.  I've made a few noises about fixing that over the years,
> and here's a new one.
> 
> This rearranges the device detection phase so that we poll all the ports
> in parallel until either all ports have detected a device or one second has
> elapsed.  Devices are still attached in the same order, just faster.
> 
> The diff doesn't really show what's going on, since it's mostly splitting up
> ahci_port_portreset into a few smaller pieces.
> 
> VMware's emulated ahci always has 32 ports, so this cuts about 30 seconds off
> boot time if you use that for some reason.  Qemu's has fewer ports, so it
> only cuts 4s or so off in my testing.  Similar improvements can be expected
> on desktop systems since they tend to have some extra sata ports, but
> laptops are unlikely to see any difference.
> 
> ok?

Better version that actually preserves the port command register state across
resets, rather than throwing it away and replacing it with garbage:


diff --git a/sys/dev/ic/ahci.c b/sys/dev/ic/ahci.c
index 9057d44ff78..9523ff1a4f1 100644
--- a/sys/dev/ic/ahci.c
+++ b/sys/dev/ic/ahci.c
@@ -72,6 +72,7 @@ void  ahci_enable_interrupts(struct ahci_port 
*);
 
 intahci_init(struct ahci_softc *);
 intahci_port_alloc(struct ahci_softc *, u_int);
+void   ahci_port_detect(struct ahci_softc *, u_int);
 void   ahci_port_free(struct ahci_softc *, u_int);
 intahci_port_init(struct ahci_softc *, u_int);
 
@@ -80,6 +81,9 @@ int   ahci_port_stop(struct ahci_port *, int);
 intahci_port_clo(struct ahci_port *);
 intahci_port_softreset(struct ahci_port *);
 intahci_port_portreset(struct ahci_port *, int);
+void   ahci_port_portreset_start(struct ahci_port *);
+intahci_port_portreset_poll(struct ahci_port *);
+intahci_port_portreset_finish(struct ahci_port *, int);
 intahci_port_signature(struct ahci_port *);
 intahci_pmp_port_softreset(struct ahci_port *, int);
 intahci_pmp_port_portreset(struct ahci_port *, int);
@@ -173,7 +177,7 @@ ahci_attach(struct ahci_softc *sc)
 {
struct atascsi_attach_args  aaa;
u_int32_t   pi;
-   int i;
+   int i, j, done;
 
if (sc->sc_port_start == NULL)
sc->sc_port_start = ahci_default_port_start;
@@ -268,6 +272,37 @@ noccc:
 
if (ahci_port_alloc(sc, i) == ENOMEM)
goto freeports;
+
+   if (sc->sc_ports[i] != NULL)
+   ahci_port_portreset_start(sc->sc_ports[i]);
+   }
+
+   /*
+* Poll for device detection until all ports report a device, or one
+* second has elapsed.
+*/
+   for (i = 0; i < 1000; i++) {
+   done = 1;
+   for (j = 0; j < AHCI_MAX_PORTS; j++) {
+   if (sc->sc_ports[j] == NULL)
+   continue;
+
+   if (ahci_port_portreset_poll(sc->sc_ports[j]))
+   done = 0;
+   }
+
+   if (done)
+   break;
+
+   delay(1000);
+   }
+
+   /*
+* Finish device detection on all ports that initialized.
+*/
+   for (i = 0; i < AHCI_MAX_PORTS; i++) {
+   if (sc->sc_ports[i] != NULL)
+   ahci_port_detect(sc, i);
}
 
memset(, 0, sizeof(aaa));
@@ -446,7 +481,6 @@ ahci_port_alloc(struct ahci_softc *sc, u_int port)
u_int32_t   cmd;
struct ahci_cmd_hdr *hdr;
struct ahci_cmd_table   *table;
-   const char  *speed;
int i, rc = ENOMEM;
 
ap = malloc(sizeof(*ap), M_DEVBUF, M_NOWAIT | M_ZERO);
@@ -594,10 +628,25 @@ nomem:
 
/* Wait for ICC change to complete */
ahci_pwait_clr(ap, AHCI_PREG_CMD, AHCI_PREG_CMD_ICC, 1);
+   rc = 0;
 
-   /* Reset port */
-   rc = ahci_port_portreset(ap, 1);
+freeport:
+   if (rc != 0)
+   ahci_port_free(sc, port);
+reterr:
+   return (rc);
+}
+
+void
+ahci_port_detect(struct ahci_softc *sc, u_int port)
+{
+   struct ahci_port*ap;
+   const char  *speed;
+   int rc;
+
+   ap = sc->sc_ports[port];
 
+   rc = ahci_port_portreset_finish(ap, 1);
switch (rc) {
case ENODEV:
switch (ahci_pread(ap, 

Re: [patch] Add -z and -Z to apmd for automatic suspend/hibernate

2017-08-13 Thread Martijn van Duren
Hello Jesper,

On 08/12/17 23:39, Jesper Wallin wrote:
> Hello tech@
> 
> I've been stuck with fsck for way to many times now because of me
> forgetting to connect the AC power. This patch will add -z and -Z
> followed by the percentage. apmd will try to suspend or hibernate the
> system if the AC is not connected and the estimated battery life goes
> below the specified percentage.
> 
I've also been bitten by this a couple of times, but you can also solve
this via the sensorsd framework, which is how I've done it.

I'm no expert in this area and I'm not going to make any statements on
whether we should add this or not, but two (non functionality) nits
inline for future reference.

martijn@
> 
> Jesper Wallin
> 
> 
> Index: usr.sbin/apmd/apmd.8
> ===
> RCS file: /cvs/src/usr.sbin/apmd/apmd.8,v
> retrieving revision 1.47
> diff -u -p -r1.47 apmd.8
> --- usr.sbin/apmd/apmd.8  12 Feb 2015 14:03:49 -  1.47
> +++ usr.sbin/apmd/apmd.8  12 Aug 2017 21:18:28 -
> @@ -113,6 +113,16 @@ The polling rate defaults to
>  once per 10 minutes, but may be specified using the
>  .Fl t
>  command-line flag.
> +.It Fl z Ar percent
> +Automatically suspend the system if no AC is connected and the
> +estimated battery life is equal or below
> +.Ar percent .
> +.It Fl Z Ar percent
> +Automatically hibernate the system if no AC is connected and the
> +estimated battery life is equal or below
> +.Ar percent .
> +This will supersedes
> +.Fl z .
>  .El
>  .Pp
>  When a client requests a suspend or stand-by state,
> Index: usr.sbin/apmd/apmd.c
> ===
> RCS file: /cvs/src/usr.sbin/apmd/apmd.c,v
> retrieving revision 1.79
> diff -u -p -r1.79 apmd.c
> --- usr.sbin/apmd/apmd.c  16 Nov 2015 17:35:05 -  1.79
> +++ usr.sbin/apmd/apmd.c  12 Aug 2017 21:18:28 -
> @@ -94,8 +94,8 @@ void
>  usage(void)
>  {
>   fprintf(stderr,
> - "usage: %s [-AadHLs] [-f devname] [-S sockname] [-t seconds]\n",
> - __progname);
> + "usage: %s [-AadHLs] [-f devname] [-S sockname] [-t seconds] "
> + "[-z percent] [-Z percent]\n", __progname);
>   exit(1);
>  }
>  
> @@ -348,6 +348,8 @@ main(int argc, char *argv[])
>  {
>   const char *fname = apmdev;
>   int ctl_fd, sock_fd, ch, suspends, standbys, hibernates, resumes;
> + int autoaction = 0;
> + int autolimit = 0;
>   int statonly = 0;
>   int powerstatus = 0, powerbak = 0, powerchange = 0;
>   int noacsleep = 0;
> @@ -361,7 +363,7 @@ main(int argc, char *argv[])
>   int ncpu;
>   size_t ncpu_sz = sizeof(ncpu);
>  
> - while ((ch = getopt(argc, argv, "aACdHLsf:t:S:")) != -1)
> + while ((ch = getopt(argc, argv, "aACdHLsf:t:S:z:Z:")) != -1)
>   switch(ch) {
>   case 'a':
>   noacsleep = 1;
> @@ -402,6 +404,14 @@ main(int argc, char *argv[])
>   doperf = PERF_MANUAL;
>   setperfpolicy("high");
>   break;
> + case 'z':
> + autoaction = 1;
Use a define here to remove the use of magic numbers.
Similar discussion has been going around for the lidsuspend sysctl.
> + autolimit = strtoul(optarg, NULL, 0);
Use strtonum here, and check for errors.
> + break;
> + case 'Z':
> + autoaction = 2;
> + autolimit = strtoul(optarg, NULL, 0);
Same here.
> + break;
>   case '?':
>   default:
>   usage();
> @@ -479,6 +489,20 @@ main(int argc, char *argv[])
>   if (powerstatus != powerbak) {
>   powerstatus = powerbak;
>   powerchange = 1;
> + }
> +
> + if (!powerstatus && autoaction &&
> + autolimit > (int)pinfo.battery_life) {
> + syslog(LOG_NOTICE, "estimated battery life 
> %d%%, "
> + "autoaction limit set to %d%% .",
> + pinfo.battery_life,
> + autolimit
> + );
> +
> + if (autoaction == 1)
> + suspend(ctl_fd);
> + else
> + hibernate(ctl_fd);
>   }
>   }
>  
>