xref: /freebsd/sys/dev/usb/usb_error.c (revision 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f)
102ac6454SAndrew Thompson /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
402ac6454SAndrew Thompson  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
502ac6454SAndrew Thompson  *
602ac6454SAndrew Thompson  * Redistribution and use in source and binary forms, with or without
702ac6454SAndrew Thompson  * modification, are permitted provided that the following conditions
802ac6454SAndrew Thompson  * are met:
902ac6454SAndrew Thompson  * 1. Redistributions of source code must retain the above copyright
1002ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer.
1102ac6454SAndrew Thompson  * 2. Redistributions in binary form must reproduce the above copyright
1202ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer in the
1302ac6454SAndrew Thompson  *    documentation and/or other materials provided with the distribution.
1402ac6454SAndrew Thompson  *
1502ac6454SAndrew Thompson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1602ac6454SAndrew Thompson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1702ac6454SAndrew Thompson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1802ac6454SAndrew Thompson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1902ac6454SAndrew Thompson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2002ac6454SAndrew Thompson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2102ac6454SAndrew Thompson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2202ac6454SAndrew Thompson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2302ac6454SAndrew Thompson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2402ac6454SAndrew Thompson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2502ac6454SAndrew Thompson  * SUCH DAMAGE.
2602ac6454SAndrew Thompson  */
2702ac6454SAndrew Thompson 
28d2b99310SHans Petter Selasky #ifdef USB_GLOBAL_INCLUDE_FILE
29d2b99310SHans Petter Selasky #include USB_GLOBAL_INCLUDE_FILE
30d2b99310SHans Petter Selasky #else
31ed6d949aSAndrew Thompson #include <sys/stdint.h>
32ed6d949aSAndrew Thompson #include <sys/stddef.h>
33ed6d949aSAndrew Thompson #include <sys/param.h>
34ed6d949aSAndrew Thompson #include <sys/queue.h>
35ed6d949aSAndrew Thompson #include <sys/types.h>
36ed6d949aSAndrew Thompson #include <sys/systm.h>
37ed6d949aSAndrew Thompson #include <sys/kernel.h>
38ed6d949aSAndrew Thompson #include <sys/bus.h>
39ed6d949aSAndrew Thompson #include <sys/module.h>
40ed6d949aSAndrew Thompson #include <sys/lock.h>
41ed6d949aSAndrew Thompson #include <sys/mutex.h>
42ed6d949aSAndrew Thompson #include <sys/condvar.h>
43ed6d949aSAndrew Thompson #include <sys/sysctl.h>
44ed6d949aSAndrew Thompson #include <sys/sx.h>
45ed6d949aSAndrew Thompson #include <sys/unistd.h>
46ed6d949aSAndrew Thompson #include <sys/callout.h>
47ed6d949aSAndrew Thompson #include <sys/malloc.h>
48ed6d949aSAndrew Thompson #include <sys/priv.h>
4902ac6454SAndrew Thompson 
50ed6d949aSAndrew Thompson #include <dev/usb/usb.h>
51ed6d949aSAndrew Thompson #include <dev/usb/usbdi.h>
52d2b99310SHans Petter Selasky #endif			/* USB_GLOBAL_INCLUDE_FILE */
5302ac6454SAndrew Thompson 
5402ac6454SAndrew Thompson static const char* usb_errstr_table[USB_ERR_MAX] = {
5502ac6454SAndrew Thompson 	[USB_ERR_NORMAL_COMPLETION]	= "USB_ERR_NORMAL_COMPLETION",
5602ac6454SAndrew Thompson 	[USB_ERR_PENDING_REQUESTS]	= "USB_ERR_PENDING_REQUESTS",
5702ac6454SAndrew Thompson 	[USB_ERR_NOT_STARTED]		= "USB_ERR_NOT_STARTED",
5802ac6454SAndrew Thompson 	[USB_ERR_INVAL]			= "USB_ERR_INVAL",
5902ac6454SAndrew Thompson 	[USB_ERR_NOMEM]			= "USB_ERR_NOMEM",
6002ac6454SAndrew Thompson 	[USB_ERR_CANCELLED]		= "USB_ERR_CANCELLED",
6102ac6454SAndrew Thompson 	[USB_ERR_BAD_ADDRESS]		= "USB_ERR_BAD_ADDRESS",
6202ac6454SAndrew Thompson 	[USB_ERR_BAD_BUFSIZE]		= "USB_ERR_BAD_BUFSIZE",
6302ac6454SAndrew Thompson 	[USB_ERR_BAD_FLAG]		= "USB_ERR_BAD_FLAG",
6402ac6454SAndrew Thompson 	[USB_ERR_NO_CALLBACK]		= "USB_ERR_NO_CALLBACK",
6502ac6454SAndrew Thompson 	[USB_ERR_IN_USE]		= "USB_ERR_IN_USE",
6602ac6454SAndrew Thompson 	[USB_ERR_NO_ADDR]		= "USB_ERR_NO_ADDR",
6702ac6454SAndrew Thompson 	[USB_ERR_NO_PIPE]		= "USB_ERR_NO_PIPE",
6802ac6454SAndrew Thompson 	[USB_ERR_ZERO_NFRAMES]		= "USB_ERR_ZERO_NFRAMES",
6902ac6454SAndrew Thompson 	[USB_ERR_ZERO_MAXP]		= "USB_ERR_ZERO_MAXP",
7002ac6454SAndrew Thompson 	[USB_ERR_SET_ADDR_FAILED]	= "USB_ERR_SET_ADDR_FAILED",
7102ac6454SAndrew Thompson 	[USB_ERR_NO_POWER]		= "USB_ERR_NO_POWER",
7202ac6454SAndrew Thompson 	[USB_ERR_TOO_DEEP]		= "USB_ERR_TOO_DEEP",
7302ac6454SAndrew Thompson 	[USB_ERR_IOERROR]		= "USB_ERR_IOERROR",
7402ac6454SAndrew Thompson 	[USB_ERR_NOT_CONFIGURED]	= "USB_ERR_NOT_CONFIGURED",
7502ac6454SAndrew Thompson 	[USB_ERR_TIMEOUT]		= "USB_ERR_TIMEOUT",
7602ac6454SAndrew Thompson 	[USB_ERR_SHORT_XFER]		= "USB_ERR_SHORT_XFER",
7702ac6454SAndrew Thompson 	[USB_ERR_STALLED]		= "USB_ERR_STALLED",
7802ac6454SAndrew Thompson 	[USB_ERR_INTERRUPTED]		= "USB_ERR_INTERRUPTED",
7902ac6454SAndrew Thompson 	[USB_ERR_DMA_LOAD_FAILED]	= "USB_ERR_DMA_LOAD_FAILED",
8002ac6454SAndrew Thompson 	[USB_ERR_BAD_CONTEXT]		= "USB_ERR_BAD_CONTEXT",
8102ac6454SAndrew Thompson 	[USB_ERR_NO_ROOT_HUB]		= "USB_ERR_NO_ROOT_HUB",
8202ac6454SAndrew Thompson 	[USB_ERR_NO_INTR_THREAD]	= "USB_ERR_NO_INTR_THREAD",
8302ac6454SAndrew Thompson 	[USB_ERR_NOT_LOCKED]		= "USB_ERR_NOT_LOCKED",
8402ac6454SAndrew Thompson };
8502ac6454SAndrew Thompson 
8602ac6454SAndrew Thompson /*------------------------------------------------------------------------*
87a593f6b8SAndrew Thompson  *	usbd_errstr
8802ac6454SAndrew Thompson  *
8902ac6454SAndrew Thompson  * This function converts an USB error code into a string.
9002ac6454SAndrew Thompson  *------------------------------------------------------------------------*/
9102ac6454SAndrew Thompson const char *
usbd_errstr(usb_error_t err)92a593f6b8SAndrew Thompson usbd_errstr(usb_error_t err)
9302ac6454SAndrew Thompson {
9402ac6454SAndrew Thompson 	return (err < USB_ERR_MAX ? usb_errstr_table[err] : "USB_ERR_UNKNOWN");
9502ac6454SAndrew Thompson }
96