1184610Salfred/* $FreeBSD: releng/10.2/sys/dev/usb/usb_error.c 246122 2013-01-30 15:26:04Z hselasky $ */
2184610Salfred/*-
3184610Salfred * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
4184610Salfred *
5184610Salfred * Redistribution and use in source and binary forms, with or without
6184610Salfred * modification, are permitted provided that the following conditions
7184610Salfred * are met:
8184610Salfred * 1. Redistributions of source code must retain the above copyright
9184610Salfred *    notice, this list of conditions and the following disclaimer.
10184610Salfred * 2. Redistributions in binary form must reproduce the above copyright
11184610Salfred *    notice, this list of conditions and the following disclaimer in the
12184610Salfred *    documentation and/or other materials provided with the distribution.
13184610Salfred *
14184610Salfred * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15184610Salfred * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16184610Salfred * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17184610Salfred * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18184610Salfred * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19184610Salfred * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20184610Salfred * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21184610Salfred * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22184610Salfred * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23184610Salfred * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24184610Salfred * SUCH DAMAGE.
25184610Salfred */
26184610Salfred
27246122Shselasky#ifdef USB_GLOBAL_INCLUDE_FILE
28246122Shselasky#include USB_GLOBAL_INCLUDE_FILE
29246122Shselasky#else
30194677Sthompsa#include <sys/stdint.h>
31194677Sthompsa#include <sys/stddef.h>
32194677Sthompsa#include <sys/param.h>
33194677Sthompsa#include <sys/queue.h>
34194677Sthompsa#include <sys/types.h>
35194677Sthompsa#include <sys/systm.h>
36194677Sthompsa#include <sys/kernel.h>
37194677Sthompsa#include <sys/bus.h>
38194677Sthompsa#include <sys/module.h>
39194677Sthompsa#include <sys/lock.h>
40194677Sthompsa#include <sys/mutex.h>
41194677Sthompsa#include <sys/condvar.h>
42194677Sthompsa#include <sys/sysctl.h>
43194677Sthompsa#include <sys/sx.h>
44194677Sthompsa#include <sys/unistd.h>
45194677Sthompsa#include <sys/callout.h>
46194677Sthompsa#include <sys/malloc.h>
47194677Sthompsa#include <sys/priv.h>
48184610Salfred
49194677Sthompsa#include <dev/usb/usb.h>
50194677Sthompsa#include <dev/usb/usbdi.h>
51246122Shselasky#endif			/* USB_GLOBAL_INCLUDE_FILE */
52184610Salfred
53188048Sthompsastatic const char* usb_errstr_table[USB_ERR_MAX] = {
54188048Sthompsa	[USB_ERR_NORMAL_COMPLETION]	= "USB_ERR_NORMAL_COMPLETION",
55188076Sthompsa	[USB_ERR_PENDING_REQUESTS]	= "USB_ERR_PENDING_REQUESTS",
56188076Sthompsa	[USB_ERR_NOT_STARTED]		= "USB_ERR_NOT_STARTED",
57188076Sthompsa	[USB_ERR_INVAL]			= "USB_ERR_INVAL",
58188076Sthompsa	[USB_ERR_NOMEM]			= "USB_ERR_NOMEM",
59188076Sthompsa	[USB_ERR_CANCELLED]		= "USB_ERR_CANCELLED",
60188048Sthompsa	[USB_ERR_BAD_ADDRESS]		= "USB_ERR_BAD_ADDRESS",
61188048Sthompsa	[USB_ERR_BAD_BUFSIZE]		= "USB_ERR_BAD_BUFSIZE",
62188048Sthompsa	[USB_ERR_BAD_FLAG]		= "USB_ERR_BAD_FLAG",
63188076Sthompsa	[USB_ERR_NO_CALLBACK]		= "USB_ERR_NO_CALLBACK",
64188048Sthompsa	[USB_ERR_IN_USE]		= "USB_ERR_IN_USE",
65188048Sthompsa	[USB_ERR_NO_ADDR]		= "USB_ERR_NO_ADDR",
66188048Sthompsa	[USB_ERR_NO_PIPE]		= "USB_ERR_NO_PIPE",
67188076Sthompsa	[USB_ERR_ZERO_NFRAMES]		= "USB_ERR_ZERO_NFRAMES",
68188076Sthompsa	[USB_ERR_ZERO_MAXP]		= "USB_ERR_ZERO_MAXP",
69188076Sthompsa	[USB_ERR_SET_ADDR_FAILED]	= "USB_ERR_SET_ADDR_FAILED",
70188048Sthompsa	[USB_ERR_NO_POWER]		= "USB_ERR_NO_POWER",
71188076Sthompsa	[USB_ERR_TOO_DEEP]		= "USB_ERR_TOO_DEEP",
72188076Sthompsa	[USB_ERR_IOERROR]		= "USB_ERR_IOERROR",
73188076Sthompsa	[USB_ERR_NOT_CONFIGURED]	= "USB_ERR_NOT_CONFIGURED",
74188076Sthompsa	[USB_ERR_TIMEOUT]		= "USB_ERR_TIMEOUT",
75188048Sthompsa	[USB_ERR_SHORT_XFER]		= "USB_ERR_SHORT_XFER",
76188048Sthompsa	[USB_ERR_STALLED]		= "USB_ERR_STALLED",
77188076Sthompsa	[USB_ERR_INTERRUPTED]		= "USB_ERR_INTERRUPTED",
78188076Sthompsa	[USB_ERR_DMA_LOAD_FAILED]	= "USB_ERR_DMA_LOAD_FAILED",
79188076Sthompsa	[USB_ERR_BAD_CONTEXT]		= "USB_ERR_BAD_CONTEXT",
80188076Sthompsa	[USB_ERR_NO_ROOT_HUB]		= "USB_ERR_NO_ROOT_HUB",
81188076Sthompsa	[USB_ERR_NO_INTR_THREAD]	= "USB_ERR_NO_INTR_THREAD",
82188076Sthompsa	[USB_ERR_NOT_LOCKED]		= "USB_ERR_NOT_LOCKED",
83188048Sthompsa};
84188076Sthompsa
85184610Salfred/*------------------------------------------------------------------------*
86194228Sthompsa *	usbd_errstr
87184610Salfred *
88184610Salfred * This function converts an USB error code into a string.
89184610Salfred *------------------------------------------------------------------------*/
90184610Salfredconst char *
91194228Sthompsausbd_errstr(usb_error_t err)
92184610Salfred{
93188048Sthompsa	return (err < USB_ERR_MAX ? usb_errstr_table[err] : "USB_ERR_UNKNOWN");
94184610Salfred}
95