1 /* $MirOS: src/sys/dev/ic/wdcevent.h,v 1.2 2005/03/06 21:27:41 tg Exp $ */
2 /* $OpenBSD: wdcevent.h,v 1.4 2003/09/28 21:01:43 grange Exp $ */
3 
4 /*
5  * Copyright (c) 2001 Constantine Sapuntzakis
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Neither the name of the author nor the names of any co-contributors
13  *    may be used to endorse or promote products derived from this software
14  *    without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26  * THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  */
29 
30 #ifndef WDCEVENT_H
31 #define WDCEVENT_H
32 
33 enum wdcevent_type {
34 	WDCEVENT_STATUS = 1,
35 	WDCEVENT_ERROR,
36 	WDCEVENT_ATAPI_CMD,
37 	WDCEVENT_ATAPI_DONE,
38 	WDCEVENT_ATA_SHORT,
39 	WDCEVENT_ATA_LONG,
40 	WDCEVENT_SET_DRIVE1,
41 	WDCEVENT_SET_DRIVE0,
42 	WDCEVENT_REG,
43 	WDCEVENT_ATA_EXT
44 };
45 
46 #ifdef _KERNEL
47 
48 void wdc_log(struct channel_softc *chp, enum wdcevent_type type,
49     unsigned int size, char  val[]);
50 
WDC_LOG_STATUS(struct channel_softc * chp,u_int8_t status)51 static __inline void WDC_LOG_STATUS(struct channel_softc *chp,
52     u_int8_t status) {
53 	if (chp->ch_prev_log_status == status)
54 		return;
55 
56 	chp->ch_prev_log_status = status;
57 	wdc_log(chp, WDCEVENT_STATUS, 1, &status);
58 }
59 
WDC_LOG_ERROR(struct channel_softc * chp,u_int8_t error)60 static __inline void WDC_LOG_ERROR(struct channel_softc *chp,
61     u_int8_t error) {
62 	wdc_log(chp, WDCEVENT_ERROR, 1, &error);
63 }
64 
WDC_LOG_ATAPI_CMD(struct channel_softc * chp,int drive,int flags,int len,void * cmd)65 static __inline void WDC_LOG_ATAPI_CMD(struct channel_softc *chp, int drive,
66     int flags, int len, void *cmd) {
67 	u_int8_t record[20];
68 
69 	record[0] = (flags >> 8);
70 	record[1] = flags & 0xff;
71 	memmove(&record[2], cmd, len);
72 
73 	wdc_log(chp, WDCEVENT_ATAPI_CMD, len + 2, record);
74 }
75 
WDC_LOG_ATAPI_DONE(struct channel_softc * chp,int drive,int flags,u_int8_t error)76 static __inline void WDC_LOG_ATAPI_DONE(struct channel_softc *chp, int drive,
77     int flags, u_int8_t error) {
78 	char record[3] = {flags >> 8, flags & 0xff, error};
79 	wdc_log(chp, WDCEVENT_ATAPI_DONE, 3, record);
80 }
81 
WDC_LOG_ATA_CMDSHORT(struct channel_softc * chp,u_int8_t cmd)82 static __inline void WDC_LOG_ATA_CMDSHORT(struct channel_softc *chp, u_int8_t cmd) {
83 	wdc_log(chp, WDCEVENT_ATA_SHORT, 1, &cmd);
84 }
85 
WDC_LOG_ATA_CMDLONG(struct channel_softc * chp,u_int8_t head,u_int8_t precomp,u_int8_t cylinhi,u_int8_t cylinlo,u_int8_t sector,u_int8_t count,u_int8_t command)86 static __inline void WDC_LOG_ATA_CMDLONG(struct channel_softc *chp,
87     u_int8_t head, u_int8_t precomp, u_int8_t cylinhi, u_int8_t cylinlo,
88     u_int8_t sector, u_int8_t count, u_int8_t command) {
89 	char record[8] = { head, precomp, cylinhi, cylinlo,
90 			   sector, count, command };
91 
92 	wdc_log(chp, WDCEVENT_ATA_LONG, 7, record);
93 }
94 
WDC_LOG_SET_DRIVE(struct channel_softc * chp,u_int8_t drive)95 static __inline void WDC_LOG_SET_DRIVE(struct channel_softc *chp,
96     u_int8_t drive) {
97 	wdc_log(chp, drive ? WDCEVENT_SET_DRIVE1 : WDCEVENT_SET_DRIVE0,
98 	    0, NULL);
99 }
100 
WDC_LOG_REG(struct channel_softc * chp,enum wdc_regs reg,u_int16_t val)101 static __inline void WDC_LOG_REG(struct channel_softc *chp,
102     enum wdc_regs reg, u_int16_t val) {
103 	char record[3];
104 
105 	record[0] = reg;
106 	record[1] = (val >> 8);
107 	record[2] = val & 0xff;
108 
109 	wdc_log(chp, WDCEVENT_REG, 3, record);
110 }
111 
WDC_LOG_ATA_CMDEXT(struct channel_softc * chp,u_int8_t lba_hi1,u_int8_t lba_hi2,u_int8_t lba_mi1,u_int8_t lba_mi2,u_int8_t lba_lo1,u_int8_t lba_lo2,u_int8_t count1,u_int8_t count2,u_int8_t command)112 static __inline void WDC_LOG_ATA_CMDEXT(struct channel_softc *chp,
113     u_int8_t lba_hi1, u_int8_t lba_hi2, u_int8_t lba_mi1, u_int8_t lba_mi2,
114     u_int8_t lba_lo1, u_int8_t lba_lo2, u_int8_t count1, u_int8_t count2,
115     u_int8_t command) {
116 	char record[9] = { lba_hi1, lba_hi2, lba_mi1, lba_mi2,
117 			   lba_lo1, lba_lo2, count1, count2, command };
118 
119 	wdc_log(chp, WDCEVENT_ATA_EXT, 9, record);
120 }
121 
122 #endif	/* _KERNEL */
123 
124 #endif	/* WDCEVENT_H */
125