summaryrefslogtreecommitdiffstats
path: root/sys/i386/scsi/btreg.h
blob: 7563bb03af70aea54438797b85a28f0f3727afd2 (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
141
142
143
144
145
146
147
148
149
/*
 * Written by Julian Elischer (julian@tfs.com)
 * for TRW Financial Systems for use under the MACH(2.5) operating system.
 *
 * TRW Financial Systems, in accordance with their agreement with Carnegie
 * Mellon University, makes this software available to CMU to distribute
 * or use in any manner that they see fit as long as this message is kept with
 * the software. For this reason TFS also grants any other persons or
 * organizations permission to use or modify this software.
 *
 * TFS supplies this software to be publicly redistributed
 * on the understanding that TFS is not responsible for the correct
 * functioning of this software in any circumstances.
 *
 *      $Id$
 */

#ifndef _BTREG_H_
#define _BTREG_H_

#include "bt.h"

/*
 * Mail box defs  etc.
 * these could be bigger but we need the bt_data to fit on a single page..
 */

#define BT_MBX_SIZE     32      /* mail box size  (MAX 255 MBxs) */
                                /* don't need that many really */
#define BT_CCB_MAX      32      /* store up to 32CCBs at any one time */
                                /* in bt742a H/W ( Not MAX ? ) */
#define CCB_HASH_SIZE   32      /* when we have a physical addr. for */
                                /* a ccb and need to find the ccb in */
                                /* space, look it up in the hash table */
#define BT_NSEG		33	/* 
				 * Number of SG segments per command
				 * Max of 2048???
				 */

typedef unsigned long int physaddr;

struct bt_scat_gath {
        unsigned long seg_len;
        physaddr seg_addr;
};

typedef struct bt_mbx_out {     
	physaddr ccb_addr;
	unsigned char dummy[3]; 
	unsigned char cmd;
} BT_MBO;

typedef struct bt_mbx_in {      
	physaddr ccb_addr;    
	unsigned char btstat;   
	unsigned char sdstat;   
	unsigned char dummy;    
	unsigned char stat;     
} BT_MBI;

struct bt_mbx {
	BT_MBO  mbo[BT_MBX_SIZE];
#define		BT_MBO_FREE	0x0	/* MBO intry is free */
#define		BT_MBO_START	0x1	/* MBO activate entry */
#define		BT_MBO_ABORT	0x2	/* MBO abort entry */
	BT_MBI  mbi[BT_MBX_SIZE]; 
#define		BT_MBI_FREE	0x0	/* MBI entry is free */ 
#define		BT_MBI_OK	0x1	/* completed without error */
#define		BT_MBI_ABORT	0x2	/* aborted ccb */
#define		BT_MBI_UNKNOWN	0x3	/* Tried to abort invalid CCB */
#define		BT_MBI_ERROR	0x4	/* Completed with error */
	BT_MBO *tmbo;			/* Target Mail Box out */
	BT_MBI *tmbi;			/* Target Mail Box in */
};


struct bt_ccb {
	unsigned char opcode;
#define		BT_INITIATOR_CCB	0x00	/* SCSI Initiator CCB */
#define		BT_TARGET_CCB		0x01	/* SCSI Target CCB */
#define		BT_INIT_SCAT_GATH_CCB	0x02	/* SCSI Initiator w/sg */
#define		BT_RESET_CCB		0x81	/* SCSI Bus reset */
	unsigned char:3, data_in:1, data_out:1,:3;
	unsigned char scsi_cmd_length;
	unsigned char req_sense_length;
	unsigned long data_length;
	physaddr data_addr;
	unsigned char dummy[2];
	unsigned char host_stat;
#define		BT_OK		0x00	/* cmd ok */
#define		BT_LINK_OK	0x0a	/* Link cmd ok */
#define		BT_LINK_IT	0x0b	/* Link cmd ok + int */
#define		BT_SEL_TIMEOUT	0x11	/* Selection time out */
#define		BT_OVER_UNDER	0x12	/* Data over/under run */
#define		BT_BUS_FREE	0x13	/* Bus dropped at unexpected time */
#define		BT_INV_BUS	0x14	/* Invalid bus phase/sequence */
#define		BT_BAD_MBO	0x15	/* Incorrect MBO cmd */
#define		BT_BAD_CCB	0x16	/* Incorrect ccb opcode */ 
#define		BT_BAD_LINK	0x17	/* Not same values of LUN for links */
#define		BT_INV_TARGET	0x18	/* Invalid target direction */
#define		BT_CCB_DUP	0x19	/* Duplicate CCB received */
#define		BT_INV_CCB	0x1a	/* Invalid CCB or segment list */
#define		BT_ABORTED	42	/* pseudo value from driver */
	unsigned char target_stat;
	unsigned char target;
	unsigned char lun; 
	unsigned char scsi_cmd[12];	/* 12 bytes (bytes only) */
	unsigned char dummy2[1];
	unsigned char link_id;
	physaddr link_addr;
	physaddr sense_ptr;
	struct	scsi_sense_data scsi_sense;
	struct	bt_scat_gath scat_gath[BT_NSEG];
	struct	bt_ccb *next;
	struct	scsi_xfer *xfer;	/* the scsi_xfer for this cmd */
	struct	bt_mbx_out *mbx;	/* pointer to mail box */
	int	flags;
#define		CCB_FREE	0
#define		CCB_ACTIVE	1
#define		CCB_ABORTED	2
	struct bt_ccb *nexthash;	/* if two hash the same */
	physaddr hashkey;		/*physaddr of this ccb */
};

struct bt_data {
	int	bt_base;			/* base port for each board */
	struct	bt_mbx bt_mbx;			/* all our mailboxes */
	struct	bt_ccb *bt_ccb_free;		/* list of free CCBs */
	struct	bt_ccb *ccbhash[CCB_HASH_SIZE];	/* phys to kv hash */
	int	bt_int;				/* int. read off board */
	int	bt_dma;				/* DMA channel read of board */
	int	bt_scsi_dev;			/* adapters scsi id */
	int	numccbs;			/* how many we have malloc'd */
	int	bt_bounce;			/* should we bounce? */
	int	unit;				/* The zero in bt0 */
	struct	scsi_link sc_link;		/* prototype for devs */
};

extern struct bt_data *btdata[NBT];

extern u_long bt_unit;

struct bt_data *bt_alloc __P((int unit, u_long iobase));
void bt_free __P((struct bt_data *bt));
void bt_intr __P((void *arg));
int bt_init __P((struct bt_data *bt)); 
int bt_attach __P((struct bt_data *bt));

#endif	/* _BT_H_ */
OpenPOWER on IntegriCloud