Module Name: src
Committed By: skrll
Date: Mon Oct 12 10:18:55 UTC 2015
Modified Files:
src/sys/dev/usb [nick-nhusb]: usbdi.c usbdivar.h
Log Message:
Provide init/fini methods for HCDs
To generate a diff of this commit:
cvs rdiff -u -r1.162.2.31 -r1.162.2.32 src/sys/dev/usb/usbdi.c
cvs rdiff -u -r1.109.2.18 -r1.109.2.19 src/sys/dev/usb/usbdivar.h
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/usbdi.c
diff -u src/sys/dev/usb/usbdi.c:1.162.2.31 src/sys/dev/usb/usbdi.c:1.162.2.32
--- src/sys/dev/usb/usbdi.c:1.162.2.31 Sun Oct 11 09:17:51 2015
+++ src/sys/dev/usb/usbdi.c Mon Oct 12 10:18:54 2015
@@ -1,12 +1,13 @@
-/* $NetBSD: usbdi.c,v 1.162.2.31 2015/10/11 09:17:51 skrll Exp $ */
+/* $NetBSD: usbdi.c,v 1.162.2.32 2015/10/12 10:18:54 skrll Exp $ */
/*
- * Copyright (c) 1998, 2012 The NetBSD Foundation, Inc.
+ * Copyright (c) 1998, 2012, 2015 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Lennart Augustsson ([email protected]) at
- * Carlstedt Research & Technology and Matthew R. Green ([email protected]).
+ * Carlstedt Research & Technology, Matthew R. Green ([email protected]),
+ * and Nick Hudson.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -31,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.162.2.31 2015/10/11 09:17:51 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.162.2.32 2015/10/12 10:18:54 skrll Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@@ -492,13 +493,14 @@ usbd_create_xfer(struct usbd_pipe *pipe,
unsigned int nframes, struct usbd_xfer **xp)
{
KASSERT(xp != NULL);
+ void *buf;
struct usbd_xfer *xfer = usbd_alloc_xfer(pipe->up_dev, nframes);
if (xfer == NULL)
return ENOMEM;
if (len) {
- void *buf = usbd_alloc_buffer(xfer, len);
+ buf = usbd_alloc_buffer(xfer, len);
if (!buf) {
usbd_free_xfer(xfer);
return ENOMEM;
@@ -508,6 +510,16 @@ usbd_create_xfer(struct usbd_pipe *pipe,
xfer->ux_flags = flags;
xfer->ux_nframes = nframes;
+ if (xfer->ux_pipe->up_methods->upm_init) {
+ int err = xfer->ux_pipe->up_methods->upm_init(xfer);
+ if (err) {
+ if (buf)
+ usbd_free_buffer(xfer);
+ usbd_free_xfer(xfer);
+ return err;
+ }
+ }
+
*xp = xfer;
return 0;
}
@@ -515,6 +527,10 @@ usbd_create_xfer(struct usbd_pipe *pipe,
void usbd_destroy_xfer(struct usbd_xfer *xfer)
{
+ if (xfer->ux_pipe->up_methods->upm_fini) {
+ xfer->ux_pipe->up_methods->upm_fini(xfer);
+ }
+
usbd_free_xfer(xfer);
}
@@ -1053,17 +1069,10 @@ usbd_do_request_flags_pipe(struct usbd_d
ASSERT_SLEEPABLE();
- xfer = usbd_alloc_xfer(dev, 0);
- if (xfer == NULL)
- return USBD_NOMEM;
-
- if (UGETW(req->wLength) != 0) {
- void *buf = usbd_alloc_buffer(xfer, UGETW(req->wLength));
- if (buf == NULL) {
- err = USBD_NOMEM;
- goto bad;
- }
- }
+ size_t len = UGETW(req->wLength);
+ int error = usbd_create_xfer(dev->ud_pipe0, len, 0, 0, &xfer);
+ if (error)
+ return error;
usbd_setup_default_xfer(xfer, dev, 0, timeout, req,
data, UGETW(req->wLength), flags, 0);
@@ -1084,11 +1093,11 @@ usbd_do_request_flags_pipe(struct usbd_d
if (actlen != NULL)
*actlen = xfer->ux_actlen;
- bad:
+ usbd_destroy_xfer(xfer);
+
if (err) {
USBHIST_LOG(usbdebug, "returning err = %d", err, 0, 0, 0);
}
- usbd_free_xfer(xfer);
return err;
}
Index: src/sys/dev/usb/usbdivar.h
diff -u src/sys/dev/usb/usbdivar.h:1.109.2.18 src/sys/dev/usb/usbdivar.h:1.109.2.19
--- src/sys/dev/usb/usbdivar.h:1.109.2.18 Sun Oct 11 09:17:51 2015
+++ src/sys/dev/usb/usbdivar.h Mon Oct 12 10:18:54 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: usbdivar.h,v 1.109.2.18 2015/10/11 09:17:51 skrll Exp $ */
+/* $NetBSD: usbdivar.h,v 1.109.2.19 2015/10/12 10:18:54 skrll Exp $ */
/*
* Copyright (c) 1998, 2012 The NetBSD Foundation, Inc.
@@ -105,6 +105,8 @@ struct usbd_bus_methods {
};
struct usbd_pipe_methods {
+ int (*upm_init)(struct usbd_xfer *);
+ void (*upm_fini)(struct usbd_xfer *);
usbd_status (*upm_transfer)(struct usbd_xfer *);
usbd_status (*upm_start)(struct usbd_xfer *);
void (*upm_abort)(struct usbd_xfer *);