iplleoint.c
16.2 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
/*
* F i l e N a m e : i p l l e o i n t . c
*
****************************************************************************
* (C) Copyright ALPS Electric Co., Ltd. 1995-1996
****************************************************************************
* Version
*
* ver Date
* ---- --------
* 1.10 '96-11-22 Add _ERRCHK definition to be enable to return code in
* cdb for sense-code.
* 1.09 '96-10-30 Change seek complete interrupt check.
* Move leoiplChk_err_retry() function to iplleomecha.c
* 1.08 '96-10-02 Change recaliblate execute fail handling.
* Change c2syndrome 0 check. (cast u64 -> u32)
* 1.07 '96-10-01 Change OSPiHandle structure errStatus have each blocks .
* 1.06 '96-07-30 Change error handling .
* 1.05 '96-07-29 Rewrite for phase1 new OS.
* 1.04 '96-06-17 Add c2 over-run check.
* 1.03 '96-04-11 Move read sector data transfer location.
* 1.02 '96-02-27 Rename iplint.c to iplleoint.c .
* 1.01 '96-02-03 Debug.
* 1.00 '95-12-20 Initial revision .
****************************************************************************
*/
#include "os.h"
#include <ultra64.h>
#include "leodefine.h"
#include "leodrive.h"
#include "iplleomacro.h"
#include "leoappli.h"
/**************************************
* PROTOTYPE DEFINITION
**************************************/
void leoiplInterrupt(void *arg);
static u32 leoiplread_write_track(void);
static u32 leoiplChk_mecha_int(void);
static void leoiplsetup_BM(void);
static u32 leoiplchk_err_reg(void);
/**************************************
* EXTERNALY DEFINITION FUNCTIONS
**************************************/
extern u16 leoiplLba_to_phys(u32 lba);
extern void leoiplSet_mseq(void);
/**************************************/
/* RAM LOCATIONS */
/**************************************/
OSMesg LeoIPLc2ctrl_que_buf;
OSMesgQueue LeoIPLc2ctrl_que;
/**************************************
* EXTERNALY DEFINITION RAM LOCATIONS
**************************************/
extern OSThread LeoIPLinterruptThread;
extern OSMesgQueue LeoIPLevent_que;
extern OSMesgQueue LeoIPLcontrol_que;
extern OSMesgQueue LeoIPLdma_que;
extern OSIoMesg LeoIPLdmaIOMesgBuf;
extern u8 *LeoIPLwrite_pointer;
extern u32 LeoIPLasic_bm_ctl_shadow;
extern u32 LeoIPLasic_seq_ctl_shadow;
extern struct block_param_form LeoIPLc2_param;
extern struct tgt_param_form LeoIPLtgt_param;
extern volatile u16 LeoIPLrw_flags;
extern u8 LeoIPLC2_Syndrome[2][SEC_SIZE_ZONE0][C2_SECS_PER_BLK];
extern OSPiHandle *LeoIPLPiInfo;
extern OSIoMesg LeoIPLPiDmaParam;
extern OSMesg LeoIPLcur_command;
/**************************************
* MACRO DEFINITIONS *
**************************************/
#define read_command ((LEOCmdRead *)LeoIPLcur_command)
#define osSyncPrintf(a,b)
/**********************************************************
* Function : leoiplInterrupt
* ---------------------------------------------------------
* Description : read interrupt handler.
* IN : write_pointer .. buffer address
* OUT : non
**********************************************************/
void leoiplInterrupt(void *arg)
{
u32 message;
u32 tg_blocks;
osCreateMesgQueue(IPLC2_CTRL_QUE, &LeoIPLc2ctrl_que_buf, 1/*size*/);
for (;;)
{
/* wait task start */
(void)osStopThread(&LeoIPLinterruptThread);
tg_blocks = read_command->xfer_blks;
LeoIPLwrite_pointer = (u8*)read_command->buff_ptr;
do
{
/* convert logical to physical to seek */
leoiplLba_to_phys(LeoIPLtgt_param.lba);
message = leoiplSeek_read_i();
if (message)
goto complete;
if (LeoIPLtgt_param.rdwr_blocks > tg_blocks) /* compare blocks in tk and blocks to read */
LeoIPLtgt_param.rdwr_blocks = tg_blocks;
LeoIPLtgt_param.lba += LeoIPLtgt_param.rdwr_blocks;
tg_blocks -= LeoIPLtgt_param.rdwr_blocks;
message = leoiplread_write_track();
if (message)
goto complete;
read_command->rw_bytes = (u32)LeoIPLwrite_pointer - (u32)read_command->buff_ptr;
} while(tg_blocks);
message = (u32)MES_RW_COMPLETE;
complete:
osSendMesg(IPLCONTROL_QUE, (OSMesg)message, OS_MESG_BLOCK);
}
}
u32 leoiplread_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 */
/* calc while seek */
block_param.bytes = LeoIPLtgt_param.sec_bytes;
block_param.blkbytes = LeoIPLtgt_param.blk_bytes;
block_param.pntr = (void*)LeoIPLwrite_pointer;
LeoIPLwrite_pointer += block_param.blkbytes;
if (LeoIPLtgt_param.rdwr_blocks == 2)
LeoIPLwrite_pointer += block_param.blkbytes;
retry_cntr = 0;
#ifdef _ERRCHK
tgt_param_bk = LeoIPLtgt_param;
pntr_bk = block_param.pntr;
#endif
for (;;) /* loop with seek */
{
#ifdef _ERRCHK
LeoIPLtgt_param = tgt_param_bk;
block_param.pntr = pntr_bk;
#endif
LeoIPLPiInfo->transferInfo.transferMode = LEO_BLOCK_MODE; /* block, track or sector */
LeoIPLPiInfo->transferInfo.blockNum = 0; /* which block transfer(not set if track mode) */
LeoIPLPiInfo->transferInfo.block[0].C1ErrNum = 0; /* initialize parameter */
LeoIPLPiInfo->transferInfo.block[0].sectorSize = block_param.bytes;
LeoIPLPiInfo->transferInfo.block[0].dramAddr = (void*)block_param.pntr;
LeoIPLPiInfo->transferInfo.block[0].C2Addr = &LeoIPLC2_Syndrome[0][0][0];
if (LeoIPLrw_flags & SECTOR_READ)
{
LeoIPLtgt_param.rdwr_blocks = 1;
LeoIPLPiInfo->transferInfo.transferMode = LEO_SECTOR_MODE; /* block, track or sector */
}
else if (LeoIPLtgt_param.rdwr_blocks == 2)
{
LeoIPLPiInfo->transferInfo.transferMode = LEO_TRACK_MODE; /* block, track or sector */
LeoIPLPiInfo->transferInfo.block[1] = LeoIPLPiInfo->transferInfo.block[0];
LeoIPLPiInfo->transferInfo.block[1].C2Addr = &LeoIPLC2_Syndrome[1][0][0];
LeoIPLPiInfo->transferInfo.block[1].dramAddr =
(u8*)((u32)LeoIPLPiInfo->transferInfo.block[1].dramAddr + (u32)block_param.blkbytes);
}
/***************************/
/* seek complete interrupt */
/***************************/
if (message = leoiplChk_mecha_int())
{
goto track_end;
}
leoiplSet_mseq(); /* set drive sequencer for read while seek */
leoiplsetup_BM();
/***************************/
/* Do read/write operation */
/***************************/
LeoIPLPiInfo->transferInfo.bmCtlShadow = LeoIPLasic_bm_ctl_shadow;
LeoIPLPiInfo->transferInfo.seqCtlShadow = LeoIPLasic_seq_ctl_shadow;
/******************/
/* read operation */
/******************/
/* check C2-ECC OVER-RUN ERR for first block (C2 correction is in progress) */
if (LeoIPLrw_flags & LOCK_C2_PARAM)
{
/* wait c2_correction complete message */
(void)osRecvMesg(IPLC2_CTRL_QUE, (OSMesg*)NULL, OS_MESG_BLOCK);
osSendMesg(IPLC2_CTRL_QUE, MES_NONE, OS_MESG_NOBLOCK);
}
LeoIPLPiInfo->transferInfo.cmdType = OS_READ; /* disk_read, disk-write or others */
if (LeoIPLrw_flags & SECTOR_READ)
osInvalDCache((void*)block_param.pntr, block_param.bytes);
else
osInvalDCache((void*)block_param.pntr, block_param.blkbytes*LeoIPLtgt_param.rdwr_blocks);
/* Start sequencer and dma for read */
leoiplAd16StartDma(OS_READ);
for (block = 0 ; LeoIPLtgt_param.rdwr_blocks; block++)
{
(void)osRecvMesg(IPLDMA_QUE, (OSMesg*)&message, OS_MESG_BLOCK);
LeoIPLasic_bm_ctl_shadow = LeoIPLPiInfo->transferInfo.bmCtlShadow;
LeoIPLasic_seq_ctl_shadow = LeoIPLPiInfo->transferInfo.seqCtlShadow;
message = LeoIPLPiInfo->transferInfo.block[block].errStatus;
if (message)
goto track_end;
/* CHECK SECTOR READ MODE */
if (LeoIPLrw_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 (LeoIPLPiInfo->transferInfo.block[block].C1ErrNum)
{ /* c1 err exist */
if (LeoIPLPiInfo->transferInfo.block[block].C1ErrSector[0] < USR_SECS_PER_BLK)
{ /* do c2-ecc */
if (LeoIPLtgt_param.rdwr_blocks == 1) /* last block check */
{ /* check C2 data xfer over-run err */
leoiplGet_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 = &LeoIPLC2_Syndrome[0][0][0];
else
temp = &LeoIPLC2_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 = LeoIPLPiInfo->transferInfo.block[block].C1ErrNum;
block_param.err_pos[0] = LeoIPLPiInfo->transferInfo.block[block].C1ErrSector[0];
block_param.err_pos[1] = LeoIPLPiInfo->transferInfo.block[block].C1ErrSector[1];
block_param.err_pos[2] = LeoIPLPiInfo->transferInfo.block[block].C1ErrSector[2];
block_param.err_pos[3] = LeoIPLPiInfo->transferInfo.block[block].C1ErrSector[3];
/* wait c2_correction complete message */
(void)osRecvMesg(IPLC2_CTRL_QUE, NULL, OS_MESG_BLOCK);
LeoIPLrw_flags |= LOCK_C2_PARAM;
LeoIPLc2_param = block_param;
osSendMesg(IPLCONTROL_QUE, (OSMesg)MES_REQ_C2_CORR, OS_MESG_BLOCK);
}
}
else
{ /* c1 err not exist */
/* check c2 16byte */
if (LeoIPLtgt_param.rdwr_blocks == 1)
{ /* check index error(last block only) */
if ( (*(u32 *)&LeoIPLC2_Syndrome[block][0][0]) | (*(u32 *)&LeoIPLC2_Syndrome[block][0][ 4]) |
(*(u32 *)&LeoIPLC2_Syndrome[block][0][8]) | (*(u32 *)&LeoIPLC2_Syndrome[block][0][12]) )
{
/* INDEX DETECTION ERROR */
message = LEO_SENSE_NO_REFERENCE_POSITION_FOUND; /* INDEX NOT FOUND */
goto track_end;
}
}
/* no error */
}
LeoIPLtgt_param.start_block ^= 1;
LeoIPLtgt_param.rdwr_blocks--;
block_param.pntr += block_param.blkbytes;
#ifdef _ERRCHK
if ((read_command->header.reserve1 == LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION)
&& (retry_cntr >= read_command->header.reserve3) )
{
tgt_param_bk = LeoIPLtgt_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
/********************************/
/* Retry Operation */
/********************************/
track_end:
if (message == LEO_SENSE_WRITE_FAULT)
message = leoiplchk_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;
}
#endif
do_retry:
if (LeoIPLrw_flags & NO_RETRY)
break;
if (leoiplChk_err_retry(message))
break;
if (retry_cntr++ >= MAX_RETRY)
break;
/* do retry */
if (leoChk_recal(retry_cntr))
{
message = leoiplSend_asic_cmd_w(ASIC_RECAL, 0x00);
if (message)
goto do_retry;
}
if (message == LEO_SENSE_NO_REFERENCE_POSITION_FOUND)
{
message = leoiplDetect_index_w(); /* Index lock */
if (message)
goto do_retry;
}
message = leoiplSeek_read_i();
if (message)
goto do_retry; /* retry seek NG case */
} /* end of for(;;) */
#ifdef _ERRCHK
read_command->header.reserve7 = retry_cntr;
#endif
return message;
}
/**********************************************************
* Function : leoiplChk_mecha_int
* ---------------------------------------------------------
* Description : mecha int or error int handler.
* IN : non
* OUT : non
* ARG : message .. status register value.
* RET : error sense code
**********************************************************/
u32 leoiplChk_mecha_int(void)
{
u32 message;
u32 index_status;
/* seek complete interrupt */
message = leoiplWait_mecha_cmd_done(ASIC_RD_SEEK);
if (message == 0)
{
leoiplGet_leo_cur_tk(&index_status);
if ((index_status & BIT_INDEX_LOCK) != BIT_INDEX_LOCK)
message = LEO_SENSE_NO_REFERENCE_POSITION_FOUND; /* Index Lock error */
}
return message;
}
/**********************************************************
* Function : leoiplsetup_BM
* ---------------------------------------------------------
* Description :
* IN : non
* OUT : non
* ARG : non
* RET : error sense code
**********************************************************/
void leoiplsetup_BM(void)
{
/* setup BM_CTL registor */
leoiplClear_bm_error(); /* Clear BM error */
/* set start sector number */
if (LeoIPLtgt_param.start_block)
LeoIPLasic_bm_ctl_shadow = (u32)(ALL_SECS_PER_BLK << 16);
else
LeoIPLasic_bm_ctl_shadow = (u32)(0x00000000); /* start at sector 0 */
LeoIPLasic_bm_ctl_shadow |= BM_MODE; /* Set BM Read Mode */
if (LeoIPLtgt_param.rdwr_blocks == 2)
LeoIPLasic_bm_ctl_shadow |= BM_XFERBLKS; /* Xfer 2 Blocks */
/* Set BM_MODE,BM_XFERBLKS,TSN */
leoiplAd16WriteIo(ASIC_BM_CTL, LeoIPLasic_bm_ctl_shadow);
}
/**********************************************************
* Function : leoiplchk_err_reg
* ---------------------------------------------------------
* Description : Use this routine if ISR return Write-Fault err.
* IN : non
* OUT : non
* ARG : non
* RET : error sense code
**********************************************************/
static u32 leoiplchk_err_reg(void)
{
u32 sense;
u32 index_status;
leoiplGet_leo_err_sec(&sense); /* get error info */
leoiplClear_bm_error(); /* set/reset bit 12 of bm reg */
if (sense & BIT_NO_DISK)
return LEO_SENSE_MEDIUM_NOT_PRESENT; /* 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))
return LEO_SENSE_UNRECOVERED_READ_ERROR; /* UNCORRECTABLE ERROR */
else if (sense & BIT_AM_FAIL)
return LEO_SENSE_NO_REFERENCE_POSITION_FOUND; /* AM NOT FOUND */
else
{ /* OFFTRACK or SPINDLE_FAIL */
leoiplGet_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;
}
}