Module Name:    src
Committed By:   mrg
Date:           Tue May  7 05:17:23 UTC 2019

Modified Files:
        src/sys/dev/usb: uplcom.c

Log Message:
convert to USBHIST style debugging.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/sys/dev/usb/uplcom.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/uplcom.c
diff -u src/sys/dev/usb/uplcom.c:1.82 src/sys/dev/usb/uplcom.c:1.83
--- src/sys/dev/usb/uplcom.c:1.82	Sun May  5 03:17:54 2019
+++ src/sys/dev/usb/uplcom.c	Tue May  7 05:17:22 2019
@@ -1,4 +1,5 @@
-/*	$NetBSD: uplcom.c,v 1.82 2019/05/05 03:17:54 mrg Exp $	*/
+/*	$NetBSD: uplcom.c,v 1.83 2019/05/07 05:17:22 mrg Exp $	*/
+
 /*
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -34,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uplcom.c,v 1.82 2019/05/05 03:17:54 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uplcom.c,v 1.83 2019/05/07 05:17:22 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -52,6 +53,7 @@ __KERNEL_RCSID(0, "$NetBSD: uplcom.c,v 1
 #include <sys/proc.h>
 #include <sys/device.h>
 #include <sys/poll.h>
+#include <sys/sysctl.h>
 
 #include <dev/usb/usb.h>
 #include <dev/usb/usbcdc.h>
@@ -60,16 +62,51 @@ __KERNEL_RCSID(0, "$NetBSD: uplcom.c,v 1
 #include <dev/usb/usbdi_util.h>
 #include <dev/usb/usbdevs.h>
 #include <dev/usb/usb_quirks.h>
+#include <dev/usb/usbhist.h>
 
 #include <dev/usb/ucomvar.h>
 
-#ifdef UPLCOM_DEBUG
-#define DPRINTFN(n, x)  if (uplcomdebug > (n)) printf x
-int	uplcomdebug = 0;
+#ifdef USB_DEBUG
+#ifndef UPLCOM_DEBUG
+#define uplcomdebug 0
 #else
-#define DPRINTFN(n, x)
-#endif
-#define DPRINTF(x) DPRINTFN(0, x)
+int	uplcomdebug = 0;
+
+SYSCTL_SETUP(sysctl_hw_uplcom_setup, "sysctl hw.uplcom setup")
+{
+	int err;
+	const struct sysctlnode *rnode;
+	const struct sysctlnode *cnode;
+
+	err = sysctl_createv(clog, 0, NULL, &rnode,
+	    CTLFLAG_PERMANENT, CTLTYPE_NODE, "uplcom",
+	    SYSCTL_DESCR("uplcom global controls"),
+	    NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL);
+
+	if (err)
+		goto fail;
+
+	/* control debugging printfs */
+	err = sysctl_createv(clog, 0, &rnode, &cnode,
+	    CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT,
+	    "debug", SYSCTL_DESCR("Enable debugging output"),
+	    NULL, 0, &uplcomdebug, sizeof(uplcomdebug), CTL_CREATE, CTL_EOL);
+	if (err)
+		goto fail;
+
+	return;
+fail:
+	aprint_error("%s: sysctl_createv failed (err = %d)\n", __func__, err);
+}
+
+#endif /* UCOM_DEBUG */
+#endif /* USB_DEBUG */
+
+
+#define DPRINTF(FMT,A,B,C,D)    USBHIST_LOGN(uplcomdebug,1,FMT,A,B,C,D)
+#define DPRINTFN(N,FMT,A,B,C,D) USBHIST_LOGN(uplcomdebug,N,FMT,A,B,C,D)
+#define UPLCOMHIST_FUNC()       USBHIST_FUNC()
+#define UPLCOMHIST_CALLED(name) USBHIST_CALLED(uplcomdebug)
 
 #define	UPLCOM_CONFIG_INDEX	0
 #define	UPLCOM_IFACE_INDEX	0
@@ -232,6 +269,9 @@ uplcom_attach(device_t parent, device_t 
 	int i;
 	struct ucom_attach_args ucaa;
 
+	UPLCOMHIST_FUNC(); UPLCOMHIST_CALLED();
+	DPRINTF("sc=%p", sc, 0, 0, 0);
+
 	sc->sc_dev = self;
 
 	aprint_naive("\n");
@@ -243,8 +283,6 @@ uplcom_attach(device_t parent, device_t 
 
 	sc->sc_udev = dev;
 
-	DPRINTF(("\n\nuplcom attach: sc=%p\n", sc));
-
 	/* initialize endpoints */
 	ucaa.ucaa_bulkin = ucaa.ucaa_bulkout = -1;
 	sc->sc_intr_number = -1;
@@ -268,9 +306,9 @@ uplcom_attach(device_t parent, device_t 
 #ifdef UPLCOM_DEBUG
 	/* print the chip type */
 	if (sc->sc_type == UPLCOM_TYPE_HX) {
-		DPRINTF(("uplcom_attach: chiptype HX\n"));
+		DPRINTF("chiptype HX", 0, 0, 0, 0);
 	} else {
-		DPRINTF(("uplcom_attach: chiptype 0\n"));
+		DPRINTF("chiptype 0", 0, 0, 0, 0);
 	}
 #endif
 
@@ -414,8 +452,8 @@ uplcom_attach(device_t parent, device_t 
 
 	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev, sc->sc_dev);
 
-	DPRINTF(("uplcom: in=0x%x out=0x%x intr=0x%x\n",
-			ucaa.ucaa_bulkin, ucaa.ucaa_bulkout, sc->sc_intr_number ));
+	DPRINTF("in=0x%x out=0x%x intr=0x%x",
+	    ucaa.ucaa_bulkin, ucaa.ucaa_bulkout, sc->sc_intr_number, 0);
 	sc->sc_subdev = config_found_sm_loc(self, "ucombus", NULL, &ucaa,
 					    ucomprint, ucomsubmatch);
 
@@ -430,17 +468,20 @@ uplcom_childdet(device_t self, device_t 
 {
 	struct uplcom_softc *sc = device_private(self);
 
+	UPLCOMHIST_FUNC(); UPLCOMHIST_CALLED();
+
 	KASSERT(sc->sc_subdev == child);
 	sc->sc_subdev = NULL;
 }
-
+ 
 int
 uplcom_detach(device_t self, int flags)
 {
 	struct uplcom_softc *sc = device_private(self);
 	int rv = 0;
 
-	DPRINTF(("uplcom_detach: sc=%p flags=%d\n", sc, flags));
+	UPLCOMHIST_FUNC(); UPLCOMHIST_CALLED();
+	DPRINTF("sc=%p flags=%d", sc, flags, 0, 0);
 
 	if (sc->sc_intr_pipe != NULL) {
 		usbd_abort_pipe(sc->sc_intr_pipe);
@@ -599,7 +640,8 @@ void
 uplcom_dtr(struct uplcom_softc *sc, int onoff)
 {
 
-	DPRINTF(("uplcom_dtr: onoff=%d\n", onoff));
+	UPLCOMHIST_FUNC(); UPLCOMHIST_CALLED();
+	DPRINTF("onoff=%d", onoff, 0, 0, 0);
 
 	if (sc->sc_dtr != -1 && !sc->sc_dtr == !onoff)
 		return;
@@ -612,7 +654,8 @@ uplcom_dtr(struct uplcom_softc *sc, int 
 void
 uplcom_rts(struct uplcom_softc *sc, int onoff)
 {
-	DPRINTF(("uplcom_rts: onoff=%d\n", onoff));
+	UPLCOMHIST_FUNC(); UPLCOMHIST_CALLED();
+	DPRINTF("onoff=%d", onoff, 0, 0, 0);
 
 	if (sc->sc_rts != -1 && !sc->sc_rts == !onoff)
 		return;
@@ -627,7 +670,8 @@ uplcom_break(struct uplcom_softc *sc, in
 {
 	usb_device_request_t req;
 
-	DPRINTF(("uplcom_break: onoff=%d\n", onoff));
+	UPLCOMHIST_FUNC(); UPLCOMHIST_CALLED();
+	DPRINTF("onoff=%d", onoff, 0, 0, 0);
 
 	req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
 	req.bRequest = UCDC_SEND_BREAK;
@@ -644,7 +688,7 @@ uplcom_set_crtscts(struct uplcom_softc *
 	usb_device_request_t req;
 	usbd_status err;
 
-	DPRINTF(("uplcom_set_crtscts: on\n"));
+	UPLCOMHIST_FUNC(); UPLCOMHIST_CALLED();
 
 	req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
 	req.bRequest = UPLCOM_SET_REQUEST;
@@ -657,8 +701,7 @@ uplcom_set_crtscts(struct uplcom_softc *
 
 	err = usbd_do_request(sc->sc_udev, &req, 0);
 	if (err) {
-		DPRINTF(("uplcom_set_crtscts: failed, err=%s\n",
-			usbd_errstr(err)));
+		DPRINTF("failed, err=%d", err, 0, 0, 0);
 		return err;
 	}
 
@@ -671,12 +714,14 @@ uplcom_set_line_coding(struct uplcom_sof
 	usb_device_request_t req;
 	usbd_status err;
 
-	DPRINTF(("uplcom_set_line_coding: rate=%d fmt=%d parity=%d bits=%d\n",
+	UPLCOMHIST_FUNC(); UPLCOMHIST_CALLED();
+
+	DPRINTF("rate=%d fmt=%d parity=%d bits=%d",
 		UGETDW(state->dwDTERate), state->bCharFormat,
-		state->bParityType, state->bDataBits));
+		state->bParityType, state->bDataBits);
 
 	if (memcmp(state, &sc->sc_line_state, UCDC_LINE_STATE_LENGTH) == 0) {
-		DPRINTF(("uplcom_set_line_coding: already set\n"));
+		DPRINTF("already set", 0, 0, 0, 0);
 		return USBD_NORMAL_COMPLETION;
 	}
 
@@ -688,8 +733,7 @@ uplcom_set_line_coding(struct uplcom_sof
 
 	err = usbd_do_request(sc->sc_udev, &req, state);
 	if (err) {
-		DPRINTF(("uplcom_set_line_coding: failed, err=%s\n",
-			usbd_errstr(err)));
+		DPRINTF("failed, err=%u", err, 0, 0, 0);
 		return err;
 	}
 
@@ -705,7 +749,8 @@ uplcom_param(void *addr, int portno, str
 	usbd_status err;
 	usb_cdc_line_state_t ls;
 
-	DPRINTF(("uplcom_param: sc=%p\n", sc));
+	UPLCOMHIST_FUNC(); UPLCOMHIST_CALLED();
+	DPRINTF("sc=%p", sc, 0, 0, 0);
 
 	USETDW(ls.dwDTERate, t->c_ospeed);
 	if (ISSET(t->c_cflag, CSTOPB))
@@ -736,7 +781,7 @@ uplcom_param(void *addr, int portno, str
 
 	err = uplcom_set_line_coding(sc, &ls);
 	if (err) {
-		DPRINTF(("uplcom_param: err=%s\n", usbd_errstr(err)));
+		DPRINTF("err=%d", err, 0, 0, 0);
 		return EIO;
 	}
 
@@ -747,20 +792,22 @@ uplcom_param(void *addr, int portno, str
 		uplcom_set_line_state(sc);
 
 	if (err) {
-		DPRINTF(("uplcom_param: err=%s\n", usbd_errstr(err)));
+		DPRINTF("err=%d", err, 0, 0, 0);
 		return EIO;
 	}
 
 	return 0;
 }
 
-Static usbd_status
+usbd_status
 uplcom_vendor_control_write(struct usbd_device *dev, uint16_t value,
     uint16_t index)
 {
 	usb_device_request_t req;
 	usbd_status err;
 
+	UPLCOMHIST_FUNC(); UPLCOMHIST_CALLED();
+
 	req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
 	req.bRequest = UPLCOM_SET_REQUEST;
 	USETW(req.wValue, value);
@@ -770,8 +817,7 @@ uplcom_vendor_control_write(struct usbd_
 	err = usbd_do_request(dev, &req, NULL);
 
 	if (err) {
-		DPRINTF(("uplcom_open: vendor write failed, err=%s (%d)\n",
-			    usbd_errstr(err), err));
+		DPRINTF("vendor write failed, err=%d", err, 0, 0, 0);
 	}
 
 	return err;
@@ -782,12 +828,13 @@ uplcom_open(void *addr, int portno)
 {
 	struct uplcom_softc *sc = addr;
 	usbd_status err;
+ 
+	UPLCOMHIST_FUNC(); UPLCOMHIST_CALLED();
+	DPRINTF("sc=%p", sc, 0, 0, 0);
 
 	if (sc->sc_dying)
 		return EIO;
 
-	DPRINTF(("uplcom_open: sc=%p\n", sc));
-
 	/* Some unknown device frobbing. */
 	if (sc->sc_type == UPLCOM_TYPE_HX)
 		uplcom_vendor_control_write(sc->sc_udev, 2, 0x44);
@@ -801,9 +848,8 @@ uplcom_open(void *addr, int portno)
 			sc->sc_intr_buf, sc->sc_isize,
 			uplcom_intr, USBD_DEFAULT_INTERVAL);
 		if (err) {
-			DPRINTF(("%s: cannot open interrupt pipe (addr %d)\n",
-				device_xname(sc->sc_dev), sc->sc_intr_number));
-					return EIO;
+			DPRINTF("cannot open interrupt pipe (addr %d)",
+				sc->sc_intr_number, 0, 0, 0);
 		}
 	}
 
@@ -819,11 +865,12 @@ uplcom_close(void *addr, int portno)
 	struct uplcom_softc *sc = addr;
 	int err;
 
+	UPLCOMHIST_FUNC(); UPLCOMHIST_CALLED();
+	DPRINTF("sc=%p", sc, 0, 0, 0);
+
 	if (sc->sc_dying)
 		return;
 
-	DPRINTF(("uplcom_close: close\n"));
-
 	if (sc->sc_intr_pipe != NULL) {
 		err = usbd_abort_pipe(sc->sc_intr_pipe);
 		if (err)
@@ -845,6 +892,8 @@ uplcom_intr(struct usbd_xfer *xfer, void
 	u_char *buf = sc->sc_intr_buf;
 	u_char pstatus;
 
+	UPLCOMHIST_FUNC(); UPLCOMHIST_CALLED();
+
 	if (sc->sc_dying)
 		return;
 
@@ -852,14 +901,12 @@ uplcom_intr(struct usbd_xfer *xfer, void
 		if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
 			return;
 
-		DPRINTF(("%s: abnormal status: %s\n", device_xname(sc->sc_dev),
-			usbd_errstr(status)));
+		DPRINTF("abnormal status: %u", status, 0, 0, 0);
 		usbd_clear_endpoint_stall_async(sc->sc_intr_pipe);
 		return;
 	}
 
-	DPRINTF(("%s: uplcom status = %02x\n", device_xname(sc->sc_dev),
-	    buf[8]));
+	DPRINTF("uplcom status = %02x", buf[8], 0, 0, 0);
 
 	sc->sc_lsr = sc->sc_msr = 0;
 	pstatus = buf[8];
@@ -879,7 +926,7 @@ uplcom_get_status(void *addr, int portno
 {
 	struct uplcom_softc *sc = addr;
 
-	DPRINTF(("uplcom_get_status:\n"));
+	UPLCOMHIST_FUNC(); UPLCOMHIST_CALLED();
 
 	*lsr = sc->sc_lsr;
 	*msr = sc->sc_msr;
@@ -893,10 +940,12 @@ uplcom_ioctl(void *addr, int portno, u_l
 	struct uplcom_softc *sc = addr;
 	int error = 0;
 
+	UPLCOMHIST_FUNC(); UPLCOMHIST_CALLED();
+
 	if (sc->sc_dying)
 		return EIO;
 
-	DPRINTF(("uplcom_ioctl: cmd=0x%08lx\n", cmd));
+	DPRINTF("cmd=0x%08lx", cmd, 0, 0, 0);
 
 	switch (cmd) {
 	case TIOCNOTTY:
@@ -907,7 +956,7 @@ uplcom_ioctl(void *addr, int portno, u_l
 		break;
 
 	default:
-		DPRINTF(("uplcom_ioctl: unknown\n"));
+		DPRINTF("unknown", 0, 0, 0, 0);
 		error = ENOTTY;
 		break;
 	}

Reply via email to