This source file includes following definitions.
- enable_board
- init_board
- pas16_hw_detect
- pas16_setup
- pas16_detect
- pas16_biosparam
- NCR5380_pread
- NCR5380_pwrite
1 #define AUTOSENSE
2 #define PSEUDO_DMA
3 #define FOO
4 #define UNSAFE
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 #ifdef MODULE
106 #include <linux/module.h>
107 #endif
108
109 #include <asm/system.h>
110 #include <linux/signal.h>
111 #include <linux/proc_fs.h>
112 #include <linux/sched.h>
113 #include <asm/io.h>
114 #include <linux/blk.h>
115 #include "scsi.h"
116 #include "hosts.h"
117 #include "pas16.h"
118 #define AUTOPROBE_IRQ
119 #include "NCR5380.h"
120 #include "constants.h"
121 #include "sd.h"
122
123 #include<linux/stat.h>
124
125 struct proc_dir_entry proc_scsi_pas16 = {
126 PROC_SCSI_PAS16, 5, "pas16",
127 S_IFDIR | S_IRUGO | S_IXUGO, 2
128 };
129 static int pas_maxi = 0;
130 static int pas_wmaxi = 0;
131
132
133 int scsi_irq_translate[] =
134 { 0, 0, 1, 2, 3, 4, 5, 6, 0, 0, 7, 8, 9, 0, 10, 11 };
135
136
137
138
139
140
141 int default_irqs[] = { PAS16_DEFAULT_BOARD_1_IRQ,
142 PAS16_DEFAULT_BOARD_2_IRQ,
143 PAS16_DEFAULT_BOARD_3_IRQ,
144 PAS16_DEFAULT_BOARD_4_IRQ
145 };
146
147 static struct override {
148 unsigned short io_port;
149 int irq;
150 } overrides
151 #ifdef PAS16_OVERRIDE
152 [] = PAS16_OVERRIDE;
153 #else
154 [4] = {{0,IRQ_AUTO}, {0,IRQ_AUTO}, {0,IRQ_AUTO},
155 {0,IRQ_AUTO}};
156 #endif
157
158 #define NO_OVERRIDES (sizeof(overrides) / sizeof(struct override))
159
160 static struct base {
161 unsigned short io_port;
162 int noauto;
163 } bases[] = { {PAS16_DEFAULT_BASE_1, 0},
164 {PAS16_DEFAULT_BASE_2, 0},
165 {PAS16_DEFAULT_BASE_3, 0},
166 {PAS16_DEFAULT_BASE_4, 0}
167 };
168
169 #define NO_BASES (sizeof (bases) / sizeof (struct base))
170
171 unsigned short pas16_offset[ 8 ] =
172 {
173 0x1c00,
174 0x1c01,
175 0x1c02,
176 0x1c03,
177 0x3c00,
178 0x3c01,
179 0x3c02,
180
181
182 0x3c03,
183
184
185 };
186
187
188
189
190
191
192
193
194
195
196
197 #if 1
198 #define rtrc(i) {inb(0x3da); outb(0x31, 0x3c0); outb((i), 0x3c0);}
199 #else
200 #define rtrc(i) {}
201 #endif
202
203
204
205
206
207
208
209
210
211
212
213 void enable_board( int board_num, unsigned short port )
214 {
215 outb( 0xbc + board_num, MASTER_ADDRESS_PTR );
216 outb( port >> 2, MASTER_ADDRESS_PTR );
217 }
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232 void init_board( unsigned short io_port, int irq, int force_irq )
233 {
234 unsigned int tmp;
235 unsigned int pas_irq_code;
236
237
238
239 outb( 0x30, io_port + P_TIMEOUT_COUNTER_REG );
240 outb( 0x01, io_port + P_TIMEOUT_STATUS_REG_OFFSET );
241 outb( 0x01, io_port + WAIT_STATE );
242
243 NCR5380_read( RESET_PARITY_INTERRUPT_REG );
244
245
246
247
248 pas_irq_code = ( irq < 16 ) ? scsi_irq_translate[irq] : 0;
249 tmp = inb( io_port + IO_CONFIG_3 );
250
251 if( (( tmp & 0x0f ) == pas_irq_code) && pas_irq_code > 0
252 && !force_irq )
253 {
254 printk( "pas16: WARNING: Can't use same irq as sound "
255 "driver -- interrupts disabled\n" );
256
257 outb( 0x4d, io_port + SYS_CONFIG_4 );
258 }
259 else
260 {
261 tmp = ( tmp & 0x0f ) | ( pas_irq_code << 4 );
262 outb( tmp, io_port + IO_CONFIG_3 );
263
264
265 outb( 0x6d, io_port + SYS_CONFIG_4 );
266 }
267 }
268
269
270
271
272
273
274
275
276
277
278
279
280 int pas16_hw_detect( unsigned short board_num )
281 {
282 unsigned char board_rev, tmp;
283 unsigned short io_port = bases[ board_num ].io_port;
284
285
286
287
288
289
290
291
292 enable_board( board_num, io_port );
293
294
295 board_rev = inb( io_port + PCB_CONFIG );
296
297 if( board_rev == 0xff )
298 return 0;
299
300 tmp = board_rev ^ 0xe0;
301
302 outb( tmp, io_port + PCB_CONFIG );
303 tmp = inb( io_port + PCB_CONFIG );
304 outb( board_rev, io_port + PCB_CONFIG );
305
306 if( board_rev != tmp )
307 return 0;
308
309 if( ( inb( io_port + OPERATION_MODE_1 ) & 0x03 ) != 0x03 )
310 return 0;
311
312
313
314
315
316
317 outb( 0x01, io_port + WAIT_STATE );
318 NCR5380_write( MODE_REG, 0x20 );
319 if( NCR5380_read( MODE_REG ) != 0x20 )
320 return 0;
321 NCR5380_write( MODE_REG, 0x00 );
322 if( NCR5380_read( MODE_REG ) != 0x00 )
323 return 0;
324
325 return 1;
326 }
327
328
329
330
331
332
333
334
335
336
337
338
339 void pas16_setup(char *str, int *ints) {
340 static int commandline_current = 0;
341 int i;
342 if (ints[0] != 2)
343 printk("pas16_setup : usage pas16=io_port,irq\n");
344 else
345 if (commandline_current < NO_OVERRIDES) {
346 overrides[commandline_current].io_port = (unsigned short) ints[1];
347 overrides[commandline_current].irq = ints[2];
348 for (i = 0; i < NO_BASES; ++i)
349 if (bases[i].io_port == (unsigned short) ints[1]) {
350 bases[i].noauto = 1;
351 break;
352 }
353 ++commandline_current;
354 }
355 }
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370 int pas16_detect(Scsi_Host_Template * tpnt) {
371 static int current_override = 0;
372 static unsigned short current_base = 0;
373 struct Scsi_Host *instance;
374 unsigned short io_port;
375 int count;
376
377 tpnt->proc_dir = &proc_scsi_pas16;
378 tpnt->proc_info = &pas16_proc_info;
379
380 for (count = 0; current_override < NO_OVERRIDES; ++current_override) {
381 io_port = 0;
382
383 if (overrides[current_override].io_port)
384 {
385 io_port = overrides[current_override].io_port;
386 enable_board( current_override, io_port );
387 init_board( io_port, overrides[current_override].irq, 1 );
388 }
389 else
390 for (; !io_port && (current_base < NO_BASES); ++current_base) {
391 #if (PDEBUG & PDEBUG_INIT)
392 printk("scsi-pas16 : probing io_port %04x\n", (unsigned int) bases[current_base].io_port);
393 #endif
394 if ( !bases[current_base].noauto &&
395 pas16_hw_detect( current_base ) ){
396 io_port = bases[current_base].io_port;
397 init_board( io_port, default_irqs[ current_base ], 0 );
398 #if (PDEBUG & PDEBUG_INIT)
399 printk("scsi-pas16 : detected board.\n");
400 #endif
401 }
402 }
403
404
405 #if defined(PDEBUG) && (PDEBUG & PDEBUG_INIT)
406 printk("scsi-pas16 : io_port = %04x\n", (unsigned int) io_port);
407 #endif
408
409 if (!io_port)
410 break;
411
412 instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
413 instance->io_port = io_port;
414
415 NCR5380_init(instance, 0);
416
417 if (overrides[current_override].irq != IRQ_AUTO)
418 instance->irq = overrides[current_override].irq;
419 else
420 instance->irq = NCR5380_probe_irq(instance, PAS16_IRQS);
421
422 if (instance->irq != IRQ_NONE)
423 if (request_irq(instance->irq, pas16_intr, SA_INTERRUPT, "pas16", NULL)) {
424 printk("scsi%d : IRQ%d not free, interrupts disabled\n",
425 instance->host_no, instance->irq);
426 instance->irq = IRQ_NONE;
427 }
428
429 if (instance->irq == IRQ_NONE) {
430 printk("scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
431 printk("scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
432
433 outb( 0x4d, io_port + SYS_CONFIG_4 );
434 outb( (inb(io_port + IO_CONFIG_3) & 0x0f), io_port + IO_CONFIG_3 );
435 }
436
437 #if defined(PDEBUG) && (PDEBUG & PDEBUG_INIT)
438 printk("scsi%d : irq = %d\n", instance->host_no, instance->irq);
439 #endif
440
441 printk("scsi%d : at 0x%04x", instance->host_no, (int)
442 instance->io_port);
443 if (instance->irq == IRQ_NONE)
444 printk (" interrupts disabled");
445 else
446 printk (" irq %d", instance->irq);
447 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
448 CAN_QUEUE, CMD_PER_LUN, PAS16_PUBLIC_RELEASE);
449 NCR5380_print_options(instance);
450 printk("\n");
451
452 ++current_override;
453 ++count;
454 }
455 return count;
456 }
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478 int pas16_biosparam(Disk * disk, kdev_t dev, int * ip)
479 {
480 int size = disk->capacity;
481 ip[0] = 64;
482 ip[1] = 32;
483 ip[2] = size >> 11;
484 if( ip[2] > 1024 ) {
485 ip[0]=255;
486 ip[1]=63;
487 ip[2]=size/(63*255);
488 if( ip[2] > 1023 )
489 ip[2] = 1023;
490 }
491
492 return 0;
493 }
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508 static inline int NCR5380_pread (struct Scsi_Host *instance, unsigned char *dst,
509 int len) {
510 register unsigned char *d = dst;
511 register unsigned short reg = (unsigned short) (instance->io_port +
512 P_DATA_REG_OFFSET);
513 register i = len;
514 int ii = 0;
515
516 while ( !(inb(instance->io_port + P_STATUS_REG_OFFSET) & P_ST_RDY) )
517 ++ii;
518
519 insb( reg, d, i );
520
521 if ( inb(instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET) & P_TS_TIM) {
522 outb( P_TS_CT, instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET);
523 printk("scsi%d : watchdog timer fired in NCR5380_pread()\n",
524 instance->host_no);
525 return -1;
526 }
527 if (ii > pas_maxi)
528 pas_maxi = ii;
529 return 0;
530 }
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545 static inline int NCR5380_pwrite (struct Scsi_Host *instance, unsigned char *src,
546 int len) {
547 register unsigned char *s = src;
548 register unsigned short reg = (instance->io_port + P_DATA_REG_OFFSET);
549 register i = len;
550 int ii = 0;
551
552 while ( !((inb(instance->io_port + P_STATUS_REG_OFFSET)) & P_ST_RDY) )
553 ++ii;
554
555 outsb( reg, s, i );
556
557 if (inb(instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET) & P_TS_TIM) {
558 outb( P_TS_CT, instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET);
559 printk("scsi%d : watchdog timer fired in NCR5380_pwrite()\n",
560 instance->host_no);
561 return -1;
562 }
563 if (ii > pas_maxi)
564 pas_wmaxi = ii;
565 return 0;
566 }
567
568 #include "NCR5380.c"
569
570 #ifdef MODULE
571
572 Scsi_Host_Template driver_template = MV_PAS16;
573
574 #include <linux/module.h>
575 #include "scsi_module.c"
576 #endif