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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [rc203soc/] [sw/] [uClinux/] [arch/] [armnommu/] [drivers/] [scsi/] [powertec.c] - Blame information for rev 1622

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1622 jcastillo
/*
2
 * linux/arch/arm/drivers/scsi/powertec.c
3
 *
4
 * Copyright (C) 1997-1998 Russell King
5
 *
6
 * This driver is based on experimentation.  Hence, it may have made
7
 * assumptions about the particular card that I have available, and
8
 * may not be reliable!
9
 *
10
 * Changelog:
11
 *  01-10-1997  RMK     Created, READONLY version.
12
 *  15-02-1998  RMK     Added DMA support and hardware definitions.
13
 *  15-04-1998  RMK     Only do PIO if FAS216 will allow it.
14
 *  02-05-1998  RMK     Moved DMA sg list into per-interface structure.
15
 */
16
 
17
#include <linux/module.h>
18
#include <linux/blk.h>
19
#include <linux/kernel.h>
20
#include <linux/string.h>
21
#include <linux/ioport.h>
22
#include <linux/sched.h>
23
#include <linux/proc_fs.h>
24
#include <linux/unistd.h>
25
#include <linux/stat.h>
26
 
27
#include <asm/delay.h>
28
#include <asm/dma.h>
29
#include <asm/ecard.h>
30
#include <asm/io.h>
31
#include <asm/irq.h>
32
#include <asm/pgtable.h>
33
 
34
#include "sd.h"
35
#include "hosts.h"
36
#include "powertec.h"
37
 
38
/* Configuration */
39
#define POWERTEC_XTALFREQ       40
40
#define POWERTEC_ASYNC_PERIOD   200
41
#define POWERTEC_SYNC_DEPTH     7
42
 
43
/*
44
 * List of devices that the driver will recognise
45
 */
46
#define POWERTECSCSI_LIST       { MANU_ALSYSTEMS, PROD_ALSYS_SCSIATAPI }
47
 
48
#define POWERTEC_FAS216_OFFSET  0xc00
49
#define POWERTEC_FAS216_SHIFT   4
50
 
51
#define POWERTEC_INTR_STATUS    0x800
52
#define POWERTEC_INTR_BIT       0x80
53
 
54
#define POWERTEC_RESET_CONTROL  0x406
55
#define POWERTEC_RESET_BIT      1
56
 
57
#define POWERTEC_TERM_CONTROL   0x806
58
#define POWERTEC_TERM_ENABLE    1
59
 
60
#define POWERTEC_INTR_CONTROL   0x407
61
#define POWERTEC_INTR_ENABLE    1
62
#define POWERTEC_INTR_DISABLE   0
63
 
64
/*
65
 * Version
66
 */
67
#define VER_MAJOR       0
68
#define VER_MINOR       0
69
#define VER_PATCH       2
70
 
71
static struct expansion_card *ecs[MAX_ECARDS];
72
 
73
/*
74
 * Use term=0,1,0,0,0 to turn terminators on/off
75
 */
76
int term[MAX_ECARDS] = { 1, 1, 1, 1, 1, 1, 1, 1 };
77
 
78
static struct proc_dir_entry proc_scsi_powertec = {
79
        PROC_SCSI_QLOGICISP, 8, "powertec",
80
        S_IFDIR | S_IRUGO | S_IXUGO, 2
81
};
82
 
83
/* Prototype: void powertecscsi_irqenable(ec, irqnr)
84
 * Purpose  : Enable interrupts on Powertec SCSI card
85
 * Params   : ec    - expansion card structure
86
 *          : irqnr - interrupt number
87
 */
88
static void
89
powertecscsi_irqenable(struct expansion_card *ec, int irqnr)
90
{
91
        unsigned int port = (unsigned int)ec->irq_data;
92
        outb(POWERTEC_INTR_ENABLE, port);
93
}
94
 
95
/* Prototype: void powertecscsi_irqdisable(ec, irqnr)
96
 * Purpose  : Disable interrupts on Powertec SCSI card
97
 * Params   : ec    - expansion card structure
98
 *          : irqnr - interrupt number
99
 */
100
static void
101
powertecscsi_irqdisable(struct expansion_card *ec, int irqnr)
102
{
103
        unsigned int port = (unsigned int)ec->irq_data;
104
        outb(POWERTEC_INTR_DISABLE, port);
105
}
106
 
107
static const expansioncard_ops_t powertecscsi_ops = {
108
        powertecscsi_irqenable,
109
        powertecscsi_irqdisable,
110
        NULL,
111
        NULL,
112
        NULL,
113
        NULL
114
};
115
 
116
/* Prototype: void powertecscsi_terminator_ctl(host, on_off)
117
 * Purpose  : Turn the Powertec SCSI terminators on or off
118
 * Params   : host   - card to turn on/off
119
 *          : on_off - !0 to turn on, 0 to turn off
120
 */
121
static void
122
powertecscsi_terminator_ctl(struct Scsi_Host *host, int on_off)
123
{
124
        PowerTecScsi_Info *info = (PowerTecScsi_Info *)host->hostdata;
125
 
126
        if (on_off)
127
                info->control.terms = POWERTEC_TERM_ENABLE;
128
        else
129
                info->control.terms = 0;
130
 
131
        outb(info->control.terms, info->control.term_port);
132
}
133
 
134
/* Prototype: void powertecscsi_intr(irq, *dev_id, *regs)
135
 * Purpose  : handle interrupts from Powertec SCSI card
136
 * Params   : irq    - interrupt number
137
 *            dev_id - user-defined (Scsi_Host structure)
138
 *            regs   - processor registers at interrupt
139
 */
140
static void
141
powertecscsi_intr(int irq, void *dev_id, struct pt_regs *regs)
142
{
143
        struct Scsi_Host *host = (struct Scsi_Host *)dev_id;
144
 
145
        fas216_intr(host);
146
}
147
 
148
static void
149
powertecscsi_invalidate(char *addr, long len, fasdmadir_t direction)
150
{
151
        unsigned int page;
152
 
153
        if (direction == DMA_OUT) {
154
                for (page = (unsigned int) addr; len > 0;
155
                     page += PAGE_SIZE, len -= PAGE_SIZE)
156
                        flush_page_to_ram(page);
157
        } else
158
                flush_cache_range(current->mm, (unsigned long)addr,
159
                                  (unsigned long)addr + len);
160
}
161
 
162
/* Prototype: fasdmatype_t powertecscsi_dma_setup(host, SCpnt, direction, min_type)
163
 * Purpose  : initialises DMA/PIO
164
 * Params   : host      - host
165
 *            SCpnt     - command
166
 *            direction - DMA on to/off of card
167
 *            min_type  - minimum DMA support that we must have for this transfer
168
 * Returns  : type of transfer to be performed
169
 */
170
static fasdmatype_t
171
powertecscsi_dma_setup(struct Scsi_Host *host, Scsi_Pointer *SCp,
172
                       fasdmadir_t direction, fasdmatype_t min_type)
173
{
174
        PowerTecScsi_Info *info = (PowerTecScsi_Info *)host->hostdata;
175
        int dmach = host->dma_channel;
176
 
177
        if (dmach != NO_DMA &&
178
            (min_type == fasdma_real_all || SCp->this_residual >= 512)) {
179
                int buf;
180
 
181
                for (buf = 1; buf <= SCp->buffers_residual &&
182
                              buf < NR_SG; buf++) {
183
                        info->dmasg[buf].address = __virt_to_bus(
184
                                (unsigned long)SCp->buffer[buf].address);
185
                        info->dmasg[buf].length = SCp->buffer[buf].length;
186
 
187
                        powertecscsi_invalidate(SCp->buffer[buf].address,
188
                                                SCp->buffer[buf].length,
189
                                                direction);
190
                }
191
 
192
                info->dmasg[0].address = __virt_to_phys((unsigned long)SCp->ptr);
193
                info->dmasg[0].length = SCp->this_residual;
194
                powertecscsi_invalidate(SCp->ptr,
195
                                        SCp->this_residual, direction);
196
 
197
                disable_dma(dmach);
198
                set_dma_sg(dmach, info->dmasg, buf);
199
                set_dma_mode(dmach,
200
                             direction == DMA_OUT ? DMA_MODE_WRITE :
201
                                                    DMA_MODE_READ);
202
                enable_dma(dmach);
203
                return fasdma_real_all;
204
        }
205
 
206
        /*
207
         * If we're not doing DMA,
208
         *  we'll do slow PIO
209
         */
210
        return fasdma_pio;
211
}
212
 
213
/* Prototype: int powertecscsi_dma_stop(host, SCpnt)
214
 * Purpose  : stops DMA/PIO
215
 * Params   : host  - host
216
 *            SCpnt - command
217
 */
218
static void
219
powertecscsi_dma_stop(struct Scsi_Host *host, Scsi_Pointer *SCp)
220
{
221
        if (host->dma_channel != NO_DMA)
222
                disable_dma(host->dma_channel);
223
}
224
 
225
/* Prototype: int powertecscsi_detect(Scsi_Host_Template * tpnt)
226
 * Purpose  : initialises PowerTec SCSI driver
227
 * Params   : tpnt - template for this SCSI adapter
228
 * Returns  : >0 if host found, 0 otherwise.
229
 */
230
int
231
powertecscsi_detect(Scsi_Host_Template *tpnt)
232
{
233
        static const card_ids powertecscsi_cids[] =
234
                        { POWERTECSCSI_LIST, { 0xffff, 0xffff} };
235
        int count = 0;
236
        struct Scsi_Host *host;
237
 
238
        tpnt->proc_dir = &proc_scsi_powertec;
239
        memset(ecs, 0, sizeof (ecs));
240
 
241
        ecard_startfind();
242
 
243
        while (1) {
244
                PowerTecScsi_Info *info;
245
 
246
                ecs[count] = ecard_find(0, powertecscsi_cids);
247
                if (!ecs[count])
248
                        break;
249
 
250
                ecard_claim(ecs[count]);
251
 
252
                host = scsi_register(tpnt, sizeof (PowerTecScsi_Info));
253
                if (!host) {
254
                        ecard_release(ecs[count]);
255
                        break;
256
                }
257
 
258
                host->io_port = ecard_address(ecs[count], ECARD_IOC, ECARD_FAST);
259
                host->irq = ecs[count]->irq;
260
                host->dma_channel = ecs[count]->dma;
261
                info = (PowerTecScsi_Info *)host->hostdata;
262
 
263
                info->control.term_port = host->io_port + POWERTEC_TERM_CONTROL;
264
                info->control.terms = term[count] ? POWERTEC_TERM_ENABLE : 0;
265
                powertecscsi_terminator_ctl(host, info->control.terms);
266
 
267
                info->info.scsi.io_port =
268
                                host->io_port + POWERTEC_FAS216_OFFSET;
269
                info->info.scsi.io_shift= POWERTEC_FAS216_SHIFT;
270
                info->info.scsi.irq             = host->irq;
271
                info->info.ifcfg.clockrate      = POWERTEC_XTALFREQ;
272
                info->info.ifcfg.select_timeout = 255;
273
                info->info.ifcfg.asyncperiod    = POWERTEC_ASYNC_PERIOD;
274
                info->info.ifcfg.sync_max_depth = POWERTEC_SYNC_DEPTH;
275
                info->info.ifcfg.cntl3          = /*CNTL3_BS8 |*/ CNTL3_FASTSCSI | CNTL3_FASTCLK;
276
                info->info.ifcfg.disconnect_ok  = 1;
277
                info->info.ifcfg.wide_max_size  = 0;
278
                info->info.dma.setup            = powertecscsi_dma_setup;
279
                info->info.dma.pseudo           = NULL;
280
                info->info.dma.stop             = powertecscsi_dma_stop;
281
 
282
                ecs[count]->irqaddr     = (unsigned char *)
283
                            ioaddr(host->io_port + POWERTEC_INTR_STATUS);
284
                ecs[count]->irqmask     = POWERTEC_INTR_BIT;
285
                ecs[count]->irq_data    = (void *)
286
                            (host->io_port + POWERTEC_INTR_CONTROL);
287
                ecs[count]->ops         = (expansioncard_ops_t *)&powertecscsi_ops;
288
 
289
                request_region(host->io_port + POWERTEC_FAS216_OFFSET,
290
                               16 << POWERTEC_FAS216_SHIFT, "powertec2-fas");
291
 
292
                if (host->irq != NO_IRQ &&
293
                    request_irq(host->irq, powertecscsi_intr,
294
                                SA_INTERRUPT, "powertec", host)) {
295
                        printk("scsi%d: IRQ%d not free, interrupts disabled\n",
296
                               host->host_no, host->irq);
297
                        host->irq = NO_IRQ;
298
                        info->info.scsi.irq = NO_IRQ;
299
                }
300
 
301
                if (host->dma_channel != NO_DMA &&
302
                    request_dma(host->dma_channel, "powertec")) {
303
                        printk("scsi%d: DMA%d not free, DMA disabled\n",
304
                               host->host_no, host->dma_channel);
305
                        host->dma_channel = NO_DMA;
306
                }
307
 
308
                fas216_init(host);
309
                ++count;
310
        }
311
        return count;
312
}
313
 
314
/* Prototype: int powertecscsi_release(struct Scsi_Host * host)
315
 * Purpose  : releases all resources used by this adapter
316
 * Params   : host - driver host structure to return info for.
317
 */
318
int powertecscsi_release(struct Scsi_Host *host)
319
{
320
        int i;
321
 
322
        fas216_release(host);
323
 
324
        if (host->irq != NO_IRQ)
325
                free_irq(host->irq, host);
326
        if (host->dma_channel != NO_DMA)
327
                free_dma(host->dma_channel);
328
        release_region(host->io_port + POWERTEC_FAS216_OFFSET,
329
                       16 << POWERTEC_FAS216_SHIFT);
330
 
331
        for (i = 0; i < MAX_ECARDS; i++)
332
                if (ecs[i] &&
333
                    host->io_port == ecard_address(ecs[i], ECARD_IOC, ECARD_FAST))
334
                        ecard_release(ecs[i]);
335
        return 0;
336
}
337
 
338
/* Prototype: const char *powertecscsi_info(struct Scsi_Host * host)
339
 * Purpose  : returns a descriptive string about this interface,
340
 * Params   : host - driver host structure to return info for.
341
 * Returns  : pointer to a static buffer containing null terminated string.
342
 */
343
const char *powertecscsi_info(struct Scsi_Host *host)
344
{
345
        PowerTecScsi_Info *info = (PowerTecScsi_Info *)host->hostdata;
346
        static char string[100], *p;
347
 
348
        p = string;
349
        p += sprintf(string, "%s at port %X ",
350
                     host->hostt->name, host->io_port);
351
 
352
        if (host->irq != NO_IRQ)
353
                p += sprintf(p, "irq %d ", host->irq);
354
        else
355
                p += sprintf(p, "NO IRQ ");
356
 
357
        if (host->dma_channel != NO_DMA)
358
                p += sprintf(p, "dma %d ", host->dma_channel);
359
        else
360
                p += sprintf(p, "NO DMA ");
361
 
362
        p += sprintf(p, "v%d.%d.%d scsi %s",
363
                     VER_MAJOR, VER_MINOR, VER_PATCH,
364
                     info->info.scsi.type);
365
 
366
        p += sprintf(p, " terminators %s",
367
                     info->control.terms ? "on" : "off");
368
 
369
        return string;
370
}
371
 
372
/* Prototype: int powertecscsi_set_proc_info(struct Scsi_Host *host, char *buffer, int length)
373
 * Purpose  : Set a driver specific function
374
 * Params   : host   - host to setup
375
 *          : buffer - buffer containing string describing operation
376
 *          : length - length of string
377
 * Returns  : -EINVAL, or 0
378
 */
379
static int
380
powertecscsi_set_proc_info(struct Scsi_Host *host, char *buffer, int length)
381
{
382
        int ret = length;
383
 
384
        if (length >= 12 && strncmp(buffer, "POWERTECSCSI", 12) == 0) {
385
                buffer += 12;
386
                length -= 12;
387
 
388
                if (length >= 5 && strncmp(buffer, "term=", 5) == 0) {
389
                        if (buffer[5] == '1')
390
                                powertecscsi_terminator_ctl(host, 1);
391
                        else if (buffer[5] == '0')
392
                                powertecscsi_terminator_ctl(host, 0);
393
                        else
394
                                ret = -EINVAL;
395
                } else
396
                        ret = -EINVAL;
397
        } else
398
                ret = -EINVAL;
399
 
400
        return ret;
401
}
402
 
403
/* Prototype: int powertecscsi_proc_info(char *buffer, char **start, off_t offset,
404
 *                                      int length, int host_no, int inout)
405
 * Purpose  : Return information about the driver to a user process accessing
406
 *            the /proc filesystem.
407
 * Params   : buffer - a buffer to write information to
408
 *            start  - a pointer into this buffer set by this routine to the start
409
 *                     of the required information.
410
 *            offset - offset into information that we have read upto.
411
 *            length - length of buffer
412
 *            host_no - host number to return information for
413
 *            inout  - 0 for reading, 1 for writing.
414
 * Returns  : length of data written to buffer.
415
 */
416
int powertecscsi_proc_info(char *buffer, char **start, off_t offset,
417
                            int length, int host_no, int inout)
418
{
419
        int pos, begin, first;
420
        struct Scsi_Host *host = scsi_hostlist;
421
        PowerTecScsi_Info *info;
422
        Scsi_Device *scd;
423
 
424
        while (host) {
425
                if (host->host_no == host_no)
426
                        break;
427
                host = host->next;
428
        }
429
        if (!host)
430
                return 0;
431
 
432
        if (inout == 1)
433
                return powertecscsi_set_proc_info(host, buffer, length);
434
 
435
        info = (PowerTecScsi_Info *)host->hostdata;
436
 
437
        begin = 0;
438
        pos = sprintf(buffer,
439
                        "PowerTec SCSI driver version %d.%d.%d\n",
440
                        VER_MAJOR, VER_MINOR, VER_PATCH);
441
        pos += sprintf(buffer + pos,
442
                        "Address: %08X    IRQ : %d     DMA : %d\n"
443
                        "FAS    : %-10s  TERM: %-3s\n\n"
444
                        "Statistics:\n",
445
                        host->io_port, host->irq, host->dma_channel,
446
                        info->info.scsi.type, info->control.terms ? "on" : "off");
447
 
448
        pos += fas216_print_stats(&info->info, buffer + pos);
449
 
450
        first = 1;
451
        pos += sprintf(buffer+pos, "\nAttached devices:");
452
 
453
        for (scd = scsi_devices; scd; scd = scd->next) {
454
                if (scd->host == host) {
455
                        if (first) {
456
                                pos += sprintf(buffer+pos, "\n");
457
                                first = 0;
458
                        }
459
 
460
                        pos += fas216_print_device(&info->info, scd, buffer + pos);
461
 
462
                        if (pos + begin < offset) {
463
                                begin += pos;
464
                                pos = 0;
465
                        }
466
                        if (pos + begin > offset + length)
467
                                break;
468
                }
469
        }
470
 
471
        if (first)
472
                pos += sprintf(buffer + pos, " none\n");
473
 
474
        *start = buffer + (offset - begin);
475
        pos -= offset - begin;
476
        if (pos > length)
477
                pos = length;
478
 
479
        return pos;
480
}
481
 
482
#ifdef MODULE
483
Scsi_Host_Template driver_template = POWERTECSCSI;
484
 
485
#include "scsi_module.c"
486
#endif

powered by: WebSVN 2.1.0

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