History log of /openbsd-current/sys/dev/usb/udcf.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.66 23-May-2024 jsg

remove unneeded includes; ok mpi@


Revision tags: OPENBSD_7_2_BASE OPENBSD_7_3_BASE OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.65 02-Jul-2022 visa

Remove unused device poll functions.

Also remove unneeded includes of <sys/poll.h> and <sys/select.h>.

Some addenda from jsg@.

OK miod@ mpi@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.64 24-Jun-2020 cheloha

kernel: use gettime(9)/getuptime(9) in lieu of time_second(9)/time_uptime(9)

time_second(9) and time_uptime(9) are widely used in the kernel to
quickly get the system UTC or system uptime as a time_t. However,
time_t is 64-bit everywhere, so it is not generally safe to use them
on 32-bit platforms: you have a split-read problem if your hardware
cannot perform atomic 64-bit reads.

This patch replaces time_second(9) with gettime(9), a safer successor
interface, throughout the kernel. Similarly, time_uptime(9) is replaced
with getuptime(9).

There is a performance cost on 32-bit platforms in exchange for
eliminating the split-read problem: instead of two register reads you
now have a lockless read loop to pull the values from the timehands.
This is really not *too* bad in the grand scheme of things, but
compared to what we were doing before it is several times slower.

There is no performance cost on 64-bit (__LP64__) platforms.

With input from visa@, dlg@, and tedu@.

Several bugs squashed by visa@.

ok kettenis@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.63 10-Aug-2019 cheloha

udcf(4): tvtohz(9)+timeout_add(9) -> timeout_add_msec(9); ok kettenis@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.62 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.61 02-Sep-2016 mpi

Avoid calling usbd_set_config_index() in *_attach() and let the stack
do it instead.

If anything bad happen due to a malformed descriptor it makes no sense
to try to attach a driver, and bail before probing.


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.60 07-Jun-2015 claudio

The Swiss Federal Government decided to shut down HBG at the end of 2011.
On 6 September 2012 at 12:02:00 UTC both antenna towers were demolished by
controlled explosives. So this is not coming back and we can tedu the
support for HBG form the DCF77 drivers.
Remided by mbalmer


# 1.59 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.58 12-Jul-2014 mpi

tedu another bunch of DVACT_DEACTIVATE handlers that do nothing but set
the 'dying' flag.


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.57 15-Apr-2013 mglocker

Get rid of various 'typedef struct' definitions and use plain structure
definitions instead. We don't change usb.h for now to stay compatible
with userland.

Tested by mpi@ on macppc and myself on i386.

ok mpi@


# 1.56 28-Mar-2013 tedu

proc.h is way too much header for usb to handle.


# 1.55 28-Mar-2013 tedu

you probably don't need to include vnode.h or reboot.h. you most definitely
absolutely do not need to include vnode.h because it includes uvm_extern.h
and you want the idiotic TRUE FALSE defines from uvm.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.54 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


Revision tags: OPENBSD_4_9_BASE
# 1.53 25-Jan-2011 jakemsr

garbage collect "usb events". without /dev/usb there is no way to access
them from userland, and nothing in the kernel uses them.

ok krw@, miod@


# 1.52 17-Dec-2010 jasper

- use usb_lookup() instead of handrolled macro

ok jakemsr@


# 1.51 06-Dec-2010 jakemsr

* replace per-driver dying and/or other state variables with use of
usbd_deactivete() and usbd_is_dying()
* use usbd_deactivate() in activate()/DEACTIVATE
* convert a few more direct checks of the associated bus' dying flag
with usbd_is_dying()


# 1.50 23-Oct-2010 jakemsr

check that a timeout(9) has been initialized before deleting it

ok phessler


# 1.49 23-Oct-2010 jakemsr

create another kthread to run xfer abort tasks. xfer abort tasks cannot
be run from the generic task kthread, because xfers that need to be
aborted block newly queued tasks from running (i.e. the xfer to be aborted
blocks the abort of that task). as there are now three types of usb
tasks, add an argument to usb_init_task() and another member to struct
usb_task to specify the task type.

fixes boot hangs that are showing up because we now use usb tasks to
attach/detach usb devices.


# 1.48 24-Sep-2010 yuo

remove dying flag in detach() function.
The dying flag will be set in activate()/DEACTIVATE.

ok deraadt@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.47 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_6_BASE
# 1.46 26-Apr-2009 cnst

in ca_attach() there is no need to set .value and .flags of sensors to 0,
since autoconf(9) allocates softc with M_ZERO; ok deraadt


Revision tags: OPENBSD_4_5_BASE
# 1.45 21-Nov-2008 mbalmer

Kill some whitespace, removed unneeded stuff at the end of a list.


Revision tags: OPENBSD_4_4_BASE
# 1.44 10-Jul-2008 mbalmer

Don't terminate the array of matching product/vendor IDs with { 0, 0 }
when usb_lookup is used. If a device indeed has 0 as vendor and product
ID, like the HP DL165 BMC Server Engines SE USB Device, a wrong driver
will attach and the machine will most pbly crash.

Problem reported Rivo Nurges <rix@estpak.ee>
cvs: ----------------------------------------------------------------------


# 1.43 06-Jul-2008 mbalmer

Use UT_{READ|WRITE}_VENDOR_DEVICE instead of self defined values.


# 1.42 05-Jul-2008 mbalmer

Add support for the new Expert mouseCLOCK USB II that uses an FTDI
FT232R chip to interface the receiver (instead of the NetCologne
chip used on older models). Only the DCF77 and HBG receivers are
supported.

A sidenote: Gude ADS not only provides me with receivers and
documentation, but as a result of my feedback on their older receivers
the new ones now have proper USB product IDs to distinguish between
DCF77, HBG, and MSF.


Revision tags: OPENBSD_4_3_BASE
# 1.41 23-Nov-2007 mbalmer

Make sure that variables used during detach are initialized during attach.
Discussed with dlg.


# 1.40 23-Nov-2007 mbalmer

No need for process context to degrade the sensor status.
Discussed with kettenis.


# 1.39 11-Oct-2007 deraadt

treat usb vendor/product names as a locator, and have usbd_print handle it,
so that it shows up before the :. as a result, all the usb devices do not
need to have name printing code anymore. all this now works and prints
nicely because usbd_probe_and_attach() is serialized. ok kettenis


Revision tags: OPENBSD_4_2_BASE
# 1.38 14-Jun-2007 mbalmer

Remove the definition and usage of the USB_DECLARE_DRIVER_CLASS and
USB_DECLARE_DRIVER macros.

No binary change.

ok dlg.


# 1.37 12-Jun-2007 mbalmer

Remove the definition and use of the device_ptr_t which was a struct device *.

No binary change.

ok mk.


# 1.36 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEVNAME macro.

(This might look easy, but it was a big diff. Thanks to dlg and especially jsg
for looking over it; we found at least four mistakes in the initial diff.)

ok jsg.


# 1.35 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEV macro. It only created confusion
and the address of it's argument: USBDEV(sc->sc_dev) yields &sc->sc_dev.

No binary changes.

ok jsg.


# 1.34 06-Jun-2007 mk

Mechanical removal of USBBASEDEVICE. No binary change.

Tested by thib and myself.

ok mbalmer jsg


# 1.33 27-May-2007 jsg

Farewell USB_{ATTACH,MATCH,DETACH}* you will not be missed.
ok deraadt@ krw@ mbalmer@


# 1.32 21-Apr-2007 art

Back out last. the world is not i386.


# 1.31 21-Apr-2007 mbalmer

Remove unused header files.


# 1.30 22-Mar-2007 deraadt

split userland & kernel struct sensor/sensordev so that the addition
of new fields in the future is less disruptive. This is done similar
to how struct proc is handled for ps(1). ok jmc (man page changes)
tested fkr simon, and more suggestions from millert


Revision tags: OPENBSD_4_1_BASE
# 1.29 02-Jan-2007 mbalmer

return is not a function.


# 1.28 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.27 10-Dec-2006 mbalmer

Make sure the bit collecting is restarted after signal loss.


# 1.26 10-Dec-2006 mbalmer

restart collecting bits immediately after a parity error, i.e. use the frame
immediately following the corrupt one; there is no no need to skip it by
waiting for the next minute gap and the sensor value has valid data one
minute earlier than before.


# 1.25 10-Dec-2006 mbalmer

Re-arm signal loss detection only after we received a bit, not in itself. This
prevents the signal loss function from being called repeatedly when we have
no signal.


# 1.24 10-Dec-2006 mbalmer

Faster synchronization after an unexpected minute gap.
Only look at the skew value if it is != 0.
Remove some dead code.


# 1.23 06-Dec-2006 mbalmer

When compiled with UDCF_DEBUG, only output the bits received when
udcfdebug > 1.


# 1.22 05-Dec-2006 mbalmer

Add code to detect (and eliminate) statistical outliers. Tested by me and
naddy; many thanks to naddy for continous testing and feedback during the
last weeks.

ok naddy


# 1.21 15-Nov-2006 mbalmer

Fix an integer type promotion that can lead to wrong offsets on 64 bit arches.
Problem and solution found by Christian "Naddy" Weisgerber <naddy@openbsd.org>,
thanks!


# 1.20 28-Oct-2006 mbalmer

- Use better names for the variables containing the timeouts in Hz instead of
just t1-t10.
- Remove some unused variables.
- Restructure some functions to remove some levels of indentation.


# 1.19 27-Oct-2006 mbalmer

udcf(4) degraded the sensor status from OK to WARNING on the first receiption
error, which is to fast as this does not give ntpd the opportunity to use the
sensor value.

If we decode a valid time information, it has to be available to applications
for some minimal time. I choose a value of 5 minutes. If we do not receive
any new valid time information during this period, the sensor will be degraded
to WARNING, and after another fifteen minutes it will be further degraded to
CRITICAL.

"makes sense to me" henning@, "sure" deraadt@


# 1.18 14-Oct-2006 mbalmer

Apply some formatting.


# 1.17 11-Oct-2006 mbalmer

Make the timedelta sensor appear right when a device is plugged-in, with a
status of SENSOR_S_UNKNOWN. Do not set the SENSOR_FINVALID bit, sysctl
hw.sensors does not list sensors with this flags set and we want to the sensor
when the device is present.

ok henning


Revision tags: OPENBSD_4_0_BASE
# 1.16 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.15 19-Jun-2006 mbalmer

remove the no longer needed time calculations now that we have them in
sys/kern/clock_subr.c


# 1.14 19-Jun-2006 deraadt

move clock_subr.c to a better place, and now it is always in the kernel
so that things can use it; tested on all architectures; ok kettenis


# 1.13 17-Jun-2006 mbalmer

udcf(4) no longer needs the file sys/dev/clock_subr.c to be compiled and linked
to the kernel, the two functions it used from this file are now included in
the driver itself (like in nmea(4)). udcf(4) can now be enabled to the zaurus,
too. in fact on all arches that have USB support.


# 1.12 12-Jun-2006 mbalmer

Typos in comments.


# 1.11 05-Jun-2006 mbalmer

cleanup.


# 1.10 04-Jun-2006 mbalmer

- ntpd no longer needs the NTP identifier as part of a timedelta sensor
description.
- create the timedelta sensors as early as possible, but mark them invalid
as long as there is no real data.
- update docs accordingly


# 1.9 28-May-2006 mbalmer

Change the timedelta sensor descritpion so that the first four bytes contain
the NTP identifier (filled with spaces), followed by a space and the station
name (which might be the same as the NTP identifier).

All timedelta sensor have to follow this scheme as OpenNTPD needs it.

Requested by henning.


# 1.8 27-May-2006 mbalmer

There is no longer the need to create INVALID sensors on stock, the sensor
framework will create hotplug events for sensor addition/deletion. ntpd
will catch these events.


# 1.7 27-May-2006 mbalmer

When the device is attached, immediately create the timedelta sensor with the
SENSOR_FINVALID flag set and without a description. We do not need a dummy
description as a sensor with the FINVALID flags set will not show up or be used
anyways. It's merely an indication to applications that there is a sensor that
will eventually have a correct value.

The SENSOR_FINVALID flag is removed and the description is set to the proper
clockname as soon as we have received the first valid time information.

This enables ntpd to check for hotplug events and rescan the list of timedelta
sensors after a hotplug event.

discussed with deraadt.


# 1.6 27-Apr-2006 mbalmer

cope with recent changes in the sensor framework

- provide the timedelta in nanoseconds
- provide a timestamp in the sensor

support for HBG and DCF77:

- detect clocktype (DCF77 or HBG) and set it once is the sensor description


# 1.5 22-Apr-2006 mbalmer

Simplify time calculations.

help and ok kettenis@


# 1.4 21-Apr-2006 mbalmer

make udcf work as a SENSOR_TIMEDELTA type sensor. The sensor value is the
offset between the time of the device and the localtime in mSec.

the sensor status is set to OK once we received a complete and valid time
information.

help and ok deraadt


# 1.3 20-Apr-2006 deraadt

open/close/cdevsw code goes bye bye; ok mbalber


# 1.2 20-Apr-2006 mbalmer

- remove the 'needs-flag' from the udcf entry in files.usb and the #ifdef NUDCF
idom in udcf.c
- declare t1 to t7 as static to prevent the risk of name clashes
- add two missing function prototypes

help and ok miod@


# 1.1 19-Apr-2006 mbalmer

Driver to decode the DCF77 time code using a USB attached Gude Expert
mouseCLOCK device; without a mechanism to pass data out.

ok deraadt


# 1.65 02-Jul-2022 visa

Remove unused device poll functions.

Also remove unneeded includes of <sys/poll.h> and <sys/select.h>.

Some addenda from jsg@.

OK miod@ mpi@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.64 24-Jun-2020 cheloha

kernel: use gettime(9)/getuptime(9) in lieu of time_second(9)/time_uptime(9)

time_second(9) and time_uptime(9) are widely used in the kernel to
quickly get the system UTC or system uptime as a time_t. However,
time_t is 64-bit everywhere, so it is not generally safe to use them
on 32-bit platforms: you have a split-read problem if your hardware
cannot perform atomic 64-bit reads.

This patch replaces time_second(9) with gettime(9), a safer successor
interface, throughout the kernel. Similarly, time_uptime(9) is replaced
with getuptime(9).

There is a performance cost on 32-bit platforms in exchange for
eliminating the split-read problem: instead of two register reads you
now have a lockless read loop to pull the values from the timehands.
This is really not *too* bad in the grand scheme of things, but
compared to what we were doing before it is several times slower.

There is no performance cost on 64-bit (__LP64__) platforms.

With input from visa@, dlg@, and tedu@.

Several bugs squashed by visa@.

ok kettenis@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.63 10-Aug-2019 cheloha

udcf(4): tvtohz(9)+timeout_add(9) -> timeout_add_msec(9); ok kettenis@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.62 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.61 02-Sep-2016 mpi

Avoid calling usbd_set_config_index() in *_attach() and let the stack
do it instead.

If anything bad happen due to a malformed descriptor it makes no sense
to try to attach a driver, and bail before probing.


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.60 07-Jun-2015 claudio

The Swiss Federal Government decided to shut down HBG at the end of 2011.
On 6 September 2012 at 12:02:00 UTC both antenna towers were demolished by
controlled explosives. So this is not coming back and we can tedu the
support for HBG form the DCF77 drivers.
Remided by mbalmer


# 1.59 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.58 12-Jul-2014 mpi

tedu another bunch of DVACT_DEACTIVATE handlers that do nothing but set
the 'dying' flag.


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.57 15-Apr-2013 mglocker

Get rid of various 'typedef struct' definitions and use plain structure
definitions instead. We don't change usb.h for now to stay compatible
with userland.

Tested by mpi@ on macppc and myself on i386.

ok mpi@


# 1.56 28-Mar-2013 tedu

proc.h is way too much header for usb to handle.


# 1.55 28-Mar-2013 tedu

you probably don't need to include vnode.h or reboot.h. you most definitely
absolutely do not need to include vnode.h because it includes uvm_extern.h
and you want the idiotic TRUE FALSE defines from uvm.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.54 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


Revision tags: OPENBSD_4_9_BASE
# 1.53 25-Jan-2011 jakemsr

garbage collect "usb events". without /dev/usb there is no way to access
them from userland, and nothing in the kernel uses them.

ok krw@, miod@


# 1.52 17-Dec-2010 jasper

- use usb_lookup() instead of handrolled macro

ok jakemsr@


# 1.51 06-Dec-2010 jakemsr

* replace per-driver dying and/or other state variables with use of
usbd_deactivete() and usbd_is_dying()
* use usbd_deactivate() in activate()/DEACTIVATE
* convert a few more direct checks of the associated bus' dying flag
with usbd_is_dying()


# 1.50 23-Oct-2010 jakemsr

check that a timeout(9) has been initialized before deleting it

ok phessler


# 1.49 23-Oct-2010 jakemsr

create another kthread to run xfer abort tasks. xfer abort tasks cannot
be run from the generic task kthread, because xfers that need to be
aborted block newly queued tasks from running (i.e. the xfer to be aborted
blocks the abort of that task). as there are now three types of usb
tasks, add an argument to usb_init_task() and another member to struct
usb_task to specify the task type.

fixes boot hangs that are showing up because we now use usb tasks to
attach/detach usb devices.


# 1.48 24-Sep-2010 yuo

remove dying flag in detach() function.
The dying flag will be set in activate()/DEACTIVATE.

ok deraadt@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.47 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_6_BASE
# 1.46 26-Apr-2009 cnst

in ca_attach() there is no need to set .value and .flags of sensors to 0,
since autoconf(9) allocates softc with M_ZERO; ok deraadt


Revision tags: OPENBSD_4_5_BASE
# 1.45 21-Nov-2008 mbalmer

Kill some whitespace, removed unneeded stuff at the end of a list.


Revision tags: OPENBSD_4_4_BASE
# 1.44 10-Jul-2008 mbalmer

Don't terminate the array of matching product/vendor IDs with { 0, 0 }
when usb_lookup is used. If a device indeed has 0 as vendor and product
ID, like the HP DL165 BMC Server Engines SE USB Device, a wrong driver
will attach and the machine will most pbly crash.

Problem reported Rivo Nurges <rix@estpak.ee>
cvs: ----------------------------------------------------------------------


# 1.43 06-Jul-2008 mbalmer

Use UT_{READ|WRITE}_VENDOR_DEVICE instead of self defined values.


# 1.42 05-Jul-2008 mbalmer

Add support for the new Expert mouseCLOCK USB II that uses an FTDI
FT232R chip to interface the receiver (instead of the NetCologne
chip used on older models). Only the DCF77 and HBG receivers are
supported.

A sidenote: Gude ADS not only provides me with receivers and
documentation, but as a result of my feedback on their older receivers
the new ones now have proper USB product IDs to distinguish between
DCF77, HBG, and MSF.


Revision tags: OPENBSD_4_3_BASE
# 1.41 23-Nov-2007 mbalmer

Make sure that variables used during detach are initialized during attach.
Discussed with dlg.


# 1.40 23-Nov-2007 mbalmer

No need for process context to degrade the sensor status.
Discussed with kettenis.


# 1.39 11-Oct-2007 deraadt

treat usb vendor/product names as a locator, and have usbd_print handle it,
so that it shows up before the :. as a result, all the usb devices do not
need to have name printing code anymore. all this now works and prints
nicely because usbd_probe_and_attach() is serialized. ok kettenis


Revision tags: OPENBSD_4_2_BASE
# 1.38 14-Jun-2007 mbalmer

Remove the definition and usage of the USB_DECLARE_DRIVER_CLASS and
USB_DECLARE_DRIVER macros.

No binary change.

ok dlg.


# 1.37 12-Jun-2007 mbalmer

Remove the definition and use of the device_ptr_t which was a struct device *.

No binary change.

ok mk.


# 1.36 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEVNAME macro.

(This might look easy, but it was a big diff. Thanks to dlg and especially jsg
for looking over it; we found at least four mistakes in the initial diff.)

ok jsg.


# 1.35 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEV macro. It only created confusion
and the address of it's argument: USBDEV(sc->sc_dev) yields &sc->sc_dev.

No binary changes.

ok jsg.


# 1.34 06-Jun-2007 mk

Mechanical removal of USBBASEDEVICE. No binary change.

Tested by thib and myself.

ok mbalmer jsg


# 1.33 27-May-2007 jsg

Farewell USB_{ATTACH,MATCH,DETACH}* you will not be missed.
ok deraadt@ krw@ mbalmer@


# 1.32 21-Apr-2007 art

Back out last. the world is not i386.


# 1.31 21-Apr-2007 mbalmer

Remove unused header files.


# 1.30 22-Mar-2007 deraadt

split userland & kernel struct sensor/sensordev so that the addition
of new fields in the future is less disruptive. This is done similar
to how struct proc is handled for ps(1). ok jmc (man page changes)
tested fkr simon, and more suggestions from millert


Revision tags: OPENBSD_4_1_BASE
# 1.29 02-Jan-2007 mbalmer

return is not a function.


# 1.28 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.27 10-Dec-2006 mbalmer

Make sure the bit collecting is restarted after signal loss.


# 1.26 10-Dec-2006 mbalmer

restart collecting bits immediately after a parity error, i.e. use the frame
immediately following the corrupt one; there is no no need to skip it by
waiting for the next minute gap and the sensor value has valid data one
minute earlier than before.


# 1.25 10-Dec-2006 mbalmer

Re-arm signal loss detection only after we received a bit, not in itself. This
prevents the signal loss function from being called repeatedly when we have
no signal.


# 1.24 10-Dec-2006 mbalmer

Faster synchronization after an unexpected minute gap.
Only look at the skew value if it is != 0.
Remove some dead code.


# 1.23 06-Dec-2006 mbalmer

When compiled with UDCF_DEBUG, only output the bits received when
udcfdebug > 1.


# 1.22 05-Dec-2006 mbalmer

Add code to detect (and eliminate) statistical outliers. Tested by me and
naddy; many thanks to naddy for continous testing and feedback during the
last weeks.

ok naddy


# 1.21 15-Nov-2006 mbalmer

Fix an integer type promotion that can lead to wrong offsets on 64 bit arches.
Problem and solution found by Christian "Naddy" Weisgerber <naddy@openbsd.org>,
thanks!


# 1.20 28-Oct-2006 mbalmer

- Use better names for the variables containing the timeouts in Hz instead of
just t1-t10.
- Remove some unused variables.
- Restructure some functions to remove some levels of indentation.


# 1.19 27-Oct-2006 mbalmer

udcf(4) degraded the sensor status from OK to WARNING on the first receiption
error, which is to fast as this does not give ntpd the opportunity to use the
sensor value.

If we decode a valid time information, it has to be available to applications
for some minimal time. I choose a value of 5 minutes. If we do not receive
any new valid time information during this period, the sensor will be degraded
to WARNING, and after another fifteen minutes it will be further degraded to
CRITICAL.

"makes sense to me" henning@, "sure" deraadt@


# 1.18 14-Oct-2006 mbalmer

Apply some formatting.


# 1.17 11-Oct-2006 mbalmer

Make the timedelta sensor appear right when a device is plugged-in, with a
status of SENSOR_S_UNKNOWN. Do not set the SENSOR_FINVALID bit, sysctl
hw.sensors does not list sensors with this flags set and we want to the sensor
when the device is present.

ok henning


Revision tags: OPENBSD_4_0_BASE
# 1.16 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.15 19-Jun-2006 mbalmer

remove the no longer needed time calculations now that we have them in
sys/kern/clock_subr.c


# 1.14 19-Jun-2006 deraadt

move clock_subr.c to a better place, and now it is always in the kernel
so that things can use it; tested on all architectures; ok kettenis


# 1.13 17-Jun-2006 mbalmer

udcf(4) no longer needs the file sys/dev/clock_subr.c to be compiled and linked
to the kernel, the two functions it used from this file are now included in
the driver itself (like in nmea(4)). udcf(4) can now be enabled to the zaurus,
too. in fact on all arches that have USB support.


# 1.12 12-Jun-2006 mbalmer

Typos in comments.


# 1.11 05-Jun-2006 mbalmer

cleanup.


# 1.10 04-Jun-2006 mbalmer

- ntpd no longer needs the NTP identifier as part of a timedelta sensor
description.
- create the timedelta sensors as early as possible, but mark them invalid
as long as there is no real data.
- update docs accordingly


# 1.9 28-May-2006 mbalmer

Change the timedelta sensor descritpion so that the first four bytes contain
the NTP identifier (filled with spaces), followed by a space and the station
name (which might be the same as the NTP identifier).

All timedelta sensor have to follow this scheme as OpenNTPD needs it.

Requested by henning.


# 1.8 27-May-2006 mbalmer

There is no longer the need to create INVALID sensors on stock, the sensor
framework will create hotplug events for sensor addition/deletion. ntpd
will catch these events.


# 1.7 27-May-2006 mbalmer

When the device is attached, immediately create the timedelta sensor with the
SENSOR_FINVALID flag set and without a description. We do not need a dummy
description as a sensor with the FINVALID flags set will not show up or be used
anyways. It's merely an indication to applications that there is a sensor that
will eventually have a correct value.

The SENSOR_FINVALID flag is removed and the description is set to the proper
clockname as soon as we have received the first valid time information.

This enables ntpd to check for hotplug events and rescan the list of timedelta
sensors after a hotplug event.

discussed with deraadt.


# 1.6 27-Apr-2006 mbalmer

cope with recent changes in the sensor framework

- provide the timedelta in nanoseconds
- provide a timestamp in the sensor

support for HBG and DCF77:

- detect clocktype (DCF77 or HBG) and set it once is the sensor description


# 1.5 22-Apr-2006 mbalmer

Simplify time calculations.

help and ok kettenis@


# 1.4 21-Apr-2006 mbalmer

make udcf work as a SENSOR_TIMEDELTA type sensor. The sensor value is the
offset between the time of the device and the localtime in mSec.

the sensor status is set to OK once we received a complete and valid time
information.

help and ok deraadt


# 1.3 20-Apr-2006 deraadt

open/close/cdevsw code goes bye bye; ok mbalber


# 1.2 20-Apr-2006 mbalmer

- remove the 'needs-flag' from the udcf entry in files.usb and the #ifdef NUDCF
idom in udcf.c
- declare t1 to t7 as static to prevent the risk of name clashes
- add two missing function prototypes

help and ok miod@


# 1.1 19-Apr-2006 mbalmer

Driver to decode the DCF77 time code using a USB attached Gude Expert
mouseCLOCK device; without a mechanism to pass data out.

ok deraadt


# 1.64 24-Jun-2020 cheloha

kernel: use gettime(9)/getuptime(9) in lieu of time_second(9)/time_uptime(9)

time_second(9) and time_uptime(9) are widely used in the kernel to
quickly get the system UTC or system uptime as a time_t. However,
time_t is 64-bit everywhere, so it is not generally safe to use them
on 32-bit platforms: you have a split-read problem if your hardware
cannot perform atomic 64-bit reads.

This patch replaces time_second(9) with gettime(9), a safer successor
interface, throughout the kernel. Similarly, time_uptime(9) is replaced
with getuptime(9).

There is a performance cost on 32-bit platforms in exchange for
eliminating the split-read problem: instead of two register reads you
now have a lockless read loop to pull the values from the timehands.
This is really not *too* bad in the grand scheme of things, but
compared to what we were doing before it is several times slower.

There is no performance cost on 64-bit (__LP64__) platforms.

With input from visa@, dlg@, and tedu@.

Several bugs squashed by visa@.

ok kettenis@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.63 10-Aug-2019 cheloha

udcf(4): tvtohz(9)+timeout_add(9) -> timeout_add_msec(9); ok kettenis@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.62 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.61 02-Sep-2016 mpi

Avoid calling usbd_set_config_index() in *_attach() and let the stack
do it instead.

If anything bad happen due to a malformed descriptor it makes no sense
to try to attach a driver, and bail before probing.


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.60 07-Jun-2015 claudio

The Swiss Federal Government decided to shut down HBG at the end of 2011.
On 6 September 2012 at 12:02:00 UTC both antenna towers were demolished by
controlled explosives. So this is not coming back and we can tedu the
support for HBG form the DCF77 drivers.
Remided by mbalmer


# 1.59 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.58 12-Jul-2014 mpi

tedu another bunch of DVACT_DEACTIVATE handlers that do nothing but set
the 'dying' flag.


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.57 15-Apr-2013 mglocker

Get rid of various 'typedef struct' definitions and use plain structure
definitions instead. We don't change usb.h for now to stay compatible
with userland.

Tested by mpi@ on macppc and myself on i386.

ok mpi@


# 1.56 28-Mar-2013 tedu

proc.h is way too much header for usb to handle.


# 1.55 28-Mar-2013 tedu

you probably don't need to include vnode.h or reboot.h. you most definitely
absolutely do not need to include vnode.h because it includes uvm_extern.h
and you want the idiotic TRUE FALSE defines from uvm.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.54 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


Revision tags: OPENBSD_4_9_BASE
# 1.53 25-Jan-2011 jakemsr

garbage collect "usb events". without /dev/usb there is no way to access
them from userland, and nothing in the kernel uses them.

ok krw@, miod@


# 1.52 17-Dec-2010 jasper

- use usb_lookup() instead of handrolled macro

ok jakemsr@


# 1.51 06-Dec-2010 jakemsr

* replace per-driver dying and/or other state variables with use of
usbd_deactivete() and usbd_is_dying()
* use usbd_deactivate() in activate()/DEACTIVATE
* convert a few more direct checks of the associated bus' dying flag
with usbd_is_dying()


# 1.50 23-Oct-2010 jakemsr

check that a timeout(9) has been initialized before deleting it

ok phessler


# 1.49 23-Oct-2010 jakemsr

create another kthread to run xfer abort tasks. xfer abort tasks cannot
be run from the generic task kthread, because xfers that need to be
aborted block newly queued tasks from running (i.e. the xfer to be aborted
blocks the abort of that task). as there are now three types of usb
tasks, add an argument to usb_init_task() and another member to struct
usb_task to specify the task type.

fixes boot hangs that are showing up because we now use usb tasks to
attach/detach usb devices.


# 1.48 24-Sep-2010 yuo

remove dying flag in detach() function.
The dying flag will be set in activate()/DEACTIVATE.

ok deraadt@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.47 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_6_BASE
# 1.46 26-Apr-2009 cnst

in ca_attach() there is no need to set .value and .flags of sensors to 0,
since autoconf(9) allocates softc with M_ZERO; ok deraadt


Revision tags: OPENBSD_4_5_BASE
# 1.45 21-Nov-2008 mbalmer

Kill some whitespace, removed unneeded stuff at the end of a list.


Revision tags: OPENBSD_4_4_BASE
# 1.44 10-Jul-2008 mbalmer

Don't terminate the array of matching product/vendor IDs with { 0, 0 }
when usb_lookup is used. If a device indeed has 0 as vendor and product
ID, like the HP DL165 BMC Server Engines SE USB Device, a wrong driver
will attach and the machine will most pbly crash.

Problem reported Rivo Nurges <rix@estpak.ee>
cvs: ----------------------------------------------------------------------


# 1.43 06-Jul-2008 mbalmer

Use UT_{READ|WRITE}_VENDOR_DEVICE instead of self defined values.


# 1.42 05-Jul-2008 mbalmer

Add support for the new Expert mouseCLOCK USB II that uses an FTDI
FT232R chip to interface the receiver (instead of the NetCologne
chip used on older models). Only the DCF77 and HBG receivers are
supported.

A sidenote: Gude ADS not only provides me with receivers and
documentation, but as a result of my feedback on their older receivers
the new ones now have proper USB product IDs to distinguish between
DCF77, HBG, and MSF.


Revision tags: OPENBSD_4_3_BASE
# 1.41 23-Nov-2007 mbalmer

Make sure that variables used during detach are initialized during attach.
Discussed with dlg.


# 1.40 23-Nov-2007 mbalmer

No need for process context to degrade the sensor status.
Discussed with kettenis.


# 1.39 11-Oct-2007 deraadt

treat usb vendor/product names as a locator, and have usbd_print handle it,
so that it shows up before the :. as a result, all the usb devices do not
need to have name printing code anymore. all this now works and prints
nicely because usbd_probe_and_attach() is serialized. ok kettenis


Revision tags: OPENBSD_4_2_BASE
# 1.38 14-Jun-2007 mbalmer

Remove the definition and usage of the USB_DECLARE_DRIVER_CLASS and
USB_DECLARE_DRIVER macros.

No binary change.

ok dlg.


# 1.37 12-Jun-2007 mbalmer

Remove the definition and use of the device_ptr_t which was a struct device *.

No binary change.

ok mk.


# 1.36 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEVNAME macro.

(This might look easy, but it was a big diff. Thanks to dlg and especially jsg
for looking over it; we found at least four mistakes in the initial diff.)

ok jsg.


# 1.35 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEV macro. It only created confusion
and the address of it's argument: USBDEV(sc->sc_dev) yields &sc->sc_dev.

No binary changes.

ok jsg.


# 1.34 06-Jun-2007 mk

Mechanical removal of USBBASEDEVICE. No binary change.

Tested by thib and myself.

ok mbalmer jsg


# 1.33 27-May-2007 jsg

Farewell USB_{ATTACH,MATCH,DETACH}* you will not be missed.
ok deraadt@ krw@ mbalmer@


# 1.32 21-Apr-2007 art

Back out last. the world is not i386.


# 1.31 21-Apr-2007 mbalmer

Remove unused header files.


# 1.30 22-Mar-2007 deraadt

split userland & kernel struct sensor/sensordev so that the addition
of new fields in the future is less disruptive. This is done similar
to how struct proc is handled for ps(1). ok jmc (man page changes)
tested fkr simon, and more suggestions from millert


Revision tags: OPENBSD_4_1_BASE
# 1.29 02-Jan-2007 mbalmer

return is not a function.


# 1.28 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.27 10-Dec-2006 mbalmer

Make sure the bit collecting is restarted after signal loss.


# 1.26 10-Dec-2006 mbalmer

restart collecting bits immediately after a parity error, i.e. use the frame
immediately following the corrupt one; there is no no need to skip it by
waiting for the next minute gap and the sensor value has valid data one
minute earlier than before.


# 1.25 10-Dec-2006 mbalmer

Re-arm signal loss detection only after we received a bit, not in itself. This
prevents the signal loss function from being called repeatedly when we have
no signal.


# 1.24 10-Dec-2006 mbalmer

Faster synchronization after an unexpected minute gap.
Only look at the skew value if it is != 0.
Remove some dead code.


# 1.23 06-Dec-2006 mbalmer

When compiled with UDCF_DEBUG, only output the bits received when
udcfdebug > 1.


# 1.22 05-Dec-2006 mbalmer

Add code to detect (and eliminate) statistical outliers. Tested by me and
naddy; many thanks to naddy for continous testing and feedback during the
last weeks.

ok naddy


# 1.21 15-Nov-2006 mbalmer

Fix an integer type promotion that can lead to wrong offsets on 64 bit arches.
Problem and solution found by Christian "Naddy" Weisgerber <naddy@openbsd.org>,
thanks!


# 1.20 28-Oct-2006 mbalmer

- Use better names for the variables containing the timeouts in Hz instead of
just t1-t10.
- Remove some unused variables.
- Restructure some functions to remove some levels of indentation.


# 1.19 27-Oct-2006 mbalmer

udcf(4) degraded the sensor status from OK to WARNING on the first receiption
error, which is to fast as this does not give ntpd the opportunity to use the
sensor value.

If we decode a valid time information, it has to be available to applications
for some minimal time. I choose a value of 5 minutes. If we do not receive
any new valid time information during this period, the sensor will be degraded
to WARNING, and after another fifteen minutes it will be further degraded to
CRITICAL.

"makes sense to me" henning@, "sure" deraadt@


# 1.18 14-Oct-2006 mbalmer

Apply some formatting.


# 1.17 11-Oct-2006 mbalmer

Make the timedelta sensor appear right when a device is plugged-in, with a
status of SENSOR_S_UNKNOWN. Do not set the SENSOR_FINVALID bit, sysctl
hw.sensors does not list sensors with this flags set and we want to the sensor
when the device is present.

ok henning


Revision tags: OPENBSD_4_0_BASE
# 1.16 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.15 19-Jun-2006 mbalmer

remove the no longer needed time calculations now that we have them in
sys/kern/clock_subr.c


# 1.14 19-Jun-2006 deraadt

move clock_subr.c to a better place, and now it is always in the kernel
so that things can use it; tested on all architectures; ok kettenis


# 1.13 17-Jun-2006 mbalmer

udcf(4) no longer needs the file sys/dev/clock_subr.c to be compiled and linked
to the kernel, the two functions it used from this file are now included in
the driver itself (like in nmea(4)). udcf(4) can now be enabled to the zaurus,
too. in fact on all arches that have USB support.


# 1.12 12-Jun-2006 mbalmer

Typos in comments.


# 1.11 05-Jun-2006 mbalmer

cleanup.


# 1.10 04-Jun-2006 mbalmer

- ntpd no longer needs the NTP identifier as part of a timedelta sensor
description.
- create the timedelta sensors as early as possible, but mark them invalid
as long as there is no real data.
- update docs accordingly


# 1.9 28-May-2006 mbalmer

Change the timedelta sensor descritpion so that the first four bytes contain
the NTP identifier (filled with spaces), followed by a space and the station
name (which might be the same as the NTP identifier).

All timedelta sensor have to follow this scheme as OpenNTPD needs it.

Requested by henning.


# 1.8 27-May-2006 mbalmer

There is no longer the need to create INVALID sensors on stock, the sensor
framework will create hotplug events for sensor addition/deletion. ntpd
will catch these events.


# 1.7 27-May-2006 mbalmer

When the device is attached, immediately create the timedelta sensor with the
SENSOR_FINVALID flag set and without a description. We do not need a dummy
description as a sensor with the FINVALID flags set will not show up or be used
anyways. It's merely an indication to applications that there is a sensor that
will eventually have a correct value.

The SENSOR_FINVALID flag is removed and the description is set to the proper
clockname as soon as we have received the first valid time information.

This enables ntpd to check for hotplug events and rescan the list of timedelta
sensors after a hotplug event.

discussed with deraadt.


# 1.6 27-Apr-2006 mbalmer

cope with recent changes in the sensor framework

- provide the timedelta in nanoseconds
- provide a timestamp in the sensor

support for HBG and DCF77:

- detect clocktype (DCF77 or HBG) and set it once is the sensor description


# 1.5 22-Apr-2006 mbalmer

Simplify time calculations.

help and ok kettenis@


# 1.4 21-Apr-2006 mbalmer

make udcf work as a SENSOR_TIMEDELTA type sensor. The sensor value is the
offset between the time of the device and the localtime in mSec.

the sensor status is set to OK once we received a complete and valid time
information.

help and ok deraadt


# 1.3 20-Apr-2006 deraadt

open/close/cdevsw code goes bye bye; ok mbalber


# 1.2 20-Apr-2006 mbalmer

- remove the 'needs-flag' from the udcf entry in files.usb and the #ifdef NUDCF
idom in udcf.c
- declare t1 to t7 as static to prevent the risk of name clashes
- add two missing function prototypes

help and ok miod@


# 1.1 19-Apr-2006 mbalmer

Driver to decode the DCF77 time code using a USB attached Gude Expert
mouseCLOCK device; without a mechanism to pass data out.

ok deraadt


# 1.63 10-Aug-2019 cheloha

udcf(4): tvtohz(9)+timeout_add(9) -> timeout_add_msec(9); ok kettenis@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.62 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.61 02-Sep-2016 mpi

Avoid calling usbd_set_config_index() in *_attach() and let the stack
do it instead.

If anything bad happen due to a malformed descriptor it makes no sense
to try to attach a driver, and bail before probing.


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.60 07-Jun-2015 claudio

The Swiss Federal Government decided to shut down HBG at the end of 2011.
On 6 September 2012 at 12:02:00 UTC both antenna towers were demolished by
controlled explosives. So this is not coming back and we can tedu the
support for HBG form the DCF77 drivers.
Remided by mbalmer


# 1.59 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.58 12-Jul-2014 mpi

tedu another bunch of DVACT_DEACTIVATE handlers that do nothing but set
the 'dying' flag.


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.57 15-Apr-2013 mglocker

Get rid of various 'typedef struct' definitions and use plain structure
definitions instead. We don't change usb.h for now to stay compatible
with userland.

Tested by mpi@ on macppc and myself on i386.

ok mpi@


# 1.56 28-Mar-2013 tedu

proc.h is way too much header for usb to handle.


# 1.55 28-Mar-2013 tedu

you probably don't need to include vnode.h or reboot.h. you most definitely
absolutely do not need to include vnode.h because it includes uvm_extern.h
and you want the idiotic TRUE FALSE defines from uvm.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.54 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


Revision tags: OPENBSD_4_9_BASE
# 1.53 25-Jan-2011 jakemsr

garbage collect "usb events". without /dev/usb there is no way to access
them from userland, and nothing in the kernel uses them.

ok krw@, miod@


# 1.52 17-Dec-2010 jasper

- use usb_lookup() instead of handrolled macro

ok jakemsr@


# 1.51 06-Dec-2010 jakemsr

* replace per-driver dying and/or other state variables with use of
usbd_deactivete() and usbd_is_dying()
* use usbd_deactivate() in activate()/DEACTIVATE
* convert a few more direct checks of the associated bus' dying flag
with usbd_is_dying()


# 1.50 23-Oct-2010 jakemsr

check that a timeout(9) has been initialized before deleting it

ok phessler


# 1.49 23-Oct-2010 jakemsr

create another kthread to run xfer abort tasks. xfer abort tasks cannot
be run from the generic task kthread, because xfers that need to be
aborted block newly queued tasks from running (i.e. the xfer to be aborted
blocks the abort of that task). as there are now three types of usb
tasks, add an argument to usb_init_task() and another member to struct
usb_task to specify the task type.

fixes boot hangs that are showing up because we now use usb tasks to
attach/detach usb devices.


# 1.48 24-Sep-2010 yuo

remove dying flag in detach() function.
The dying flag will be set in activate()/DEACTIVATE.

ok deraadt@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.47 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_6_BASE
# 1.46 26-Apr-2009 cnst

in ca_attach() there is no need to set .value and .flags of sensors to 0,
since autoconf(9) allocates softc with M_ZERO; ok deraadt


Revision tags: OPENBSD_4_5_BASE
# 1.45 21-Nov-2008 mbalmer

Kill some whitespace, removed unneeded stuff at the end of a list.


Revision tags: OPENBSD_4_4_BASE
# 1.44 10-Jul-2008 mbalmer

Don't terminate the array of matching product/vendor IDs with { 0, 0 }
when usb_lookup is used. If a device indeed has 0 as vendor and product
ID, like the HP DL165 BMC Server Engines SE USB Device, a wrong driver
will attach and the machine will most pbly crash.

Problem reported Rivo Nurges <rix@estpak.ee>
cvs: ----------------------------------------------------------------------


# 1.43 06-Jul-2008 mbalmer

Use UT_{READ|WRITE}_VENDOR_DEVICE instead of self defined values.


# 1.42 05-Jul-2008 mbalmer

Add support for the new Expert mouseCLOCK USB II that uses an FTDI
FT232R chip to interface the receiver (instead of the NetCologne
chip used on older models). Only the DCF77 and HBG receivers are
supported.

A sidenote: Gude ADS not only provides me with receivers and
documentation, but as a result of my feedback on their older receivers
the new ones now have proper USB product IDs to distinguish between
DCF77, HBG, and MSF.


Revision tags: OPENBSD_4_3_BASE
# 1.41 23-Nov-2007 mbalmer

Make sure that variables used during detach are initialized during attach.
Discussed with dlg.


# 1.40 23-Nov-2007 mbalmer

No need for process context to degrade the sensor status.
Discussed with kettenis.


# 1.39 11-Oct-2007 deraadt

treat usb vendor/product names as a locator, and have usbd_print handle it,
so that it shows up before the :. as a result, all the usb devices do not
need to have name printing code anymore. all this now works and prints
nicely because usbd_probe_and_attach() is serialized. ok kettenis


Revision tags: OPENBSD_4_2_BASE
# 1.38 14-Jun-2007 mbalmer

Remove the definition and usage of the USB_DECLARE_DRIVER_CLASS and
USB_DECLARE_DRIVER macros.

No binary change.

ok dlg.


# 1.37 12-Jun-2007 mbalmer

Remove the definition and use of the device_ptr_t which was a struct device *.

No binary change.

ok mk.


# 1.36 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEVNAME macro.

(This might look easy, but it was a big diff. Thanks to dlg and especially jsg
for looking over it; we found at least four mistakes in the initial diff.)

ok jsg.


# 1.35 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEV macro. It only created confusion
and the address of it's argument: USBDEV(sc->sc_dev) yields &sc->sc_dev.

No binary changes.

ok jsg.


# 1.34 06-Jun-2007 mk

Mechanical removal of USBBASEDEVICE. No binary change.

Tested by thib and myself.

ok mbalmer jsg


# 1.33 27-May-2007 jsg

Farewell USB_{ATTACH,MATCH,DETACH}* you will not be missed.
ok deraadt@ krw@ mbalmer@


# 1.32 21-Apr-2007 art

Back out last. the world is not i386.


# 1.31 21-Apr-2007 mbalmer

Remove unused header files.


# 1.30 22-Mar-2007 deraadt

split userland & kernel struct sensor/sensordev so that the addition
of new fields in the future is less disruptive. This is done similar
to how struct proc is handled for ps(1). ok jmc (man page changes)
tested fkr simon, and more suggestions from millert


Revision tags: OPENBSD_4_1_BASE
# 1.29 02-Jan-2007 mbalmer

return is not a function.


# 1.28 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.27 10-Dec-2006 mbalmer

Make sure the bit collecting is restarted after signal loss.


# 1.26 10-Dec-2006 mbalmer

restart collecting bits immediately after a parity error, i.e. use the frame
immediately following the corrupt one; there is no no need to skip it by
waiting for the next minute gap and the sensor value has valid data one
minute earlier than before.


# 1.25 10-Dec-2006 mbalmer

Re-arm signal loss detection only after we received a bit, not in itself. This
prevents the signal loss function from being called repeatedly when we have
no signal.


# 1.24 10-Dec-2006 mbalmer

Faster synchronization after an unexpected minute gap.
Only look at the skew value if it is != 0.
Remove some dead code.


# 1.23 06-Dec-2006 mbalmer

When compiled with UDCF_DEBUG, only output the bits received when
udcfdebug > 1.


# 1.22 05-Dec-2006 mbalmer

Add code to detect (and eliminate) statistical outliers. Tested by me and
naddy; many thanks to naddy for continous testing and feedback during the
last weeks.

ok naddy


# 1.21 15-Nov-2006 mbalmer

Fix an integer type promotion that can lead to wrong offsets on 64 bit arches.
Problem and solution found by Christian "Naddy" Weisgerber <naddy@openbsd.org>,
thanks!


# 1.20 28-Oct-2006 mbalmer

- Use better names for the variables containing the timeouts in Hz instead of
just t1-t10.
- Remove some unused variables.
- Restructure some functions to remove some levels of indentation.


# 1.19 27-Oct-2006 mbalmer

udcf(4) degraded the sensor status from OK to WARNING on the first receiption
error, which is to fast as this does not give ntpd the opportunity to use the
sensor value.

If we decode a valid time information, it has to be available to applications
for some minimal time. I choose a value of 5 minutes. If we do not receive
any new valid time information during this period, the sensor will be degraded
to WARNING, and after another fifteen minutes it will be further degraded to
CRITICAL.

"makes sense to me" henning@, "sure" deraadt@


# 1.18 14-Oct-2006 mbalmer

Apply some formatting.


# 1.17 11-Oct-2006 mbalmer

Make the timedelta sensor appear right when a device is plugged-in, with a
status of SENSOR_S_UNKNOWN. Do not set the SENSOR_FINVALID bit, sysctl
hw.sensors does not list sensors with this flags set and we want to the sensor
when the device is present.

ok henning


Revision tags: OPENBSD_4_0_BASE
# 1.16 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.15 19-Jun-2006 mbalmer

remove the no longer needed time calculations now that we have them in
sys/kern/clock_subr.c


# 1.14 19-Jun-2006 deraadt

move clock_subr.c to a better place, and now it is always in the kernel
so that things can use it; tested on all architectures; ok kettenis


# 1.13 17-Jun-2006 mbalmer

udcf(4) no longer needs the file sys/dev/clock_subr.c to be compiled and linked
to the kernel, the two functions it used from this file are now included in
the driver itself (like in nmea(4)). udcf(4) can now be enabled to the zaurus,
too. in fact on all arches that have USB support.


# 1.12 12-Jun-2006 mbalmer

Typos in comments.


# 1.11 05-Jun-2006 mbalmer

cleanup.


# 1.10 04-Jun-2006 mbalmer

- ntpd no longer needs the NTP identifier as part of a timedelta sensor
description.
- create the timedelta sensors as early as possible, but mark them invalid
as long as there is no real data.
- update docs accordingly


# 1.9 28-May-2006 mbalmer

Change the timedelta sensor descritpion so that the first four bytes contain
the NTP identifier (filled with spaces), followed by a space and the station
name (which might be the same as the NTP identifier).

All timedelta sensor have to follow this scheme as OpenNTPD needs it.

Requested by henning.


# 1.8 27-May-2006 mbalmer

There is no longer the need to create INVALID sensors on stock, the sensor
framework will create hotplug events for sensor addition/deletion. ntpd
will catch these events.


# 1.7 27-May-2006 mbalmer

When the device is attached, immediately create the timedelta sensor with the
SENSOR_FINVALID flag set and without a description. We do not need a dummy
description as a sensor with the FINVALID flags set will not show up or be used
anyways. It's merely an indication to applications that there is a sensor that
will eventually have a correct value.

The SENSOR_FINVALID flag is removed and the description is set to the proper
clockname as soon as we have received the first valid time information.

This enables ntpd to check for hotplug events and rescan the list of timedelta
sensors after a hotplug event.

discussed with deraadt.


# 1.6 27-Apr-2006 mbalmer

cope with recent changes in the sensor framework

- provide the timedelta in nanoseconds
- provide a timestamp in the sensor

support for HBG and DCF77:

- detect clocktype (DCF77 or HBG) and set it once is the sensor description


# 1.5 22-Apr-2006 mbalmer

Simplify time calculations.

help and ok kettenis@


# 1.4 21-Apr-2006 mbalmer

make udcf work as a SENSOR_TIMEDELTA type sensor. The sensor value is the
offset between the time of the device and the localtime in mSec.

the sensor status is set to OK once we received a complete and valid time
information.

help and ok deraadt


# 1.3 20-Apr-2006 deraadt

open/close/cdevsw code goes bye bye; ok mbalber


# 1.2 20-Apr-2006 mbalmer

- remove the 'needs-flag' from the udcf entry in files.usb and the #ifdef NUDCF
idom in udcf.c
- declare t1 to t7 as static to prevent the risk of name clashes
- add two missing function prototypes

help and ok miod@


# 1.1 19-Apr-2006 mbalmer

Driver to decode the DCF77 time code using a USB attached Gude Expert
mouseCLOCK device; without a mechanism to pass data out.

ok deraadt


# 1.62 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.61 02-Sep-2016 mpi

Avoid calling usbd_set_config_index() in *_attach() and let the stack
do it instead.

If anything bad happen due to a malformed descriptor it makes no sense
to try to attach a driver, and bail before probing.


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.60 07-Jun-2015 claudio

The Swiss Federal Government decided to shut down HBG at the end of 2011.
On 6 September 2012 at 12:02:00 UTC both antenna towers were demolished by
controlled explosives. So this is not coming back and we can tedu the
support for HBG form the DCF77 drivers.
Remided by mbalmer


# 1.59 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.58 12-Jul-2014 mpi

tedu another bunch of DVACT_DEACTIVATE handlers that do nothing but set
the 'dying' flag.


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.57 15-Apr-2013 mglocker

Get rid of various 'typedef struct' definitions and use plain structure
definitions instead. We don't change usb.h for now to stay compatible
with userland.

Tested by mpi@ on macppc and myself on i386.

ok mpi@


# 1.56 28-Mar-2013 tedu

proc.h is way too much header for usb to handle.


# 1.55 28-Mar-2013 tedu

you probably don't need to include vnode.h or reboot.h. you most definitely
absolutely do not need to include vnode.h because it includes uvm_extern.h
and you want the idiotic TRUE FALSE defines from uvm.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.54 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


Revision tags: OPENBSD_4_9_BASE
# 1.53 25-Jan-2011 jakemsr

garbage collect "usb events". without /dev/usb there is no way to access
them from userland, and nothing in the kernel uses them.

ok krw@, miod@


# 1.52 17-Dec-2010 jasper

- use usb_lookup() instead of handrolled macro

ok jakemsr@


# 1.51 06-Dec-2010 jakemsr

* replace per-driver dying and/or other state variables with use of
usbd_deactivete() and usbd_is_dying()
* use usbd_deactivate() in activate()/DEACTIVATE
* convert a few more direct checks of the associated bus' dying flag
with usbd_is_dying()


# 1.50 23-Oct-2010 jakemsr

check that a timeout(9) has been initialized before deleting it

ok phessler


# 1.49 23-Oct-2010 jakemsr

create another kthread to run xfer abort tasks. xfer abort tasks cannot
be run from the generic task kthread, because xfers that need to be
aborted block newly queued tasks from running (i.e. the xfer to be aborted
blocks the abort of that task). as there are now three types of usb
tasks, add an argument to usb_init_task() and another member to struct
usb_task to specify the task type.

fixes boot hangs that are showing up because we now use usb tasks to
attach/detach usb devices.


# 1.48 24-Sep-2010 yuo

remove dying flag in detach() function.
The dying flag will be set in activate()/DEACTIVATE.

ok deraadt@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.47 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_6_BASE
# 1.46 26-Apr-2009 cnst

in ca_attach() there is no need to set .value and .flags of sensors to 0,
since autoconf(9) allocates softc with M_ZERO; ok deraadt


Revision tags: OPENBSD_4_5_BASE
# 1.45 21-Nov-2008 mbalmer

Kill some whitespace, removed unneeded stuff at the end of a list.


Revision tags: OPENBSD_4_4_BASE
# 1.44 10-Jul-2008 mbalmer

Don't terminate the array of matching product/vendor IDs with { 0, 0 }
when usb_lookup is used. If a device indeed has 0 as vendor and product
ID, like the HP DL165 BMC Server Engines SE USB Device, a wrong driver
will attach and the machine will most pbly crash.

Problem reported Rivo Nurges <rix@estpak.ee>
cvs: ----------------------------------------------------------------------


# 1.43 06-Jul-2008 mbalmer

Use UT_{READ|WRITE}_VENDOR_DEVICE instead of self defined values.


# 1.42 05-Jul-2008 mbalmer

Add support for the new Expert mouseCLOCK USB II that uses an FTDI
FT232R chip to interface the receiver (instead of the NetCologne
chip used on older models). Only the DCF77 and HBG receivers are
supported.

A sidenote: Gude ADS not only provides me with receivers and
documentation, but as a result of my feedback on their older receivers
the new ones now have proper USB product IDs to distinguish between
DCF77, HBG, and MSF.


Revision tags: OPENBSD_4_3_BASE
# 1.41 23-Nov-2007 mbalmer

Make sure that variables used during detach are initialized during attach.
Discussed with dlg.


# 1.40 23-Nov-2007 mbalmer

No need for process context to degrade the sensor status.
Discussed with kettenis.


# 1.39 11-Oct-2007 deraadt

treat usb vendor/product names as a locator, and have usbd_print handle it,
so that it shows up before the :. as a result, all the usb devices do not
need to have name printing code anymore. all this now works and prints
nicely because usbd_probe_and_attach() is serialized. ok kettenis


Revision tags: OPENBSD_4_2_BASE
# 1.38 14-Jun-2007 mbalmer

Remove the definition and usage of the USB_DECLARE_DRIVER_CLASS and
USB_DECLARE_DRIVER macros.

No binary change.

ok dlg.


# 1.37 12-Jun-2007 mbalmer

Remove the definition and use of the device_ptr_t which was a struct device *.

No binary change.

ok mk.


# 1.36 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEVNAME macro.

(This might look easy, but it was a big diff. Thanks to dlg and especially jsg
for looking over it; we found at least four mistakes in the initial diff.)

ok jsg.


# 1.35 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEV macro. It only created confusion
and the address of it's argument: USBDEV(sc->sc_dev) yields &sc->sc_dev.

No binary changes.

ok jsg.


# 1.34 06-Jun-2007 mk

Mechanical removal of USBBASEDEVICE. No binary change.

Tested by thib and myself.

ok mbalmer jsg


# 1.33 27-May-2007 jsg

Farewell USB_{ATTACH,MATCH,DETACH}* you will not be missed.
ok deraadt@ krw@ mbalmer@


# 1.32 21-Apr-2007 art

Back out last. the world is not i386.


# 1.31 21-Apr-2007 mbalmer

Remove unused header files.


# 1.30 22-Mar-2007 deraadt

split userland & kernel struct sensor/sensordev so that the addition
of new fields in the future is less disruptive. This is done similar
to how struct proc is handled for ps(1). ok jmc (man page changes)
tested fkr simon, and more suggestions from millert


Revision tags: OPENBSD_4_1_BASE
# 1.29 02-Jan-2007 mbalmer

return is not a function.


# 1.28 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.27 10-Dec-2006 mbalmer

Make sure the bit collecting is restarted after signal loss.


# 1.26 10-Dec-2006 mbalmer

restart collecting bits immediately after a parity error, i.e. use the frame
immediately following the corrupt one; there is no no need to skip it by
waiting for the next minute gap and the sensor value has valid data one
minute earlier than before.


# 1.25 10-Dec-2006 mbalmer

Re-arm signal loss detection only after we received a bit, not in itself. This
prevents the signal loss function from being called repeatedly when we have
no signal.


# 1.24 10-Dec-2006 mbalmer

Faster synchronization after an unexpected minute gap.
Only look at the skew value if it is != 0.
Remove some dead code.


# 1.23 06-Dec-2006 mbalmer

When compiled with UDCF_DEBUG, only output the bits received when
udcfdebug > 1.


# 1.22 05-Dec-2006 mbalmer

Add code to detect (and eliminate) statistical outliers. Tested by me and
naddy; many thanks to naddy for continous testing and feedback during the
last weeks.

ok naddy


# 1.21 15-Nov-2006 mbalmer

Fix an integer type promotion that can lead to wrong offsets on 64 bit arches.
Problem and solution found by Christian "Naddy" Weisgerber <naddy@openbsd.org>,
thanks!


# 1.20 28-Oct-2006 mbalmer

- Use better names for the variables containing the timeouts in Hz instead of
just t1-t10.
- Remove some unused variables.
- Restructure some functions to remove some levels of indentation.


# 1.19 27-Oct-2006 mbalmer

udcf(4) degraded the sensor status from OK to WARNING on the first receiption
error, which is to fast as this does not give ntpd the opportunity to use the
sensor value.

If we decode a valid time information, it has to be available to applications
for some minimal time. I choose a value of 5 minutes. If we do not receive
any new valid time information during this period, the sensor will be degraded
to WARNING, and after another fifteen minutes it will be further degraded to
CRITICAL.

"makes sense to me" henning@, "sure" deraadt@


# 1.18 14-Oct-2006 mbalmer

Apply some formatting.


# 1.17 11-Oct-2006 mbalmer

Make the timedelta sensor appear right when a device is plugged-in, with a
status of SENSOR_S_UNKNOWN. Do not set the SENSOR_FINVALID bit, sysctl
hw.sensors does not list sensors with this flags set and we want to the sensor
when the device is present.

ok henning


Revision tags: OPENBSD_4_0_BASE
# 1.16 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.15 19-Jun-2006 mbalmer

remove the no longer needed time calculations now that we have them in
sys/kern/clock_subr.c


# 1.14 19-Jun-2006 deraadt

move clock_subr.c to a better place, and now it is always in the kernel
so that things can use it; tested on all architectures; ok kettenis


# 1.13 17-Jun-2006 mbalmer

udcf(4) no longer needs the file sys/dev/clock_subr.c to be compiled and linked
to the kernel, the two functions it used from this file are now included in
the driver itself (like in nmea(4)). udcf(4) can now be enabled to the zaurus,
too. in fact on all arches that have USB support.


# 1.12 12-Jun-2006 mbalmer

Typos in comments.


# 1.11 05-Jun-2006 mbalmer

cleanup.


# 1.10 04-Jun-2006 mbalmer

- ntpd no longer needs the NTP identifier as part of a timedelta sensor
description.
- create the timedelta sensors as early as possible, but mark them invalid
as long as there is no real data.
- update docs accordingly


# 1.9 28-May-2006 mbalmer

Change the timedelta sensor descritpion so that the first four bytes contain
the NTP identifier (filled with spaces), followed by a space and the station
name (which might be the same as the NTP identifier).

All timedelta sensor have to follow this scheme as OpenNTPD needs it.

Requested by henning.


# 1.8 27-May-2006 mbalmer

There is no longer the need to create INVALID sensors on stock, the sensor
framework will create hotplug events for sensor addition/deletion. ntpd
will catch these events.


# 1.7 27-May-2006 mbalmer

When the device is attached, immediately create the timedelta sensor with the
SENSOR_FINVALID flag set and without a description. We do not need a dummy
description as a sensor with the FINVALID flags set will not show up or be used
anyways. It's merely an indication to applications that there is a sensor that
will eventually have a correct value.

The SENSOR_FINVALID flag is removed and the description is set to the proper
clockname as soon as we have received the first valid time information.

This enables ntpd to check for hotplug events and rescan the list of timedelta
sensors after a hotplug event.

discussed with deraadt.


# 1.6 27-Apr-2006 mbalmer

cope with recent changes in the sensor framework

- provide the timedelta in nanoseconds
- provide a timestamp in the sensor

support for HBG and DCF77:

- detect clocktype (DCF77 or HBG) and set it once is the sensor description


# 1.5 22-Apr-2006 mbalmer

Simplify time calculations.

help and ok kettenis@


# 1.4 21-Apr-2006 mbalmer

make udcf work as a SENSOR_TIMEDELTA type sensor. The sensor value is the
offset between the time of the device and the localtime in mSec.

the sensor status is set to OK once we received a complete and valid time
information.

help and ok deraadt


# 1.3 20-Apr-2006 deraadt

open/close/cdevsw code goes bye bye; ok mbalber


# 1.2 20-Apr-2006 mbalmer

- remove the 'needs-flag' from the udcf entry in files.usb and the #ifdef NUDCF
idom in udcf.c
- declare t1 to t7 as static to prevent the risk of name clashes
- add two missing function prototypes

help and ok miod@


# 1.1 19-Apr-2006 mbalmer

Driver to decode the DCF77 time code using a USB attached Gude Expert
mouseCLOCK device; without a mechanism to pass data out.

ok deraadt