leoint.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
/*
* F i l e N a m e : l e o i n t . c
*
****************************************************************************
* (C) Copyright ALPS Electric Co., Ltd. 1995-1996
****************************************************************************
* Version
*
* ver Date
* ---- --------
* 1.10 '97-02-22 Move leoChk_err_retry() to top of retry ope to correct UA handle.
* Change LEO_SENSE_MEDIUM_NOT_PRESENT to LEO_SENSE_EJECTED_ILLEGALLY_RESUME in leochk_err_reg().
* 1.09 '97-01-10 Change sense code name to LEO_SENSE_ILLEGAL_SECTOR_SIZE.
* 1.08 '96-12-24 Add "#ifdef _LONGCMD" for long command.
* 1.07 '96-10-30 Change seek completer interrupt check.
* Move leoChk_err_retry() in leomecha.c
* 1.06a '96-10-07 Enable bad-ecc write if SYSTEMWRITE is defined.
* 1.06 '96-10-02 Change recaliblate execute fail handling.
* Change c2syndrome 0 check. (cast u64 -> u32)
* 1.05 '96-10-01 Change OSPiHandle structure, make errStatus for each blocks.
* 1.04 '96-07-30 Change error handling .
* 1.03 '96-07-29 Rewrite for phase1 new OS.
* 1.02 '96-06-06 Add check C2 over-run err.
* 1.01 '96-02-27 Rename int.c to leoint.c
* 1.00 '95-12-20 Initial revision .
****************************************************************************
*/
#include "os.h"
#include <ultra64.h>
#include "leodefine.h"
#include "leodrive.h"
#include "leomacro.h"
#include "leoappli.h"
#ifdef _LONGCMD
#include "leospappli.h"
#endif
/**************************************
* PROTOTYPE DEFINITION
**************************************/
void leointerrupt(void *arg);
static u32 read_write_track(void);
static u32 leoChk_mecha_int(void);
static void leosetup_BM(void);
static u32 leochk_err_reg(void);
/**************************************
* EXTERNALY DEFINITION FUNCTIONS
**************************************/
extern u16 leoLba_to_phys(u32 lba);
extern void leoSet_mseq(u16 rwmode);
extern u32 leoChk_err_retry(u32 sense);
/**************************************/
/* RAM LOCATIONS */
/**************************************/
OSMesg LEOc2ctrl_que_buf;
OSMesgQueue LEOc2ctrl_que;
extern OSPiHandle *LEOPiInfo;
extern OSMesg LEOcur_command;
/**************************************
* EXTERNALY DEFINITION RAM LOCATIONS
**************************************/
extern OSThread LEOinterruptThread;
extern OSMesgQueue LEOcontrol_que;
extern OSMesgQueue LEOdma_que;
extern u8 *LEOwrite_pointer;
extern u32 LEOasic_bm_ctl_shadow;
extern u32 LEOasic_seq_ctl_shadow;
extern struct block_param_form LEOc2_param;
extern struct tgt_param_form LEOtgt_param;
extern volatile u16 LEOrw_flags;
extern u8 LEOC2_Syndrome[2][SEC_SIZE_ZONE0][C2_SECS_PER_BLK];
extern OSPiHandle *LEOPiInfo;
extern OSIoMesg LEOPiDmaParam;
/**************************************
* MACRO DEFINITONS *
**************************************/
#define read_command ((LEOCmdRead *)LEOcur_command)
#ifdef _LONGCMD
#define read_long_command ((LEOCmdReadLong *)LEOcur_command)
#endif
/**********************************************************
* Function : leointerrupt
* ---------------------------------------------------------
* Description : read
* IN : non
* OUT : non
**********************************************************/
void leointerrupt(void *arg)
{
u32 result;
u32 tg_blocks;
osCreateMesgQueue(C2_CTRL_QUE, &LEOc2ctrl_que_buf, 1/*size*/);
for (;;)
{
/* wait task start */
(void)osStopThread(&LEOinterruptThread);
tg_blocks = read_command->xfer_blks;
LEOwrite_pointer = (u8*)read_command->buff_ptr;
do
{
/* convert logical to physical to seek */
leoLba_to_phys(LEOtgt_param.lba);
#ifdef _LONGCMD
if (LEOrw_flags & FIXSIZE)
{
if (LEOtgt_param.sec_bytes < read_long_command->size)
{
result = LEO_SENSE_ILLEGAL_SECTOR_SIZE;
goto complete;
}
}
#endif
/* issue seek command to drive */
if (LEOrw_flags & WRITE_MODE)
result = leoSeek_write_i();
else
result = leoSeek_read_i();
if (result)
goto complete;
#ifdef _LONGCMD
if (LEOrw_flags & (SECTOR_READ+LONG_RW))
LEOtgt_param.rdwr_blocks = 1;
else if (LEOtgt_param.rdwr_blocks > tg_blocks) /* compare blocks in tk and blocks to read */
LEOtgt_param.rdwr_blocks = tg_blocks;
#else
if (LEOrw_flags & SECTOR_READ)
LEOtgt_param.rdwr_blocks = 1;
else if (LEOtgt_param.rdwr_blocks > tg_blocks) /* compare blocks in tk and blocks to read */
LEOtgt_param.rdwr_blocks = tg_blocks;
#endif
LEOtgt_param.lba += LEOtgt_param.rdwr_blocks;
tg_blocks -= LEOtgt_param.rdwr_blocks;
result = read_write_track();
if (result)
goto complete;
read_command->rw_bytes = (u32)LEOwrite_pointer - (u32)read_command->buff_ptr;
} while(tg_blocks);
result = (u32)MES_RW_COMPLETE;
complete:
osSendMesg(CONTROL_QUE, (OSMesg)result, OS_MESG_BLOCK);
}
}
u32 read_write_track(void)
{
u32 message;
u32 block;
u32 retry_cntr;
struct block_param_form block_param;
#ifdef _ERRCHK
struct tgt_param_form tgt_param_bk;
void *pntr_bk;
#endif
/* here seek operation already start and waiting done */
#ifdef _LONGCMD
block_param.bytes = LEOtgt_param.sec_bytes;
if (LEOrw_flags & (LONG_RW+FIXSIZE+SECTOR_READ))
{
if (LEOrw_flags & FIXSIZE)
{
block_param.bytes = read_long_command->size;
}
if (LEOrw_flags & LONG_RW)
{
block_param.bytes += 8;
}
block_param.blkbytes = block_param.bytes * USR_SECS_PER_BLK;
if (LEOrw_flags & SECTOR_READ)
block_param.blkbytes = block_param.bytes;
}
else
{
block_param.blkbytes = LEOtgt_param.blk_bytes;
}
#else
block_param.bytes = LEOtgt_param.sec_bytes;
block_param.blkbytes = LEOtgt_param.blk_bytes;
#if 1
if (LEOrw_flags & SECTOR_READ)
block_param.blkbytes = block_param.bytes;
#endif
#endif
block_param.pntr = (void*)LEOwrite_pointer;
LEOwrite_pointer += block_param.blkbytes;
if (LEOtgt_param.rdwr_blocks == 2)
LEOwrite_pointer += block_param.blkbytes;
retry_cntr = 0;
#ifdef _ERRCHK
tgt_param_bk = LEOtgt_param;
pntr_bk = block_param.pntr;
#endif
for (;;) /* loop with seek */
{
#ifdef _ERRCHK
LEOtgt_param = tgt_param_bk;
block_param.pntr = pntr_bk;
#endif
do /* while(0) */
{
LEOPiInfo->transferInfo.transferMode = LEO_BLOCK_MODE; /* block, track or sector */
LEOPiInfo->transferInfo.blockNum = 0; /* which block transfer(not set if track mode) */
LEOPiInfo->transferInfo.block[0].C1ErrNum = 0; /* initialize parameter */
LEOPiInfo->transferInfo.block[0].sectorSize = block_param.bytes;
LEOPiInfo->transferInfo.block[0].dramAddr = (void*)block_param.pntr;
LEOPiInfo->transferInfo.block[0].C2Addr = &LEOC2_Syndrome[0][0][0];
if (LEOrw_flags & SECTOR_READ)
{
LEOtgt_param.rdwr_blocks = 1;
LEOPiInfo->transferInfo.transferMode = LEO_SECTOR_MODE; /* block, track or sector */
}
else if (LEOtgt_param.rdwr_blocks == 2)
{
LEOPiInfo->transferInfo.transferMode = LEO_TRACK_MODE; /* block, track or sector */
LEOPiInfo->transferInfo.block[1] = LEOPiInfo->transferInfo.block[0];
LEOPiInfo->transferInfo.block[1].C2Addr = &LEOC2_Syndrome[1][0][0];
LEOPiInfo->transferInfo.block[1].dramAddr =
(u8*)((u32)LEOPiInfo->transferInfo.block[1].dramAddr + (u32)block_param.blkbytes);
}
/***************************/
/* seek complete interrupt */
/***************************/
if (message = leoChk_mecha_int())
{
break;
}
if (LEOrw_flags & WRITE_MODE)
leoSet_mseq(W_MODE); /* set drive sequencer for write */
else
leoSet_mseq(R_MODE); /* set drive sequencer for read */
leosetup_BM();
/***************************/
/* Do read/write operation */
/***************************/
LEOPiInfo->transferInfo.bmCtlShadow = LEOasic_bm_ctl_shadow;
LEOPiInfo->transferInfo.seqCtlShadow = LEOasic_seq_ctl_shadow;
if (LEOrw_flags & WRITE_MODE)
{
u16 bnum;
/*******************/
/* WRITE OPERATION */
/*******************/
LEOPiInfo->transferInfo.cmdType = OS_WRITE; /* disk_read, disk-write or others */
osWritebackDCache((void*)block_param.pntr, block_param.blkbytes*LEOtgt_param.rdwr_blocks);
/* Start sequencer and dma */
leoAd16StartDma(OS_WRITE);
(void)osRecvMesg(DMA_QUE, NULL, OS_MESG_BLOCK);
LEOasic_bm_ctl_shadow = LEOPiInfo->transferInfo.bmCtlShadow;
LEOasic_seq_ctl_shadow = LEOPiInfo->transferInfo.seqCtlShadow;
bnum = LEOPiInfo->transferInfo.blockNum;
message = LEOPiInfo->transferInfo.block[bnum].errStatus;
#ifdef _ERRCHK
goto track_end;
#else
if (message == 0)
{
return message;
}
goto track_end;
#endif
}
/******************/
/* read operation */
/******************/
/* check C2-ECC OVER-RUN ERR for first block (C2 correction is in progress) */
if (LEOrw_flags & LOCK_C2_PARAM)
{
/* wait last block C2 Correction complete message */
(void)osRecvMesg(C2_CTRL_QUE, NULL, OS_MESG_BLOCK);
osSendMesg(C2_CTRL_QUE, MES_NONE, OS_MESG_NOBLOCK);
}
LEOPiInfo->transferInfo.cmdType = OS_READ; /* disk_read, disk-write or others */
#if 0
if (LEOrw_flags & SECTOR_READ)
osInvalDCache((void*)block_param.pntr, block_param.bytes);
else
#endif
osInvalDCache((void*)block_param.pntr, block_param.blkbytes*LEOtgt_param.rdwr_blocks);
/* Start sequencer and dma for read */
leoAd16StartDma(OS_READ);
for (block = 0 ; LEOtgt_param.rdwr_blocks; block++)
{
(void)osRecvMesg(DMA_QUE, NULL, OS_MESG_BLOCK);
LEOasic_bm_ctl_shadow = LEOPiInfo->transferInfo.bmCtlShadow;
LEOasic_seq_ctl_shadow = LEOPiInfo->transferInfo.seqCtlShadow;
message = LEOPiInfo->transferInfo.block[block].errStatus;
if (message)
goto track_end;
/* CHECK SECTOR READ MODE */
if (LEOrw_flags & SECTOR_READ)
{
#ifdef _ERRCHK
message = LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION;
goto track_end;
#else
return LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION;
#endif
}
/* check if C2 required? */
if (LEOPiInfo->transferInfo.block[block].C1ErrNum)
{ /* c1 err exist */
if (LEOPiInfo->transferInfo.block[block].C1ErrSector[0] < USR_SECS_PER_BLK)
{ /* do c2-ecc */
if (LEOtgt_param.rdwr_blocks == 1) /* last block check */
{ /* check C2 data xfer over-run err */
leoGet_leo_err_sec(&message);
if (message & BIT_OVER_RUN)
{
message = LEO_SENSE_DATA_PHASE_ERROR; /* XFER OVER RUN */
goto track_end;
}
}
{
u8 *temp;
u32 c2datasize;
if (block == 0)
temp = &LEOC2_Syndrome[0][0][0];
else
temp = &LEOC2_Syndrome[1][0][0];
c2datasize = (u32)block_param.bytes * (u32)C2_SECS_PER_BLK;
block_param.c2buff_e = temp + c2datasize; /* c2buffer_last_adr+1 */
osInvalDCache((void*)temp, c2datasize);
}
block_param.err_num = LEOPiInfo->transferInfo.block[block].C1ErrNum;
block_param.err_pos[0] = LEOPiInfo->transferInfo.block[block].C1ErrSector[0];
block_param.err_pos[1] = LEOPiInfo->transferInfo.block[block].C1ErrSector[1];
block_param.err_pos[2] = LEOPiInfo->transferInfo.block[block].C1ErrSector[2];
block_param.err_pos[3] = LEOPiInfo->transferInfo.block[block].C1ErrSector[3];
/* wait C2 Correction complete message */
(void)osRecvMesg(C2_CTRL_QUE, NULL, OS_MESG_BLOCK);
LEOrw_flags |= LOCK_C2_PARAM;
LEOc2_param = block_param;
osSendMesg(CONTROL_QUE, (OSMesg)MES_REQ_C2_CORR, OS_MESG_BLOCK);
}
}
else
{ /* c1 err not exist */
/* check c2 16byte */
if (LEOtgt_param.rdwr_blocks == 1)
{ /* check index error(last block only) */
if ( (*(u32 *)&LEOC2_Syndrome[block][0][0]) | (*(u32 *)&LEOC2_Syndrome[block][0][ 4]) |
(*(u32 *)&LEOC2_Syndrome[block][0][8]) | (*(u32 *)&LEOC2_Syndrome[block][0][12]) )
{
/* INDEX DETECTION ERROR 顼ѹ */
message = LEO_SENSE_UNRECOVERED_READ_ERROR; /* UNCORECTABLE */
goto track_end;
}
}
/* no error */
}
block_param.pntr += block_param.blkbytes;
LEOtgt_param.start_block ^= 1;
LEOtgt_param.rdwr_blocks--;
#ifdef _ERRCHK
if ((read_command->header.reserve1 == LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION)
&& (retry_cntr >= read_command->header.reserve3) )
{
tgt_param_bk = LEOtgt_param;
pntr_bk = block_param.pntr;
}
}
message = LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION;
goto track_end;
#else
}
return LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION;
#endif
} while (0);
track_end:
/********************************/
/* Error Handling */
/********************************/
if (message == LEO_SENSE_WRITE_FAULT) /* ISR detect err case */
message = leochk_err_reg();
#ifdef _ERRCHK
if (message == LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION)
message = read_command->header.reserve1;
if ( (message == LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION) &&
(retry_cntr >= read_command->header.reserve3) )
{
break;
}
#else
#ifdef _LONGCMD
if (message == LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION)
break;
#endif
#endif
/********************************/
/* Retry Operation */
/********************************/
do_retry:
if (leoChk_err_retry(message)) /* Put this check at top of retry ope to set UA */
break;
if (LEOrw_flags & NO_RETRY)
break;
if (retry_cntr++ == MAX_RETRY)
break;
/* do retry */
if (leoChk_recal(retry_cntr))
{
message = leoSend_asic_cmd_w(ASIC_RECAL, 0x00);
if (message)
goto do_retry;
}
if ( (message == LEO_SENSE_NO_REFERENCE_POSITION_FOUND) ||
( (message == LEO_SENSE_UNRECOVERED_READ_ERROR) && (retry_cntr == MAX_RETRY/2) ))
{
message = leoDetect_index_w(); /* Detect index signal */
if (message)
goto do_retry;
}
if (LEOrw_flags & WRITE_MODE)
message = leoSeek_write_i();
else
message = leoSeek_read_i();
if (message)
goto do_retry;
} /* end of for(;;) */
#ifdef _ERRCHK
read_command->header.reserve7 = retry_cntr;
#endif
return message;
}
/**********************************************************
* Function : leoChk_mecha_int
* ---------------------------------------------------------
* Description : mecha int or error int handler.
* IN : non
* OUT : non
* ARG : message .. status register value.
* RET : error sense code
**********************************************************/
u32 leoChk_mecha_int(void)
{
u32 stat;
u32 index_stat;
/* seek complete interrupt */
stat = leoWait_mecha_cmd_done(ASIC_RD_SEEK);
if (stat == 0)
{
leoGet_leo_cur_tk(&index_stat);
if ((index_stat & BIT_INDEX_LOCK) != BIT_INDEX_LOCK)
stat = LEO_SENSE_NO_REFERENCE_POSITION_FOUND; /* Index Lock error */
}
return stat;
}
/**********************************************************
* Function : leosetup_BM
* ---------------------------------------------------------
* Description :
* IN : non
* OUT : non
* ARG : non
* RET : error sense code
**********************************************************/
void leosetup_BM(void)
{
/* BM_CTL register must be set after seek done */
leoClear_bm_error();
/* set start sector number */
if (LEOtgt_param.start_block)
LEOasic_bm_ctl_shadow = (u32)(ALL_SECS_PER_BLK << 16);
else
LEOasic_bm_ctl_shadow = (u32)(0x00000000); /* start at index */
if (!(LEOrw_flags & WRITE_MODE))
LEOasic_bm_ctl_shadow |= BM_MODE; /* Set BM Read Mode */
if (LEOtgt_param.rdwr_blocks == 2)
LEOasic_bm_ctl_shadow |= BM_XFERBLKS; /* Xfer 2 Blocks */
/* Set BM_MODE,BM_XFERBLKS,TSN */
leoAd16WriteIo(ASIC_BM_CTL, LEOasic_bm_ctl_shadow);
}
/**********************************************************
* Function : leochk_err_reg
* ---------------------------------------------------------
* Description : Use this routine if ISR return Write-Fault err.
* IN : non
* OUT : non
* ARG : non
* RET : error sense code
**********************************************************/
static u32 leochk_err_reg(void)
{
u32 sense;
u32 index_status;
leoGet_leo_err_sec(&sense); /* read error register */
leoClear_bm_error(); /* clear error info because it's already used */
if (sense & BIT_NO_DISK)
return LEO_SENSE_EJECTED_ILLEGALLY_RESUME; /* NO DISK */
else if (sense & BIT_OVER_RUN)
return LEO_SENSE_DATA_PHASE_ERROR; /* XFER OVER RUN */
else if (sense & (BIT_CLOCK_UNLOCK+BIT_MICRO_FAIL))
{
if (LEOrw_flags & WRITE_MODE)
return LEO_SENSE_WRITE_FAULT; /* WRITE FAULT */
return LEO_SENSE_UNRECOVERED_READ_ERROR; /* UNCORRECTABLE ERROR */
}
else if (sense & BIT_AM_FAIL)
return LEO_SENSE_NO_REFERENCE_POSITION_FOUND; /* AM NOT FOUND */
#ifdef _LONGCMD
else if (sense & BIT_SELF_STOP)
return LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION;
#endif
else
{ /* OFFTRACK or SPINDLE_FAIL */
leoGet_leo_cur_tk(&index_status);
if ((index_status & BIT_INDEX_LOCK) == BIT_INDEX_LOCK)
return LEO_SENSE_TRACK_FOLLOWING_ERROR;
else
return LEO_SENSE_NO_REFERENCE_POSITION_FOUND; /* drive lost index */
}
}