iplleomecha.c
16 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
/*
* F i l e N a m e : i p l l e o m e c h a . c
*
****************************************************************************
* (C) Copyright ALPS Electric Co., Ltd. 1995-1996
****************************************************************************
* Version:
*
* ver Date
* ---- --------
* 1.06 '97-06-23 Add check of return value of osRecvMesg in leoiplRecv_event_mesg().
* Inhibit retry for DIAG-error in leoiplChk_err_retry().
* 1.05 '96-10-30 Add leoiplWait_mecha_cmd_done(), leoiplRecv_event_mesg() .
* Move leoiplChk_err_retry() functoin from leoint.c .
* Change leoiplChk_err_retry() function.
* SC_DEVICE_COMMUNICATION_FAIL, SC_COMMAND_PHASE_ERROR is non retry.
* 1.04 '96-07-25 Delete iplleoClear_mecha_int() macro .
* 1.03 '96-02-27 Rename iplmecha.c to iplleomecha.c .
* Debug "if" to call clr_sys_read() in leoAnalize_asic_status().
* 1.02 '96-02-13 Clear EVENT_QUE before command write to drive.
* 1.01 '96-02-03 Debug chk_done_status(),analize_asic_status()
* 1.00 '95-12-20 Initial revision .
****************************************************************************
*/
#define _ASIC_IF
#include "os.h"
#include <ultra64.h>
#include "leodefine.h"
#include "leodrive.h"
#include "iplleomacro.h"
#include "leoappli.h"
/*************************************/
/* PROTOTYPE */
/*************************************/
u8 leoiplAnalize_asic_status(u32 cur_status);
u8 leoiplChk_asic_ready(u32 asic_cmd);
u8 leoiplChk_done_status(u32 asic_cmd);
u8 leoiplSend_asic_cmd_i(u32 asic_cmd, u32 asic_data);
u8 leoiplWait_mecha_cmd_done(u32 asic_cmd );
u8 leoiplSend_asic_cmd_w(u32 asic_cmd, u32 asic_data);
u8 leoiplSeek_read_i(void);
u8 leoiplDetect_index_w(void);
u32 leoiplChk_err_retry(u32 sense);
u8 leoiplRecv_event_mesg(s32 control);
void leoiplDrive_reset(void);
/*************************************/
/* EXTERNAL FUNCTIONS */
/*************************************/
extern OSMesgQueue LeoIPLevent_que;
extern OSMesg LeoIPLcur_command;
extern u8 LeoIPLdrive_flag;
extern struct tgt_param_form LeoIPLtgt_param;
extern OSPiHandle *LeoIPLPiInfo;
/* ==========================================================================
* Function : leoiplAnalize_asic_status
* --------------------------------------------------------------------------
* Description : Analize drive status register to check mecha condition.
* --------------------------------------------------------------------------
* IN : NON
* OUT : NON
* ARG : cur_status .. drive status to check
* RET : 0 - GOOD
* : NOT 0 - ERROR SENSE CODE
* ==========================================================================
*/
u8 leoiplAnalize_asic_status(u32 cur_status)
{
if ((cur_status^=LEO_STAT_DISK) & (LEO_STAT_DISK + LEO_STAT_BUSY + LEO_STAT_RESET + LEO_STAT_DISK_CHANGE +
LEO_STAT_MECHA_ERROR + LEO_STAT_NC_CHK ) )
{
/* HardWare err, reset or disk-chg.Clear system info flag to re-read */
if (cur_status & (LEO_STAT_DISK + LEO_STAT_BUSY + LEO_STAT_RESET + LEO_STAT_DISK_CHANGE + LEO_STAT_NC_CHK ) )
leoiplClr_sys_read();
/*--------------------------*/
/* check HardWare err first */
/*--------------------------*/
/* Communication error ? */
if (cur_status & LEO_STAT_NC_CHK)
return(LEO_SENSE_DEVICE_COMMUNICATION_FAILURE);
/* Busy ? */
if ((cur_status & (LEO_STAT_BUSY+LEO_STAT_RESET)) == LEO_STAT_BUSY)
return(LEO_SENSE_COMMAND_PHASE_ERROR);
/*---------------------------------------------*/
/* CHECK RESET / DISK-CHANGE / NO-DISK */
/*---------------------------------------------*/
/* Reset ? */
if (cur_status & LEO_STAT_RESET)
return (LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED);
/* No disk ? */
if (cur_status & LEO_STAT_DISK)
return (LEO_SENSE_MEDIUM_NOT_PRESENT);
/* Disk Changed ? */
if (cur_status & LEO_STAT_DISK_CHANGE)
return (LEO_SENSE_MEDIUM_MAY_HAVE_CHANGED);
/*---------------------------------------------*/
/* CHECK other err */
/*---------------------------------------------*/
/* Other mecha error ? */
if (cur_status & LEO_STAT_MECHA_ERROR)
return (LEO_SENSE_NO_SEEK_COMPLETE);
}
/* OK */
return LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION;
}
/* ==========================================================================
* Function : leoiplChk_asic_ready
* --------------------------------------------------------------------------
* Description : Pre-Check drive status to issue command to drive.
* --------------------------------------------------------------------------
* IN : non
* OUT : non
* ARG : asic_cmd .. command to drive
* RET : 0 - good.
* : not 0 - no good . error sense code .
* ==========================================================================
*/
u8 leoiplChk_asic_ready(u32 asic_cmd)
{
u32 cur_status;
u32 sense_code;
leoiplGet_leo_status(&cur_status);
sense_code = leoiplAnalize_asic_status(cur_status);
switch (sense_code)
{
case LEO_SENSE_MEDIUM_MAY_HAVE_CHANGED:
if (asic_cmd == ASIC_CLR_CHGFLG)
return LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION;
case LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED:
if (!(cur_status & LEO_STAT_BUSY))
{
/* Clear reset/disk-change flag in drive */
if (asic_cmd == ASIC_CLR_RSTFLG)
return LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION;
if (leoiplRecv_event_mesg(OS_MESG_NOBLOCK))
return (LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED);
leoiplAd16WriteIo(ASIC_CMD, ASIC_CLR_RSTFLG);
if (leoiplRecv_event_mesg(OS_MESG_BLOCK))
return (LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED);
}
break;
case LEO_SENSE_MEDIUM_NOT_PRESENT:
/* Disk needed ? */
if (asic_cmd & ASIC_NEED_DISK_IN)
break;
case LEO_SENSE_NO_SEEK_COMPLETE:
return LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION;
default:
;
}
return sense_code;
}
/* ==========================================================================
* Function : leoiplChk_done_status
* --------------------------------------------------------------------------
* Description : Post Check of mecha command to drive.
* --------------------------------------------------------------------------
* IN : non
* OUT : non
* ARG : asic_cmd .. command to drive
* RET : 0 - good.
* : not 0 - error sense code .
* ==========================================================================
*/
u8 leoiplChk_done_status(u32 asic_cmd)
{
u32 cur_status,code;
leoiplGet_leo_status(&cur_status);
code = leoiplAnalize_asic_status(cur_status);
switch (code)
{
case LEO_SENSE_MEDIUM_MAY_HAVE_CHANGED:
case LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED:
if (!(cur_status & LEO_STAT_BUSY))
{
/* Clear reset/disk-change flag */
if (leoiplRecv_event_mesg(OS_MESG_NOBLOCK))
return (LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED);
leoiplAd16WriteIo(ASIC_CMD, ASIC_CLR_RSTFLG);
if (leoiplRecv_event_mesg(OS_MESG_BLOCK))
return (LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED);
}
break;
case LEO_SENSE_MEDIUM_NOT_PRESENT:
/* error if command needs disk */
if (asic_cmd & ASIC_NEED_DISK_IN)
break;
return LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION;
case LEO_SENSE_NO_SEEK_COMPLETE:
/* request more information */
leoiplAd16WriteIo(ASIC_DATA, 0x00);
if (leoiplRecv_event_mesg(OS_MESG_NOBLOCK))
return (LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED);
leoiplAd16WriteIo(ASIC_CMD , ASIC_REQ_STATUS);
/* wait done */
if (leoiplRecv_event_mesg(OS_MESG_BLOCK))
return (LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED);
leoiplGet_leo_asic_data(&cur_status);
if (code = leoiplChk_asic_ready(ASIC_REQ_STATUS))
return code;
/* setup error sense code */
if (cur_status & MC_ERR_DIAGNOSTIC) /* drive diag err */
return(LEO_SENSE_DIAGNOSTIC_FAILURE);
if (cur_status & MC_ERR_SERVO_DATA) /* servo read err */
return(LEO_SENSE_NO_REFERENCE_POSITION_FOUND);
if (cur_status & MC_ERR_INDEX) /* Index detect error or timing NG */
return(LEO_SENSE_DRIVE_NOT_READY);
if (cur_status & MC_ERR_SETRING_TIMEOUT) /* seek timeout */
return(LEO_SENSE_NO_SEEK_COMPLETE);
if (cur_status & MC_INVALID_PARAM) /* invalid parameter(data) */
return(LEO_SENSE_INCOMPATIBLE_MEDIUM_INSTALLED); /* (invalid disk-type or seek out of range) */
return(LEO_SENSE_DEVICE_COMMUNICATION_FAILURE); /* unknown command */
/*case LEO_SENSE_DEVICE_COMMUNICATION_FAILURE:*/
/*case LEO_SENSE_COMMAND_PHASE_ERROR: */
default:
;
}
return code;
}
/* ==========================================================================
* Function : leoiplSend_asic_cmd_i
* --------------------------------------------------------------------------
* Description : Issue commnad to drive. not wait done.
* --------------------------------------------------------------------------
* IN : NON
* OUT : ((LEOCmdHeader *)LeoIPLcur_command)->sense is set at error.
* ARG : asic_cmd : command, asic_data : data to drive
* RET : 0 - command issue normally
* : not 0 - error sense code . command do not issue.
* ==========================================================================
*/
u8 leoiplSend_asic_cmd_i(u32 asic_cmd, u32 asic_data)
{
u8 status;
if (status = leoiplChk_asic_ready(asic_cmd))
return(((LEOCmdHeader *)LeoIPLcur_command)->sense = status);
/* ASICのレジスタに指定のデータとコマンドを発行する */
leoiplAd16WriteIo(ASIC_DATA, asic_data);
if (leoiplRecv_event_mesg(OS_MESG_NOBLOCK))
return(((LEOCmdHeader *)LeoIPLcur_command)->sense = LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED);
leoiplAd16WriteIo(ASIC_CMD , asic_cmd );
return(FUNC_OK);
}
/* ==========================================================================
* Function : leoiplWait_mecha_cmd_done
* --------------------------------------------------------------------------
* Description : Wait drive command done and check error.
* --------------------------------------------------------------------------
* IN : non
* OUT : ((LEOCmdHeader *)LeoIPLcur_command)->sense is set at error
* ARG : command code that drive executing.
* RET : 00 - good
* : 00以外 - error sense code.
* ==========================================================================
*/
u8 leoiplWait_mecha_cmd_done(u32 asic_cmd )
{
u32 status;
/* wait done */
if (leoiplRecv_event_mesg(OS_MESG_BLOCK))
return(LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED);
/* check done status */
if (status = leoiplChk_done_status(asic_cmd))
return(status);
return(FUNC_OK);
}
/* ==========================================================================
* Function : leoiplSend_asic_cmd_w
* --------------------------------------------------------------------------
* Description : Issue command to drive,waiting done and check error.
* --------------------------------------------------------------------------
* IN : NON
* OUT : ((LEOCmdHeader *)LeoIPLcur_command)->sense is set at error
* ARG : command and data to issue to drive
* RET : 00 - good
* : 00以外 - error sense code
* ==========================================================================
*/
u8 leoiplSend_asic_cmd_w(u32 asic_cmd, u32 asic_data)
{
u32 status;
if (status = leoiplSend_asic_cmd_i(asic_cmd, asic_data))
return (status);
return (status = leoiplWait_mecha_cmd_done(asic_cmd) );
}
/* ==========================================================================
* Function : leoiplSeek_read_i
* --------------------------------------------------------------------------
* Description : Issue seek command (not wait done)
* --------------------------------------------------------------------------
* IN : LEOcur_command, LeoIPLtgt_param.XXX
* OUT : non
* ARG : non
* RET : 0 - good
* : not 0 - error sense code
* ==========================================================================
*/
u8 leoiplSeek_read_i(void)
{
return leoiplSend_asic_cmd_i(ASIC_RD_SEEK, (u32)LeoIPLtgt_param.cylinder << 16);
}
/* ==========================================================================
* Function : leoiplDetect_index_w
* --------------------------------------------------------------------------
* Description : Issue Index lock command , wait done and check error
* --------------------------------------------------------------------------
* IN : non
* OUT : non
* ARG : non
* RET : 0 - good
* : not 0 - error sense code
* ==========================================================================
*/
u8 leoiplDetect_index_w(void)
{
return leoiplSend_asic_cmd_w(ASIC_INDEX_LOCK_RETRY, 0);
}
/**********************************************************
* Function : leoiplChk_err_retry
* ---------------------------------------------------------
* Description : Check retry enable or not .
* IN : non
* OUT : non
* ARG : sense ....sense code of error
* RET : 0 ...... ENABLE RETRY.
* NOT 0... DISABLE RETRY.COMMAND SHOULD BE STOP.
**********************************************************/
u32 leoiplChk_err_retry(u32 sense)
{
switch (sense)
{
case LEO_SENSE_MEDIUM_MAY_HAVE_CHANGED:
case LEO_SENSE_MEDIUM_NOT_PRESENT: /* no disk */
case LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED: /* drive reset */
case LEO_SENSE_DEVICE_COMMUNICATION_FAILURE: /* ドライブの接続不良 */
case LEO_SENSE_COMMAND_PHASE_ERROR:
case LEO_SENSE_DIAGNOSTIC_FAILURE:
return -1;
default:
;
}
return 0;
}
/* ==========================================================================
* Function : leoiplRecv_event_mesg
* --------------------------------------------------------------------------
* Descriprion : Wait event que message.
* Do drive reset if NMI-reset is detected
* --------------------------------------------------------------------------
* IN : NON
* OUT : NON
* ARG : control ( OS_MESG_BLOCK / OS_MESG_NOBLOCK )
* RET : 0 - GOOD
* : NOT 0 - NMI_RESET is detected
* ==========================================================================
*/
u8 leoiplRecv_event_mesg(s32 control)
{
u32 done_mesg;
/* WAIT DONE MESSAGE */
if (osRecvMesg(IPLEVENT_QUE, (OSMesg*)&done_mesg, control) == 0)
{
if (done_mesg == (u32)MES_NMI_RESET)
{
/* Reset drive if done_mesg is NMI_RESET */
leoiplDrive_reset();
return (0xff);
}
}
return 0;
}
/* ==========================================================================
* Function : leoiplDrive_reset
* --------------------------------------------------------------------------
* Description : Do drive reset .
* --------------------------------------------------------------------------
* IN : non
* OUT : non
* ARG : non
* RET : non
* ==========================================================================
*/
void leoiplDrive_reset(void)
{
leoiplAd16WriteIo(ASIC_HARD_RESET, ASIC_RESET_CODE);
}