leowrite.c
5.5 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
* F i l e N a m e : l e o w r i t e . c
*
****************************************************************************
* (C) Copyright ALPS Electric Co., Ltd. 1995-1996
****************************************************************************
* Version:
*
* ver date
* ---- --------
* 1.05 '97-01-10 Change sense code name to LEO_SENSE_ILLEGAL_SECTOR_SIZE.
* 1.04 '96-12-24 Delete "SYSTEMWRITE" and add "#ifdef _LONGCMD" for long command.
* 1.03a '96-10-07 Enable system area write if SYSTEMWRITE is defined.
* 1.03 '96-07-20 Move track/retry operation to leoint.c .
* 1.02 '96-04-11 Move retry judgment location .
* Delete TRACK_COMPLETE message .
* 1.01 '96-02-27 Rename file name write.c to leowrite.c .
* 1.00 '95-12-20 Initial Revision.
****************************************************************************
*/
#include <ultra64.h>
#include "leodefine.h"
#include "leodrive.h"
#include "leomacro.h"
#include "leoappli.h"
#ifdef _LONGCMD
#include "leospappli.h"
#endif
/**************************************
* PROTOTYPE DEFINITION
**************************************/
void leoWrite(void);
#ifdef _LONGCMD
static void leoWriteCommon(void);
#endif
/**************************************
* EXTERNALY DEFINITION FUNCTIONS
**************************************/
extern u16 leoLba_to_phys(u32 lba);
/**************************************
* EXTERNALY DEFINITION RAM LOCATIONS
**************************************/
extern OSThread LEOinterruptThread;
extern OSMesgQueue LEOcontrol_que;
extern OSMesg LEOcur_command;
extern u8 LEOdisk_type;
extern struct tgt_param_form LEOtgt_param;
extern u16 LEOrw_flags;
extern u16 LEOBYTE_TBL2[ZONES_PER_DRV];
extern u16 LEORAM_START_LBA[DISK_TYPES];
/**************************************
* MACROS
**************************************/
#define write_command ((LEOCmdWrite *)LEOcur_command)
#ifdef _LONGCMD
#define write_long_command ((LEOCmdWriteLong *)LEOcur_command)
#define ALLTK_WRT
#endif
#ifdef _LONGCMD
/**********************************************************
* Function : leoWriteLong
* ---------------------------------------------------------
* Description : excute write long command
* IN : LEOcur_command
* OUT : *LEOcur_command
**********************************************************/
void leoWriteLong(void)
{
if (write_long_command->header.control & 0x01)
LEOrw_flags = WRITE_MODE+LONG_RW;
else
{
LEOrw_flags = WRITE_MODE+FIXSIZE;
leoLba_to_phys(write_long_command->lba);
if ( (write_long_command->size & 7)
|| (write_long_command->size == 0)
|| (write_long_command->size > LEOtgt_param.sec_bytes) )
{
if (write_long_command->size == (LEOtgt_param.sec_bytes+8))
LEOrw_flags = LONG_RW;
else
{
write_long_command->header.sense = LEO_SENSE_ILLEGAL_SECTOR_SIZE;
write_long_command->header.status = LEO_STATUS_CHECK_CONDITION;
return;
}
}
}
leoWriteCommon();
}
/*===========================================================================
* Function : void leoWrite(void)
* ---------------------------------------------------------------------------
* Function : Execute write commnad
* IN : LEOcur_command, LEOdisk_type
* OUT : *LEOcur_command
* ARG : non
* RET : non
* =========================================================================*/
void leoWrite(void)
{
LEOrw_flags = WRITE_MODE; /* clear C2,sectormode flag */
leoWriteCommon();
}
void leoWriteCommon(void)
#else
void leoWrite(void)
#endif
{
u32 message;
u32 start_lba;
u32 xfer_blk;
u32 write_bytes = 0;
u8 retry_count = 0;
/* set start lba and blocks */
start_lba = write_command->lba;
xfer_blk = write_command->xfer_blks;
#ifdef _LONGCMD
start_lba += SYSTEM_LBAS;
if ((start_lba | xfer_blk) & 0xffff0000)
goto invalid_lba;
#else
if ((start_lba | xfer_blk) & 0xffff0000)
goto invalid_lba;
start_lba += SYSTEM_LBAS;
#endif
/* CHECK LBA AND BLOCKS VALUE */
if ( (start_lba > MAX_P_LBA) || ((start_lba+xfer_blk)>(MAX_P_LBA+1)) )
{
invalid_lba:
/* OUT OF RANGE ERROR */
write_command->header.sense = LEO_SENSE_LBA_OUT_OF_RANGE;
write_command->header.status = LEO_STATUS_CHECK_CONDITION;
return;
}
#ifndef ALLTK_WRT
/* RAM AREA ? */
if (start_lba < LEORAM_START_LBA[LEOdisk_type])
{
write_command->header.sense = LEO_SENSE_WRITE_PROTECT_ERROR;
write_command->header.status = LEO_STATUS_CHECK_CONDITION;
return; /* 範囲外の場合は、エラー終了 */
}
#endif
if (xfer_blk == 0)
{
write_command->header.sense = LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION;
write_command->header.status = LEO_STATUS_GOOD;
return;
}
#ifdef _LONGCMD
LEOrw_flags |= WRITE_MODE;
#else
LEOrw_flags = WRITE_MODE;
#endif
LEOtgt_param.lba = start_lba;
osStartThread(&LEOinterruptThread);
(void)osRecvMesg(CONTROL_QUE, (OSMesg*)&message, OS_MESG_BLOCK);
if (message != (u32)MES_RW_COMPLETE)
{
/* error */
write_command->header.sense = message;
write_command->header.status = LEO_STATUS_CHECK_CONDITION;
return;
}
/* SET DONE STATUS */
write_command->header.sense = LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION;
write_command->header.status = LEO_STATUS_GOOD;
}