/*---------------------------------------------------------------------------*\
 *   
 *   Copyright (C) 2006 AVM GmbH <fritzbox_info@avm.de>
 *
 *   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 version 2 of the License.
 *
 *   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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
\*---------------------------------------------------------------------------*/

#if !defined (_ahcidef_h_)
#define _ahcidef_h_

#include <linux/usb.h>

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
/* <<<< 'urb_t' is obsolete now. To come over thousands of error messages */
/* 	related to this definition, I simply added this: */
typedef struct urb urb_t;

/* These status codes seem to have vanished as well... TODO: still valid??? */
#define USB_ST_NOERROR			0
#define USB_ST_CRC			(-EILSEQ)
#define USB_ST_BITSTUFF			(-EPROTO)
#define USB_ST_NORESPONSE		(-ETIMEDOUT)	/* device not responding/handshaking */
#define USB_ST_DATAOVERRUN		(-EOVERFLOW)
#define USB_ST_DATAUNDERRUN		(-EREMOTEIO)
#define USB_ST_BUFFEROVERRUN		(-ECOMM)
#define USB_ST_BUFFERUNDERRUN		(-ENOSR)
#define USB_ST_INTERNALERROR		(-EPROTO) 	/* unknown error */
#define USB_ST_SHORT_PACKET		(-EREMOTEIO)
#define USB_ST_PARTIAL_ERROR		(-EXDEV)	/* ISO transfer only partially completed */
#define USB_ST_URB_KILLED		(-ENOENT)	/* URB canceled by user */
#define USB_ST_URB_PENDING		(-EINPROGRESS)
#define USB_ST_REMOVED			(-ENODEV) 	/* device not existing or removed */
#define USB_ST_TIMEOUT			(-ETIMEDOUT)	/* communication timed out, also in urb->status */
#define USB_ST_NOTSUPPORTED		(-ENOSYS)			
#define USB_ST_BANDWIDTH_ERROR		(-ENOSPC)	/* too much bandwidth used */
#define USB_ST_URB_INVALID_ERROR	(-EINVAL)	/* invalid value/transfer type */
#define USB_ST_URB_REQUEST_ERROR	(-ENXIO)	/* invalid endpoint  */
#define USB_ST_STALL			(-EPIPE) 	/* pipe stalled, also in urb->status */

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
/* TODO: Macro name longer than replaced string??? */
#define AHCI_INLINE_PREFIX		static inline

/* <<<< #define this one to activate debug output! */
//#define CONFIG_AHCI_DEBUG

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
typedef unsigned int			AHCI_DWORD;	/* 1 DWORD, 4 BYTEs */
typedef unsigned char			AHCI_BYTE;	/* 1 BYTE */
typedef unsigned char			AHCI_FLAG;	/* 1 BIT */

typedef unsigned int			AHCI_DATA_ADR;	/* 1 BYTE ALIGNMENT */
typedef unsigned int			AHCI_DESC_ADR;	/* 16 BYTEs ALIGNMENT */
typedef unsigned int			AHCI_DWORD_POS;	/* 4 BYTEs ALIGNMENT */
typedef unsigned short			AHCI_DESC_POS;	/* 16 BYTEs ALIGNMENT */

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
#define AHCI_isAligned(p)		((((unsigned) p)&3)==0)

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
#define CONFIG_AHCI_NUMPORTS 		2
#define CONFIG_AHCI_RX_MEMSIZE		(4*1024)

#define AHCI_MAX_OUT_BLOCK_SIZE 	(1024)
#define AHCI_MAX_IN_BLOCK_SIZE 		(8*1024)


#define AHCI_MAX(a,b)			((a >= b)?a:b)
#define AHCI_MIN(a,b)			((a <= b)?a:b)

#if defined (info)
/* <<<< 'info' has been #defined in usb.h:1154 */
#undef info
#endif

#define	AHCI_DEBUG_LEVEL		1

#if defined (CONFIG_AHCI_DEBUG)
#define assert(a)			((a)?((void)0):(printk(KERN_INFO "assert %s(%d): FAILED: %s\n",__FILE__,__LINE__,#a),0))
#define info(a)				((a)?((void)0):(printk(KERN_INFO "info %s(%d): FAILED: %s\n",__FILE__,__LINE__,#a),0))
#define PrintInfo(a...)			printk(KERN_INFO a)
#define PrintWarning(a...)		printk(KERN_INFO a)
#define PrintError(a...)		printk(KERN_ERR a)
#define PrintCritical(a...)		printk(KERN_INFO a)
#else
#define assert(a)
#define info(a)
#define PrintInfo(a...)
#define PrintWarning(a...)
#define PrintError(a...)
#define PrintCritical(a...)
#endif

#define PrintInfoRelease(a...)		printk(KERN_INFO a)

#endif
