leomecha.c
20 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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
/*
* F i l e N a m e : l e o m e c h a . c
*
****************************************************************************
* (C) Copyright ALPS Electric Co., Ltd. 1995-1996
****************************************************************************
* Version
*
* ver Date
* ---- --------
* 1.09 '98-02-17 Add OFFSET WRITE SEEK routine for B114.
* 1.08 '97-06-23 Inhibit retry for DIAG-error in leoChk_err_retry().
* 1.07 '97-06-18 Add check of return value of osRecvMesg() in leoRecv_event_mesg().
* 1.06 '97-02-19 Add UA operation.
* Add LEO_SENSE_EJECTED_ILLEGALLY_RESUME.
* 1.05 '96-12-24 Change ram name.
* 1.04 '96-10-31 Add leoWait_mecha_cmd_done(), leoRecal_w(), leoSeek_w(),
* leoRecv_event_mesg() for NMI_RESET .
* Move leoChk_err_retry() from leoint.c.
* Add SC_DEVICE_COMMUNICATION_FAIL, SC_COMMAND_PHASE_ERROR
* in leoChk_err_retry().
* 1.03 '96-09-17 Change leoChk_asic_ready(), ASIC_CUR_STATUS is argment.
* 1.02 '96-07-25 Add leoAnalize_asic_status(); leoChk_asic_ready();
* leoChk_done_status(); leoSend_asic_cmd_i();
* leoSend_asic_cmd_w(); leoDetect_index_w();
* for phase1.5 .
* 1.01 '96-02-27 Rename asic_if.c to leomecha.c
* 1.00 '95-12-20 Initial revision .
****************************************************************************
*/
#define _WRITER
#define _ASIC_IF
#include "os.h"
#include <ultra64.h>
#include "leodefine.h"
#include "leodrive.h"
#include "leomacro.h"
#include "leoappli.h"
#ifdef _WRITER
#include "leowriter.h"
#endif
/*************************************/
/* 関数プロトタイプ宣言 */
/*************************************/
u8 leoAnalize_asic_status(void );
u8 leoChk_asic_ready(u32 asic_cmd);
u8 leoChk_done_status(u32 asic_cmd);
u8 leoSend_asic_cmd_i(u32 asic_cmd, u32 asic_data);
u8 leoWait_mecha_cmd_done(u32 asic_cmd );
u8 leoSend_asic_cmd_w(u32 asic_cmd, u32 asic_data);
u8 leoDetect_index_w(void);
u8 leoRecal_i(void);
u8 leoRecal_w(void);
u8 leoSeek_i(u16 rwmode);
u8 leoSeek_w(void);
u8 leoRecv_event_mesg(s32 control);
void leoDrive_reset(void);
#ifdef _WRITER
u8 leoOffset_Seek_i(u16 dir_ctrl);
#endif
/*************************************/
/* 外部参照の関数 */
/*************************************/
static u32 asic_cur_status;
static u32 unit_atten;
#define UA_RESET 0x02
#define UA_MEDIUMCHANGE 0x01
/*************************************/
/* 外部参照変数 */
/*************************************/
extern OSMesgQueue LEOevent_que;
extern OSMesg LEOcur_command;
extern u8 LEOdrive_flag;
extern struct tgt_param_form LEOtgt_param;
extern OSPiHandle *LEOPiInfo;
/* ==========================================================================
* Function : leoAnalize_asic_status
* --------------------------------------------------------------------------
* Description : Analize drive status register to check mecha condition.
* --------------------------------------------------------------------------
* IN : NON
* OUT : NON
* ARG : NON
* RET : 0 - GOOD
* : NOT 0 - ERROR SENSE CODE
* ==========================================================================
*/
u8 leoAnalize_asic_status(void)
{
u32 curr_stat;
leoGet_leo_status(&asic_cur_status);
curr_stat = asic_cur_status ^ LEO_STAT_DISK;
if (curr_stat & (LEO_STAT_DISK + LEO_STAT_BUSY + LEO_STAT_RESET + LEO_STAT_DISK_CHANGE
+ LEO_STAT_MECHA_ERROR + LEO_STAT_NC_CHK ) )
{
/* CLEAR FLAG TO FORCE RE-READ SYSTEM INFO */
if (curr_stat & (LEO_STAT_DISK + LEO_STAT_BUSY + LEO_STAT_RESET + LEO_STAT_DISK_CHANGE
+ LEO_STAT_NC_CHK ) )
leoClr_sys_read();
/*--------------------------*/
/* check HardWare err first */
/*--------------------------*/
/* Drive communication fail ? */
if (curr_stat & LEO_STAT_NC_CHK)
return(LEO_SENSE_DEVICE_COMMUNICATION_FAILURE);
/* Drive BUSY ? */
if ((curr_stat & (LEO_STAT_BUSY+LEO_STAT_RESET)) == LEO_STAT_BUSY)
return(LEO_SENSE_COMMAND_PHASE_ERROR);
/*---------------------------------------------*/
/* CHECK RESET / DISK-CHANGE / NO-DISK */
/*---------------------------------------------*/
/* RESET ? */
if (curr_stat & LEO_STAT_RESET)
{
unit_atten |= UA_RESET;
return (LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED);
}
/* NO DISK ? */
if (curr_stat & LEO_STAT_DISK)
return (LEO_SENSE_EJECTED_ILLEGALLY_RESUME);
/* DISK CHANGED ? */
if (curr_stat & LEO_STAT_DISK_CHANGE)
{
unit_atten |= UA_MEDIUMCHANGE;
return (LEO_SENSE_MEDIUM_MAY_HAVE_CHANGED);
}
/*---------------------------------------------*/
/* CHECK other err */
/*---------------------------------------------*/
/* MECHA ERROR ? */
if (curr_stat & LEO_STAT_MECHA_ERROR)
return (LEO_SENSE_NO_SEEK_COMPLETE);
}
/* ASIC status is OK */
return LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION;
}
/* ==========================================================================
* Function : leoChk_asic_ready
* --------------------------------------------------------------------------
* Description : Pre-check to command to drive.
* Clear system info flag if reset/disk-change detected
* --------------------------------------------------------------------------
* IN : non
* OUT : non
* ARG : asic_cmd command code to drive
* RET : 0 - good
* : not 0 - not good . sense code is returned
* ==========================================================================
*/
u8 leoChk_asic_ready(u32 asic_cmd)
{
u32 sense_code;
sense_code = leoAnalize_asic_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:
/* clear drive flag */
if (!(asic_cur_status & LEO_STAT_BUSY))
{
if (asic_cmd == ASIC_CLR_RSTFLG)
return LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION;
if (leoRecv_event_mesg(OS_MESG_NOBLOCK))
return (LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED);
leoAd16WriteIo(ASIC_CMD, ASIC_CLR_RSTFLG);
if (leoRecv_event_mesg(OS_MESG_BLOCK))
return (LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED);
}
break;
case LEO_SENSE_EJECTED_ILLEGALLY_RESUME:
/* Do this command needs disk ? */
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 : leoChk_done_status
* --------------------------------------------------------------------------
* Description : Post check of command
* Clear system info flag if reset/disk-change is detected
* --------------------------------------------------------------------------
* IN : NON
* OUT : NON
* ARG : asic_cmd .. Command code to drive
* RET : 0 - GOOD
* : NOT 0 - ERROR SENSE CODE
* ==========================================================================
*/
u8 leoChk_done_status(u32 asic_cmd)
{
u32 asic_data,code;
code = leoAnalize_asic_status();
switch (code)
{
case LEO_SENSE_MEDIUM_MAY_HAVE_CHANGED:
case LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED:
if (!(asic_cur_status & LEO_STAT_BUSY))
{
/* clear reset/disk-change flag */
if (leoRecv_event_mesg(OS_MESG_NOBLOCK))
return LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED;
leoAd16WriteIo(ASIC_CMD, ASIC_CLR_RSTFLG);
if (leoRecv_event_mesg(OS_MESG_BLOCK))
return LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED;
}
break;
case LEO_SENSE_EJECTED_ILLEGALLY_RESUME:
/* 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 infomation */
leoAd16WriteIo(ASIC_DATA, 0x00);
if (leoRecv_event_mesg(OS_MESG_NOBLOCK))
return (LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED);
leoAd16WriteIo(ASIC_CMD , ASIC_REQ_STATUS);
/* wait done */
if (leoRecv_event_mesg(OS_MESG_BLOCK))
return (LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED);
leoGet_leo_asic_data(&asic_data);
if (code = leoChk_asic_ready(ASIC_REQ_STATUS))
return code;
/* Analize error info */
if (asic_data & MC_ERR_DIAGNOSTIC) /* drive diag err */
return(LEO_SENSE_DIAGNOSTIC_FAILURE);
if (asic_data & MC_ERR_SERVO_DATA) /* servo read err */
return(LEO_SENSE_NO_REFERENCE_POSITION_FOUND);
if (asic_data & MC_ERR_INDEX) /* index detect error or timing NG */
return(LEO_SENSE_DRIVE_NOT_READY);
if (asic_data & MC_ERR_SETRING_TIMEOUT) /* seek timeout */
return(LEO_SENSE_NO_SEEK_COMPLETE);
if (asic_data & 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 : leoSend_asic_cmd_i
* --------------------------------------------------------------------------
* Description : Issue commnad to drive. not wait done.
* --------------------------------------------------------------------------
* IN : NON
* OUT : ((LEOCmdHeader *)LEOcur_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 leoSend_asic_cmd_i(u32 asic_cmd, u32 asic_data)
{
u8 status;
if (status = leoChk_asic_ready(asic_cmd))
return(((LEOCmdHeader *)LEOcur_command)->sense = status);
/* Issue command,data to drive */
leoAd16WriteIo(ASIC_DATA, asic_data);
if (leoRecv_event_mesg(OS_MESG_NOBLOCK))
return(((LEOCmdHeader *)LEOcur_command)->sense = LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED);
leoAd16WriteIo(ASIC_CMD , asic_cmd );
return(FUNC_OK);
}
/* ==========================================================================
* Function : leoWait_mecha_cmd_done
* --------------------------------------------------------------------------
* Description : Wait drive command done and check error.
* --------------------------------------------------------------------------
* IN : non
* OUT : ((LEOCmdHeader *)LEOcur_command)->sense is set at error
* ARG : command code that drive executing.
* RET : 00 - good
* : 00以外 - error sense code.
* ==========================================================================
*/
u8 leoWait_mecha_cmd_done(u32 asic_cmd )
{
u32 done_stat;
/* Wait done */
if (leoRecv_event_mesg(OS_MESG_BLOCK))
return(LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED);
/* Check done status */
if (done_stat = leoChk_done_status(asic_cmd))
return(done_stat);
return(FUNC_OK);
}
/* ==========================================================================
* Function : leoSend_asic_cmd_w
* --------------------------------------------------------------------------
* Description : Issue command to drive,waiting done and check error.
* --------------------------------------------------------------------------
* IN : NON
* OUT : ((LEOCmdHeader *)LEOcur_command)->sense is set at error
* ARG : command and data to issue to drive
* RET : 00 - good
* : 00以外 - error sense code
* ==========================================================================
*/
u8 leoSend_asic_cmd_w(u32 asic_cmd, u32 asic_data)
{
u32 wstatus;
if (wstatus = leoSend_asic_cmd_i(asic_cmd, asic_data))
return (wstatus);
return leoWait_mecha_cmd_done(asic_cmd);
}
/* ==========================================================================
* Function : leoDetect_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 leoDetect_index_w(void)
{
return leoSend_asic_cmd_w(ASIC_INDEX_LOCK_RETRY, 0);
}
/* ==========================================================================
* Function : leoRecal_i
* --------------------------------------------------------------------------
* Description : Issue Recaliblate command (not wait done)
* --------------------------------------------------------------------------
* IN : LEOcur_command
* OUT : NON
* ARG : NON
* RET : 0 - GOOD
* : not 0 - error sense code
* ==========================================================================
*/
u8 leoRecal_i(void)
{
return leoSend_asic_cmd_i(ASIC_RECAL, 0x00);
}
u8 leoRecal_w(void)
{
return leoSend_asic_cmd_w(ASIC_RECAL, 0x00);
}
/* ==========================================================================
* Function : leoSeek_i
* --------------------------------------------------------------------------
* Description : Issue seek command (not wait done)
* --------------------------------------------------------------------------
* IN : LEOcur_command, LEOtgt_param.XXX
* OUT : non
* ARG : rwmode - choice read or write
* RET : 0 - good
* : not 0 - error sense code
* ==========================================================================
*/
u8 leoSeek_i(u16 rwmode)
{
u32 tgt_tk;
/* calc data parameter */
tgt_tk = (u32)(((LEOtgt_param.head << 12) + LEOtgt_param.cylinder) << 16);
if (rwmode == R_MODE)
return leoSend_asic_cmd_i(ASIC_RD_SEEK, tgt_tk);
else
return leoSend_asic_cmd_i(ASIC_WR_SEEK, tgt_tk);
}
u8 leoSeek_w(void)
{
u8 sksense;
if (sksense = leoSeek_i(R_MODE))
return (sksense);
return leoWait_mecha_cmd_done(ASIC_RD_SEEK);
}
/* ==========================================================================
* Function : leoRecv_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 leoRecv_event_mesg(s32 control)
{
u32 done_mesg;
/* WAIT DONE MESSAGE */
if (osRecvMesg(EVENT_QUE, (OSMesg*)&done_mesg, control) == 0)
{
if (done_mesg == (u32)MES_NMI_RESET)
{
/* Reset drive if done_mesg is NMI_RESET */
leoDrive_reset();
return (0xff);
}
}
return 0;
}
/**********************************************************
* Function : leoChk_err_retry
* ---------------------------------------------------------
* Description : Check retry enable or not .
* IN : non
* OUT :
* ARG : sense .. sense code of error.
* RETURN: 0 ...... ENABLE RETRY.
* NOT 0... DISABLE RETRY.COMMAND SHOULD BE STOP.
**********************************************************/
u32 leoChk_err_retry(u32 sense)
{
switch (sense)
{
case LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED: /* drive reset */
unit_atten |= UA_RESET;
case LEO_SENSE_MEDIUM_MAY_HAVE_CHANGED:
unit_atten |= UA_MEDIUMCHANGE;
case LEO_SENSE_DEVICE_COMMUNICATION_FAILURE:
case LEO_SENSE_COMMAND_PHASE_ERROR:
case LEO_SENSE_MEDIUM_NOT_PRESENT: /* no disk */
case LEO_SENSE_EJECTED_ILLEGALLY_RESUME: /* no disk */
case LEO_SENSE_DIAGNOSTIC_FAILURE:
leoClr_sys_read();
return -1;
default:
;
}
return 0;
}
/* ==========================================================================
* Function : leoChk_cur_drvmode
* --------------------------------------------------------------------------
* Description : check status and set flags for test unit ready command.
* leoAnalize_asic_status() must be call before.
* --------------------------------------------------------------------------
* IN : NON
* OUT : NON
* ARG : NON
* RET : flags for TEST UNIT READY command
* ==========================================================================
*/
u8 leoChk_cur_drvmode(void)
{
u8 devstat;
devstat = 0x00;
/* DISK EXIST ? */
if (!(asic_cur_status & LEO_STAT_DISK) )
devstat |= LEO_TEST_UNIT_MR;
/* HEAD RETRACTED ? */
if (asic_cur_status & LEO_STAT_HEAD_RETRACT)
devstat |= LEO_TEST_UNIT_RE;
/* SPINDLE ON ? */
if (asic_cur_status & LEO_STAT_SPM_OFF)
devstat |= LEO_TEST_UNIT_SS;
return(devstat);
}
/* ==========================================================================
* Function : leoDrive_reset
* --------------------------------------------------------------------------
* Description : Do drive reset .
* --------------------------------------------------------------------------
* IN : non
* OUT : non
* ARG : non
* RET : non
* ==========================================================================
*/
void leoDrive_reset(void)
{
leoAd16WriteIo(ASIC_HARD_RESET, ASIC_RESET_CODE);
}
/* ==========================================================================
* Function : leoChkUnit_atten leoRetUnit_atten leoSetUnit_atten
* --------------------------------------------------------------------------
* Description : Handle unit attention condition.
* --------------------------------------------------------------------------
* IN : non
* OUT : non
* ARG : non
* RET : non
* ==========================================================================
*/
u32 leoChkUnit_atten(void)
{
return unit_atten;
}
u32 leoRetUnit_atten(void)
{
if (unit_atten & UA_RESET)
{
return LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED;
}
if (unit_atten & UA_MEDIUMCHANGE)
{
return LEO_SENSE_MEDIUM_MAY_HAVE_CHANGED;
}
return LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION;
}
void leoClrUA_RESET(void)
{
unit_atten &= ~(UA_RESET+UA_MEDIUMCHANGE);
}
void leoClrUA_MEDIUM_CHANGED(void)
{
unit_atten &= ~UA_MEDIUMCHANGE;
}
void leoInitUnit_atten(void)
{
unit_atten = 0;
}
#ifdef _WRITER
u8 leoOffset_Seek_i(u16 dir_ctrl)
{
u32 tgt_tk;
if (!dir_ctrl)
/* OFFSET - */
tgt_tk = (u32)(((LEOtgt_param.head << 12) + (LEOtgt_param.cylinder | 0x8000)) << 16);
else
/* OFFSET + */
tgt_tk = (u32)(((LEOtgt_param.head << 12) + LEOtgt_param.cylinder) << 16);
return leoSend_asic_cmd_i(ASIC_WR_OFFSET_SEEK, tgt_tk);
}
#endif