usb_error.c revision 302408
117680Spst/* $FreeBSD: stable/11/sys/dev/usb/usb_error.c 246122 2013-01-30 15:26:04Z hselasky $ */
217680Spst/*-
317680Spst * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
417680Spst *
517680Spst * Redistribution and use in source and binary forms, with or without
617680Spst * modification, are permitted provided that the following conditions
717680Spst * are met:
817680Spst * 1. Redistributions of source code must retain the above copyright
917680Spst *    notice, this list of conditions and the following disclaimer.
1017680Spst * 2. Redistributions in binary form must reproduce the above copyright
1117680Spst *    notice, this list of conditions and the following disclaimer in the
1217680Spst *    documentation and/or other materials provided with the distribution.
1317680Spst *
1417680Spst * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1517680Spst * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1617680Spst * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1717680Spst * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1817680Spst * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1917680Spst * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2017680Spst * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2117680Spst * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2217680Spst * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2317680Spst * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2417680Spst * SUCH DAMAGE.
2517680Spst */
2617680Spst
2717680Spst#ifdef USB_GLOBAL_INCLUDE_FILE
2817680Spst#include USB_GLOBAL_INCLUDE_FILE
2917680Spst#else
3017680Spst#include <sys/stdint.h>
3117680Spst#include <sys/stddef.h>
3217680Spst#include <sys/param.h>
3317680Spst#include <sys/queue.h>
3417680Spst#include <sys/types.h>
3517680Spst#include <sys/systm.h>
3617680Spst#include <sys/kernel.h>
3717680Spst#include <sys/bus.h>
3817680Spst#include <sys/module.h>
3917680Spst#include <sys/lock.h>
4017680Spst#include <sys/mutex.h>
4117680Spst#include <sys/condvar.h>
4217680Spst#include <sys/sysctl.h>
4317680Spst#include <sys/sx.h>
4417680Spst#include <sys/unistd.h>
4517680Spst#include <sys/callout.h>
4617680Spst#include <sys/malloc.h>
4717680Spst#include <sys/priv.h>
4817680Spst
4917680Spst#include <dev/usb/usb.h>
5017680Spst#include <dev/usb/usbdi.h>
5117680Spst#endif			/* USB_GLOBAL_INCLUDE_FILE */
5217680Spst
5317680Spststatic const char* usb_errstr_table[USB_ERR_MAX] = {
5417680Spst	[USB_ERR_NORMAL_COMPLETION]	= "USB_ERR_NORMAL_COMPLETION",
5517680Spst	[USB_ERR_PENDING_REQUESTS]	= "USB_ERR_PENDING_REQUESTS",
5617680Spst	[USB_ERR_NOT_STARTED]		= "USB_ERR_NOT_STARTED",
5717680Spst	[USB_ERR_INVAL]			= "USB_ERR_INVAL",
5817680Spst	[USB_ERR_NOMEM]			= "USB_ERR_NOMEM",
5917680Spst	[USB_ERR_CANCELLED]		= "USB_ERR_CANCELLED",
6017680Spst	[USB_ERR_BAD_ADDRESS]		= "USB_ERR_BAD_ADDRESS",
6117680Spst	[USB_ERR_BAD_BUFSIZE]		= "USB_ERR_BAD_BUFSIZE",
6217680Spst	[USB_ERR_BAD_FLAG]		= "USB_ERR_BAD_FLAG",
6317680Spst	[USB_ERR_NO_CALLBACK]		= "USB_ERR_NO_CALLBACK",
6417680Spst	[USB_ERR_IN_USE]		= "USB_ERR_IN_USE",
6517680Spst	[USB_ERR_NO_ADDR]		= "USB_ERR_NO_ADDR",
6617680Spst	[USB_ERR_NO_PIPE]		= "USB_ERR_NO_PIPE",
6717680Spst	[USB_ERR_ZERO_NFRAMES]		= "USB_ERR_ZERO_NFRAMES",
6817680Spst	[USB_ERR_ZERO_MAXP]		= "USB_ERR_ZERO_MAXP",
6917680Spst	[USB_ERR_SET_ADDR_FAILED]	= "USB_ERR_SET_ADDR_FAILED",
7017680Spst	[USB_ERR_NO_POWER]		= "USB_ERR_NO_POWER",
7117680Spst	[USB_ERR_TOO_DEEP]		= "USB_ERR_TOO_DEEP",
7217680Spst	[USB_ERR_IOERROR]		= "USB_ERR_IOERROR",
7317680Spst	[USB_ERR_NOT_CONFIGURED]	= "USB_ERR_NOT_CONFIGURED",
7417680Spst	[USB_ERR_TIMEOUT]		= "USB_ERR_TIMEOUT",
7517680Spst	[USB_ERR_SHORT_XFER]		= "USB_ERR_SHORT_XFER",
7617680Spst	[USB_ERR_STALLED]		= "USB_ERR_STALLED",
7717680Spst	[USB_ERR_INTERRUPTED]		= "USB_ERR_INTERRUPTED",
7817680Spst	[USB_ERR_DMA_LOAD_FAILED]	= "USB_ERR_DMA_LOAD_FAILED",
7917680Spst	[USB_ERR_BAD_CONTEXT]		= "USB_ERR_BAD_CONTEXT",
8017680Spst	[USB_ERR_NO_ROOT_HUB]		= "USB_ERR_NO_ROOT_HUB",
8117680Spst	[USB_ERR_NO_INTR_THREAD]	= "USB_ERR_NO_INTR_THREAD",
8217680Spst	[USB_ERR_NOT_LOCKED]		= "USB_ERR_NOT_LOCKED",
8317680Spst};
8417680Spst
8517680Spst/*------------------------------------------------------------------------*
8617680Spst *	usbd_errstr
8717680Spst *
8817680Spst * This function converts an USB error code into a string.
8917680Spst *------------------------------------------------------------------------*/
9017680Spstconst char *
9117680Spstusbd_errstr(usb_error_t err)
9217680Spst{
9317680Spst	return (err < USB_ERR_MAX ? usb_errstr_table[err] : "USB_ERR_UNKNOWN");
9417680Spst}
9517680Spst