2010-08-28 05:59:27 +08:00
|
|
|
/*
|
|
|
|
* Written by Oron Peled <oron@actcom.co.il>
|
|
|
|
* Copyright (C) 2004-2006, Xorcom
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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 Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <linux/version.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/delay.h> /* for udelay */
|
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
#include <asm/atomic.h>
|
|
|
|
#include <asm/timex.h>
|
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
#include <linux/usb.h>
|
|
|
|
#include "xpd.h"
|
|
|
|
#include "xproto.h"
|
|
|
|
#include "xbus-core.h"
|
|
|
|
#include "xframe_queue.h"
|
|
|
|
#ifdef DEBUG
|
|
|
|
#include "card_fxs.h"
|
|
|
|
#include "card_fxo.h"
|
|
|
|
#endif
|
|
|
|
#include "parport_debug.h"
|
|
|
|
|
|
|
|
static const char rcsid[] = "$Id$";
|
|
|
|
|
2012-01-12 03:56:35 +08:00
|
|
|
/* must be before dahdi_debug.h */
|
|
|
|
static DEF_PARM(int, debug, 0, 0644, "Print DBG statements");
|
2010-08-28 05:59:27 +08:00
|
|
|
static DEF_PARM(int, usb1, 0, 0644, "Allow using USB 1.1 interfaces");
|
|
|
|
static DEF_PARM(uint, tx_sluggish, 2000, 0644, "A sluggish transmit (usec)");
|
2012-01-11 23:22:46 +08:00
|
|
|
static DEF_PARM(uint, drop_pcm_after, 6, 0644,
|
2015-07-20 17:11:07 +08:00
|
|
|
"Number of consecutive tx_sluggish to start dropping PCM");
|
|
|
|
static DEF_PARM(uint, sluggish_pcm_keepalive, 50, 0644,
|
|
|
|
"During sluggish -- Keep-alive PCM (1 every #)");
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
#include "dahdi_debug.h"
|
|
|
|
|
|
|
|
#define XUSB_PRINTK(level, xusb, fmt, ...) \
|
|
|
|
printk(KERN_ ## level "%s-%s: xusb-%d (%s) [%s]: " fmt, #level, \
|
2012-01-12 03:56:35 +08:00
|
|
|
THIS_MODULE->name, (xusb)->index, xusb->path, \
|
|
|
|
xusb->serial, ## __VA_ARGS__)
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
#define XUSB_DBG(bits, xusb, fmt, ...) \
|
2012-01-12 03:56:35 +08:00
|
|
|
((void)((debug & (DBG_ ## bits)) && XUSB_PRINTK(DEBUG, \
|
|
|
|
xusb, "%s: " fmt, __func__, ## __VA_ARGS__)))
|
|
|
|
#define XUSB_ERR(xusb, fmt, ...) \
|
|
|
|
XUSB_PRINTK(ERR, xusb, fmt, ## __VA_ARGS__)
|
|
|
|
#define XUSB_NOTICE(xusb, fmt, ...) \
|
|
|
|
XUSB_PRINTK(NOTICE, xusb, fmt, ## __VA_ARGS__)
|
|
|
|
#define XUSB_INFO(xusb, fmt, ...) \
|
|
|
|
XUSB_PRINTK(INFO, xusb, fmt, ## __VA_ARGS__)
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/* Get a minor range for your devices from the usb maintainer */
|
|
|
|
#define USB_SKEL_MINOR_BASE 192
|
|
|
|
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
#define PROC_USBXPP_SUMMARY "xpp_usb"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34)
|
2012-01-11 23:22:46 +08:00
|
|
|
#define usb_alloc_coherent(dev, size, mem_flags, dma) \
|
2010-08-28 05:59:27 +08:00
|
|
|
usb_buffer_alloc(dev, size, mem_flags, dma)
|
2012-01-11 23:22:46 +08:00
|
|
|
#define usb_free_coherent(dev, size, addr, dma) \
|
2010-08-28 05:59:27 +08:00
|
|
|
usb_buffer_free(dev, size, addr, dma)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG_PCM_TIMING
|
2012-01-11 23:22:46 +08:00
|
|
|
static cycles_t stamp_last_pcm_read;
|
2010-08-28 05:59:27 +08:00
|
|
|
static cycles_t accumulate_diff;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct xusb_model_info;
|
|
|
|
|
|
|
|
struct xusb_endpoint {
|
2012-01-11 23:22:46 +08:00
|
|
|
int ep_addr;
|
|
|
|
int max_size;
|
|
|
|
usb_complete_t callback;
|
2010-08-28 05:59:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum xusb_dir {
|
|
|
|
XUSB_RECV = 0,
|
|
|
|
XUSB_SEND = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
static __must_check int xframe_send_pcm(xbus_t *xbus, xframe_t *xframe);
|
|
|
|
static __must_check int xframe_send_cmd(xbus_t *xbus, xframe_t *xframe);
|
|
|
|
static __must_check xframe_t *alloc_xframe(xbus_t *xbus, gfp_t flags);
|
|
|
|
static void free_xframe(xbus_t *xbus, xframe_t *frm);
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
static struct xbus_ops xusb_ops = {
|
2010-08-28 05:59:27 +08:00
|
|
|
.xframe_send_pcm = xframe_send_pcm,
|
|
|
|
.xframe_send_cmd = xframe_send_cmd,
|
|
|
|
.alloc_xframe = alloc_xframe,
|
|
|
|
.free_xframe = free_xframe,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
XUSB_N_RX_FRAMES,
|
|
|
|
XUSB_N_TX_FRAMES,
|
|
|
|
XUSB_N_RX_ERRORS,
|
|
|
|
XUSB_N_TX_ERRORS,
|
2015-07-20 17:11:07 +08:00
|
|
|
XUSB_N_RX_DROPS,
|
|
|
|
XUSB_N_TX_DROPS,
|
2010-08-28 05:59:27 +08:00
|
|
|
XUSB_N_RCV_ZERO_LEN,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define XUSB_COUNTER(xusb, counter) ((xusb)->counters[XUSB_N_ ## counter])
|
|
|
|
|
|
|
|
#define C_(x) [ XUSB_N_ ## x ] = { #x }
|
|
|
|
|
|
|
|
static struct xusb_counters {
|
2012-01-11 23:22:46 +08:00
|
|
|
char *name;
|
2010-08-28 05:59:27 +08:00
|
|
|
} xusb_counters[] = {
|
2015-07-20 17:11:07 +08:00
|
|
|
C_(RX_FRAMES),
|
|
|
|
C_(TX_FRAMES),
|
|
|
|
C_(RX_ERRORS),
|
|
|
|
C_(TX_ERRORS),
|
|
|
|
C_(RX_DROPS),
|
|
|
|
C_(TX_DROPS),
|
|
|
|
C_(RCV_ZERO_LEN),
|
|
|
|
};
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
#undef C_
|
|
|
|
|
|
|
|
#define XUSB_COUNTER_MAX ARRAY_SIZE(xusb_counters)
|
|
|
|
|
|
|
|
#define MAX_PENDING_WRITES 100
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
static KMEM_CACHE_T *xusb_cache;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
typedef struct xusb xusb_t;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A uframe is our low level representation of a frame.
|
2012-01-11 23:16:34 +08:00
|
|
|
*
|
2010-08-28 05:59:27 +08:00
|
|
|
* It contains the metadata for the usb stack (a urb)
|
|
|
|
* and the metadata for the xbus-core (an xframe)
|
|
|
|
* as well as pointing to the data (transfer_buffer, transfer_buffer_length)
|
|
|
|
* directionality (send/receive) and ownership (xusb).
|
|
|
|
*/
|
|
|
|
struct uframe {
|
2012-01-11 23:22:46 +08:00
|
|
|
unsigned long uframe_magic;
|
2010-08-28 05:59:27 +08:00
|
|
|
#define UFRAME_MAGIC 654321L
|
2012-01-11 23:22:46 +08:00
|
|
|
struct urb urb;
|
|
|
|
xframe_t xframe;
|
|
|
|
size_t transfer_buffer_length;
|
|
|
|
void *transfer_buffer; /* max XFRAME_DATASIZE */
|
|
|
|
xusb_t *xusb;
|
2010-08-28 05:59:27 +08:00
|
|
|
};
|
|
|
|
|
2012-01-12 03:56:35 +08:00
|
|
|
#define urb_to_uframe(urb) \
|
|
|
|
container_of(urb, struct uframe, urb)
|
|
|
|
#define xframe_to_uframe(xframe) \
|
|
|
|
container_of(xframe, struct uframe, xframe)
|
|
|
|
#define xusb_of(xbus) \
|
|
|
|
((xusb_t *)((xbus)->transport.priv))
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
#define USEC_BUCKET 100 /* usec */
|
|
|
|
#define NUM_BUCKETS 15
|
|
|
|
#define BUCKET_START (500/USEC_BUCKET) /* skip uninteresting */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* USB XPP Bus (a USB Device)
|
|
|
|
*/
|
|
|
|
struct xusb {
|
2012-01-11 23:22:46 +08:00
|
|
|
uint xbus_num;
|
|
|
|
struct usb_device *udev; /* save off the usb device pointer */
|
2012-01-12 03:56:35 +08:00
|
|
|
struct usb_interface *interface; /* the interface for this device */
|
2012-01-11 23:22:46 +08:00
|
|
|
unsigned char minor; /* the starting minor number for this device */
|
|
|
|
uint index;
|
|
|
|
char path[XBUS_DESCLEN]; /* a unique path */
|
|
|
|
|
|
|
|
struct xusb_model_info *model_info;
|
|
|
|
struct xusb_endpoint endpoints[2]; /* RECV/SEND endpoints */
|
|
|
|
|
|
|
|
int present; /* if the device is not disconnected */
|
|
|
|
atomic_t pending_writes; /* submited but not out yet */
|
|
|
|
atomic_t pending_reads; /* submited but not in yet */
|
|
|
|
struct semaphore sem; /* locks this structure */
|
|
|
|
int counters[XUSB_COUNTER_MAX];
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/* metrics */
|
2012-01-11 23:22:46 +08:00
|
|
|
struct timeval last_tx;
|
|
|
|
unsigned int max_tx_delay;
|
|
|
|
uint usb_tx_delay[NUM_BUCKETS];
|
|
|
|
uint sluggish_debounce;
|
2015-07-20 17:11:07 +08:00
|
|
|
bool drop_pcm; /* due to sluggishness */
|
2012-01-11 23:22:46 +08:00
|
|
|
atomic_t usb_sluggish_count;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
const char *manufacturer;
|
|
|
|
const char *product;
|
|
|
|
const char *serial;
|
|
|
|
const char *interface_name;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2010-09-25 06:44:53 +08:00
|
|
|
static DEFINE_SPINLOCK(xusb_lock);
|
2012-01-11 23:22:46 +08:00
|
|
|
static xusb_t *xusb_array[MAX_BUSES] = { };
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
static unsigned bus_count;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/* prevent races between open() and disconnect() */
|
2014-05-12 22:02:35 +08:00
|
|
|
static DEFINE_MUTEX(protect_xusb_devices);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* AsteriskNow kernel has backported the "lean" callback from 2.6.20
|
|
|
|
* to 2.6.19 without any macro to notify of this fact -- how lovely.
|
|
|
|
* Debian-Etch and Centos5 are using 2.6.18 for now (lucky for us).
|
|
|
|
* Fedora6 jumped from 2.6.18 to 2.6.20. So far luck is on our side ;-)
|
|
|
|
*/
|
2012-01-11 23:21:13 +08:00
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19)
|
2010-08-28 05:59:27 +08:00
|
|
|
#define USB_PASS_CB(u) struct urb *u, struct pt_regs *regs
|
|
|
|
#else
|
|
|
|
#define USB_PASS_CB(u) struct urb *u
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void xpp_send_callback(USB_PASS_CB(urb));
|
|
|
|
static void xpp_receive_callback(USB_PASS_CB(urb));
|
2012-01-11 23:22:46 +08:00
|
|
|
static int xusb_probe(struct usb_interface *interface,
|
|
|
|
const struct usb_device_id *id);
|
|
|
|
static void xusb_disconnect(struct usb_interface *interface);
|
2010-08-28 05:59:27 +08:00
|
|
|
#ifdef CONFIG_PROC_FS
|
2013-05-22 04:33:18 +08:00
|
|
|
static const struct file_operations xusb_read_proc_ops;
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Updates the urb+xframe metadata from the uframe information.
|
|
|
|
*/
|
|
|
|
static void uframe_recompute(struct uframe *uframe, enum xusb_dir dir)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct urb *urb = &uframe->urb;
|
|
|
|
xusb_t *xusb = uframe->xusb;
|
|
|
|
struct usb_device *udev = xusb->udev;
|
|
|
|
struct xusb_endpoint *xusb_ep = &xusb->endpoints[dir];
|
|
|
|
unsigned int ep_addr = xusb_ep->ep_addr;
|
|
|
|
usb_complete_t urb_cb = xusb_ep->callback;
|
|
|
|
unsigned int epnum = ep_addr & USB_ENDPOINT_NUMBER_MASK;
|
|
|
|
int pipe = usb_pipein(ep_addr)
|
|
|
|
? usb_rcvbulkpipe(udev, epnum)
|
|
|
|
: usb_sndbulkpipe(udev, epnum);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(uframe->uframe_magic != UFRAME_MAGIC);
|
2012-01-11 23:22:46 +08:00
|
|
|
usb_fill_bulk_urb(urb, udev, pipe, uframe->transfer_buffer,
|
|
|
|
uframe->transfer_buffer_length, urb_cb, uframe);
|
2012-03-14 04:09:12 +08:00
|
|
|
urb->transfer_flags = (URB_NO_TRANSFER_DMA_MAP);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static xframe_t *alloc_xframe(xbus_t *xbus, gfp_t gfp_flags)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct uframe *uframe;
|
|
|
|
xusb_t *xusb;
|
|
|
|
void *p;
|
|
|
|
int size;
|
|
|
|
static int rate_limit;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xbus);
|
|
|
|
xusb = xusb_of(xbus);
|
|
|
|
BUG_ON(!xusb);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xusb->present) {
|
|
|
|
if ((rate_limit++ % 1003) == 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
XUSB_ERR(xusb,
|
2012-01-12 03:56:35 +08:00
|
|
|
"abort allocations during "
|
|
|
|
"device disconnect (%d)\n",
|
|
|
|
rate_limit);
|
2010-08-28 05:59:27 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
size =
|
|
|
|
min(xusb->endpoints[XUSB_SEND].max_size,
|
|
|
|
xusb->endpoints[XUSB_RECV].max_size);
|
2010-08-28 05:59:27 +08:00
|
|
|
uframe = kmem_cache_alloc(xusb_cache, gfp_flags);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!uframe) {
|
|
|
|
if ((rate_limit++ % 1003) == 0)
|
2012-01-11 23:22:46 +08:00
|
|
|
XUSB_ERR(xusb, "frame allocation failed (%d)\n",
|
|
|
|
rate_limit);
|
2010-08-28 05:59:27 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
usb_init_urb(&uframe->urb);
|
2012-01-11 23:22:46 +08:00
|
|
|
p = usb_alloc_coherent(xusb->udev, size, gfp_flags,
|
|
|
|
&uframe->urb.transfer_dma);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!p) {
|
|
|
|
if ((rate_limit++ % 1003) == 0)
|
2012-01-11 23:22:46 +08:00
|
|
|
XUSB_ERR(xusb, "buffer allocation failed (%d)\n",
|
|
|
|
rate_limit);
|
2010-08-28 05:59:27 +08:00
|
|
|
kmem_cache_free(xusb_cache, uframe);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
uframe->uframe_magic = UFRAME_MAGIC;
|
|
|
|
uframe->transfer_buffer_length = size;
|
|
|
|
uframe->transfer_buffer = p;
|
|
|
|
uframe->xusb = xusb;
|
2012-01-11 23:22:46 +08:00
|
|
|
xframe_init(xbus, &uframe->xframe, uframe->transfer_buffer,
|
|
|
|
uframe->transfer_buffer_length, uframe);
|
2010-08-28 05:59:27 +08:00
|
|
|
return &uframe->xframe;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_xframe(xbus_t *xbus, xframe_t *xframe)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct uframe *uframe = xframe_to_uframe(xframe);
|
|
|
|
struct urb *urb = &uframe->urb;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(xbus->transport.priv != uframe->xusb);
|
|
|
|
//XUSB_INFO(uframe->xusb, "frame_free\n");
|
|
|
|
usb_free_coherent(urb->dev, uframe->transfer_buffer_length,
|
2012-01-11 23:22:46 +08:00
|
|
|
urb->transfer_buffer, urb->transfer_dma);
|
2010-08-28 05:59:27 +08:00
|
|
|
memset(uframe, 0, sizeof(*uframe));
|
|
|
|
kmem_cache_free(xusb_cache, uframe);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Actuall frame sending -- both PCM and commands.
|
|
|
|
*/
|
|
|
|
static int do_send_xframe(xbus_t *xbus, xframe_t *xframe)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct urb *urb;
|
|
|
|
xusb_t *xusb;
|
|
|
|
int ret = 0;
|
|
|
|
struct uframe *uframe;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xframe);
|
|
|
|
BUG_ON(xframe->xframe_magic != XFRAME_MAGIC);
|
|
|
|
xusb = xusb_of(xbus);
|
|
|
|
BUG_ON(!xusb);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xusb->present) {
|
2012-01-11 23:22:46 +08:00
|
|
|
static int rate_limit;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if ((rate_limit++ % 1003) == 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
XUSB_ERR(xusb,
|
2012-01-12 03:56:35 +08:00
|
|
|
"abort do_send_xframe during "
|
|
|
|
"device disconnect (%d)\n",
|
|
|
|
rate_limit);
|
2010-08-28 05:59:27 +08:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If something really bad happend, do not overflow the USB stack
|
|
|
|
*/
|
2012-01-11 23:20:05 +08:00
|
|
|
if (atomic_read(&xusb->pending_writes) > MAX_PENDING_WRITES) {
|
2012-01-11 23:22:46 +08:00
|
|
|
static int rate_limit;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if ((rate_limit++ % 5000) == 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
XUSB_ERR(xusb,
|
2012-01-12 03:56:35 +08:00
|
|
|
"USB device is totaly stuck. "
|
|
|
|
"Dropping packets (#%d).\n",
|
|
|
|
rate_limit);
|
2010-08-28 05:59:27 +08:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
uframe = xframe->priv;
|
|
|
|
BUG_ON(!uframe);
|
|
|
|
BUG_ON(uframe->uframe_magic != UFRAME_MAGIC);
|
|
|
|
uframe_recompute(uframe, XUSB_SEND);
|
|
|
|
urb = &uframe->urb;
|
|
|
|
BUG_ON(!urb);
|
|
|
|
/* update urb length */
|
|
|
|
urb->transfer_buffer_length = XFRAME_LEN(xframe);
|
|
|
|
do_gettimeofday(&xframe->tv_submitted);
|
|
|
|
ret = usb_submit_urb(urb, GFP_ATOMIC);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (ret < 0) {
|
2010-08-28 05:59:27 +08:00
|
|
|
static int rate_limit;
|
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if ((rate_limit++ % 1000) == 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_ERR(xbus, "%s: usb_submit_urb failed: %d\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
__func__, ret);
|
2010-08-28 05:59:27 +08:00
|
|
|
ret = -EBADF;
|
|
|
|
goto failure;
|
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
// if (debug)
|
|
|
|
// dump_xframe("USB_FRAME_SEND", xbus, xframe, debug);
|
2010-08-28 05:59:27 +08:00
|
|
|
atomic_inc(&xusb->pending_writes);
|
|
|
|
return 0;
|
|
|
|
failure:
|
|
|
|
XUSB_COUNTER(xusb, TX_ERRORS)++;
|
|
|
|
FREE_SEND_XFRAME(xbus, xframe); /* return to pool */
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PCM wrapper
|
|
|
|
*/
|
|
|
|
static int xframe_send_pcm(xbus_t *xbus, xframe_t *xframe)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xusb_t *xusb;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xbus);
|
|
|
|
BUG_ON(!xframe);
|
|
|
|
xusb = xusb_of(xbus);
|
|
|
|
BUG_ON(!xusb);
|
2015-07-20 17:11:07 +08:00
|
|
|
if (xusb->drop_pcm) {
|
|
|
|
static int rate_limit;
|
|
|
|
|
|
|
|
if ((rate_limit++ % 1000) == 0)
|
|
|
|
XUSB_ERR(xusb, "Sluggish USB: drop tx-pcm (%d)\n",
|
|
|
|
rate_limit);
|
|
|
|
/* Let trickle of TX-PCM, so Astribank will not reset */
|
|
|
|
if (sluggish_pcm_keepalive &&
|
|
|
|
((rate_limit % sluggish_pcm_keepalive) != 0)) {
|
|
|
|
XUSB_COUNTER(xusb, TX_DROPS)++;
|
|
|
|
goto err;
|
|
|
|
}
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
return do_send_xframe(xbus, xframe);
|
2015-07-20 17:11:07 +08:00
|
|
|
err:
|
|
|
|
FREE_SEND_XFRAME(xbus, xframe); /* return to pool */
|
|
|
|
return -EIO;
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* commands wrapper
|
|
|
|
*/
|
|
|
|
static int xframe_send_cmd(xbus_t *xbus, xframe_t *xframe)
|
|
|
|
{
|
|
|
|
BUG_ON(!xbus);
|
|
|
|
BUG_ON(!xframe);
|
2012-01-11 23:17:09 +08:00
|
|
|
//XBUS_INFO(xbus, "%s:\n", __func__);
|
2010-08-28 05:59:27 +08:00
|
|
|
return do_send_xframe(xbus, xframe);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get a urb from the receive_pool and submit it on the read endpoint.
|
|
|
|
*/
|
|
|
|
static bool xusb_listen(xusb_t *xusb)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus_t *xbus = xbus_num(xusb->xbus_num);
|
|
|
|
xframe_t *xframe;
|
|
|
|
struct uframe *uframe;
|
|
|
|
int ret = 0;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xbus);
|
|
|
|
xframe = ALLOC_RECV_XFRAME(xbus);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xframe) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_ERR(xbus, "Empty receive_pool\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
uframe = xframe_to_uframe(xframe);
|
|
|
|
uframe_recompute(uframe, XUSB_RECV);
|
|
|
|
ret = usb_submit_urb(&uframe->urb, GFP_ATOMIC);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (ret < 0) {
|
2010-08-28 05:59:27 +08:00
|
|
|
static int rate_limit;
|
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if ((rate_limit++ % 1000) == 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_ERR(xbus, "%s: usb_submit_urb failed: %d\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
__func__, ret);
|
2010-08-28 05:59:27 +08:00
|
|
|
FREE_RECV_XFRAME(xbus, xframe);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
atomic_inc(&xusb->pending_reads);
|
|
|
|
ret = 1;
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------- XPP USB Bus Handling -------------------*/
|
|
|
|
|
|
|
|
enum XUSB_MODELS {
|
|
|
|
MODEL_FPGA_XPD
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct xusb_model_info {
|
2012-01-11 23:22:46 +08:00
|
|
|
const char *desc;
|
|
|
|
int iface_num;
|
|
|
|
struct xusb_endpoint in;
|
|
|
|
struct xusb_endpoint out;
|
2010-08-28 05:59:27 +08:00
|
|
|
} model_table[] = {
|
|
|
|
[MODEL_FPGA_XPD] = {
|
2012-01-13 01:12:48 +08:00
|
|
|
.iface_num = 0,
|
|
|
|
.in = { .ep_addr = 0x86 },
|
|
|
|
.out = { .ep_addr = 0x02 },
|
|
|
|
.desc = "FPGA_XPD"
|
|
|
|
},
|
|
|
|
};
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/* table of devices that work with this driver */
|
2012-01-11 23:22:46 +08:00
|
|
|
static const struct usb_device_id xusb_table[] = {
|
2012-01-12 03:56:35 +08:00
|
|
|
/* FPGA_FXS */ {USB_DEVICE(0xE4E4, 0x1132),
|
2012-01-13 01:12:48 +08:00
|
|
|
.driver_info = (kernel_ulong_t)&model_table[MODEL_FPGA_XPD]},
|
2012-01-12 03:56:35 +08:00
|
|
|
/* FPGA_1141 */ {USB_DEVICE(0xE4E4, 0x1142),
|
2012-01-13 01:12:48 +08:00
|
|
|
.driver_info = (kernel_ulong_t)&model_table[MODEL_FPGA_XPD]},
|
2012-01-12 03:56:35 +08:00
|
|
|
/* FPGA_1151 */ {USB_DEVICE(0xE4E4, 0x1152),
|
2012-01-13 01:12:48 +08:00
|
|
|
.driver_info = (kernel_ulong_t)&model_table[MODEL_FPGA_XPD]},
|
2012-01-12 03:56:35 +08:00
|
|
|
/* FPGA_1161 */ {USB_DEVICE(0xE4E4, 0x1162),
|
2012-01-13 01:12:48 +08:00
|
|
|
.driver_info = (kernel_ulong_t)&model_table[MODEL_FPGA_XPD]},
|
2012-01-12 03:56:35 +08:00
|
|
|
/* Terminate */ {}
|
2010-08-28 05:59:27 +08:00
|
|
|
};
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
MODULE_DEVICE_TABLE(usb, xusb_table);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-12 03:56:35 +08:00
|
|
|
/*
|
|
|
|
* USB specific object needed to register this driver
|
|
|
|
* with the usb subsystem
|
|
|
|
*/
|
2010-08-28 05:59:27 +08:00
|
|
|
static struct usb_driver xusb_driver = {
|
2012-01-11 23:22:46 +08:00
|
|
|
.name = "xpp_usb",
|
|
|
|
.probe = xusb_probe,
|
|
|
|
.disconnect = xusb_disconnect,
|
|
|
|
.id_table = xusb_table,
|
2010-08-28 05:59:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* File operations needed when we register this driver.
|
|
|
|
* This assumes that this driver NEEDS file operations,
|
|
|
|
* of course, which means that the driver is expected
|
|
|
|
* to have a node in the /dev directory. If the USB
|
|
|
|
* device were for a network interface then the driver
|
|
|
|
* would use "struct net_driver" instead, and a serial
|
|
|
|
* device would use "struct tty_driver".
|
|
|
|
*/
|
2012-01-13 01:13:15 +08:00
|
|
|
static const struct file_operations xusb_fops = {
|
2010-08-28 05:59:27 +08:00
|
|
|
/*
|
|
|
|
* The owner field is part of the module-locking
|
|
|
|
* mechanism. The idea is that the kernel knows
|
|
|
|
* which module to increment the use-counter of
|
|
|
|
* BEFORE it calls the device's open() function.
|
|
|
|
* This also means that the kernel can decrement
|
|
|
|
* the use-counter again before calling release()
|
|
|
|
* or should the open() function fail.
|
|
|
|
*/
|
2012-01-11 23:22:46 +08:00
|
|
|
.owner = THIS_MODULE,
|
2010-08-28 05:59:27 +08:00
|
|
|
};
|
|
|
|
|
2012-01-11 23:16:34 +08:00
|
|
|
/*
|
2010-08-28 05:59:27 +08:00
|
|
|
* usb class driver info in order to get a minor number from the usb core,
|
|
|
|
* and to have the device registered with devfs and the driver core
|
|
|
|
*/
|
|
|
|
static struct usb_class_driver xusb_class = {
|
2012-01-11 23:22:46 +08:00
|
|
|
.name = "usb/xpp_usb%d",
|
|
|
|
.fops = &xusb_fops,
|
|
|
|
.minor_base = USB_SKEL_MINOR_BASE,
|
2010-08-28 05:59:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that an endpoint's wMaxPacketSize attribute is 512. This
|
2012-01-11 23:16:34 +08:00
|
|
|
* indicates that it is a USB2's high speed end point.
|
2010-08-28 05:59:27 +08:00
|
|
|
*
|
|
|
|
* If it is 64, it means we have a USB1 controller. By default we do not
|
|
|
|
* support it and just fail the probe of the device. However if the user
|
|
|
|
* has set usb1=1, we continue and just put a notice.
|
|
|
|
*
|
|
|
|
* Returns true if all OK, false otherwise.
|
|
|
|
*/
|
|
|
|
static int check_usb1(struct usb_endpoint_descriptor *endpoint)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
const char *msg =
|
|
|
|
(usb_pipein(endpoint->bEndpointAddress)) ? "input" : "output";
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (endpoint->wMaxPacketSize >= sizeof(xpacket_t))
|
2010-08-28 05:59:27 +08:00
|
|
|
return 1;
|
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (usb1) {
|
2012-01-12 03:56:35 +08:00
|
|
|
NOTICE("USB1 endpoint detected: "
|
|
|
|
"USB %s endpoint 0x%X support only wMaxPacketSize=%d\n",
|
|
|
|
msg,
|
|
|
|
endpoint->bEndpointAddress,
|
|
|
|
endpoint->wMaxPacketSize);
|
2010-08-28 05:59:27 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2012-01-12 03:56:35 +08:00
|
|
|
NOTICE("USB1 endpoint detected: "
|
|
|
|
"Device disabled. To enable: usb1=1, and read docs. "
|
|
|
|
"(%s, endpoint %d, size %d)\n",
|
|
|
|
msg, endpoint->bEndpointAddress, endpoint->wMaxPacketSize);
|
2010-08-28 05:59:27 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set up the endpoint information
|
|
|
|
* check out the endpoints
|
2012-01-12 03:56:35 +08:00
|
|
|
* FIXME: Should be simplified (above 2.6.10) to use
|
|
|
|
* usb_dev->ep_in[0..16] and usb_dev->ep_out[0..16]
|
2010-08-28 05:59:27 +08:00
|
|
|
*/
|
2012-01-11 23:22:46 +08:00
|
|
|
static int set_endpoints(xusb_t *xusb, struct usb_host_interface *iface_desc,
|
|
|
|
struct xusb_model_info *model_info)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct usb_endpoint_descriptor *endpoint;
|
|
|
|
struct xusb_endpoint *xusb_ep;
|
|
|
|
int ep_addr;
|
2010-08-28 05:59:27 +08:00
|
|
|
int i;
|
|
|
|
|
2012-01-12 03:56:35 +08:00
|
|
|
#define BULK_ENDPOINT(ep) \
|
|
|
|
(((ep)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == \
|
|
|
|
USB_ENDPOINT_XFER_BULK)
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
|
|
|
|
endpoint = &iface_desc->endpoint[i].desc;
|
|
|
|
ep_addr = endpoint->bEndpointAddress;
|
2012-01-11 23:16:34 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!BULK_ENDPOINT(endpoint)) {
|
2012-01-11 23:22:46 +08:00
|
|
|
DBG(DEVICES,
|
|
|
|
"endpoint 0x%x is not bulk: mbAttributes=0x%X\n",
|
|
|
|
ep_addr, endpoint->bmAttributes);
|
2010-08-28 05:59:27 +08:00
|
|
|
continue;
|
|
|
|
}
|
2012-01-13 01:12:48 +08:00
|
|
|
if (usb_pipein(ep_addr)) { /* Input */
|
2012-01-11 23:20:05 +08:00
|
|
|
if (ep_addr == model_info->in.ep_addr) {
|
2010-08-28 05:59:27 +08:00
|
|
|
if (!check_usb1(endpoint))
|
|
|
|
return 0;
|
|
|
|
xusb_ep = &xusb->endpoints[XUSB_RECV];
|
|
|
|
xusb_ep->ep_addr = ep_addr;
|
|
|
|
xusb_ep->max_size = endpoint->wMaxPacketSize;
|
|
|
|
xusb_ep->callback = xpp_receive_callback;
|
|
|
|
}
|
2012-01-13 01:12:48 +08:00
|
|
|
} else { /* Output */
|
2012-01-11 23:20:05 +08:00
|
|
|
if (ep_addr == model_info->out.ep_addr) {
|
2010-08-28 05:59:27 +08:00
|
|
|
if (!check_usb1(endpoint))
|
|
|
|
return 0;
|
|
|
|
xusb_ep = &xusb->endpoints[XUSB_SEND];
|
|
|
|
xusb_ep->ep_addr = ep_addr;
|
|
|
|
xusb_ep->max_size = endpoint->wMaxPacketSize;
|
|
|
|
xusb_ep->callback = xpp_send_callback;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
if (!xusb->endpoints[XUSB_RECV].ep_addr
|
|
|
|
|| !xusb->endpoints[XUSB_SEND].ep_addr) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XUSB_ERR(xusb, "Couldn't find bulk-in or bulk-out endpoints\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
DBG(DEVICES, "in=0x%02X out=0x%02X\n",
|
|
|
|
xusb->endpoints[XUSB_RECV].ep_addr,
|
|
|
|
xusb->endpoints[XUSB_SEND].ep_addr);
|
2010-08-28 05:59:27 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xusb_probe
|
|
|
|
*
|
|
|
|
* Called by the usb core when a new device is connected that it thinks
|
|
|
|
* this driver might be interested in.
|
|
|
|
*/
|
2012-01-11 23:22:46 +08:00
|
|
|
static int xusb_probe(struct usb_interface *interface,
|
|
|
|
const struct usb_device_id *id)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct usb_device *udev = interface_to_usbdev(interface);
|
|
|
|
struct usb_host_interface *iface_desc =
|
|
|
|
usb_altnum_to_altsetting(interface, 0);
|
|
|
|
xusb_t *xusb = NULL;
|
|
|
|
struct xusb_model_info *model_info =
|
|
|
|
(struct xusb_model_info *)id->driver_info;
|
2010-08-28 05:59:27 +08:00
|
|
|
#ifdef CONFIG_PROC_FS
|
2012-01-11 23:22:46 +08:00
|
|
|
struct proc_dir_entry *procsummary = NULL;
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus_t *xbus = NULL;
|
|
|
|
unsigned long flags;
|
|
|
|
int retval = -ENOMEM;
|
|
|
|
int i;
|
2012-01-11 23:16:34 +08:00
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
DBG(DEVICES, "New XUSB device MODEL=%s\n", model_info->desc);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (iface_desc->desc.bInterfaceNumber != model_info->iface_num) {
|
2010-08-28 05:59:27 +08:00
|
|
|
DBG(DEVICES, "Skip interface #%d != #%d\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
iface_desc->desc.bInterfaceNumber, model_info->iface_num);
|
2010-08-28 05:59:27 +08:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
2014-05-12 22:02:35 +08:00
|
|
|
mutex_lock(&protect_xusb_devices);
|
2012-03-14 04:09:12 +08:00
|
|
|
if ((retval = usb_reset_device(udev)) < 0) {
|
2010-08-28 05:59:27 +08:00
|
|
|
ERR("usb_reset_device failed: %d\n", retval);
|
|
|
|
goto probe_failed;
|
|
|
|
}
|
|
|
|
if (!model_info) {
|
2012-01-11 23:16:34 +08:00
|
|
|
ERR("Missing endpoint setup for this device %d:%d\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
udev->descriptor.idVendor, udev->descriptor.idProduct);
|
2010-08-28 05:59:27 +08:00
|
|
|
retval = -ENODEV;
|
|
|
|
goto probe_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate memory for our device state and initialize it */
|
|
|
|
xusb = KZALLOC(sizeof(xusb_t), GFP_KERNEL);
|
|
|
|
if (xusb == NULL) {
|
|
|
|
ERR("xpp_usb: Unable to allocate new xpp usb bus\n");
|
|
|
|
retval = -ENOMEM;
|
|
|
|
goto probe_failed;
|
|
|
|
}
|
2010-11-05 00:40:29 +08:00
|
|
|
sema_init(&xusb->sem, 1);
|
2010-08-28 05:59:27 +08:00
|
|
|
atomic_set(&xusb->pending_writes, 0);
|
|
|
|
atomic_set(&xusb->pending_reads, 0);
|
|
|
|
atomic_set(&xusb->usb_sluggish_count, 0);
|
|
|
|
xusb->udev = udev;
|
|
|
|
xusb->interface = interface;
|
|
|
|
xusb->model_info = model_info;
|
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!set_endpoints(xusb, iface_desc, model_info)) {
|
2010-08-28 05:59:27 +08:00
|
|
|
retval = -ENODEV;
|
|
|
|
goto probe_failed;
|
|
|
|
}
|
|
|
|
xusb->serial = udev->serial;
|
|
|
|
xusb->manufacturer = udev->manufacturer;
|
|
|
|
xusb->product = udev->product;
|
|
|
|
xusb->interface_name = iface_desc->string;
|
2012-01-11 23:22:46 +08:00
|
|
|
INFO("XUSB: %s -- %s -- %s\n", xusb->manufacturer, xusb->product,
|
|
|
|
xusb->interface_name);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/* allow device read, write and ioctl */
|
|
|
|
xusb->present = 1;
|
|
|
|
|
|
|
|
/* we can register the device now, as it is ready */
|
|
|
|
usb_set_intfdata(interface, xusb);
|
2012-01-11 23:22:46 +08:00
|
|
|
retval = usb_register_dev(interface, &xusb_class);
|
2010-08-28 05:59:27 +08:00
|
|
|
if (retval) {
|
|
|
|
/* something prevented us from registering this driver */
|
2012-01-11 23:22:46 +08:00
|
|
|
ERR("Not able to get a minor for this device.\n");
|
2010-08-28 05:59:27 +08:00
|
|
|
goto probe_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
xusb->minor = interface->minor;
|
|
|
|
|
|
|
|
/* let the user know what node this device is now attached to */
|
|
|
|
DBG(DEVICES, "USB XPP device now attached to minor %d\n", xusb->minor);
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus =
|
|
|
|
xbus_new(&xusb_ops,
|
|
|
|
min(xusb->endpoints[XUSB_SEND].max_size,
|
|
|
|
xusb->endpoints[XUSB_RECV].max_size), &udev->dev,
|
|
|
|
xusb);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xbus) {
|
2010-08-28 05:59:27 +08:00
|
|
|
retval = -ENOMEM;
|
|
|
|
goto probe_failed;
|
|
|
|
}
|
2011-11-02 22:08:12 +08:00
|
|
|
snprintf(xbus->transport.model_string,
|
2012-01-11 23:22:46 +08:00
|
|
|
ARRAY_SIZE(xbus->transport.model_string), "usb:%04x/%04x/%x",
|
|
|
|
udev->descriptor.idVendor, udev->descriptor.idProduct,
|
|
|
|
udev->descriptor.bcdDevice);
|
2010-08-28 05:59:27 +08:00
|
|
|
spin_lock_irqsave(&xusb_lock, flags);
|
2012-01-11 23:20:05 +08:00
|
|
|
for (i = 0; i < MAX_BUSES; i++) {
|
|
|
|
if (xusb_array[i] == NULL)
|
2010-08-28 05:59:27 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&xusb_lock, flags);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (i >= MAX_BUSES) {
|
2010-08-28 05:59:27 +08:00
|
|
|
ERR("xpp_usb: Too many XPP USB buses\n");
|
|
|
|
retval = -ENOMEM;
|
|
|
|
goto probe_failed;
|
|
|
|
}
|
2012-01-12 03:56:35 +08:00
|
|
|
/* May trunacte... ignore */
|
|
|
|
usb_make_path(udev, xusb->path, XBUS_DESCLEN);
|
2010-08-28 05:59:27 +08:00
|
|
|
snprintf(xbus->connector, XBUS_DESCLEN, "%s", xusb->path);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xusb->serial && xusb->serial[0])
|
2010-08-28 05:59:27 +08:00
|
|
|
snprintf(xbus->label, LABEL_SIZE, "usb:%s", xusb->serial);
|
|
|
|
xusb->index = i;
|
|
|
|
xusb_array[i] = xusb;
|
|
|
|
XUSB_DBG(DEVICES, xusb, "GOT XPP USB BUS: %s\n", xbus->connector);
|
|
|
|
|
|
|
|
#ifdef CONFIG_PROC_FS
|
2012-01-11 23:22:46 +08:00
|
|
|
DBG(PROC,
|
|
|
|
"Creating proc entry " PROC_USBXPP_SUMMARY " in bus proc dir.\n");
|
2013-05-22 04:33:18 +08:00
|
|
|
procsummary = proc_create_data(PROC_USBXPP_SUMMARY, 0444,
|
|
|
|
xbus->proc_xbus_dir, &xusb_read_proc_ops,
|
|
|
|
xusb);
|
2010-08-28 05:59:27 +08:00
|
|
|
if (!procsummary) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_ERR(xbus, "Failed to create proc file '%s'\n",
|
|
|
|
PROC_USBXPP_SUMMARY);
|
2010-08-28 05:59:27 +08:00
|
|
|
// FIXME: better error handling
|
|
|
|
retval = -EIO;
|
|
|
|
goto probe_failed;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
bus_count++;
|
|
|
|
xusb->xbus_num = xbus->num;
|
|
|
|
/* prepare several pending frames for receive side */
|
2012-01-11 23:20:05 +08:00
|
|
|
for (i = 0; i < 10; i++)
|
2012-01-11 23:22:46 +08:00
|
|
|
xusb_listen(xusb);
|
2010-08-28 05:59:27 +08:00
|
|
|
xbus_connect(xbus);
|
2014-05-12 22:02:35 +08:00
|
|
|
mutex_unlock(&protect_xusb_devices);
|
2010-08-28 05:59:27 +08:00
|
|
|
return retval;
|
|
|
|
probe_failed:
|
|
|
|
ERR("Failed to initialize xpp usb bus: %d\n", retval);
|
|
|
|
usb_set_intfdata(interface, NULL);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xusb) {
|
2012-01-13 01:12:48 +08:00
|
|
|
if (xusb->minor) { /* passed registration phase */
|
2010-08-28 05:59:27 +08:00
|
|
|
ERR("Calling usb_deregister_dev()\n");
|
|
|
|
usb_deregister_dev(interface, &xusb_class);
|
|
|
|
}
|
|
|
|
ERR("Removing failed xusb\n");
|
|
|
|
KZFREE(xusb);
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xbus) {
|
2010-08-28 05:59:27 +08:00
|
|
|
#ifdef CONFIG_PROC_FS
|
2012-01-11 23:20:05 +08:00
|
|
|
if (procsummary) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_DBG(PROC, xbus,
|
|
|
|
"Remove proc_entry: " PROC_USBXPP_SUMMARY
|
|
|
|
"\n");
|
|
|
|
remove_proc_entry(PROC_USBXPP_SUMMARY,
|
|
|
|
xbus->proc_xbus_dir);
|
2010-08-28 05:59:27 +08:00
|
|
|
procsummary = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
ERR("Calling xbus_disconnect()\n");
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus_disconnect(xbus); // Blocking until fully deactivated!
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2014-05-12 22:02:35 +08:00
|
|
|
mutex_unlock(&protect_xusb_devices);
|
2010-08-28 05:59:27 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xusb_disconnect
|
|
|
|
*
|
|
|
|
* Called by the usb core when the device is removed from the system.
|
|
|
|
*
|
|
|
|
* This routine guarantees that the driver will not submit any more urbs
|
|
|
|
* by clearing dev->udev. It is also supposed to terminate any currently
|
|
|
|
* active urbs. Unfortunately, usb_bulk_msg(), used in xusb_read(), does
|
|
|
|
* not provide any way to do this. But at least we can cancel an active
|
|
|
|
* write.
|
|
|
|
*/
|
|
|
|
static void xusb_disconnect(struct usb_interface *interface)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct usb_host_interface *iface_desc =
|
|
|
|
usb_altnum_to_altsetting(interface, 0);
|
|
|
|
xusb_t *xusb;
|
|
|
|
xbus_t *xbus;
|
|
|
|
int i;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
DBG(DEVICES, "CALLED on interface #%d\n",
|
|
|
|
iface_desc->desc.bInterfaceNumber);
|
2010-08-28 05:59:27 +08:00
|
|
|
/* prevent races with open() */
|
2014-05-12 22:02:35 +08:00
|
|
|
mutex_lock(&protect_xusb_devices);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
xusb = usb_get_intfdata(interface);
|
|
|
|
usb_set_intfdata(interface, NULL);
|
|
|
|
xusb->present = 0;
|
|
|
|
xbus = xbus_num(xusb->xbus_num);
|
|
|
|
|
|
|
|
/* find our xusb */
|
2012-01-11 23:20:05 +08:00
|
|
|
for (i = 0; i < MAX_BUSES; i++) {
|
|
|
|
if (xusb_array[i] == xusb)
|
2010-08-28 05:59:27 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
BUG_ON(i >= MAX_BUSES);
|
|
|
|
xusb_array[i] = NULL;
|
|
|
|
|
|
|
|
#ifdef CONFIG_PROC_FS
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xbus->proc_xbus_dir) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_DBG(PROC, xbus,
|
|
|
|
"Remove proc_entry: " PROC_USBXPP_SUMMARY "\n");
|
2010-08-28 05:59:27 +08:00
|
|
|
remove_proc_entry(PROC_USBXPP_SUMMARY, xbus->proc_xbus_dir);
|
|
|
|
}
|
|
|
|
#endif
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus_disconnect(xbus); // Blocking until fully deactivated!
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
down(&xusb->sem);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/* give back our minor */
|
|
|
|
usb_deregister_dev(interface, &xusb_class);
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
up(&xusb->sem);
|
2010-08-28 05:59:27 +08:00
|
|
|
DBG(DEVICES, "Semaphore released\n");
|
|
|
|
XUSB_INFO(xusb, "now disconnected\n");
|
|
|
|
KZFREE(xusb);
|
|
|
|
|
2014-05-12 22:02:35 +08:00
|
|
|
mutex_unlock(&protect_xusb_devices);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void xpp_send_callback(USB_PASS_CB(urb))
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct uframe *uframe = urb_to_uframe(urb);
|
|
|
|
xframe_t *xframe = &uframe->xframe;
|
|
|
|
xusb_t *xusb = uframe->xusb;
|
|
|
|
xbus_t *xbus = xbus_num(xusb->xbus_num);
|
|
|
|
struct timeval now;
|
|
|
|
long usec;
|
|
|
|
int writes = atomic_read(&xusb->pending_writes);
|
|
|
|
int i;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xbus) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XUSB_ERR(xusb,
|
2012-01-12 03:56:35 +08:00
|
|
|
"Sent URB does not belong to a valid xbus...\n");
|
2010-08-28 05:59:27 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
//flip_parport_bit(6);
|
|
|
|
atomic_dec(&xusb->pending_writes);
|
|
|
|
do_gettimeofday(&now);
|
|
|
|
xusb->last_tx = xframe->tv_submitted;
|
|
|
|
usec = usec_diff(&now, &xframe->tv_submitted);
|
2016-01-13 18:19:04 +08:00
|
|
|
if (usec < 0)
|
|
|
|
usec = 0; /* System clock jumped */
|
2012-01-11 23:20:05 +08:00
|
|
|
if (usec > xusb->max_tx_delay)
|
2010-08-28 05:59:27 +08:00
|
|
|
xusb->max_tx_delay = usec;
|
|
|
|
i = usec / USEC_BUCKET;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (i >= NUM_BUCKETS)
|
2010-08-28 05:59:27 +08:00
|
|
|
i = NUM_BUCKETS - 1;
|
|
|
|
xusb->usb_tx_delay[i]++;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (unlikely(usec > tx_sluggish)) {
|
|
|
|
if (xusb->sluggish_debounce++ > drop_pcm_after) {
|
2012-01-11 23:22:46 +08:00
|
|
|
static int rate_limit;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-12 03:56:35 +08:00
|
|
|
/* skip first messages */
|
|
|
|
if ((rate_limit++ % 1003) == 500)
|
2010-08-28 05:59:27 +08:00
|
|
|
XUSB_NOTICE(xusb,
|
2012-01-12 03:56:35 +08:00
|
|
|
"Sluggish USB. Dropping next PCM frame "
|
|
|
|
"(pending_writes=%d)\n",
|
|
|
|
writes);
|
2015-07-20 17:11:07 +08:00
|
|
|
atomic_inc(&xusb->usb_sluggish_count);
|
|
|
|
xusb->drop_pcm = 1;
|
2010-08-28 05:59:27 +08:00
|
|
|
xusb->sluggish_debounce = 0;
|
|
|
|
}
|
2015-07-20 17:11:07 +08:00
|
|
|
} else {
|
2010-08-28 05:59:27 +08:00
|
|
|
xusb->sluggish_debounce = 0;
|
2015-07-20 17:11:07 +08:00
|
|
|
xusb->drop_pcm = 0;
|
|
|
|
}
|
2010-08-28 05:59:27 +08:00
|
|
|
/* sync/async unlink faults aren't errors */
|
2012-01-11 23:22:46 +08:00
|
|
|
if (urb->status
|
|
|
|
&& !(urb->status == -ENOENT || urb->status == -ECONNRESET)) {
|
|
|
|
static int rate_limit;
|
2012-01-11 23:20:05 +08:00
|
|
|
if ((rate_limit++ % 1000) < 10) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XUSB_ERR(xusb,
|
2012-01-12 03:56:35 +08:00
|
|
|
"nonzero write bulk status received: "
|
|
|
|
"%d (pending_writes=%d)\n",
|
|
|
|
urb->status, writes);
|
2010-08-28 05:59:27 +08:00
|
|
|
dump_xframe("usb-write-error", xbus, xframe, DBG_ANY);
|
|
|
|
}
|
|
|
|
XUSB_COUNTER(xusb, TX_ERRORS)++;
|
|
|
|
} else
|
|
|
|
XUSB_COUNTER(xusb, TX_FRAMES)++;
|
|
|
|
FREE_SEND_XFRAME(xbus, xframe);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xusb->present)
|
2010-08-28 05:59:27 +08:00
|
|
|
XUSB_ERR(xusb, "A urb from non-connected device?\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xpp_receive_callback(USB_PASS_CB(urb))
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct uframe *uframe = urb_to_uframe(urb);
|
|
|
|
xframe_t *xframe = &uframe->xframe;
|
|
|
|
xusb_t *xusb = uframe->xusb;
|
|
|
|
xbus_t *xbus = xbus_num(xusb->xbus_num);
|
|
|
|
size_t size;
|
|
|
|
bool do_resubmit = 1;
|
|
|
|
struct timeval now;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
do_gettimeofday(&now);
|
|
|
|
atomic_dec(&xusb->pending_reads);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xbus) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XUSB_ERR(xusb,
|
2012-01-12 03:56:35 +08:00
|
|
|
"Received URB does not belong to a valid xbus...\n");
|
2010-08-28 05:59:27 +08:00
|
|
|
return;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xusb->present) {
|
2010-08-28 05:59:27 +08:00
|
|
|
do_resubmit = 0;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if (urb->status) {
|
2012-01-11 23:22:46 +08:00
|
|
|
DBG(GENERAL, "nonzero read bulk status received: %d\n",
|
|
|
|
urb->status);
|
2010-08-28 05:59:27 +08:00
|
|
|
XUSB_COUNTER(xusb, RX_ERRORS)++;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
size = urb->actual_length;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (size == 0) {
|
2012-01-11 23:22:46 +08:00
|
|
|
static int rate_limit;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if ((rate_limit++ % 5003) == 0)
|
2012-01-11 23:22:46 +08:00
|
|
|
XUSB_NOTICE(xusb, "Received a zero length URBs (%d)\n",
|
|
|
|
rate_limit);
|
2010-08-28 05:59:27 +08:00
|
|
|
XUSB_COUNTER(xusb, RCV_ZERO_LEN)++;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
atomic_set(&xframe->frame_len, size);
|
|
|
|
xframe->tv_received = now;
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
// if (debug)
|
|
|
|
// dump_xframe("USB_FRAME_RECEIVE", xbus, xframe, debug);
|
2010-08-28 05:59:27 +08:00
|
|
|
XUSB_COUNTER(xusb, RX_FRAMES)++;
|
2015-07-20 17:11:07 +08:00
|
|
|
if (xusb->drop_pcm) {
|
|
|
|
/* some protocol analysis */
|
|
|
|
static int rate_limit;
|
|
|
|
xpacket_t *pack = (xpacket_t *)(xframe->packets);
|
|
|
|
bool is_pcm = XPACKET_IS_PCM(pack);
|
|
|
|
|
|
|
|
if (is_pcm) {
|
|
|
|
if ((rate_limit++ % 1000) == 0)
|
|
|
|
XUSB_ERR(xusb,
|
|
|
|
"Sluggish USB: drop rx-pcm (%d)\n",
|
|
|
|
rate_limit);
|
|
|
|
/* Let trickle of RX-PCM, so Astribank will not reset */
|
|
|
|
if (sluggish_pcm_keepalive &&
|
|
|
|
((rate_limit % sluggish_pcm_keepalive)
|
|
|
|
!= 0)) {
|
|
|
|
XUSB_COUNTER(xusb, RX_DROPS)++;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-28 05:59:27 +08:00
|
|
|
/* Send UP */
|
|
|
|
xbus_receive_xframe(xbus, xframe);
|
|
|
|
end:
|
2012-01-11 23:20:05 +08:00
|
|
|
if (do_resubmit)
|
2010-08-28 05:59:27 +08:00
|
|
|
xusb_listen(xusb);
|
|
|
|
return;
|
|
|
|
err:
|
|
|
|
FREE_RECV_XFRAME(xbus, xframe);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------- Initialization -------------------------*/
|
|
|
|
|
|
|
|
static void xpp_usb_cleanup(void)
|
|
|
|
{
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xusb_cache) {
|
2010-08-28 05:59:27 +08:00
|
|
|
kmem_cache_destroy(xusb_cache);
|
|
|
|
xusb_cache = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init xpp_usb_init(void)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int ret;
|
2010-08-28 05:59:27 +08:00
|
|
|
//xusb_t *xusb;
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
xusb_cache =
|
|
|
|
kmem_cache_create("xusb_cache", sizeof(xframe_t) + XFRAME_DATASIZE,
|
2012-01-11 23:21:13 +08:00
|
|
|
#if (LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 22)) && defined(CONFIG_SLUB)
|
2012-01-11 23:22:46 +08:00
|
|
|
0, SLAB_STORE_USER,
|
2010-08-28 05:59:27 +08:00
|
|
|
#else
|
2012-01-11 23:22:46 +08:00
|
|
|
0, 0,
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
2012-01-11 23:21:13 +08:00
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23)
|
2012-01-11 23:22:46 +08:00
|
|
|
NULL,
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
2012-01-11 23:22:46 +08:00
|
|
|
NULL);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xusb_cache) {
|
2010-08-28 05:59:27 +08:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* register this driver with the USB subsystem */
|
|
|
|
ret = usb_register(&xusb_driver);
|
|
|
|
if (ret) {
|
|
|
|
ERR("usb_register failed. Error number %d\n", ret);
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
failure:
|
|
|
|
xpp_usb_cleanup();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit xpp_usb_shutdown(void)
|
|
|
|
{
|
|
|
|
DBG(GENERAL, "\n");
|
|
|
|
/* deregister this driver with the USB subsystem */
|
|
|
|
usb_deregister(&xusb_driver);
|
|
|
|
xpp_usb_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
|
2013-05-22 04:33:18 +08:00
|
|
|
static int xusb_read_proc_show(struct seq_file *sfile, void *data)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
unsigned long flags;
|
|
|
|
int i;
|
2010-08-28 05:59:27 +08:00
|
|
|
//unsigned long stamp = jiffies;
|
2013-05-22 04:33:18 +08:00
|
|
|
xusb_t *xusb = sfile->private;
|
2012-01-11 23:22:46 +08:00
|
|
|
uint usb_tx_delay[NUM_BUCKETS];
|
|
|
|
const int mark_limit = tx_sluggish / USEC_BUCKET;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xusb)
|
2013-05-22 04:33:18 +08:00
|
|
|
return 0;
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
// TODO: probably needs a per-xusb lock:
|
|
|
|
spin_lock_irqsave(&xusb_lock, flags);
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "Device: %03d/%03d\n", xusb->udev->bus->busnum,
|
2012-01-11 23:22:46 +08:00
|
|
|
xusb->udev->devnum);
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "USB: manufacturer=%s\n", xusb->manufacturer);
|
|
|
|
seq_printf(sfile, "USB: product=%s\n", xusb->product);
|
|
|
|
seq_printf(sfile, "USB: serial=%s\n", xusb->serial);
|
|
|
|
seq_printf(sfile, "Minor: %d\nModel Info: %s\n", xusb->minor,
|
2012-01-11 23:22:46 +08:00
|
|
|
xusb->model_info->desc);
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile,
|
2012-01-11 23:22:46 +08:00
|
|
|
"Endpoints:\n" "\tIn: 0x%02X - Size: %d)\n"
|
|
|
|
"\tOut: 0x%02X - Size: %d)\n",
|
|
|
|
xusb->endpoints[XUSB_RECV].ep_addr,
|
|
|
|
xusb->endpoints[XUSB_RECV].max_size,
|
|
|
|
xusb->endpoints[XUSB_SEND].ep_addr,
|
|
|
|
xusb->endpoints[XUSB_SEND].max_size);
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\npending_writes=%d\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
atomic_read(&xusb->pending_writes));
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "pending_reads=%d\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
atomic_read(&xusb->pending_reads));
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "max_tx_delay=%d\n", xusb->max_tx_delay);
|
2010-08-28 05:59:27 +08:00
|
|
|
xusb->max_tx_delay = 0;
|
|
|
|
#ifdef DEBUG_PCM_TIMING
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile,
|
2012-01-11 23:22:46 +08:00
|
|
|
"\nstamp_last_pcm_read=%lld accumulate_diff=%lld\n",
|
|
|
|
stamp_last_pcm_read, accumulate_diff);
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
|
|
|
memcpy(usb_tx_delay, xusb->usb_tx_delay, sizeof(usb_tx_delay));
|
2015-07-20 17:11:07 +08:00
|
|
|
seq_printf(sfile, "usb_tx_delay[%dus - %dus]: ",
|
|
|
|
USEC_BUCKET * BUCKET_START,
|
|
|
|
USEC_BUCKET * NUM_BUCKETS);
|
2012-01-11 23:20:05 +08:00
|
|
|
for (i = BUCKET_START; i < NUM_BUCKETS; i++) {
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "%6d ", usb_tx_delay[i]);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (i == mark_limit)
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "| ");
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2015-07-20 17:11:07 +08:00
|
|
|
seq_printf(sfile, "\nSluggish events: %d\n",
|
|
|
|
atomic_read(&xusb->usb_sluggish_count));
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\nCOUNTERS:\n");
|
2012-01-11 23:20:05 +08:00
|
|
|
for (i = 0; i < XUSB_COUNTER_MAX; i++) {
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\t%-15s = %d\n", xusb_counters[i].name,
|
2012-01-11 23:22:46 +08:00
|
|
|
xusb->counters[i]);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
#if 0
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "<-- len=%d\n", len);
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
|
|
|
spin_unlock_irqrestore(&xusb_lock, flags);
|
2013-05-22 04:33:18 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2013-05-22 04:33:18 +08:00
|
|
|
static int xusb_read_proc_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
return single_open(file, xusb_read_proc_show, PDE_DATA(inode));
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
|
2013-05-22 04:33:18 +08:00
|
|
|
static const struct file_operations xusb_read_proc_ops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = xusb_read_proc_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = single_release,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("XPP USB Transport Driver");
|
|
|
|
MODULE_AUTHOR("Oron Peled <oron@actcom.co.il>");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
module_init(xpp_usb_init);
|
|
|
|
module_exit(xpp_usb_shutdown);
|