summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/sys/dktp/hba.h
blob: 4cb24f349edac4f1954f4d19f9cdb65f1c5533db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef	_SYS_DKTP_HBA_H
#define	_SYS_DKTP_HBA_H

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include <sys/scsi/impl/pkt_wrapper.h>

#ifdef	__cplusplus
extern "C" {
#endif

#define	TRUE		1
#define	FALSE		0
#define	UNDEFINED 	-1

#define	SEC_INUSEC	1000000

#define	PRF		prom_printf


#define	HBA_INTPROP(devi, pname, pval, plen) \
	(ddi_prop_op(DDI_DEV_T_NONE, (devi), PROP_LEN_AND_VAL_BUF, \
		DDI_PROP_DONTPASS, (pname), (caddr_t)(pval), (plen)))

#define	HBA_KVTOP(vaddr, shf, msk) \
		((paddr_t)(hat_getkpfnum((caddr_t)(vaddr)) << (shf)) | \
			    ((uintptr_t)(vaddr) & (msk)))

#define	HBA_MAX_ATT_DEVICES 56	    /* Max devices attached to one dev	*/
#define	HBA_MAX_CDB_LEN  CDB_GROUP5 /* Max size of a SCSI CDB		*/

#define	HBA_CFLAG_FREE	0x0001	    /* packet is on free list 		*/
#define	HBA_CFLAG_ERROR	0x0002	    /* packet is retry for error	*/

#define	SDEV2ADDR(devp) (&((devp)->sd_address))
#define	SDEV2TRAN(devp) ((devp)->sd_address.a_hba_tran)
#define	PKT2TRAN(pktp)	((pktp)->pkt_address.a_hba_tran)
#define	ADDR2TRAN(ap)	((ap)->a_hba_tran)

#define	HBA_SETGEOM(hd, sec) (((hd) << 16) | (sec))
#define	HBA_KMFLAG(callback) (((callback) == DDI_DMA_SLEEP) \
	? KM_SLEEP: KM_NOSLEEP)

#ifdef  _KERNEL
#ifdef  __STDC__
extern opaque_t scsi_create_cbthread(ddi_iblock_cookie_t lkarg, int sleep);
extern void	scsi_destroy_cbthread(opaque_t cbhdl);
extern void 	scsi_run_cbthread(opaque_t cbhdl, struct scsi_cmd *cmd);
extern void	scsi_iopb_fast_free(caddr_t *base, caddr_t p);
extern int 	scsi_iopb_fast_zalloc(caddr_t *listp, dev_info_t *dip,
			ddi_dma_lim_t *limp, uint_t len, caddr_t *iopbp);
extern int 	scsi_iopb_fast_alloc(caddr_t *listp, dev_info_t *dip,
			ddi_dma_lim_t *limp, uint_t len, caddr_t *iopbp);
extern void 	scsi_htos_3byte(uchar_t *, ulong_t);
extern void 	scsi_htos_long(uchar_t *, ulong_t);
extern void 	scsi_htos_short(uchar_t *, ushort_t);
extern ulong_t 	scsi_stoh_3byte(uchar_t *);
extern ulong_t 	scsi_stoh_long(ulong_t);
extern ushort_t	scsi_stoh_short(ushort_t);
extern struct scsi_pkt *scsi_impl_dmaget(struct scsi_pkt *pkt,
	opaque_t dmatoken, int (*callback)(), caddr_t callback_arg,
	ddi_dma_lim_t *dmalimp);

#else   /* __STDC__ */

extern opaque_t scsi_create_cbthread();
extern void	scsi_destroy_cbthread();
extern void 	scsi_run_cbthread();
extern void 	scsi_iopb_fast_free();
extern int 	scsi_iopb_fast_zalloc();
extern int 	scsi_iopb_fast_alloc();
extern void 	scsi_htos_3byte();
extern void 	scsi_htos_long();
extern void 	scsi_htos_short();
extern ulong_t 	scsi_stoh_3byte();
extern ulong_t 	scsi_stoh_long();
extern ushort_t	scsi_stoh_short();
extern struct scsi_pkt *scsi_impl_dmaget();

#endif  /* __STDC__ */

#define	SCSI_CB_DESTROY		0x0001

struct	scsi_cbthread {
	int	cb_flag;		/* misc flags			*/
	kmutex_t cb_mutex;		/* mutex on local struct 	*/
	kcondvar_t cb_cv;		/* condition variable		*/
	kthread_t *cb_thread;
	struct	scsi_cmd *cb_head;	/* queue head pointer		*/
	struct	scsi_cmd *cb_tail;	/* queue tail pointer		*/
};


extern uint8_t	inb(int port);
extern uint16_t	inw(int port);
extern uint32_t	inl(int port);
extern void	repinsb(int port, uint8_t *addr, int count);
extern void	repinsw(int port, uint16_t *addr, int count);
extern void	repinsd(int port, uint32_t *addr, int count);

extern void	outb(int port, uint8_t value);
extern void	outw(int port, uint16_t value);
extern void	outl(int port, uint32_t value);
extern void	repoutsb(int port, uint8_t *addr, int count);
extern void	repoutsw(int port, uint16_t *addr, int count);
extern void	repoutsd(int port, uint32_t *addr, int count);

#endif	/* _KERNEL */

#ifdef	__cplusplus
}
#endif

#endif	/* _SYS_DKTP_HBA_H */