OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [scsi/] [dec_esp.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 * dec_esp.c: Driver for SCSI chips on IOASIC based TURBOchannel DECstations
3
 *            and TURBOchannel PMAZ-A cards
4
 *
5
 * TURBOchannel changes by Harald Koerfgen
6
 * PMAZ-A support by David Airlie
7
 *
8
 * based on jazz_esp.c:
9
 * Copyright (C) 1997 Thomas Bogendoerfer (tsbogend@alpha.franken.de)
10
 *
11
 * jazz_esp is based on David S. Miller's ESP driver and cyber_esp
12
 *
13
 * 20000819 - Small PMAZ-AA fixes by Florian Lohoff <flo@rfc822.org>
14
 *            Be warned the PMAZ-AA works currently as a single card.
15
 *            Dont try to put multiple cards in one machine - They are
16
 *            both detected but it may crash under high load garbling your
17
 *            data.
18
 * 20001005     - Initialization fixes for 2.4.0-test9
19
 *                        Florian Lohoff <flo@rfc822.org>
20
 *
21
 *      Copyright (C) 2002, 2003  Maciej W. Rozycki
22
 */
23
 
24
#include <linux/kernel.h>
25
#include <linux/delay.h>
26
#include <linux/types.h>
27
#include <linux/string.h>
28
#include <linux/slab.h>
29
#include <linux/blk.h>
30
#include <linux/proc_fs.h>
31
#include <linux/spinlock.h>
32
#include <linux/stat.h>
33
 
34
#include <asm/dma.h>
35
#include <asm/irq.h>
36
#include <asm/pgtable.h>
37
#include <asm/system.h>
38
 
39
#include <asm/dec/interrupts.h>
40
#include <asm/dec/ioasic.h>
41
#include <asm/dec/ioasic_addrs.h>
42
#include <asm/dec/ioasic_ints.h>
43
#include <asm/dec/machtype.h>
44
#include <asm/dec/tc.h>
45
 
46
#include "scsi.h"
47
#include "hosts.h"
48
#include "NCR53C9x.h"
49
#include "dec_esp.h"
50
 
51
 
52
static int  dma_bytes_sent(struct NCR_ESP *esp, int fifo_count);
53
static void dma_drain(struct NCR_ESP *esp);
54
static int  dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd * sp);
55
static void dma_dump_state(struct NCR_ESP *esp);
56
static void dma_init_read(struct NCR_ESP *esp, u32 vaddress, int length);
57
static void dma_init_write(struct NCR_ESP *esp, u32 vaddress, int length);
58
static void dma_ints_off(struct NCR_ESP *esp);
59
static void dma_ints_on(struct NCR_ESP *esp);
60
static int  dma_irq_p(struct NCR_ESP *esp);
61
static int  dma_ports_p(struct NCR_ESP *esp);
62
static void dma_setup(struct NCR_ESP *esp, u32 addr, int count, int write);
63
static void dma_mmu_get_scsi_one(struct NCR_ESP *esp, Scsi_Cmnd * sp);
64
static void dma_mmu_get_scsi_sgl(struct NCR_ESP *esp, Scsi_Cmnd * sp);
65
static void dma_advance_sg(Scsi_Cmnd * sp);
66
 
67
static void pmaz_dma_drain(struct NCR_ESP *esp);
68
static void pmaz_dma_init_read(struct NCR_ESP *esp, u32 vaddress, int length);
69
static void pmaz_dma_init_write(struct NCR_ESP *esp, u32 vaddress, int length);
70
static void pmaz_dma_ints_off(struct NCR_ESP *esp);
71
static void pmaz_dma_ints_on(struct NCR_ESP *esp);
72
static void pmaz_dma_setup(struct NCR_ESP *esp, u32 addr, int count, int write);
73
static void pmaz_dma_mmu_get_scsi_one(struct NCR_ESP *esp, Scsi_Cmnd * sp);
74
 
75
#define TC_ESP_RAM_SIZE 0x20000
76
#define ESP_TGT_DMA_SIZE ((TC_ESP_RAM_SIZE/7) & ~(sizeof(int)-1))
77
#define ESP_NCMD 7
78
 
79
#define TC_ESP_DMAR_MASK  0x1ffff
80
#define TC_ESP_DMAR_WRITE 0x80000000
81
#define TC_ESP_DMA_ADDR(x) ((unsigned)(x) & TC_ESP_DMAR_MASK)
82
 
83
u32 esp_virt_buffer;
84
int scsi_current_length;
85
 
86
volatile unsigned char cmd_buffer[16];
87
volatile unsigned char pmaz_cmd_buffer[16];
88
                                /* This is where all commands are put
89
                                 * before they are trasfered to the ESP chip
90
                                 * via PIO.
91
                                 */
92
 
93
static void scsi_dma_merr_int(int, void *, struct pt_regs *);
94
static void scsi_dma_err_int(int, void *, struct pt_regs *);
95
static void scsi_dma_int(int, void *, struct pt_regs *);
96
 
97
static Scsi_Host_Template driver_template = SCSI_DEC_ESP;
98
 
99
#include "scsi_module.c"
100
 
101
/***************************************************************** Detection */
102
int dec_esp_detect(Scsi_Host_Template * tpnt)
103
{
104
        struct NCR_ESP *esp;
105
        struct ConfigDev *esp_dev;
106
        int slot;
107
        unsigned long mem_start;
108
 
109
        if (IOASIC) {
110
                esp_dev = 0;
111
                esp = esp_allocate(tpnt, (void *) esp_dev);
112
 
113
                /* Do command transfer with programmed I/O */
114
                esp->do_pio_cmds = 1;
115
 
116
                /* Required functions */
117
                esp->dma_bytes_sent = &dma_bytes_sent;
118
                esp->dma_can_transfer = &dma_can_transfer;
119
                esp->dma_dump_state = &dma_dump_state;
120
                esp->dma_init_read = &dma_init_read;
121
                esp->dma_init_write = &dma_init_write;
122
                esp->dma_ints_off = &dma_ints_off;
123
                esp->dma_ints_on = &dma_ints_on;
124
                esp->dma_irq_p = &dma_irq_p;
125
                esp->dma_ports_p = &dma_ports_p;
126
                esp->dma_setup = &dma_setup;
127
 
128
                /* Optional functions */
129
                esp->dma_barrier = 0;
130
                esp->dma_drain = &dma_drain;
131
                esp->dma_invalidate = 0;
132
                esp->dma_irq_entry = 0;
133
                esp->dma_irq_exit = 0;
134
                esp->dma_poll = 0;
135
                esp->dma_reset = 0;
136
                esp->dma_led_off = 0;
137
                esp->dma_led_on = 0;
138
 
139
                /* virtual DMA functions */
140
                esp->dma_mmu_get_scsi_one = &dma_mmu_get_scsi_one;
141
                esp->dma_mmu_get_scsi_sgl = &dma_mmu_get_scsi_sgl;
142
                esp->dma_mmu_release_scsi_one = 0;
143
                esp->dma_mmu_release_scsi_sgl = 0;
144
                esp->dma_advance_sg = &dma_advance_sg;
145
 
146
 
147
                /* SCSI chip speed */
148
                esp->cfreq = 25000000;
149
 
150
                esp->dregs = 0;
151
 
152
                /* ESP register base */
153
                esp->eregs = (struct ESP_regs *) (system_base + IOASIC_SCSI);
154
 
155
                /* Set the command buffer */
156
                esp->esp_command = (volatile unsigned char *) cmd_buffer;
157
 
158
                /* get virtual dma address for command buffer */
159
                esp->esp_command_dvma = virt_to_phys(cmd_buffer);
160
 
161
                esp->irq = dec_interrupt[DEC_IRQ_ASC];
162
 
163
                esp->scsi_id = 7;
164
 
165
                /* Check for differential SCSI-bus */
166
                esp->diff = 0;
167
 
168
                esp_initialize(esp);
169
 
170
                if (request_irq(esp->irq, esp_intr, SA_INTERRUPT,
171
                                "ncr53c94", NULL))
172
                        goto err_dealloc;
173
                if (request_irq(dec_interrupt[DEC_IRQ_ASC_MERR],
174
                                scsi_dma_merr_int, SA_INTERRUPT,
175
                                "ncr53c94 error", NULL))
176
                        goto err_free_irq;
177
                if (request_irq(dec_interrupt[DEC_IRQ_ASC_ERR],
178
                                scsi_dma_err_int, SA_INTERRUPT,
179
                                "ncr53c94 overrun", NULL))
180
                        goto err_free_irq_merr;
181
                if (request_irq(dec_interrupt[DEC_IRQ_ASC_DMA],
182
                                scsi_dma_int, SA_INTERRUPT,
183
                                "ncr53c94 dma", NULL))
184
                        goto err_free_irq_err;
185
 
186
        }
187
 
188
        if (TURBOCHANNEL) {
189
                while ((slot = search_tc_card("PMAZ-AA")) >= 0) {
190
                        claim_tc_card(slot);
191
 
192
                        esp_dev = 0;
193
                        esp = esp_allocate(tpnt, (void *) esp_dev);
194
 
195
                        mem_start = get_tc_base_addr(slot);
196
 
197
                        /* Store base addr into esp struct */
198
                        esp->slot = PHYSADDR(mem_start);
199
 
200
                        esp->dregs = 0;
201
                        esp->eregs = (struct ESP_regs *) (mem_start + DEC_SCSI_SREG);
202
                        esp->do_pio_cmds = 1;
203
 
204
                        /* Set the command buffer */
205
                        esp->esp_command = (volatile unsigned char *) pmaz_cmd_buffer;
206
 
207
                        /* get virtual dma address for command buffer */
208
                        esp->esp_command_dvma = virt_to_phys(pmaz_cmd_buffer);
209
 
210
                        esp->cfreq = get_tc_speed();
211
 
212
                        esp->irq = get_tc_irq_nr(slot);
213
 
214
                        /* Required functions */
215
                        esp->dma_bytes_sent = &dma_bytes_sent;
216
                        esp->dma_can_transfer = &dma_can_transfer;
217
                        esp->dma_dump_state = &dma_dump_state;
218
                        esp->dma_init_read = &pmaz_dma_init_read;
219
                        esp->dma_init_write = &pmaz_dma_init_write;
220
                        esp->dma_ints_off = &pmaz_dma_ints_off;
221
                        esp->dma_ints_on = &pmaz_dma_ints_on;
222
                        esp->dma_irq_p = &dma_irq_p;
223
                        esp->dma_ports_p = &dma_ports_p;
224
                        esp->dma_setup = &pmaz_dma_setup;
225
 
226
                        /* Optional functions */
227
                        esp->dma_barrier = 0;
228
                        esp->dma_drain = &pmaz_dma_drain;
229
                        esp->dma_invalidate = 0;
230
                        esp->dma_irq_entry = 0;
231
                        esp->dma_irq_exit = 0;
232
                        esp->dma_poll = 0;
233
                        esp->dma_reset = 0;
234
                        esp->dma_led_off = 0;
235
                        esp->dma_led_on = 0;
236
 
237
                        esp->dma_mmu_get_scsi_one = pmaz_dma_mmu_get_scsi_one;
238
                        esp->dma_mmu_get_scsi_sgl = 0;
239
                        esp->dma_mmu_release_scsi_one = 0;
240
                        esp->dma_mmu_release_scsi_sgl = 0;
241
                        esp->dma_advance_sg = 0;
242
 
243
                        if (request_irq(esp->irq, esp_intr, SA_INTERRUPT,
244
                                         "PMAZ_AA", NULL)) {
245
                                esp_deallocate(esp);
246
                                release_tc_card(slot);
247
                                continue;
248
                        }
249
                        esp->scsi_id = 7;
250
                        esp->diff = 0;
251
                        esp_initialize(esp);
252
                }
253
        }
254
 
255
        if(nesps) {
256
                printk("ESP: Total of %d ESP hosts found, %d actually in use.\n", nesps, esps_in_use);
257
                esps_running = esps_in_use;
258
                return esps_in_use;
259
        }
260
        return 0;
261
 
262
err_free_irq_err:
263
        free_irq(dec_interrupt[DEC_IRQ_ASC_ERR], scsi_dma_err_int);
264
err_free_irq_merr:
265
        free_irq(dec_interrupt[DEC_IRQ_ASC_MERR], scsi_dma_merr_int);
266
err_free_irq:
267
        free_irq(esp->irq, esp_intr);
268
err_dealloc:
269
        esp_deallocate(esp);
270
        return 0;
271
}
272
 
273
/************************************************************* DMA Functions */
274
static void scsi_dma_merr_int(int irq, void *dev_id, struct pt_regs *regs)
275
{
276
        printk("Got unexpected SCSI DMA Interrupt! < ");
277
        printk("SCSI_DMA_MEMRDERR ");
278
        printk(">\n");
279
}
280
 
281
static void scsi_dma_err_int(int irq, void *dev_id, struct pt_regs *regs)
282
{
283
        /* empty */
284
}
285
 
286
static void scsi_dma_int(int irq, void *dev_id, struct pt_regs *regs)
287
{
288
        u32 scsi_next_ptr;
289
 
290
        scsi_next_ptr = ioasic_read(IO_REG_SCSI_DMA_P);
291
 
292
        /* next page */
293
        scsi_next_ptr = (((scsi_next_ptr >> 3) + PAGE_SIZE) & PAGE_MASK) << 3;
294
        ioasic_write(IO_REG_SCSI_DMA_BP, scsi_next_ptr);
295
        fast_iob();
296
}
297
 
298
static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count)
299
{
300
        return fifo_count;
301
}
302
 
303
static void dma_drain(struct NCR_ESP *esp)
304
{
305
        u32 nw, data0, data1, scsi_data_ptr;
306
        u16 *p;
307
 
308
        nw = ioasic_read(IO_REG_SCSI_SCR);
309
 
310
        /*
311
         * Is there something in the dma buffers left?
312
         */
313
        if (nw) {
314
                scsi_data_ptr = ioasic_read(IO_REG_SCSI_DMA_P) >> 3;
315
                p = phys_to_virt(scsi_data_ptr);
316
                switch (nw) {
317
                case 1:
318
                        data0 = ioasic_read(IO_REG_SCSI_SDR0);
319
                        p[0] = data0 & 0xffff;
320
                        break;
321
                case 2:
322
                        data0 = ioasic_read(IO_REG_SCSI_SDR0);
323
                        p[0] = data0 & 0xffff;
324
                        p[1] = (data0 >> 16) & 0xffff;
325
                        break;
326
                case 3:
327
                        data0 = ioasic_read(IO_REG_SCSI_SDR0);
328
                        data1 = ioasic_read(IO_REG_SCSI_SDR1);
329
                        p[0] = data0 & 0xffff;
330
                        p[1] = (data0 >> 16) & 0xffff;
331
                        p[2] = data1 & 0xffff;
332
                        break;
333
                default:
334
                        printk("Strange: %d words in dma buffer left\n", nw);
335
                        break;
336
                }
337
        }
338
}
339
 
340
static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd * sp)
341
{
342
        return sp->SCp.this_residual;;
343
}
344
 
345
static void dma_dump_state(struct NCR_ESP *esp)
346
{
347
}
348
 
349
static void dma_init_read(struct NCR_ESP *esp, u32 vaddress, int length)
350
{
351
        u32 scsi_next_ptr, ioasic_ssr;
352
        unsigned long flags;
353
 
354
        if (vaddress & 3)
355
                panic("dec_esp.c: unable to handle partial word transfers, yet...");
356
 
357
        dma_cache_wback_inv((unsigned long) phys_to_virt(vaddress), length);
358
 
359
        spin_lock_irqsave(&ioasic_ssr_lock, flags);
360
 
361
        fast_mb();
362
        ioasic_ssr = ioasic_read(IO_REG_SSR);
363
 
364
        ioasic_ssr &= ~IO_SSR_SCSI_DMA_EN;
365
        ioasic_write(IO_REG_SSR, ioasic_ssr);
366
 
367
        fast_wmb();
368
        ioasic_write(IO_REG_SCSI_SCR, 0);
369
        ioasic_write(IO_REG_SCSI_DMA_P, vaddress << 3);
370
 
371
        /* prepare for next page */
372
        scsi_next_ptr = ((vaddress + PAGE_SIZE) & PAGE_MASK) << 3;
373
        ioasic_write(IO_REG_SCSI_DMA_BP, scsi_next_ptr);
374
 
375
        ioasic_ssr |= (IO_SSR_SCSI_DMA_DIR | IO_SSR_SCSI_DMA_EN);
376
        fast_wmb();
377
        ioasic_write(IO_REG_SSR, ioasic_ssr);
378
 
379
        fast_iob();
380
        spin_unlock_irqrestore(&ioasic_ssr_lock, flags);
381
}
382
 
383
static void dma_init_write(struct NCR_ESP *esp, u32 vaddress, int length)
384
{
385
        u32 scsi_next_ptr, ioasic_ssr;
386
        unsigned long flags;
387
 
388
        if (vaddress & 3)
389
                panic("dec_esp.c: unable to handle partial word transfers, yet...");
390
 
391
        dma_cache_wback_inv((unsigned long) phys_to_virt(vaddress), length);
392
 
393
        spin_lock_irqsave(&ioasic_ssr_lock, flags);
394
 
395
        fast_mb();
396
        ioasic_ssr = ioasic_read(IO_REG_SSR);
397
 
398
        ioasic_ssr &= ~(IO_SSR_SCSI_DMA_DIR | IO_SSR_SCSI_DMA_EN);
399
        ioasic_write(IO_REG_SSR, ioasic_ssr);
400
 
401
        fast_wmb();
402
        ioasic_write(IO_REG_SCSI_SCR, 0);
403
        ioasic_write(IO_REG_SCSI_DMA_P, vaddress << 3);
404
 
405
        /* prepare for next page */
406
        scsi_next_ptr = ((vaddress + PAGE_SIZE) & PAGE_MASK) << 3;
407
        ioasic_write(IO_REG_SCSI_DMA_BP, scsi_next_ptr);
408
 
409
        ioasic_ssr |= IO_SSR_SCSI_DMA_EN;
410
        fast_wmb();
411
        ioasic_write(IO_REG_SSR, ioasic_ssr);
412
 
413
        fast_iob();
414
        spin_unlock_irqrestore(&ioasic_ssr_lock, flags);
415
}
416
 
417
static void dma_ints_off(struct NCR_ESP *esp)
418
{
419
        disable_irq(dec_interrupt[DEC_IRQ_ASC_DMA]);
420
}
421
 
422
static void dma_ints_on(struct NCR_ESP *esp)
423
{
424
        enable_irq(dec_interrupt[DEC_IRQ_ASC_DMA]);
425
}
426
 
427
static int dma_irq_p(struct NCR_ESP *esp)
428
{
429
        return (esp->eregs->esp_status & ESP_STAT_INTR);
430
}
431
 
432
static int dma_ports_p(struct NCR_ESP *esp)
433
{
434
        /*
435
         * FIXME: what's this good for?
436
         */
437
        return 1;
438
}
439
 
440
static void dma_setup(struct NCR_ESP *esp, u32 addr, int count, int write)
441
{
442
        /*
443
         * DMA_ST_WRITE means "move data from device to memory"
444
         * so when (write) is true, it actually means READ!
445
         */
446
        if (write)
447
                dma_init_read(esp, addr, count);
448
        else
449
                dma_init_write(esp, addr, count);
450
}
451
 
452
static void dma_mmu_get_scsi_one(struct NCR_ESP *esp, Scsi_Cmnd * sp)
453
{
454
        sp->SCp.ptr = (char *)virt_to_phys(sp->request_buffer);
455
}
456
 
457
static void dma_mmu_get_scsi_sgl(struct NCR_ESP *esp, Scsi_Cmnd * sp)
458
{
459
        int sz = sp->SCp.buffers_residual;
460
        struct scatterlist *sg = sp->SCp.buffer;
461
 
462
        while (sz >= 0) {
463
                sg[sz].dma_address = virt_to_phys(sg[sz].address);
464
                sz--;
465
        }
466
        sp->SCp.ptr = (char *)(sp->SCp.buffer->dma_address);
467
}
468
 
469
static void dma_advance_sg(Scsi_Cmnd * sp)
470
{
471
        sp->SCp.ptr = (char *)(sp->SCp.buffer->dma_address);
472
}
473
 
474
static void pmaz_dma_drain(struct NCR_ESP *esp)
475
{
476
        memcpy(phys_to_virt(esp_virt_buffer),
477
                (void *)KSEG1ADDR(esp->slot + DEC_SCSI_SRAM + ESP_TGT_DMA_SIZE),
478
                scsi_current_length);
479
}
480
 
481
static void pmaz_dma_init_read(struct NCR_ESP *esp, u32 vaddress, int length)
482
{
483
        volatile u32 *dmareg =
484
                (volatile u32 *)KSEG1ADDR(esp->slot + DEC_SCSI_DMAREG);
485
 
486
        if (length > ESP_TGT_DMA_SIZE)
487
                length = ESP_TGT_DMA_SIZE;
488
 
489
        *dmareg = TC_ESP_DMA_ADDR(ESP_TGT_DMA_SIZE);
490
 
491
        iob();
492
 
493
        esp_virt_buffer = vaddress;
494
        scsi_current_length = length;
495
}
496
 
497
static void pmaz_dma_init_write(struct NCR_ESP *esp, u32 vaddress, int length)
498
{
499
        volatile u32 *dmareg =
500
                (volatile u32 *)KSEG1ADDR(esp->slot + DEC_SCSI_DMAREG);
501
 
502
        memcpy((void *)KSEG1ADDR(esp->slot + DEC_SCSI_SRAM + ESP_TGT_DMA_SIZE),
503
               phys_to_virt(vaddress), length);
504
 
505
        wmb();
506
        *dmareg = TC_ESP_DMAR_WRITE | TC_ESP_DMA_ADDR(ESP_TGT_DMA_SIZE);
507
 
508
        iob();
509
}
510
 
511
static void pmaz_dma_ints_off(struct NCR_ESP *esp)
512
{
513
}
514
 
515
static void pmaz_dma_ints_on(struct NCR_ESP *esp)
516
{
517
}
518
 
519
static void pmaz_dma_setup(struct NCR_ESP *esp, u32 addr, int count, int write)
520
{
521
        /*
522
         * DMA_ST_WRITE means "move data from device to memory"
523
         * so when (write) is true, it actually means READ!
524
         */
525
        if (write)
526
                pmaz_dma_init_read(esp, addr, count);
527
        else
528
                pmaz_dma_init_write(esp, addr, count);
529
}
530
 
531
static void pmaz_dma_mmu_get_scsi_one(struct NCR_ESP *esp, Scsi_Cmnd * sp)
532
{
533
        sp->SCp.ptr = (char *)virt_to_phys(sp->request_buffer);
534
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.