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

Subversion Repositories or1k

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/* -*- mode: c; c-basic-offset: 8 -*- */
2
 
3
/* NCR Dual 700 MCA SCSI Driver
4
 *
5
 * Copyright (C) 2001 by James.Bottomley@HansenPartnership.com
6
**-----------------------------------------------------------------------------
7
**
8
**  This program is free software; you can redistribute it and/or modify
9
**  it under the terms of the GNU General Public License as published by
10
**  the Free Software Foundation; either version 2 of the License, or
11
**  (at your option) any later version.
12
**
13
**  This program is distributed in the hope that it will be useful,
14
**  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
**  GNU General Public License for more details.
17
**
18
**  You should have received a copy of the GNU General Public License
19
**  along with this program; if not, write to the Free Software
20
**  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
**
22
**-----------------------------------------------------------------------------
23
 */
24
 
25
/* Notes:
26
 *
27
 * Most of the work is done in the chip specific module, 53c700.o
28
 *
29
 * TODO List:
30
 *
31
 * 1. Extract the SCSI ID from the voyager CMOS table (necessary to
32
 *    support multi-host environments.
33
 *
34
 * */
35
 
36
 
37
/* CHANGELOG
38
 *
39
 * Version 2.2
40
 *
41
 * Added mca_set_adapter_name().
42
 *
43
 * Version 2.1
44
 *
45
 * Modularise the driver into a Board piece (this file) and a chip
46
 * piece 53c700.[ch] and 53c700.scr, added module options.  You can
47
 * now specify the scsi id by the parameters
48
 *
49
 * NCR_D700=slot:<n> [siop:<n>] id:<n> ....
50
 *
51
 * They need to be comma separated if compiled into the kernel
52
 *
53
 * Version 2.0
54
 *
55
 * Initial implementation of TCQ (Tag Command Queueing).  TCQ is full
56
 * featured and uses the clock algorithm to keep track of outstanding
57
 * tags and guard against individual tag starvation.  Also fixed a bug
58
 * in all of the 1.x versions where the D700_data_residue() function
59
 * was returning results off by 32 bytes (and thus causing the same 32
60
 * bytes to be written twice corrupting the data block).  It turns out
61
 * the 53c700 only has a 6 bit DBC and DFIFO registers not 7 bit ones
62
 * like the 53c710 (The 710 is the only data manual still available,
63
 * which I'd been using to program the 700).
64
 *
65
 * Version 1.2
66
 *
67
 * Much improved message handling engine
68
 *
69
 * Version 1.1
70
 *
71
 * Add code to handle selection reasonably correctly.  By the time we
72
 * get the selection interrupt, we've already responded, but drop off the
73
 * bus and hope the selector will go away.
74
 *
75
 * Version 1.0:
76
 *
77
 *   Initial release.  Fully functional except for procfs and tag
78
 * command queueing.  Has only been tested on cards with 53c700-66
79
 * chips and only single ended. Features are
80
 *
81
 * 1. Synchronous data transfers to offset 8 (limit of 700-66) and
82
 *    100ns (10MHz) limit of SCSI-2
83
 *
84
 * 2. Disconnection and reselection
85
 *
86
 * Testing:
87
 *
88
 *  I've only really tested this with the 700-66 chip, but have done
89
 * soak tests in multi-device environments to verify that
90
 * disconnections and reselections are being processed correctly.
91
 * */
92
 
93
#define NCR_D700_VERSION "2.2"
94
 
95
#include <linux/config.h>
96
#include <linux/version.h>
97
#include <linux/kernel.h>
98
#include <linux/types.h>
99
#include <linux/string.h>
100
#include <linux/spinlock.h>
101
#include <linux/ioport.h>
102
#include <linux/delay.h>
103
#include <linux/sched.h>
104
#include <linux/proc_fs.h>
105
#include <linux/init.h>
106
#include <linux/mca.h>
107
#include <asm/dma.h>
108
#include <asm/system.h>
109
#include <asm/io.h>
110
#include <asm/pgtable.h>
111
#include <asm/byteorder.h>
112
#include <linux/blk.h>
113
#include <linux/module.h>
114
 
115
 
116
#include "scsi.h"
117
#include "hosts.h"
118
#include "constants.h"
119
 
120
#include "53c700.h"
121
#include "NCR_D700.h"
122
 
123
#ifndef CONFIG_MCA
124
#error "NCR_D700 driver only compiles for MCA"
125
#endif
126
 
127
#ifdef NCR_D700_DEBUG
128
#define STATIC
129
#else
130
#define STATIC static
131
#endif
132
 
133
char *NCR_D700;                 /* command line from insmod */
134
 
135
MODULE_AUTHOR("James Bottomley");
136
MODULE_DESCRIPTION("NCR Dual700 SCSI Driver");
137
MODULE_LICENSE("GPL");
138
MODULE_PARM(NCR_D700, "s");
139
 
140
static __u8 __initdata id_array[2*(MCA_MAX_SLOT_NR + 1)] =
141
        { [0 ... 2*(MCA_MAX_SLOT_NR + 1)-1] = 7 };
142
 
143
#ifdef MODULE
144
#define ARG_SEP ' '
145
#else
146
#define ARG_SEP ','
147
#endif
148
 
149
static int __init
150
param_setup(char *string)
151
{
152
        char *pos = string, *next;
153
        int slot = -1, siop = -1;
154
 
155
        while(pos != NULL && (next = strchr(pos, ':')) != NULL) {
156
                int val = (int)simple_strtoul(++next, NULL, 0);
157
 
158
                if(!strncmp(pos, "slot:", 5))
159
                        slot = val;
160
                else if(!strncmp(pos, "siop:", 5))
161
                        siop = val;
162
                else if(!strncmp(pos, "id:", 3)) {
163
                        if(slot == -1) {
164
                                printk(KERN_WARNING "NCR D700: Must specify slot for id parameter\n");
165
                        } else if(slot > MCA_MAX_SLOT_NR) {
166
                                printk(KERN_WARNING "NCR D700: Illegal slot %d for id %d\n", slot, val);
167
                        } else {
168
                                if(siop != 0 && siop != 1) {
169
                                        id_array[slot*2] = val;
170
                                        id_array[slot*2 + 1] =val;
171
                                } else {
172
                                        id_array[slot*2 + siop] = val;
173
                                }
174
                        }
175
                }
176
                if((pos = strchr(pos, ARG_SEP)) != NULL)
177
                        pos++;
178
        }
179
        return 1;
180
}
181
 
182
#ifndef MODULE
183
__setup("NCR_D700=", param_setup);
184
#endif
185
 
186
/* Detect a D700 card.  Note, because of the set up---the chips are
187
 * essentially connectecd to the MCA bus independently, it is easier
188
 * to set them up as two separate host adapters, rather than one
189
 * adapter with two channels */
190
STATIC int __init
191
D700_detect(Scsi_Host_Template *tpnt)
192
{
193
        int slot = 0;
194
        int found = 0;
195
        int differential;
196
        int banner = 1;
197
 
198
        if(!MCA_bus)
199
                return 0;
200
 
201
#ifdef MODULE
202
        if(NCR_D700)
203
                param_setup(NCR_D700);
204
#endif
205
 
206
        for(slot = 0; (slot = mca_find_adapter(NCR_D700_MCA_ID, slot)) != MCA_NOTFOUND; slot++) {
207
                int irq, i;
208
                int pos3j, pos3k, pos3a, pos3b, pos4;
209
                __u32 base_addr, offset_addr;
210
                struct Scsi_Host *host = NULL;
211
 
212
                /* enable board interrupt */
213
                pos4 = mca_read_pos(slot, 4);
214
                pos4 |= 0x4;
215
                mca_write_pos(slot, 4, pos4);
216
 
217
                mca_write_pos(slot, 6, 9);
218
                pos3j = mca_read_pos(slot, 3);
219
                mca_write_pos(slot, 6, 10);
220
                pos3k = mca_read_pos(slot, 3);
221
                mca_write_pos(slot, 6, 0);
222
                pos3a = mca_read_pos(slot, 3);
223
                mca_write_pos(slot, 6, 1);
224
                pos3b = mca_read_pos(slot, 3);
225
 
226
                base_addr = ((pos3j << 8) | pos3k) & 0xfffffff0;
227
                offset_addr = ((pos3a << 8) | pos3b) & 0xffffff70;
228
 
229
                irq = (pos4 & 0x3) + 11;
230
                if(irq >= 13)
231
                        irq++;
232
                if(banner) {
233
                        printk(KERN_NOTICE "NCR D700: Driver Version " NCR_D700_VERSION "\n"
234
                               "NCR D700:  Copyright (c) 2001 by James.Bottomley@HansenPartnership.com\n"
235
                               "NCR D700:\n");
236
                        banner = 0;
237
                }
238
                printk(KERN_NOTICE "NCR D700: found in slot %d  irq = %d  I/O base = 0x%x\n", slot, irq, offset_addr);
239
 
240
                tpnt->proc_name = "NCR_D700";
241
 
242
                /*outb(BOARD_RESET, base_addr);*/
243
 
244
                /* clear any pending interrupts */
245
                (void)inb(base_addr + 0x08);
246
                /* get modctl, used later for setting diff bits */
247
                switch(differential = (inb(base_addr + 0x08) >> 6)) {
248
                case 0x00:
249
                        /* only SIOP1 differential */
250
                        differential = 0x02;
251
                        break;
252
                case 0x01:
253
                        /* Both SIOPs differential */
254
                        differential = 0x03;
255
                        break;
256
                case 0x03:
257
                        /* No SIOPs differential */
258
                        differential = 0x00;
259
                        break;
260
                default:
261
                        printk(KERN_ERR "D700: UNEXPECTED DIFFERENTIAL RESULT 0x%02x\n",
262
                               differential);
263
                        differential = 0x00;
264
                        break;
265
                }
266
 
267
                /* plumb in both 700 chips */
268
                for(i=0; i<2; i++) {
269
                        __u32 region = offset_addr | (0x80 * i);
270
                        struct NCR_700_Host_Parameters *hostdata =
271
                                kmalloc(sizeof(struct NCR_700_Host_Parameters),
272
                                        GFP_KERNEL);
273
                        if(hostdata == NULL) {
274
                                printk(KERN_ERR "NCR D700: Failed to allocate host data for channel %d, detatching\n", i);
275
                                continue;
276
                        }
277
                        memset(hostdata, 0, sizeof(struct NCR_700_Host_Parameters));
278
                        if(request_region(region, 64, "NCR_D700") == NULL) {
279
                                printk(KERN_ERR "NCR D700: Failed to reserve IO region 0x%x\n", region);
280
                                kfree(hostdata);
281
                                continue;
282
                        }
283
 
284
                        /* Fill in the three required pieces of hostdata */
285
                        hostdata->base = region;
286
                        hostdata->differential = (((1<<i) & differential) != 0);
287
                        hostdata->clock = NCR_D700_CLOCK_MHZ;
288
                        /* and register the chip */
289
                        if((host = NCR_700_detect(tpnt, hostdata)) == NULL) {
290
                                kfree(hostdata);
291
                                release_region(host->base, 64);
292
                                continue;
293
                        }
294
                        host->irq = irq;
295
                        /* FIXME: Read this from SUS */
296
                        host->this_id = id_array[slot * 2 + i];
297
                        printk(KERN_NOTICE "NCR D700: SIOP%d, SCSI id is %d\n",
298
                               i, host->this_id);
299
                        if(request_irq(irq, NCR_700_intr, SA_SHIRQ, "NCR_D700", host)) {
300
                                printk(KERN_ERR "NCR D700, channel %d: irq problem, detatching\n", i);
301
                                scsi_unregister(host);
302
                                NCR_700_release(host);
303
                                continue;
304
                        }
305
                        found++;
306
                        mca_set_adapter_name(slot, "NCR D700 SCSI Adapter (version " NCR_D700_VERSION ")");
307
                }
308
        }
309
 
310
        return found;
311
}
312
 
313
 
314
STATIC int
315
D700_release(struct Scsi_Host *host)
316
{
317
        struct D700_Host_Parameters *hostdata =
318
                (struct D700_Host_Parameters *)host->hostdata[0];
319
 
320
        NCR_700_release(host);
321
        kfree(hostdata);
322
        free_irq(host->irq, host);
323
        release_region(host->base, 64);
324
        return 1;
325
}
326
 
327
 
328
static Scsi_Host_Template driver_template = NCR_D700_SCSI;
329
 
330
#include "scsi_module.c"
331
 

powered by: WebSVN 2.1.0

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