Commit 29b78b5a authored by David Brownell's avatar David Brownell Committed by Greg Kroah-Hartman

This is another USB API cleanup patch. It's against 2.5.5:

  
    - Moves 8 functions from usb.[hc] to hcd.[hc]
    - Also moves some data structures and types
    - Now usbdevfs and "old" HCDs #include "hcd.h"
    - Minor tweaks to the "hcd" layer (one less FIXME)
    - Minor kernel doc and comment cleanups
  
Basically this continues moving the HCD-only functionality
out of the way of normal USB device drivers.  Converging
"usb_bus" and "usb_hcd" (later!) will be a bit easier too.

I did basic sanity tests, there's little to break ... :)
  
There are still a few functions in usb.c that aren't for
general driver use.  They're mostly for enumeration,
in areas where the hub driver and HCD root hubs
need to do various kinds of magic.  It wasn't clear
how to decouple those, they can certainly wait.
parent 6d3d01de
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
* (C) Copyright 1999,2000 Thomas Sailer <sailer@ife.ee.ethz.ch>. (proc file per device) * (C) Copyright 1999,2000 Thomas Sailer <sailer@ife.ee.ethz.ch>. (proc file per device)
* (C) Copyright 1999 Deti Fliegl (new USB architecture) * (C) Copyright 1999 Deti Fliegl (new USB architecture)
* *
* $id$
*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
...@@ -61,6 +59,8 @@ ...@@ -61,6 +59,8 @@
#include <linux/usbdevice_fs.h> #include <linux/usbdevice_fs.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include "hcd.h"
#define MAX_TOPO_LEVEL 6 #define MAX_TOPO_LEVEL 6
/* Define ALLOW_SERIAL_NUMBER if you want to see the serial number of devices */ /* Define ALLOW_SERIAL_NUMBER if you want to see the serial number of devices */
...@@ -429,6 +429,10 @@ static ssize_t usb_device_dump(char **buffer, size_t *nbytes, loff_t *skip_bytes ...@@ -429,6 +429,10 @@ static ssize_t usb_device_dump(char **buffer, size_t *nbytes, loff_t *skip_bytes
* count = device count at this level * count = device count at this level
*/ */
/* If this is the root hub, display the bandwidth information */ /* If this is the root hub, display the bandwidth information */
/* FIXME high speed reserves 20% frametime for non-periodic,
* while full/low speed reserves only 10% ... so this is wrong
* for high speed busses. also, change how bandwidth is recorded.
*/
if (level == 0) if (level == 0)
data_end += sprintf(data_end, format_bandwidth, bus->bandwidth_allocated, data_end += sprintf(data_end, format_bandwidth, bus->bandwidth_allocated,
FRAME_TIME_MAX_USECS_ALLOC, FRAME_TIME_MAX_USECS_ALLOC,
......
This diff is collapsed.
/* /*
* Copyright (c) 2001 by David Brownell * Copyright (c) 2001-2002 by David Brownell
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the * under the terms of the GNU General Public License as published by the
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
*/ */
#ifdef __KERNEL__
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
/* /*
...@@ -33,8 +35,8 @@ struct usb_hcd { /* usb_bus.hcpriv points to this */ ...@@ -33,8 +35,8 @@ struct usb_hcd { /* usb_bus.hcpriv points to this */
/* /*
* housekeeping * housekeeping
*/ */
struct usb_bus *bus; /* hcd is-a bus */ struct usb_bus *bus; /* FIXME only use "self" */
struct list_head hcd_list; struct usb_bus self; /* hcd is-a bus */
const char *bus_name; const char *bus_name;
...@@ -98,6 +100,19 @@ struct hcd_timeout { /* timeouts we allocate */ ...@@ -98,6 +100,19 @@ struct hcd_timeout { /* timeouts we allocate */
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
/*
* FIXME usb_operations should vanish or become hc_driver,
* when usb_bus and usb_hcd become the same thing.
*/
struct usb_operations {
int (*allocate)(struct usb_device *);
int (*deallocate)(struct usb_device *);
int (*get_frame_number) (struct usb_device *usb_dev);
int (*submit_urb) (struct urb *urb, int mem_flags);
int (*unlink_urb) (struct urb *urb);
};
/* each driver provides one of these, and hardware init support */ /* each driver provides one of these, and hardware init support */
struct hc_driver { struct hc_driver {
...@@ -126,8 +141,6 @@ struct hc_driver { ...@@ -126,8 +141,6 @@ struct hc_driver {
/* return current frame number */ /* return current frame number */
int (*get_frame_number) (struct usb_hcd *hcd); int (*get_frame_number) (struct usb_hcd *hcd);
// FIXME: rework generic-to-specific HCD linkage (specific contains generic)
/* memory lifecycle */ /* memory lifecycle */
struct usb_hcd *(*hcd_alloc) (void); struct usb_hcd *(*hcd_alloc) (void);
void (*hcd_free) (struct usb_hcd *hcd); void (*hcd_free) (struct usb_hcd *hcd);
...@@ -152,7 +165,8 @@ struct hc_driver { ...@@ -152,7 +165,8 @@ struct hc_driver {
extern void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb); extern void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb);
#ifdef CONFIG_PCI #ifdef CONFIG_PCI
struct pci_dev;
struct pci_device_id;
extern int usb_hcd_pci_probe (struct pci_dev *dev, extern int usb_hcd_pci_probe (struct pci_dev *dev,
const struct pci_device_id *id); const struct pci_device_id *id);
extern void usb_hcd_pci_remove (struct pci_dev *dev); extern void usb_hcd_pci_remove (struct pci_dev *dev);
...@@ -204,6 +218,59 @@ extern int usb_hcd_pci_resume (struct pci_dev *dev); ...@@ -204,6 +218,59 @@ extern int usb_hcd_pci_resume (struct pci_dev *dev);
#define SetPortFeature (0x2300 | USB_REQ_SET_FEATURE) #define SetPortFeature (0x2300 | USB_REQ_SET_FEATURE)
/*-------------------------------------------------------------------------*/
/*
* Generic bandwidth allocation constants/support
*/
#define FRAME_TIME_USECS 1000L
#define BitTime(bytecount) (7 * 8 * bytecount / 6) /* with integer truncation */
/* Trying not to use worst-case bit-stuffing
of (7/6 * 8 * bytecount) = 9.33 * bytecount */
/* bytecount = data payload byte count */
#define NS_TO_US(ns) ((ns + 500L) / 1000L)
/* convert & round nanoseconds to microseconds */
extern void usb_claim_bandwidth (struct usb_device *dev, struct urb *urb,
int bustime, int isoc);
extern void usb_release_bandwidth (struct usb_device *dev, struct urb *urb,
int isoc);
/*
* Full/low speed bandwidth allocation constants/support.
*/
#define BW_HOST_DELAY 1000L /* nanoseconds */
#define BW_HUB_LS_SETUP 333L /* nanoseconds */
/* 4 full-speed bit times (est.) */
#define FRAME_TIME_BITS 12000L /* frame = 1 millisecond */
#define FRAME_TIME_MAX_BITS_ALLOC (90L * FRAME_TIME_BITS / 100L)
#define FRAME_TIME_MAX_USECS_ALLOC (90L * FRAME_TIME_USECS / 100L)
extern int usb_check_bandwidth (struct usb_device *dev, struct urb *urb);
/*-------------------------------------------------------------------------*/
extern struct usb_bus *usb_alloc_bus (struct usb_operations *);
extern void usb_free_bus (struct usb_bus *);
extern void usb_register_bus (struct usb_bus *);
extern void usb_deregister_bus (struct usb_bus *);
extern int usb_register_root_hub (struct usb_device *usb_dev,
struct device *parent_dev);
/*-------------------------------------------------------------------------*/
/* exported only within usbcore */
extern struct list_head usb_bus_list;
extern struct semaphore usb_bus_list_lock;
extern void usb_bus_get (struct usb_bus *bus);
extern void usb_bus_put (struct usb_bus *bus);
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
/* hub.h ... DeviceRemovable in 2.4.2-ac11, gone in 2.4.10 */ /* hub.h ... DeviceRemovable in 2.4.2-ac11, gone in 2.4.10 */
...@@ -217,3 +284,7 @@ extern int usb_hcd_pci_resume (struct pci_dev *dev); ...@@ -217,3 +284,7 @@ extern int usb_hcd_pci_resume (struct pci_dev *dev);
#define RUN_CONTEXT (in_irq () ? "in_irq" \ #define RUN_CONTEXT (in_irq () ? "in_irq" \
: (in_interrupt () ? "in_interrupt" : "can sleep")) : (in_interrupt () ? "in_interrupt" : "can sleep"))
#endif /* __KERNEL__ */
...@@ -73,6 +73,7 @@ ...@@ -73,6 +73,7 @@
#define OHCI_USE_NPS // force NoPowerSwitching mode #define OHCI_USE_NPS // force NoPowerSwitching mode
// #define OHCI_VERBOSE_DEBUG /* not always helpful */ // #define OHCI_VERBOSE_DEBUG /* not always helpful */
#include "hcd.h"
#include "usb-ohci.h" #include "usb-ohci.h"
......
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
#define VERSTR "$Revision: 1.275 $ time " __TIME__ " " __DATE__ #define VERSTR "$Revision: 1.275 $ time " __TIME__ " " __DATE__
#include <linux/usb.h> #include <linux/usb.h>
#include "hcd.h"
#include "usb-uhci.h" #include "usb-uhci.h"
#include "usb-uhci-debug.h" #include "usb-uhci-debug.h"
......
This diff is collapsed.
...@@ -44,8 +44,8 @@ ...@@ -44,8 +44,8 @@
/* /*
* USB directions * USB directions
*/ */
#define USB_DIR_OUT 0 #define USB_DIR_OUT 0 /* to device */
#define USB_DIR_IN 0x80 #define USB_DIR_IN 0x80 /* to host */
/* /*
* Endpoints * Endpoints
...@@ -148,12 +148,6 @@ struct usb_devmap { ...@@ -148,12 +148,6 @@ struct usb_devmap {
unsigned long devicemap[128 / (8*sizeof(unsigned long))]; unsigned long devicemap[128 / (8*sizeof(unsigned long))];
}; };
#define USB_MAXBUS 64
struct usb_busmap {
unsigned long busmap[USB_MAXBUS / (8*sizeof(unsigned long))];
};
struct usb_device; struct usb_device;
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
...@@ -516,7 +510,8 @@ struct usb_device_id { ...@@ -516,7 +510,8 @@ struct usb_device_id {
* work to connect to a device should be done when the device is opened, * work to connect to a device should be done when the device is opened,
* and undone at the last close. The disconnect code needs to address * and undone at the last close. The disconnect code needs to address
* concurrency issues with respect to open() and close() methods, as * concurrency issues with respect to open() and close() methods, as
* well as cancel any I/O requests that are still pending. * well as forcing all pending I/O requests to complete (by unlinking
* them as necessary, and blocking until the unlinks complete).
*/ */
struct usb_driver { struct usb_driver {
struct module *owner; struct module *owner;
...@@ -905,13 +900,7 @@ extern int usb_make_path(struct usb_device *dev, char *buf, size_t size); ...@@ -905,13 +900,7 @@ extern int usb_make_path(struct usb_device *dev, char *buf, size_t size);
/* Host Controller Driver (HCD) support */ /* Host Controller Driver (HCD) support */
struct usb_operations { struct usb_operations;
int (*allocate)(struct usb_device *);
int (*deallocate)(struct usb_device *);
int (*get_frame_number) (struct usb_device *usb_dev);
int (*submit_urb) (struct urb *urb, int mem_flags);
int (*unlink_urb) (struct urb *urb);
};
#define DEVNUM_ROUND_ROBIN /***** OPTION *****/ #define DEVNUM_ROUND_ROBIN /***** OPTION *****/
...@@ -944,40 +933,11 @@ struct usb_bus { ...@@ -944,40 +933,11 @@ struct usb_bus {
atomic_t refcnt; atomic_t refcnt;
}; };
extern struct usb_bus *usb_alloc_bus(struct usb_operations *); // FIXME: root_hub_string vanishes when "usb_hcd" conversion is done,
extern void usb_free_bus(struct usb_bus *); // along with pre-hcd versions of the OHCI and UHCI drivers.
extern void usb_register_bus(struct usb_bus *);
extern void usb_deregister_bus(struct usb_bus *);
extern int usb_register_root_hub(struct usb_device *usb_dev, struct device *parent_dev);
extern int usb_check_bandwidth (struct usb_device *dev, struct urb *urb);
extern void usb_claim_bandwidth (struct usb_device *dev, struct urb *urb,
int bustime, int isoc);
extern void usb_release_bandwidth(struct usb_device *dev, struct urb *urb,
int isoc);
extern int usb_root_hub_string(int id, int serial, extern int usb_root_hub_string(int id, int serial,
char *type, __u8 *data, int len); char *type, __u8 *data, int len);
/*
* Some USB 1.1 bandwidth allocation constants.
*/
#define BW_HOST_DELAY 1000L /* nanoseconds */
#define BW_HUB_LS_SETUP 333L /* nanoseconds */
/* 4 full-speed bit times (est.) */
#define FRAME_TIME_BITS 12000L /* frame = 1 millisecond */
#define FRAME_TIME_MAX_BITS_ALLOC (90L * FRAME_TIME_BITS / 100L)
#define FRAME_TIME_USECS 1000L
#define FRAME_TIME_MAX_USECS_ALLOC (90L * FRAME_TIME_USECS / 100L)
#define BitTime(bytecount) (7 * 8 * bytecount / 6) /* with integer truncation */
/* Trying not to use worst-case bit-stuffing
of (7/6 * 8 * bytecount) = 9.33 * bytecount */
/* bytecount = data payload byte count */
#define NS_TO_US(ns) ((ns + 500L) / 1000L)
/* convert & round nanoseconds to microseconds */
/* /*
* As of USB 2.0, full/low speed devices are segregated into trees. * As of USB 2.0, full/low speed devices are segregated into trees.
* One type grows from USB 1.1 host controllers (OHCI, UHCI etc). * One type grows from USB 1.1 host controllers (OHCI, UHCI etc).
...@@ -1209,13 +1169,11 @@ void usb_show_string(struct usb_device *dev, char *id, int index); ...@@ -1209,13 +1169,11 @@ void usb_show_string(struct usb_device *dev, char *id, int index);
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* /*
* bus and driver list * driver list
* exported only for usbfs (not visible outside usbcore) * exported only for usbfs (not visible outside usbcore)
*/ */
extern struct list_head usb_driver_list; extern struct list_head usb_driver_list;
extern struct list_head usb_bus_list;
extern struct semaphore usb_bus_list_lock;
/* /*
* USB device fs stuff * USB device fs stuff
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment