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/] [acornscsi.c.dag] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1622 jcastillo
/*
2
 * linux/arch/arm/drivers/scsi/acornscsi.c
3
 *
4
 *  Acorn SCSI 3 driver
5
 *  By R.M.King.
6
 *
7
 * Abandoned using the Select and Transfer command since there were
8
 * some nasty races between our software and the target devices that
9
 * were not easy to solve, and the device errata had a lot of entries
10
 * for this command, some of them quite nasty...
11
 *
12
 * Changelog:
13
 *  26-Sep-1997 RMK     Re-jigged to use the queue module.
14
 *                      Re-coded state machine to be based on driver
15
 *                      state not scsi state.  Should be easier to debug.
16
 *                      Added acornscsi_release to clean up properly.
17
 *                      Updated proc/scsi reporting.
18
 *  05-Oct-1997 RMK     Implemented writing to SCSI devices.
19
 *  06-Oct-1997 RMK     Corrected small (non-serious) bug with the connect/
20
 *                      reconnect race condition causing a warning message.
21
 *  12-Oct-1997 RMK     Added catch for re-entering interrupt routine.
22
 *  15-Oct-1997 RMK     Improved handling of commands.
23
 */
24
#define DEBUG_NO_WRITE  1
25
#define DEBUG_QUEUES    2
26
#define DEBUG_DMA       4
27
#define DEBUG_ABORT     8
28
#define DEBUG_DISCON    16
29
#define DEBUG_CONNECT   32
30
#define DEBUG_PHASES    64
31
#define DEBUG_WRITE     128
32
#define DEBUG_LINK      256
33
#define DEBUG_MESSAGES  512
34
#define DEBUG_RESET     1024
35
#define DEBUG_ALL       (DEBUG_RESET|DEBUG_MESSAGES|DEBUG_LINK|DEBUG_WRITE|\
36
                         DEBUG_PHASES|DEBUG_CONNECT|DEBUG_DISCON|DEBUG_ABORT|\
37
                         DEBUG_DMA|DEBUG_QUEUES|DEBUG_NO_WRITE)
38
 
39
/* DRIVER CONFIGURATION
40
 *
41
 * SCSI-II Tagged queue support.
42
 *
43
 * I don't have any SCSI devices that support it, so it is totally untested
44
 * (except to make sure that it doesn't interfere with any non-tagging
45
 * devices).  It is not fully implemented either - what happens when a
46
 * tagging device reconnects???
47
 *
48
 * You can tell if you have a device that supports tagged queueing my
49
 * cating (eg) /proc/scsi/acornscsi/0 and see if the SCSI revision is reported
50
 * as '2 TAG'.
51
 */
52
#define SCSI2_TAG
53
/*
54
 * SCSI-II Linked command support.
55
 *
56
 * The higher level code doesn't support linked commands yet.
57
 */
58
#undef SCSI2_LINK
59
/*
60
 * SCSI-II Synchronous transfer support.
61
 *
62
 * Tried and tested...
63
 *
64
 * SDTR_SIZE      - maximum number of un-acknowledged bytes (0 = off, 12 = max)
65
 * SDTR_PERIOD    - period of REQ signal (min=125, max=1020)
66
 * DEFAULT_PERIOD - default REQ period.
67
 */
68
#define SCSI2_SYNC
69
#define SDTR_SIZE       12
70
#define SDTR_PERIOD     125
71
#define DEFAULT_PERIOD  500
72
 
73
/*
74
 * Debugging information
75
 *
76
 * DEBUG          - bit mask from list above
77
 * DEBUG_TARGET   - is defined to the target number if you want to debug
78
 *                  a specific target. [only recon/write/dma].
79
 */
80
#define DEBUG (DEBUG_RESET|DEBUG_WRITE|DEBUG_NO_WRITE)
81
/* only allow writing to SCSI device 0 */
82
#define NO_WRITE 0xFE
83
 
84
/*#define DEBUG_TARGET 2*/
85
/*
86
 * Select timeout time (in 10ms units)
87
 *
88
 * This is the timeout used between the start of selection and the WD33C93
89
 * chip deciding that the device isn't responding.
90
 */
91
#define TIMEOUT_TIME 10
92
/*
93
 * Define this if you want to have verbose explaination of SCSI
94
 * status/messages.
95
 */
96
#undef CONFIG_ACORNSCSI_CONSTANTS
97
/*
98
 * Define this if you want to use the on board DMAC
99
 */
100
#define USE_DMAC
101
/*
102
 * List of devices that the driver will recognise
103
 */
104
#define ACORNSCSI_LIST { MANU_ACORN, PROD_ACORN_SCSI }
105
/*
106
 * ====================================================================================
107
 */
108
 
109
#ifdef DEBUG_TARGET
110
#define DBG(cmd,xxx...) \
111
  if (cmd->target == DEBUG_TARGET) { \
112
    xxx; \
113
  }
114
#else
115
#define DBG(cmd,xxx...) xxx
116
#endif
117
 
118
#ifndef STRINGIFY
119
#define STRINGIFY(x) #x
120
#endif
121
#define STR(x) STRINGIFY(x)
122
#define NO_WRITE_STR STR(NO_WRITE)
123
 
124
#include 
125
#include 
126
#include 
127
#include 
128
#include 
129
#include 
130
#include 
131
#include 
132
#include 
133
#include 
134
#include 
135
#include 
136
#include 
137
#include 
138
#include 
139
 
140
#include "../block/blk.h"
141
#include "scsi.h"
142
#include "hosts.h"
143
#include "acornscsi.h"
144
#include "constants.h"
145
 
146
#define VER_MAJOR 2
147
#define VER_MINOR 0
148
#define VER_PATCH 4
149
 
150
#ifndef ABORT_TAG
151
#define ABORT_TAG 0xd
152
#else
153
#error "Yippee!  ABORT TAG is now defined!  Remove this error!"
154
#endif
155
 
156
#ifndef NO_IRQ
157
#define NO_IRQ 255
158
#endif
159
 
160
/*
161
 * DMAC setup parameters
162
 */
163
#define INIT_DEVCON0    (DEVCON0_RQL|DEVCON0_EXW|DEVCON0_CMP)
164
#define INIT_DEVCON1    (DEVCON1_BHLD)
165
#define DMAC_READ       (MODECON_READ)
166
#define DMAC_WRITE      (MODECON_WRITE)
167
#define INIT_SBICDMA    (CTRL_DMABURST)
168
 
169
#ifdef SCSI2_LINK
170
#error SCSI2 LINKed commands not supported (yet)!
171
#endif
172
 
173
/*
174
 * Size of on-board DMA buffer
175
 */
176
#define DMAC_BUFFER_SIZE        65536
177
 
178
/*
179
 * This is used to dump the previous states of the SBIC
180
 */
181
static struct status_entry {
182
        unsigned long   when;
183
        unsigned char   ssr;
184
        unsigned char   ph;
185
        unsigned char   irq;
186
        unsigned char   unused;
187
} status[9][16];
188
static unsigned char status_ptr[9];
189
 
190
#define ADD_STATUS(_q,_ssr,_ph,_irq) \
191
({                                                      \
192
        status[(_q)][status_ptr[(_q)]].when = jiffies;  \
193
        status[(_q)][status_ptr[(_q)]].ssr  = (_ssr);   \
194
        status[(_q)][status_ptr[(_q)]].ph   = (_ph);    \
195
        status[(_q)][status_ptr[(_q)]].irq  = (_irq);   \
196
        status_ptr[(_q)] = (status_ptr[(_q)] + 1) & 15;     \
197
})
198
 
199
unsigned int sdtr_period = SDTR_PERIOD;
200
unsigned int sdtr_size   = SDTR_SIZE;
201
 
202
static struct proc_dir_entry proc_scsi_acornscsi = {
203
        PROC_SCSI_EATA, 9, "acornscsi", S_IFDIR | S_IRUGO | S_IXUGO, 2
204
};
205
 
206
static void acornscsi_done (AS_Host *host, Scsi_Cmnd **SCpntp, unsigned int result);
207
static int acornscsi_reconnect_finish (AS_Host *host);
208
static void acornscsi_dma_cleanup (AS_Host *host);
209
static void acornscsi_abortcmd (AS_Host *host, unsigned char tag);
210
 
211
/* ====================================================================================
212
 * Miscellaneous
213
 */
214
 
215
static inline void
216
sbic_arm_write (unsigned int io_port, int reg, int value)
217
{
218
    outb_t (reg, io_port);
219
    outb_t (value, io_port + 4);
220
}
221
 
222
#define sbic_arm_writenext(io,val) \
223
        outb_t ((val), (io) + 4)
224
 
225
static inline
226
int sbic_arm_read (unsigned int io_port, int reg)
227
{
228
    if(reg == ASR)
229
           return inl_t(io_port) & 255;
230
    outb_t(reg, io_port);
231
    return inl_t(io_port + 4) & 255;
232
}
233
 
234
#define sbic_arm_readnext(io) \
235
        inb_t((io) + 4)
236
 
237
#define dmac_read(io_port,reg) \
238
        inb ((io_port) + (reg))
239
 
240
#define dmac_write(io_port,reg,value) \
241
        ({ outb ((value), (io_port) + (reg)); })
242
 
243
#define dmac_clearintr(io_port) \
244
        ({ outb (0, (io_port)); })
245
 
246
static inline
247
unsigned int dmac_address (unsigned int io_port)
248
{
249
    return dmac_read (io_port, TXADRHI) << 16 |
250
           dmac_read (io_port, TXADRMD) << 8 |
251
           dmac_read (io_port, TXADRLO);
252
}
253
 
254
static
255
unsigned long acornscsi_sbic_xfcount (AS_Host *host)
256
{
257
    unsigned long length;
258
 
259
    length = sbic_arm_read (host->scsi.io_port, TRANSCNTH) << 16;
260
    length |= sbic_arm_readnext (host->scsi.io_port) << 8;
261
    length |= sbic_arm_readnext (host->scsi.io_port);
262
 
263
    return length;
264
}
265
 
266
static
267
int acornscsi_sbic_issuecmd (AS_Host *host, int command)
268
{
269
    int asr;
270
 
271
    do {
272
        asr = sbic_arm_read (host->scsi.io_port, ASR);
273
    } while (asr & ASR_CIP);
274
 
275
    sbic_arm_write (host->scsi.io_port, CMND, command);
276
 
277
    return 0;
278
}
279
 
280
static void
281
acornscsi_csdelay (unsigned int cs)
282
{
283
    unsigned long target_jiffies, flags;
284
 
285
    target_jiffies = jiffies + 1 + cs * HZ / 100;
286
 
287
    save_flags (flags);
288
    sti ();
289
 
290
    while (jiffies < target_jiffies) barrier();
291
 
292
    restore_flags (flags);
293
}
294
 
295
static
296
void acornscsi_resetcard (AS_Host *host)
297
{
298
    unsigned int i;
299
 
300
    /* assert reset line */
301
    host->card.page_reg = 0x80;
302
    outb (host->card.page_reg, host->card.io_page);
303
 
304
    /* wait 3 cs.  SCSI standard says 25ms. */
305
    acornscsi_csdelay (3);
306
 
307
    host->card.page_reg = 0;
308
    outb (host->card.page_reg, host->card.io_page);
309
 
310
    /*
311
     * Should get a reset from the card
312
     */
313
    while (!(inb (host->card.io_intr) & 8));
314
    sbic_arm_read (host->scsi.io_port, ASR);
315
    sbic_arm_read (host->scsi.io_port, SSR);
316
 
317
    /* setup sbic - WD33C93A */
318
    sbic_arm_write (host->scsi.io_port, OWNID, OWNID_EAF | host->host->this_id);
319
    sbic_arm_write (host->scsi.io_port, CMND, CMND_RESET);
320
 
321
    /*
322
     * Command should cause a reset interrupt
323
     */
324
    while (!(inb (host->card.io_intr) & 8));
325
    sbic_arm_read (host->scsi.io_port, ASR);
326
    if (sbic_arm_read (host->scsi.io_port, SSR) != 0x01)
327
        printk (KERN_CRIT "scsi%d: WD33C93A didn't give enhanced reset interrupt\n",
328
                host->host->host_no);
329
 
330
    sbic_arm_write (host->scsi.io_port, CTRL, INIT_SBICDMA | CTRL_IDI);
331
    sbic_arm_write (host->scsi.io_port, TIMEOUT, TIMEOUT_TIME);
332
    sbic_arm_write (host->scsi.io_port, SYNCHTRANSFER, SYNCHTRANSFER_2DBA);
333
    sbic_arm_write (host->scsi.io_port, SOURCEID, SOURCEID_ER | SOURCEID_DSP);
334
 
335
    host->card.page_reg = 0x40;
336
    outb (host->card.page_reg, host->card.io_page);
337
 
338
    /* setup dmac - uPC71071 */
339
    dmac_write (host->dma.io_port, INIT, 0);
340
    dmac_write (host->dma.io_port, INIT, INIT_8BIT);
341
    dmac_write (host->dma.io_port, CHANNEL, CHANNEL_0);
342
    dmac_write (host->dma.io_port, DEVCON0, INIT_DEVCON0);
343
    dmac_write (host->dma.io_port, DEVCON1, INIT_DEVCON1);
344
 
345
    host->SCpnt = NULL;
346
    host->scsi.phase = PHASE_IDLE;
347
    host->scsi.disconnectable = 0;
348
 
349
    for (i = 0; i < 8; i++) {
350
        host->busyluns[i] = 0;
351
        host->device[i].sync_state = SYNC_NEGOCIATE;
352
        host->device[i].disconnect_ok = 1;
353
    }
354
 
355
    /* wait 25 cs.  SCSI standard says 250ms. */
356
    acornscsi_csdelay (25);
357
}
358
 
359
/*=============================================================================================
360
 * Utility routines (eg. debug)
361
 */
362
#ifdef CONFIG_ACORNSCSI_CONSTANTS
363
static char *acornscsi_interrupttype[] = {
364
  "rst",  "suc",  "p/a",  "3",
365
  "term", "5",    "6",    "7",
366
  "serv", "9",    "a",    "b",
367
  "c",    "d",    "e",    "f"
368
};
369
 
370
static signed char acornscsi_map[] = {
371
  0,  1, -1, -1,  -1, -1, -1, -1,  -1, -1, -1, -1,  -1, -1, -1, -1,
372
 -1,  2, -1, -1,  -1, -1,  3, -1,   4,  5,  6,  7,   8,  9, 10, 11,
373
 12, 13, 14, -1,  -1, -1, -1, -1,   4,  5,  6,  7,   8,  9, 10, 11,
374
 -1, -1, -1, -1,  -1, -1, -1, -1,  -1, -1, -1, -1,  -1, -1, -1, -1,
375
 15, 16, 17, 18,  19, -1, -1, 20,   4,  5,  6,  7,   8,  9, 10, 11,
376
 -1, -1, -1, -1,  -1, -1, -1, -1,  -1, -1, -1, -1,  -1, -1, -1, -1,
377
 -1, -1, -1, -1,  -1, -1, -1, -1,  -1, -1, -1, -1,  -1, -1, -1, -1,
378
 -1, -1, -1, -1,  -1, -1, -1, -1,  -1, -1, -1, -1,  -1, -1, -1, -1,
379
 21, 22, -1, -1,  -1, 23, -1, -1,   4,  5,  6,  7,   8,  9, 10, 11,
380
 -1, -1, -1, -1,  -1, -1, -1, -1,  -1, -1, -1, -1,  -1, -1, -1, -1,
381
 -1, -1, -1, -1,  -1, -1, -1, -1,  -1, -1, -1, -1,  -1, -1, -1, -1,
382
 -1, -1, -1, -1,  -1, -1, -1, -1,  -1, -1, -1, -1,  -1, -1, -1, -1,
383
 -1, -1, -1, -1,  -1, -1, -1, -1,  -1, -1, -1, -1,  -1, -1, -1, -1,
384
 -1, -1, -1, -1,  -1, -1, -1, -1,  -1, -1, -1, -1,  -1, -1, -1, -1,
385
 -1, -1, -1, -1,  -1, -1, -1, -1,  -1, -1, -1, -1,  -1, -1, -1, -1,
386
 -1, -1, -1, -1,  -1, -1, -1, -1,  -1, -1, -1, -1,  -1, -1, -1, -1
387
};
388
 
389
static char *acornscsi_interruptcode[] = {
390
    /* 0 */
391
    "reset - normal mode",      /* 00 */
392
    "reset - advanced mode",    /* 01 */
393
 
394
    /* 2 */
395
    "sel",                      /* 11 */
396
    "sel+xfer",                 /* 16 */
397
    "data-out",                 /* 18 */
398
    "data-in",                  /* 19 */
399
    "cmd",                      /* 1A */
400
    "stat",                     /* 1B */
401
    "??-out",                   /* 1C */
402
    "??-in",                    /* 1D */
403
    "msg-out",                  /* 1E */
404
    "msg-in",                   /* 1F */
405
 
406
    /* 12 */
407
    "/ACK asserted",            /* 20 */
408
    "save-data-ptr",            /* 21 */
409
    "{re}sel",                  /* 22 */
410
 
411
    /* 15 */
412
    "inv cmd",                  /* 40 */
413
    "unexpected disconnect",    /* 41 */
414
    "sel timeout",              /* 42 */
415
    "P err",                    /* 43 */
416
    "P err+ATN",                /* 44 */
417
    "bad status byte",          /* 47 */
418
 
419
    /* 21 */
420
    "resel, no id",             /* 80 */
421
    "resel",                    /* 81 */
422
    "discon",                   /* 85 */
423
};
424
 
425
static
426
void print_scsi_status (unsigned int ssr)
427
{
428
    if (acornscsi_map[ssr] != -1)
429
        printk ("%s:%s",
430
                acornscsi_interrupttype[(ssr >> 4)],
431
                acornscsi_interruptcode[acornscsi_map[ssr]]);
432
    else
433
        printk ("%X:%X", ssr >> 4, ssr & 0x0f);
434
}
435
#endif
436
 
437
static
438
void print_sbic_status (int asr, int ssr, int cmdphase)
439
{
440
#ifdef CONFIG_ACORNSCSI_CONSTANTS
441
    printk ("sbic: %c%c%c%c%c%c ",
442
            asr & ASR_INT ? 'I' : 'i',
443
            asr & ASR_LCI ? 'L' : 'l',
444
            asr & ASR_BSY ? 'B' : 'b',
445
            asr & ASR_CIP ? 'C' : 'c',
446
            asr & ASR_PE  ? 'P' : 'p',
447
            asr & ASR_DBR ? 'D' : 'd');
448
    printk ("scsi: ");
449
    print_scsi_status (ssr);
450
    printk (" ph %02X\n", cmdphase);
451
#else
452
    printk ("sbic: %02X scsi: %X:%X ph: %02X\n",
453
            asr, (ssr & 0xf0)>>4, ssr & 0x0f, cmdphase);
454
#endif
455
}
456
 
457
static
458
void acornscsi_dumplog (AS_Host *host, int target)
459
{
460
    unsigned int prev;
461
    do {
462
        signed int statptr;
463
 
464
        printk ("%c:", target == 8 ? 'H' : ('0' + target));
465
        statptr = status_ptr[target] - 10;
466
 
467
        if (statptr < 0)
468
            statptr += 16;
469
 
470
        prev = status[target][statptr].when;
471
 
472
        for (; statptr != status_ptr[target]; statptr = (statptr + 1) & 15) {
473
            if (status[target][statptr].when) {
474
#ifdef CONFIG_ACORNSCSI_CONSTANTS
475
                printk ("%c%02X:S=",
476
                        status[target][statptr].irq ? '-' : ' ',
477
                        status[target][statptr].ph);
478
                print_scsi_status (status[target][statptr].ssr);
479
#else
480
                printk ("%c%02X:%02X",
481
                        status[target][statptr].irq ? '-' : ' ',
482
                        status[target][statptr].ph,
483
                        status[target][statptr].ssr);
484
#endif
485
                printk ("+%02ld",
486
                        (status[target][statptr].when - prev) < 100 ?
487
                                (status[target][statptr].when - prev) : 99);
488
                prev = status[target][statptr].when;
489
            }
490
        }
491
        printk ("\n");
492
        if (target == 8)
493
            break;
494
        target = 8;
495
    } while (1);
496
}
497
 
498
static
499
char acornscsi_target (AS_Host *host)
500
{
501
        if (host->SCpnt)
502
                return '0' + host->SCpnt->target;
503
        return 'H';
504
}
505
 
506
static
507
void acornscsi_dumpdma (AS_Host *host, char *where)
508
{
509
        unsigned int mode, addr, len;
510
 
511
        mode = dmac_read (host->dma.io_port, MODECON);
512
        addr = dmac_address (host->dma.io_port);
513
        len  = dmac_read (host->dma.io_port, TXCNTHI) << 8 |
514
               dmac_read (host->dma.io_port, TXCNTLO);
515
 
516
        printk ("scsi%d: %s: DMAC %02x @%06x+%04x msk %02x, ",
517
                host->host->host_no, where,
518
                mode, addr, (len + 1) & 0xffff,
519
                dmac_read (host->dma.io_port, MASKREG));
520
 
521
        printk ("DMA @%06x, ", host->dma.start_addr);
522
        printk ("BH @%p +%04x, ", host->scsi.SCp.ptr,
523
                host->scsi.SCp.this_residual);
524
        printk ("DT @+%04x ST @+%04x", host->dma.transferred,
525
                host->scsi.SCp.have_data_in);
526
        printk ("\n");
527
}
528
 
529
/*
530
 * Prototype: cmdtype_t acornscsi_cmdtype (int command)
531
 * Purpose  : differentiate READ from WRITE from other commands
532
 * Params   : command - command to interpret
533
 * Returns  : CMD_READ  - command reads data,
534
 *            CMD_WRITE - command writes data,
535
 *            CMD_MISC  - everything else
536
 */
537
static inline
538
cmdtype_t acornscsi_cmdtype (int command)
539
{
540
    switch (command) {
541
    case WRITE_6:  case WRITE_10:  case WRITE_12:
542
        return CMD_WRITE;
543
    case READ_6:   case READ_10:   case READ_12:
544
        return CMD_READ;
545
    default:
546
        return CMD_MISC;
547
    }
548
}
549
 
550
/*
551
 * Prototype: int acornscsi_datadirection (int command)
552
 * Purpose  : differentiate between commands that have a DATA IN phase
553
 *            and a DATA OUT phase
554
 * Params   : command - command to interpret
555
 * Returns  : DATADIR_OUT - data out phase expected
556
 *            DATADIR_IN  - data in phase expected
557
 */
558
static
559
datadir_t acornscsi_datadirection (int command)
560
{
561
    switch (command) {
562
    case CHANGE_DEFINITION:     case COMPARE:           case COPY:
563
    case COPY_VERIFY:           case LOG_SELECT:        case MODE_SELECT:
564
    case MODE_SELECT_10:        case SEND_DIAGNOSTIC:   case WRITE_BUFFER:
565
    case FORMAT_UNIT:           case REASSIGN_BLOCKS:   case RESERVE:
566
    case SEARCH_EQUAL:          case SEARCH_HIGH:       case SEARCH_LOW:
567
    case WRITE_6:               case WRITE_10:          case WRITE_VERIFY:
568
    case UPDATE_BLOCK:          case WRITE_LONG:        case WRITE_SAME:
569
    case SEARCH_HIGH_12:        case SEARCH_EQUAL_12:   case SEARCH_LOW_12:
570
    case WRITE_12:              case WRITE_VERIFY_12:   case SET_WINDOW:
571
    case MEDIUM_SCAN:           case SEND_VOLUME_TAG:   case 0xea:
572
        return DATADIR_OUT;
573
    default:
574
        return DATADIR_IN;
575
    }
576
}
577
 
578
/*
579
 * Purpose  : provide values for synchronous transfers with 33C93.
580
 * Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
581
 *      Modified by Russell King for 8MHz WD33C93A
582
 */
583
static struct sync_xfer_tbl {
584
    unsigned int period_ns;
585
    unsigned char reg_value;
586
} sync_xfer_table[] = {
587
    {   1, 0x20 },    { 249, 0x20 },    { 374, 0x30 },
588
    { 499, 0x40 },    { 624, 0x50 },    { 749, 0x60 },
589
    { 874, 0x70 },    { 999, 0x00 },    {   0,    0 }
590
};
591
 
592
/*
593
 * Prototype: int acornscsi_getperiod (unsigned char syncxfer)
594
 * Purpose  : period for the synchronous transfer setting
595
 * Params   : syncxfer SYNCXFER register value
596
 * Returns  : period in ns.
597
 */
598
static
599
int acornscsi_getperiod (unsigned char syncxfer)
600
{
601
    int i;
602
 
603
    syncxfer &= 0xf0;
604
    if (syncxfer == 0x10)
605
        syncxfer = 0;
606
 
607
    for (i = 1; sync_xfer_table[i].period_ns; i++)
608
        if (syncxfer == sync_xfer_table[i].reg_value)
609
            return sync_xfer_table[i].period_ns;
610
    return 0;
611
}
612
 
613
/*
614
 * Prototype: int round_period (unsigned int period)
615
 * Purpose  : return index into above table for a required REQ period
616
 * Params   : period - time (ns) for REQ
617
 * Returns  : table index
618
 * Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
619
 */
620
static inline
621
int round_period (unsigned int period)
622
{
623
    int i;
624
 
625
    for (i = 1; sync_xfer_table[i].period_ns; i++) {
626
        if ((period <= sync_xfer_table[i].period_ns) &&
627
            (period > sync_xfer_table[i - 1].period_ns))
628
            return i;
629
    }
630
    return 7;
631
}
632
 
633
/*
634
 * Prototype: unsigned char calc_sync_xfer (unsigned int period, unsigned int offset)
635
 * Purpose  : calculate value for 33c93s SYNC register
636
 * Params   : period - time (ns) for REQ
637
 *            offset - offset in bytes between REQ/ACK
638
 * Returns  : value for SYNC register
639
 * Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
640
 */
641
static
642
unsigned char calc_sync_xfer (unsigned int period, unsigned int offset)
643
{
644
    return sync_xfer_table[round_period(period)].reg_value |
645
                ((offset < SDTR_SIZE) ? offset : SDTR_SIZE);
646
}
647
 
648
/* ====================================================================================
649
 * Command functions
650
 */
651
/*
652
 * Function: acornscsi_kick (AS_Host *host)
653
 * Purpose : kick next command to interface
654
 * Params  : host - host to send command to
655
 * Returns : INTR_IDLE if idle, otherwise INTR_PROCESSING
656
 * Notes   : interrupts are always disabled!
657
 */
658
static
659
intr_ret_t acornscsi_kick (AS_Host *host)
660
{
661
    int from_queue = 0;
662
    Scsi_Cmnd *SCpnt;
663
 
664
    /* first check to see if a command is waiting to be executed */
665
    SCpnt = host->origSCpnt;
666
    host->origSCpnt = NULL;
667
 
668
    /* retrieve next command */
669
    if (!SCpnt) {
670
        SCpnt = queue_remove_exclude (&host->queues.issue, host->busyluns);
671
        if (!SCpnt)
672
            return INTR_IDLE;
673
 
674
        from_queue = 1;
675
    }
676
 
677
    if (host->scsi.disconnectable && host->SCpnt) {
678
        queue_add_cmd_tail (&host->queues.disconnected, host->SCpnt);
679
        host->scsi.disconnectable = 0;
680
#if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
681
        DBG(host->SCpnt, printk ("scsi%d.%c: moved command to disconnected queue\n",
682
                host->host->host_no, acornscsi_target (host)));
683
#endif
684
        host->SCpnt = NULL;
685
    }
686
 
687
    /*
688
     * If we have an interrupt pending, then we may have been reselected.
689
     * In this case, we don't want to write to the registers
690
     */
691
    if (!(sbic_arm_read (host->scsi.io_port, ASR) & (ASR_INT|ASR_BSY|ASR_CIP))) {
692
        sbic_arm_write (host->scsi.io_port, DESTID, SCpnt->target);
693
        sbic_arm_write (host->scsi.io_port, CMND, CMND_SELWITHATN);
694
    }
695
 
696
    /*
697
     * claim host busy - all of these must happen atomically wrt
698
     * our interrupt routine.  Failure means command loss.
699
     */
700
    host->scsi.phase = PHASE_CONNECTING;
701
    host->SCpnt = SCpnt;
702
    host->scsi.SCp = SCpnt->SCp;
703
    host->dma.xfer_setup = 0;
704
    host->dma.xfer_required = 0;
705
 
706
#if (DEBUG & (DEBUG_ABORT|DEBUG_CONNECT))
707
    DBG(SCpnt,printk ("scsi%d.%c: starting cmd %02X\n",
708
            host->host->host_no, '0' + SCpnt->target,
709
            SCpnt->cmnd[0]));
710
#endif
711
 
712
    if (from_queue) {
713
#ifdef SCSI2_TAG
714
        /*
715
         * tagged queueing - allocate a new tag to this command
716
         */
717
        if (SCpnt->device->tagged_queue) {
718
            SCpnt->device->current_tag += 1;
719
            if (SCpnt->device->current_tag == 0)
720
                SCpnt->device->current_tag = 1;
721
            SCpnt->tag = SCpnt->device->current_tag;
722
        } else
723
#endif
724
            set_bit (SCpnt->target * 8 + SCpnt->lun, host->busyluns);
725
 
726
        host->stats.removes += 1;
727
 
728
        switch (acornscsi_cmdtype (SCpnt->cmnd[0])) {
729
        case CMD_WRITE:
730
            host->stats.writes += 1;
731
            break;
732
        case CMD_READ:
733
            host->stats.reads += 1;
734
            break;
735
        case CMD_MISC:
736
            host->stats.miscs += 1;
737
            break;
738
        }
739
    }
740
 
741
    return INTR_PROCESSING;
742
}
743
 
744
/*
745
 * Function: void acornscsi_done (AS_Host *host, Scsi_Cmnd **SCpntp, unsigned int result)
746
 * Purpose : complete processing for command
747
 * Params  : host   - interface that completed
748
 *           result - driver byte of result
749
 */
750
static
751
void acornscsi_done (AS_Host *host, Scsi_Cmnd **SCpntp, unsigned int result)
752
{
753
    Scsi_Cmnd *SCpnt = *SCpntp;
754
 
755
    /* clean up */
756
    sbic_arm_write (host->scsi.io_port, SOURCEID, SOURCEID_ER | SOURCEID_DSP);
757
 
758
    host->stats.fins += 1;
759
 
760
    if (SCpnt) {
761
        *SCpntp = NULL;
762
 
763
        acornscsi_dma_cleanup (host);
764
 
765
        SCpnt->result = result << 16 | host->scsi.SCp.Message << 8 | host->scsi.SCp.Status;
766
 
767
        /*
768
         * In theory, this should not happen.  In practice, it seems to.
769
         * Only trigger an error if the device attempts to report all happy
770
         * but with untransferred buffers...  If we don't do something, then
771
         * data loss will occur.  Should we check SCpnt->underflow here?
772
         * It doesn't appear to be set to something meaningful by the higher
773
         * levels all the time.
774
         */
775
        if (host->scsi.SCp.ptr && result == DID_OK &&
776
                acornscsi_cmdtype (SCpnt->cmnd[0]) != CMD_MISC) {
777
            switch (status_byte (SCpnt->result)) {
778
            case CHECK_CONDITION:
779
            case COMMAND_TERMINATED:
780
            case BUSY:
781
            case QUEUE_FULL:
782
            case RESERVATION_CONFLICT:
783
                break;
784
 
785
            default:
786
                printk (KERN_ERR "scsi%d.H: incomplete data transfer detected: result=%08X command=",
787
                        host->host->host_no, SCpnt->result);
788
                print_command (SCpnt->cmnd);
789
                acornscsi_dumpdma (host, "done");
790
                acornscsi_dumplog (host, SCpnt->target);
791
                SCpnt->result &= 0xffff;
792
                SCpnt->result |= DID_ERROR << 16;
793
            }
794
        }
795
 
796
        if (!SCpnt->scsi_done)
797
            panic ("scsi%d.H: null scsi_done function in acornscsi_done", host->host->host_no);
798
 
799
        clear_bit (SCpnt->target * 8 + SCpnt->lun, host->busyluns);
800
 
801
        SCpnt->scsi_done (SCpnt);
802
    } else
803
        printk ("scsi%d: null command in acornscsi_done", host->host->host_no);
804
 
805
    host->scsi.phase = PHASE_IDLE;
806
}
807
 
808
/* ====================================================================================
809
 * DMA routines
810
 */
811
/*
812
 * Purpose  : update SCSI Data Pointer
813
 * Notes    : this will only be one SG entry or less
814
 */
815
static
816
void acornscsi_data_updateptr (AS_Host *host, Scsi_Pointer *SCp, unsigned int length)
817
{
818
    SCp->ptr += length;
819
    SCp->this_residual -= length;
820
 
821
    if (!SCp->this_residual) {
822
        if (SCp->buffers_residual) {
823
            SCp->buffer++;
824
            SCp->buffers_residual--;
825
            SCp->ptr = (char *)SCp->buffer->address;
826
            SCp->this_residual = SCp->buffer->length;
827
        } else
828
            SCp->ptr = NULL;
829
    }
830
}
831
 
832
/*
833
 * Prototype: void acornscsi_data_read (AS_Host *host, char *ptr,
834
 *                              unsigned int start_addr, unsigned int length)
835
 * Purpose  : read data from DMA RAM
836
 * Params   : host - host to transfer from
837
 *            ptr  - DRAM address
838
 *            start_addr - host mem address
839
 *            length - number of bytes to transfer
840
 * Notes    : this will only be one SG entry or less
841
 */
842
static
843
void acornscsi_data_read (AS_Host *host, char *ptr,
844
                                 unsigned int start_addr, unsigned int length)
845
{
846
    extern void __acornscsi_in (int port, char *buf, int len);
847
    unsigned int page, offset, len = length;
848
 
849
    page = (start_addr >> 12);
850
    offset = start_addr & ((1 << 12) - 1);
851
 
852
    outb ((page & 0x3f) | host->card.page_reg, host->card.io_page);
853
 
854
    while (len > 0) {
855
        unsigned int this_len;
856
 
857
        if (len + offset > (1 << 12))
858
            this_len = (1 << 12) - offset;
859
        else
860
            this_len = len;
861
 
862
        __acornscsi_in (host->card.io_ram + (offset << 1), ptr, this_len);
863
 
864
        offset += this_len;
865
        ptr += this_len;
866
        len -= this_len;
867
 
868
        if (offset == (1 << 12)) {
869
            offset = 0;
870
            page ++;
871
            outb ((page & 0x3f) | host->card.page_reg, host->card.io_page);
872
        }
873
    }
874
    outb (host->card.page_reg, host->card.io_page);
875
}
876
 
877
/*
878
 * Prototype: void acornscsi_data_write (AS_Host *host, char *ptr,
879
 *                              unsigned int start_addr, unsigned int length)
880
 * Purpose  : write data to DMA RAM
881
 * Params   : host - host to transfer from
882
 *            ptr  - DRAM address
883
 *            start_addr - host mem address
884
 *            length - number of bytes to transfer
885
 * Notes    : this will only be one SG entry or less
886
 */
887
static
888
void acornscsi_data_write (AS_Host *host, char *ptr,
889
                                 unsigned int start_addr, unsigned int length)
890
{
891
    extern void __acornscsi_out (int port, char *buf, int len);
892
    unsigned int page, offset, len = length;
893
 
894
    page = (start_addr >> 12);
895
    offset = start_addr & ((1 << 12) - 1);
896
 
897
    outb ((page & 0x3f) | host->card.page_reg, host->card.io_page);
898
 
899
    while (len > 0) {
900
        unsigned int this_len;
901
 
902
        if (len + offset > (1 << 12))
903
            this_len = (1 << 12) - offset;
904
        else
905
            this_len = len;
906
 
907
        __acornscsi_out (host->card.io_ram + (offset << 1), ptr, this_len);
908
 
909
        offset += this_len;
910
        ptr += this_len;
911
        len -= this_len;
912
 
913
        if (offset == (1 << 12)) {
914
            offset = 0;
915
            page ++;
916
            outb ((page & 0x3f) | host->card.page_reg, host->card.io_page);
917
        }
918
    }
919
    outb (host->card.page_reg, host->card.io_page);
920
}
921
 
922
/* =========================================================================================
923
 * On-board DMA routines
924
 */
925
/*
926
 * Prototype: void acornscsi_dmastop (AS_Host *host)
927
 * Purpose  : stop all DMA
928
 * Params   : host - host on which to stop DMA
929
 * Notes    : This is called when leaving DATA IN/OUT phase,
930
 *            or when interface is RESET
931
 */
932
static inline
933
void acornscsi_dma_stop (AS_Host *host)
934
{
935
    dmac_write (host->dma.io_port, MASKREG, MASK_ON);
936
    dmac_clearintr (host->dma.io_intr_clear);
937
 
938
#if (DEBUG & DEBUG_DMA)
939
    DBG(host->SCpnt, acornscsi_dumpdma (host, "stop"));
940
#endif
941
}
942
 
943
/*
944
 * Function: void acornscsi_dma_setup (AS_Host *host, dmadir_t direction)
945
 * Purpose : setup DMA controller for data transfer
946
 * Params  : host - host to setup
947
 *           direction - data transfer direction
948
 * Notes   : This is called when entering DATA I/O phase, not
949
 *           while we're in a DATA I/O phase
950
 */
951
static
952
void acornscsi_dma_setup (AS_Host *host, dmadir_t direction)
953
{
954
    unsigned int address, length, mode;
955
 
956
    host->dma.direction = direction;
957
 
958
    dmac_write (host->dma.io_port, MASKREG, MASK_ON);
959
 
960
    if (direction == DMA_OUT) {
961
#if (DEBUG & DEBUG_NO_WRITE)
962
        if (NO_WRITE & (1 << host->SCpnt->target)) {
963
            printk (KERN_CRIT "scsi%d.%c: I can't handle DMA_OUT!\n",
964
                    host->host->host_no, acornscsi_target (host));
965
            return;
966
        }
967
#endif
968
        mode = DMAC_WRITE;
969
    } else
970
        mode = DMAC_READ;
971
 
972
    /*
973
     * Allocate some buffer space, limited to half the buffer size
974
     */
975
    length = min (host->scsi.SCp.this_residual, DMAC_BUFFER_SIZE / 2);
976
    if (length) {
977
        host->dma.start_addr = address = host->dma.free_addr;
978
        host->dma.free_addr = (host->dma.free_addr + length) &
979
                                (DMAC_BUFFER_SIZE - 1);
980
 
981
        /*
982
         * Transfer data to DMA memory
983
         */
984
        if (direction == DMA_OUT)
985
            acornscsi_data_write (host, host->scsi.SCp.ptr, host->dma.start_addr,
986
                                length);
987
 
988
        length -= 1;
989
        dmac_write (host->dma.io_port, TXCNTLO, length);
990
        dmac_write (host->dma.io_port, TXCNTHI, length >> 8);
991
        dmac_write (host->dma.io_port, TXADRLO, address);
992
        dmac_write (host->dma.io_port, TXADRMD, address >> 8);
993
        dmac_write (host->dma.io_port, TXADRHI, 0);
994
        dmac_write (host->dma.io_port, MODECON, mode);
995
        dmac_write (host->dma.io_port, MASKREG, MASK_OFF);
996
 
997
#if (DEBUG & DEBUG_DMA)
998
        DBG(host->SCpnt, acornscsi_dumpdma (host, "strt"));
999
#endif
1000
        host->dma.xfer_setup = 1;
1001
    }
1002
}
1003
 
1004
/*
1005
 * Function: void acornscsi_dma_cleanup (AS_Host *host)
1006
 * Purpose : ensure that all DMA transfers are up-to-date & host->scsi.SCp is correct
1007
 * Params  : host - host to finish
1008
 * Notes   : This is called when a command is:
1009
 *              terminating, RESTORE_POINTERS, SAVE_POINTERS, DISCONECT
1010
 *         : This must not return until all transfers are completed.
1011
 */
1012
static
1013
void acornscsi_dma_cleanup (AS_Host *host)
1014
{
1015
    dmac_write (host->dma.io_port, MASKREG, MASK_ON);
1016
    dmac_clearintr (host->dma.io_intr_clear);
1017
 
1018
    /*
1019
     * Check for a pending transfer
1020
     */
1021
    if (host->dma.xfer_required) {
1022
        host->dma.xfer_required = 0;
1023
        if (host->dma.direction == DMA_IN)
1024
            acornscsi_data_read (host, host->dma.xfer_ptr,
1025
                                 host->dma.xfer_start, host->dma.xfer_length);
1026
    }
1027
 
1028
    /*
1029
     * Has a transfer been setup?
1030
     */
1031
    if (host->dma.xfer_setup) {
1032
        unsigned int transferred;
1033
 
1034
        host->dma.xfer_setup = 0;
1035
 
1036
#if (DEBUG & DEBUG_DMA)
1037
        DBG(host->SCpnt, acornscsi_dumpdma (host, "clup"));
1038
#endif
1039
 
1040
        /*
1041
         * Calculate number of bytes transferred from DMA.
1042
         */
1043
        transferred = dmac_address (host->dma.io_port) - host->dma.start_addr;
1044
        host->dma.transferred += transferred;
1045
 
1046
        if (host->dma.direction == DMA_IN)
1047
            acornscsi_data_read (host, host->scsi.SCp.ptr,
1048
                                 host->dma.start_addr, transferred);
1049
 
1050
        /*
1051
         * Update SCSI pointers
1052
         */
1053
        acornscsi_data_updateptr (host, &host->scsi.SCp, transferred);
1054
    }
1055
}
1056
 
1057
/*
1058
 * Function: void acornscsi_dmacintr (AS_Host *host)
1059
 * Purpose : handle interrupts from DMAC device
1060
 * Params  : host - host to process
1061
 * Notes   : If reading, we schedule the read to main memory &
1062
 *           allow the transfer to continue.
1063
 *         : If writing, we fill the onboard DMA memory from main
1064
 *           memory.
1065
 *         : Called whenever DMAC finished it's current transfer.
1066
 */
1067
static
1068
void acornscsi_dma_intr (AS_Host *host)
1069
{
1070
    unsigned int address, length, transferred;
1071
 
1072
#if (DEBUG & DEBUG_DMA)
1073
    DBG(host->SCpnt, acornscsi_dumpdma (host, "inti"));
1074
#endif
1075
 
1076
    dmac_write (host->dma.io_port, MASKREG, MASK_ON);
1077
    dmac_clearintr (host->dma.io_intr_clear);
1078
 
1079
    /*
1080
     * Calculate amount transferred via DMA
1081
     */
1082
    transferred = dmac_address (host->dma.io_port) - host->dma.start_addr;
1083
    host->dma.transferred += transferred;
1084
 
1085
    /*
1086
     * Schedule DMA transfer off board
1087
     */
1088
    if (host->dma.direction == DMA_IN) {
1089
        host->dma.xfer_start = host->dma.start_addr;
1090
        host->dma.xfer_length = transferred;
1091
        host->dma.xfer_ptr = host->scsi.SCp.ptr;
1092
        host->dma.xfer_required = 1;
1093
    }
1094
 
1095
    acornscsi_data_updateptr (host, &host->scsi.SCp, transferred);
1096
 
1097
    /*
1098
     * Allocate some buffer space, limited to half the on-board RAM size
1099
     */
1100
    length = min (host->scsi.SCp.this_residual, DMAC_BUFFER_SIZE / 2);
1101
    if (length) {
1102
        host->dma.start_addr = address = host->dma.free_addr;
1103
        host->dma.free_addr = (host->dma.free_addr + length) &
1104
                                (DMAC_BUFFER_SIZE - 1);
1105
 
1106
        /*
1107
         * Transfer data to DMA memory
1108
         */
1109
        if (host->dma.direction == DMA_OUT)
1110
            acornscsi_data_write (host, host->scsi.SCp.ptr, host->dma.start_addr,
1111
                                length);
1112
 
1113
        length -= 1;
1114
        dmac_write (host->dma.io_port, TXCNTLO, length);
1115
        dmac_write (host->dma.io_port, TXCNTHI, length >> 8);
1116
        dmac_write (host->dma.io_port, TXADRLO, address);
1117
        dmac_write (host->dma.io_port, TXADRMD, address >> 8);
1118
        dmac_write (host->dma.io_port, TXADRHI, 0);
1119
        dmac_write (host->dma.io_port, MASKREG, MASK_OFF);
1120
 
1121
#if (DEBUG & DEBUG_DMA)
1122
        DBG(host->SCpnt, acornscsi_dumpdma (host, "into"));
1123
#endif
1124
    } else {
1125
        host->dma.xfer_setup = 0;
1126
#if 0
1127
        /*
1128
         * If the interface still wants more, then this is an error.
1129
         * We give it another byte, but we also attempt to raise an
1130
         * attention condition.  We continue giving one byte until
1131
         * the device recognises the attention.
1132
         */
1133
        if (dmac_read (host->dma.io_port, STATUS) & STATUS_RQ0) {
1134
            acornscsi_abortcmd (host, host->SCpnt->tag);
1135
 
1136
            dmac_write (host->dma.io_port, TXCNTLO, 0);
1137
            dmac_write (host->dma.io_port, TXCNTHI, 0);
1138
            dmac_write (host->dma.io_port, TXADRLO, 0);
1139
            dmac_write (host->dma.io_port, TXADRMD, 0);
1140
            dmac_write (host->dma.io_port, TXADRHI, 0);
1141
            dmac_write (host->dma.io_port, MASKREG, MASK_OFF);
1142
        }
1143
#endif
1144
    }
1145
}
1146
 
1147
/*
1148
 * Function: void acornscsi_dma_xfer (AS_Host *host)
1149
 * Purpose : transfer data between AcornSCSI and memory
1150
 * Params  : host - host to process
1151
 */
1152
static
1153
void acornscsi_dma_xfer (AS_Host *host)
1154
{
1155
    host->dma.xfer_required = 0;
1156
 
1157
    if (host->dma.direction == DMA_IN)
1158
        acornscsi_data_read (host, host->dma.xfer_ptr,
1159
                                host->dma.xfer_start, host->dma.xfer_length);
1160
}
1161
 
1162
/*
1163
 * Function: void acornscsi_dma_adjust (AS_Host *host)
1164
 * Purpose : adjust DMA pointers & count for bytes transfered to
1165
 *           SBIC but not SCSI bus.
1166
 * Params  : host - host to adjust DMA count for
1167
 */
1168
static
1169
void acornscsi_dma_adjust (AS_Host *host)
1170
{
1171
    if (host->dma.xfer_setup) {
1172
        signed long transferred;
1173
#if (DEBUG & (DEBUG_DMA|DEBUG_WRITE))
1174
        DBG(host->SCpnt, acornscsi_dumpdma (host, "adji"));
1175
#endif
1176
        /*
1177
         * Calculate correct DMA address - DMA is ahead of SCSI bus while
1178
         * writing.
1179
         *  host->scsi.SCp.have_data_in is the number of bytes
1180
         *  actually transferred to/from the SCSI bus.
1181
         *  host->dma.transferred is the number of bytes transferred
1182
         *  over DMA since host->dma.start_addr was last set.
1183
         *
1184
         * real_dma_addr = host->dma.start_addr + host->scsi.SCp.have_data_in
1185
         *                 - host->dma.transferred
1186
         */
1187
        transferred = host->scsi.SCp.have_data_in - host->dma.transferred;
1188
        if (transferred < 0)
1189
            printk ("scsi%d.%c: Ack! DMA write correction %ld < 0!\n",
1190
                    host->host->host_no, acornscsi_target (host), transferred);
1191
        else if (transferred == 0)
1192
            host->dma.xfer_setup = 0;
1193
        else {
1194
            transferred += host->dma.start_addr;
1195
            dmac_write (host->dma.io_port, TXADRLO, transferred);
1196
            dmac_write (host->dma.io_port, TXADRMD, transferred >> 8);
1197
            dmac_write (host->dma.io_port, TXADRHI, transferred >> 16);
1198
#if (DEBUG & (DEBUG_DMA|DEBUG_WRITE))
1199
            DBG(host->SCpnt, acornscsi_dumpdma (host, "adjo"));
1200
#endif
1201
        }
1202
    }
1203
}
1204
 
1205
/* =========================================================================================
1206
 * Data I/O
1207
 */
1208
/*
1209
 * Function: void acornscsi_sendcommand (AS_Host *host)
1210
 * Purpose : send a command to a target
1211
 * Params  : host - host which is connected to target
1212
 */
1213
static
1214
void acornscsi_sendcommand (AS_Host *host)
1215
{
1216
    Scsi_Cmnd *SCpnt = host->SCpnt;
1217
    unsigned int asr;
1218
    unsigned char *cmdptr, *cmdend;
1219
 
1220
    sbic_arm_write (host->scsi.io_port, TRANSCNTH, 0);
1221
    sbic_arm_writenext (host->scsi.io_port, 0);
1222
    sbic_arm_writenext (host->scsi.io_port, SCpnt->cmd_len - host->scsi.SCp.sent_command);
1223
    acornscsi_sbic_issuecmd (host, CMND_XFERINFO);
1224
 
1225
    cmdptr = SCpnt->cmnd + host->scsi.SCp.sent_command;
1226
    cmdend = SCpnt->cmnd + SCpnt->cmd_len;
1227
 
1228
    while (cmdptr < cmdend) {
1229
        asr = sbic_arm_read (host->scsi.io_port, ASR);
1230
        if (asr & ASR_DBR)
1231
            sbic_arm_write (host->scsi.io_port, DATA, *cmdptr++);
1232
        else if (asr & ASR_INT)
1233
            break;
1234
    }
1235
    if (cmdptr >= cmdend)
1236
        host->scsi.SCp.sent_command = cmdptr - SCpnt->cmnd;
1237
    host->scsi.phase = PHASE_COMMAND;
1238
}
1239
 
1240
static
1241
void acornscsi_sendmessage (AS_Host *host)
1242
{
1243
    unsigned int message_length = msgqueue_msglength (&host->scsi.msgs);
1244
    int msgnr;
1245
    struct message *msg;
1246
 
1247
#if (DEBUG & DEBUG_MESSAGES)
1248
    printk ("scsi%d.%c: sending message ",
1249
            host->host->host_no, acornscsi_target (host));
1250
#endif
1251
 
1252
    switch (message_length) {
1253
    case 0:
1254
        acornscsi_sbic_issuecmd (host, CMND_XFERINFO | CMND_SBT);
1255
        while ((sbic_arm_read (host->scsi.io_port, ASR) & ASR_DBR) == 0);
1256
        sbic_arm_write (host->scsi.io_port, DATA, NOP);
1257
        host->scsi.last_message = NOP;
1258
#if (DEBUG & DEBUG_MESSAGES)
1259
        printk ("NOP");
1260
#endif
1261
        break;
1262
 
1263
    case 1:
1264
        acornscsi_sbic_issuecmd (host, CMND_XFERINFO | CMND_SBT);
1265
        msg = msgqueue_getmsg (&host->scsi.msgs, 0);
1266
        while ((sbic_arm_read (host->scsi.io_port, ASR) & ASR_DBR) == 0);
1267
        sbic_arm_write (host->scsi.io_port, DATA, msg->msg[0]);
1268
        host->scsi.last_message = msg->msg[0];
1269
#if (DEBUG & DEBUG_MESSAGES)
1270
        print_msg (msg->msg);
1271
#endif
1272
        break;
1273
 
1274
    default:
1275
        /*
1276
         * ANSI standard says: (SCSI-2 Rev 10c Sect 5.6.14)
1277
         * 'When a target sends this (MESSAGE_REJECT) message, it
1278
         *  shall change to MESSAGE IN phase and send this message
1279
         *  prior to requesting additional message bytes from the
1280
         *  initiator.  This provides an interlock so that the
1281
         *  initiator can determine which message byte is rejected.
1282
         */
1283
        sbic_arm_write (host->scsi.io_port, TRANSCNTH, 0);
1284
        sbic_arm_writenext (host->scsi.io_port, 0);
1285
        sbic_arm_writenext (host->scsi.io_port, message_length);
1286
        acornscsi_sbic_issuecmd (host, CMND_XFERINFO);
1287
 
1288
        msgnr = 0;
1289
        while ((msg = msgqueue_getmsg (&host->scsi.msgs, msgnr++)) != NULL) {
1290
            unsigned int asr, i;
1291
#if (DEBUG & DEBUG_MESSAGES)
1292
            print_msg (msg);
1293
#endif
1294
            for (i = 0; i < msg->length;) {
1295
                asr = sbic_arm_read(host->scsi.io_port, ASR);
1296
                if (asr & ASR_DBR)
1297
                    sbic_arm_write(host->scsi.io_port, DATA, msg->msg[i++]);
1298
                if (asr & ASR_INT)
1299
                    break;
1300
            }
1301
            host->scsi.last_message = msg->msg[0];
1302
            if (msg->msg[0] == EXTENDED_MESSAGE)
1303
                host->scsi.last_message |= msg->msg[2] << 8;
1304
            if (asr & ASR_INT)
1305
                break;
1306
        }
1307
        break;
1308
    }
1309
#if (DEBUG & DEBUG_MESSAGES)
1310
    printk ("\n");
1311
#endif
1312
}
1313
 
1314
/*
1315
 * Function: void acornscsi_readstatusbyte (AS_Host *host)
1316
 * Purpose : Read status byte from connected target
1317
 * Params  : host - host connected to target
1318
 */
1319
static
1320
void acornscsi_readstatusbyte (AS_Host *host)
1321
{
1322
    acornscsi_sbic_issuecmd (host, CMND_XFERINFO|CMND_SBT);
1323
    while ((sbic_arm_read (host->scsi.io_port, ASR) & ASR_DBR) == 0);
1324
 
1325
    host->scsi.SCp.Status = sbic_arm_read (host->scsi.io_port, DATA);
1326
}
1327
 
1328
/*
1329
 * Function: unsigned char acornscsi_readmessagebyte (AS_Host *host)
1330
 * Purpose : Read one message byte from connected target
1331
 * Params  : host - host connected to target
1332
 */
1333
static
1334
unsigned char acornscsi_readmessagebyte (AS_Host *host)
1335
{
1336
    unsigned char message;
1337
 
1338
    acornscsi_sbic_issuecmd (host, CMND_XFERINFO | CMND_SBT);
1339
    while ((sbic_arm_read (host->scsi.io_port, ASR) & ASR_DBR) == 0);
1340
 
1341
    message = sbic_arm_read (host->scsi.io_port, DATA);
1342
 
1343
    /* wait for MSGIN-XFER-PAUSED */
1344
    while ((sbic_arm_read (host->scsi.io_port, ASR) & ASR_INT) == 0);
1345
    sbic_arm_read (host->scsi.io_port, SSR);
1346
 
1347
    return message;
1348
}
1349
 
1350
/*
1351
 * Function: void acornscsi_message (AS_Host *host)
1352
 * Purpose : Read complete message from connected target & action message
1353
 * Params  : host - host connected to target
1354
 */
1355
static
1356
void acornscsi_message (AS_Host *host)
1357
{
1358
    unsigned char message[16];
1359
    unsigned int msgidx = 0, msglen = 1;
1360
 
1361
    do {
1362
        message[msgidx] = acornscsi_readmessagebyte (host);
1363
 
1364
        switch (msgidx) {
1365
        case 0:
1366
            if (message[0] == EXTENDED_MESSAGE ||
1367
                (message[0] >= 0x20 && message[0] <= 0x2f))
1368
                msglen = 2;
1369
            break;
1370
 
1371
        case 1:
1372
            if (message[0] == EXTENDED_MESSAGE)
1373
                msglen += message[msgidx];
1374
            break;
1375
        }
1376
        msgidx += 1;
1377
        if (msgidx < msglen) {
1378
            acornscsi_sbic_issuecmd (host, CMND_NEGATEACK);
1379
 
1380
            /* wait for next msg-in */
1381
            while ((sbic_arm_read (host->scsi.io_port, ASR) & ASR_INT) == 0);
1382
            sbic_arm_read (host->scsi.io_port, SSR);
1383
        }
1384
    } while (msgidx < msglen);
1385
 
1386
#if (DEBUG & DEBUG_MESSAGES)
1387
    printk (KERN_DEBUG "scsi%d.%c: message in: ",
1388
            host->host->host_no, acornscsi_target (host));
1389
    print_msg (message);
1390
    printk ("\n");
1391
#endif
1392
 
1393
    if (host->scsi.phase == PHASE_RECONNECTED) {
1394
        /*
1395
         * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.17)
1396
         * 'Whenever a target reconnects to an initiator to continue
1397
         *  a tagged I/O process, the SIMPLE QUEUE TAG message shall
1398
         *  be sent immediately following the IDENTIFY message...'
1399
         */
1400
        if (message[0] == SIMPLE_QUEUE_TAG)
1401
            host->scsi.reconnected.tag = message[1];
1402
        if (acornscsi_reconnect_finish (host))
1403
            host->scsi.phase = PHASE_MSGIN;
1404
    }
1405
 
1406
    switch (message[0]) {
1407
    case ABORT:
1408
    case ABORT_TAG:
1409
    case COMMAND_COMPLETE:
1410
        if (host->scsi.phase != PHASE_STATUSIN)
1411
            printk (KERN_ERR "scsi%d.%c: command complete following non-status in phase?\n",
1412
                    host->host->host_no, acornscsi_target (host));
1413
        host->scsi.phase = PHASE_DONE;
1414
        host->scsi.SCp.Message = message[0];
1415
        break;
1416
 
1417
    case SAVE_POINTERS:
1418
        /*
1419
         * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.20)
1420
         * 'The SAVE DATA POINTER message is sent from a target to
1421
         *  direct the initiator to copy the active data pointer to
1422
         *  the saved data pointer for the current I/O process.
1423
         */
1424
        acornscsi_dma_cleanup (host);
1425
        host->SCpnt->SCp = host->scsi.SCp;
1426
        host->SCpnt->SCp.sent_command = 0;
1427
        host->scsi.phase = PHASE_MSGIN;
1428
        break;
1429
 
1430
    case RESTORE_POINTERS:
1431
        /*
1432
         * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.19)
1433
         * 'The RESTORE POINTERS message is sent from a target to
1434
         *  direct the initiator to copy the most recently saved
1435
         *  command, data, and status pointers for the I/O process
1436
         *  to the corresponding active pointers.  The command and
1437
         *  status pointers shall be restored to the beginning of
1438
         *  the present command and status areas.'
1439
         */
1440
        acornscsi_dma_cleanup (host);
1441
        host->scsi.SCp = host->SCpnt->SCp;
1442
        host->scsi.phase = PHASE_MSGIN;
1443
        break;
1444
 
1445
    case DISCONNECT:
1446
        /*
1447
         * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 6.4.2)
1448
         * 'On those occasions when an error or exception condition occurs
1449
         *  and the target elects to repeat the information transfer, the
1450
         *  target may repeat the transfer either issuing a RESTORE POINTERS
1451
         *  message or by disconnecting without issuing a SAVE POINTERS
1452
         *  message.  When reconnection is completed, the most recent
1453
         *  saved pointer values are restored.'
1454
         */
1455
        acornscsi_dma_cleanup (host);
1456
        host->scsi.phase = PHASE_DISCONNECT;
1457
        break;
1458
 
1459
    case MESSAGE_REJECT:
1460
#if 0 /* this isn't needed any more */
1461
        /*
1462
         * If we were negociating sync transfer, we don't yet know if
1463
         * this REJECT is for the sync transfer or for the tagged queue/wide
1464
         * transfer.  Re-initiate sync transfer negociation now, and if
1465
         * we got a REJECT in response to SDTR, then it'll be set to DONE.
1466
         */
1467
        if (host->device[host->SCpnt->target].sync_state == SYNC_SENT_REQUEST)
1468
            host->device[host->SCpnt->target].sync_state = SYNC_NEGOCIATE;
1469
#endif
1470
 
1471
        /*
1472
         * If we have any messages waiting to go out, then assert ATN now
1473
         */
1474
        if (msgqueue_msglength (&host->scsi.msgs))
1475
            acornscsi_sbic_issuecmd (host, CMND_ASSERTATN);
1476
 
1477
        switch (host->scsi.last_message) {
1478
#ifdef SCSI2_TAG
1479
        case HEAD_OF_QUEUE_TAG:
1480
        case ORDERED_QUEUE_TAG:
1481
        case SIMPLE_QUEUE_TAG:
1482
            /*
1483
             * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.17)
1484
             *  If a target does not implement tagged queuing and a queue tag
1485
             *  message is received, it shall respond with a MESSAGE REJECT
1486
             *  message and accept the I/O process as if it were untagged.
1487
             */
1488
            printk (KERN_NOTICE "scsi%d.%c: disabling tagged queueing\n",
1489
                    host->host->host_no, acornscsi_target (host));
1490
            host->SCpnt->device->tagged_queue = 0;
1491
            set_bit (host->SCpnt->target * 8 + host->SCpnt->lun, &host->busyluns);
1492
            break;
1493
#endif
1494
        case EXTENDED_MESSAGE | (EXTENDED_SDTR << 8):
1495
            /*
1496
             * Target can't handle synchronous transfers
1497
             */
1498
            printk (KERN_NOTICE "scsi%d.%c: Using asynchronous transfer\n",
1499
                    host->host->host_no, acornscsi_target (host));
1500
            host->device[host->SCpnt->target].sync_xfer = SYNCHTRANSFER_2DBA;
1501
            host->device[host->SCpnt->target].sync_state = SYNC_ASYNCHRONOUS;
1502
            sbic_arm_write (host->scsi.io_port, SYNCHTRANSFER, host->device[host->SCpnt->target].sync_xfer);
1503
            break;
1504
 
1505
        default:
1506
            break;
1507
        }
1508
        break;
1509
 
1510
    case QUEUE_FULL:
1511
        /* TODO: target queue is full */
1512
        break;
1513
 
1514
    case SIMPLE_QUEUE_TAG:
1515
        /* tag queue reconnect... message[1] = queue tag.  Print something to indicate something happened! */
1516
        printk ("scsi%d.%c: reconnect queue tag %02X\n",
1517
                host->host->host_no, acornscsi_target (host),
1518
                message[1]);
1519
        break;
1520
 
1521
    case EXTENDED_MESSAGE:
1522
        switch (message[2]) {
1523
#ifdef SCSI2_SYNC
1524
        case EXTENDED_SDTR:
1525
            if (host->device[host->SCpnt->target].sync_state == SYNC_SENT_REQUEST) {
1526
                /*
1527
                 * We requested synchronous transfers.  This isn't quite right...
1528
                 * We can only say if this succeeded if we proceed on to execute the
1529
                 * command from this message.  If we get a MESSAGE PARITY ERROR,
1530
                 * and the target retries fail, then we fallback to asynchronous mode
1531
                 */
1532
                host->device[host->SCpnt->target].sync_state = SYNC_COMPLETED;
1533
                printk (KERN_NOTICE "scsi%d.%c: Using synchronous transfer, offset %d, %d ns\n",
1534
                        host->host->host_no, acornscsi_target(host),
1535
                        message[4], message[3] * 4);
1536
                host->device[host->SCpnt->target].sync_xfer =
1537
                        calc_sync_xfer (message[3] * 4, message[4]);
1538
            } else {
1539
                unsigned char period, length;
1540
                /*
1541
                 * Target requested synchronous transfers.  The agreement is only
1542
                 * to be in operation AFTER the target leaves message out phase.
1543
                 */
1544
                acornscsi_sbic_issuecmd (host, CMND_ASSERTATN);
1545
                period = max (message[3], sdtr_period / 4);
1546
                length = min (message[4], sdtr_size);
1547
                msgqueue_addmsg (&host->scsi.msgs, 5, EXTENDED_MESSAGE, 3,
1548
                                 EXTENDED_SDTR, period, length);
1549
                host->device[host->SCpnt->target].sync_xfer =
1550
                        calc_sync_xfer (period * 4, length);
1551
            }
1552
            sbic_arm_write (host->scsi.io_port, SYNCHTRANSFER, host->device[host->SCpnt->target].sync_xfer);
1553
            break;
1554
#else
1555
            /* We do not accept synchronous transfers.  Respond with a
1556
             * MESSAGE_REJECT.
1557
             */
1558
#endif
1559
 
1560
        case EXTENDED_WDTR:
1561
            /* The WD33C93A is only 8-bit.  We respond with a MESSAGE_REJECT
1562
             * to a wide data transfer request.
1563
             */
1564
        default:
1565
            acornscsi_sbic_issuecmd (host, CMND_ASSERTATN);
1566
            msgqueue_flush (&host->scsi.msgs);
1567
            msgqueue_addmsg (&host->scsi.msgs, 1, MESSAGE_REJECT);
1568
            break;
1569
        }
1570
        break;
1571
 
1572
#ifdef SCSI2_LINK
1573
    case LINKED_CMD_COMPLETE:
1574
    case LINKED_FLG_CMD_COMPLETE:
1575
        /*
1576
         * We don't support linked commands yet
1577
         */
1578
        if (0) {
1579
#if (DEBUG & DEBUG_LINK)
1580
            printk (KERN_DEBUG "scsi%d.%c: lun %d tag %d linked command complete\n",
1581
                    host->host->host_no, acornscsi_target(host), host->SCpnt->tag);
1582
#endif
1583
            /*
1584
             * A linked command should only terminate with one of these messages
1585
             * if there are more linked commands available.
1586
             */
1587
            if (!host->SCpnt->next_link) {
1588
                printk (KERN_WARNING "scsi%d.%c: lun %d tag %d linked command complete, but no next_link\n",
1589
                        instance->host_no, acornscsi_target (host), host->SCpnt->tag);
1590
                acornscsi_sbic_issuecmd (host, CMND_ASSERTATN);
1591
                msgqueue_addmsg (&host->scsi.msgs, 1, ABORT);
1592
            } else {
1593
                Scsi_Cmnd *SCpnt = host->SCpnt;
1594
 
1595
                acornscsi_dma_cleanup (host);
1596
 
1597
                host->SCpnt = host->SCpnt->next_link;
1598
                host->SCpnt->tag = SCpnt->tag;
1599
                SCpnt->result = DID_OK | host->scsi.SCp.Message << 8 | host->Scsi.SCp.Status;
1600
                SCpnt->done (SCpnt);
1601
 
1602
                /* initialise host->SCpnt->SCp */
1603
            }
1604
            break;
1605
        }
1606
#endif
1607
 
1608
    default: /* reject message */
1609
        printk (KERN_ERR "scsi%d.%c: unrecognised message %02X, rejecting\n",
1610
                host->host->host_no, acornscsi_target (host),
1611
                message[0]);
1612
        acornscsi_sbic_issuecmd (host, CMND_ASSERTATN);
1613
        msgqueue_flush (&host->scsi.msgs);
1614
        msgqueue_addmsg (&host->scsi.msgs, 1, MESSAGE_REJECT);
1615
        host->scsi.phase = PHASE_MSGIN;
1616
        break;
1617
    }
1618
    acornscsi_sbic_issuecmd (host, CMND_NEGATEACK);
1619
}
1620
 
1621
/*
1622
 * Function: int acornscsi_buildmessages (AS_Host *host)
1623
 * Purpose : build the connection messages for a host
1624
 * Params  : host - host to add messages to
1625
 */
1626
static
1627
void acornscsi_buildmessages (AS_Host *host)
1628
{
1629
#if 0
1630
    /* does the device need resetting? */
1631
    if (cmd_reset) {
1632
        msgqueue_addmsg (&host->scsi.msgs, 1, BUS_DEVICE_RESET);
1633
        return;
1634
    }
1635
#endif
1636
 
1637
    msgqueue_addmsg (&host->scsi.msgs, 1,
1638
                     IDENTIFY(host->device[host->SCpnt->target].disconnect_ok,
1639
                             host->SCpnt->lun));
1640
 
1641
#if 0
1642
    /* does the device need the current command aborted */
1643
    if (cmd_aborted) {
1644
        acornscsi_abortcmd (host->SCpnt->tag);
1645
        return;
1646
    }
1647
#endif
1648
 
1649
#ifdef SCSI2_TAG
1650
    if (host->SCpnt->tag) {
1651
        unsigned int tag_type;
1652
 
1653
        if (host->SCpnt->cmnd[0] == REQUEST_SENSE ||
1654
            host->SCpnt->cmnd[0] == TEST_UNIT_READY ||
1655
            host->SCpnt->cmnd[0] == INQUIRY)
1656
            tag_type = HEAD_OF_QUEUE_TAG;
1657
        else
1658
            tag_type = SIMPLE_QUEUE_TAG;
1659
        msgqueue_addmsg (&host->scsi.msgs, 2, tag_type, host->SCpnt->tag);
1660
    }
1661
#endif
1662
 
1663
#ifdef SCSI2_SYNC
1664
    if (host->device[host->SCpnt->target].sync_state == SYNC_NEGOCIATE) {
1665
        host->device[host->SCpnt->target].sync_state = SYNC_SENT_REQUEST;
1666
        msgqueue_addmsg (&host->scsi.msgs, 5,
1667
                         EXTENDED_MESSAGE, 3, EXTENDED_SDTR,
1668
                         sdtr_period / 4, sdtr_size);
1669
    }
1670
#endif
1671
}
1672
 
1673
/*
1674
 * Function: int acornscsi_starttransfer (AS_Host *host)
1675
 * Purpose : transfer data to/from connected target
1676
 * Params  : host - host to which target is connected
1677
 * Returns : 0 if failure
1678
 */
1679
static
1680
int acornscsi_starttransfer (AS_Host *host)
1681
{
1682
    int residual;
1683
 
1684
    if (!host->scsi.SCp.ptr /*&& host->scsi.SCp.this_residual*/) {
1685
        printk (KERN_ERR "scsi%d.%c: null buffer passed to acornscsi_starttransfer\n",
1686
                host->host->host_no, acornscsi_target (host));
1687
        return 0;
1688
    }
1689
 
1690
    residual = host->SCpnt->request_bufflen - host->scsi.SCp.have_data_in;
1691
 
1692
    sbic_arm_write (host->scsi.io_port, SYNCHTRANSFER, host->device[host->SCpnt->target].sync_xfer);
1693
    sbic_arm_writenext (host->scsi.io_port, residual >> 16);
1694
    sbic_arm_writenext (host->scsi.io_port, residual >> 8);
1695
    sbic_arm_writenext (host->scsi.io_port, residual);
1696
    acornscsi_sbic_issuecmd (host, CMND_XFERINFO);
1697
    return 1;
1698
}
1699
 
1700
/* =========================================================================================
1701
 * Connection & Disconnection
1702
 */
1703
/*
1704
 * Function : acornscsi_reconnect (AS_Host *host)
1705
 * Purpose  : reconnect a previously disconnected command
1706
 * Params   : host - host specific data
1707
 * Remarks  : SCSI spec says:
1708
 *              'The set of active pointers is restored from the set
1709
 *               of saved pointers upon reconnection of the I/O process'
1710
 */
1711
static
1712
int acornscsi_reconnect (AS_Host *host)
1713
{
1714
    unsigned int target, lun, ok = 0;
1715
 
1716
    target = sbic_arm_read (host->scsi.io_port, SOURCEID);
1717
 
1718
    if (!(target & 8))
1719
        printk (KERN_ERR "scsi%d: invalid source id after reselection "
1720
                "- device fault?\n",
1721
                host->host->host_no);
1722
 
1723
    target &= 7;
1724
 
1725
    if (host->SCpnt && !host->scsi.disconnectable) {
1726
        printk (KERN_ERR "scsi%d.%d: reconnected while command in "
1727
                "progress to target %d?\n",
1728
                host->host->host_no, target, host->SCpnt->target);
1729
        host->SCpnt = NULL;
1730
    }
1731
 
1732
    lun = sbic_arm_read (host->scsi.io_port, DATA) & 7;
1733
 
1734
    host->scsi.reconnected.target = target;
1735
    host->scsi.reconnected.lun = lun;
1736
    host->scsi.reconnected.tag = 0;
1737
 
1738
    if (host->scsi.disconnectable && host->SCpnt &&
1739
        host->SCpnt->target == target && host->SCpnt->lun == lun)
1740
        ok = 1;
1741
 
1742
    if (!ok && queue_probetgtlun (&host->queues.disconnected, target, lun))
1743
        ok = 1;
1744
 
1745
    ADD_STATUS(target, 0x81, host->scsi.phase, 0);
1746
 
1747
    if (ok) {
1748
        host->scsi.phase = PHASE_RECONNECTED;
1749
    } else {
1750
        /* this doesn't seem to work */
1751
        printk (KERN_ERR "scsi%d.%c: reselected with no command "
1752
                "to reconnect with\n",
1753
                host->host->host_no, '0' + target);
1754
        acornscsi_dumplog (host, target);
1755
        acornscsi_sbic_issuecmd (host, CMND_ASSERTATN);
1756
        msgqueue_addmsg (&host->scsi.msgs, 1, ABORT);
1757
        host->scsi.phase = PHASE_ABORTED;
1758
    }
1759
    acornscsi_sbic_issuecmd (host, CMND_NEGATEACK);
1760
    return !ok;
1761
}
1762
 
1763
/*
1764
 * Function: int acornscsi_reconect_finish (AS_Host *host)
1765
 * Purpose : finish reconnecting a command
1766
 * Params  : host - host to complete
1767
 * Returns : 0 if failed
1768
 */
1769
static
1770
int acornscsi_reconnect_finish (AS_Host *host)
1771
{
1772
    if (host->scsi.disconnectable && host->SCpnt) {
1773
        host->scsi.disconnectable = 0;
1774
        if (host->SCpnt->target == host->scsi.reconnected.target &&
1775
            host->SCpnt->lun    == host->scsi.reconnected.lun &&
1776
            host->SCpnt->tag    == host->scsi.reconnected.tag) {
1777
#if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
1778
            DBG(host->SCpnt, printk ("scsi%d.%c: reconnected",
1779
                    host->host->host_no, acornscsi_target (host)));
1780
#endif
1781
        } else {
1782
            queue_add_cmd_tail (&host->queues.disconnected, host->SCpnt);
1783
#if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
1784
            DBG(host->SCpnt, printk ("scsi%d.%c: had to move command "
1785
                    "to disconnected queue\n",
1786
                    host->host->host_no, acornscsi_target (host)));
1787
#endif
1788
            host->SCpnt = NULL;
1789
        }
1790
    }
1791
    if (!host->SCpnt) {
1792
        host->SCpnt = queue_remove_tgtluntag (&host->queues.disconnected,
1793
                                host->scsi.reconnected.target,
1794
                                host->scsi.reconnected.lun,
1795
                                host->scsi.reconnected.tag);
1796
#if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
1797
        DBG(host->SCpnt, printk ("scsi%d.%c: had to get command",
1798
                host->host->host_no, acornscsi_target (host)));
1799
#endif
1800
    }
1801
 
1802
    if (!host->SCpnt) {
1803
        acornscsi_abortcmd (host, host->scsi.reconnected.tag);
1804
        host->scsi.phase = PHASE_ABORTED;
1805
    } else {
1806
        /*
1807
         * Restore data pointer from SAVED pointers.
1808
         */
1809
        host->scsi.SCp = host->SCpnt->SCp;
1810
#if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
1811
        printk (", data pointers: [%p, %X]",
1812
                host->scsi.SCp.ptr, host->scsi.SCp.this_residual);
1813
#endif
1814
    }
1815
#if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
1816
    printk ("\n");
1817
#endif
1818
 
1819
    host->dma.transferred = host->scsi.SCp.have_data_in;
1820
 
1821
    return host->SCpnt != NULL;
1822
}
1823
 
1824
/*
1825
 * Function: void acornscsi_disconnect_unexpected (AS_Host *host)
1826
 * Purpose : handle an unexpected disconnect
1827
 * Params  : host - host on which disconnect occurred
1828
 */
1829
static
1830
void acornscsi_disconnect_unexpected (AS_Host *host)
1831
{
1832
    printk (KERN_ERR "scsi%d.%c: unexpected disconnect\n",
1833
            host->host->host_no, acornscsi_target (host));
1834
#if (DEBUG & DEBUG_ABORT)
1835
    acornscsi_dumplog (host, 8);
1836
#endif
1837
 
1838
    acornscsi_done (host, &host->SCpnt, DID_ABORT);
1839
}
1840
 
1841
/*
1842
 * Function: void acornscsi_abortcmd (AS_host *host, unsigned char tag)
1843
 * Purpose : abort a currently executing command
1844
 * Params  : host - host with connected command to abort
1845
 *           tag  - tag to abort
1846
 */
1847
static
1848
void acornscsi_abortcmd (AS_Host *host, unsigned char tag)
1849
{
1850
    sbic_arm_write (host->scsi.io_port, CMND, CMND_ASSERTATN);
1851
 
1852
    msgqueue_flush (&host->scsi.msgs);
1853
#ifdef SCSI2_TAG
1854
    if (tag)
1855
        msgqueue_addmsg (&host->scsi.msgs, 2, ABORT_TAG, tag);
1856
    else
1857
#endif
1858
        msgqueue_addmsg (&host->scsi.msgs, 1, ABORT);
1859
}
1860
 
1861
/* ==========================================================================================
1862
 * Interrupt routines.
1863
 */
1864
/*
1865
 * Function: int acornscsi_sbicintr (AS_Host *host)
1866
 * Purpose : handle interrupts from SCSI device
1867
 * Params  : host - host to process
1868
 * Returns : INTR_PROCESS if expecting another SBIC interrupt
1869
 *           INTR_IDLE if no interrupt
1870
 *           INTR_NEXT_COMMAND if we have finished processing the command
1871
 */
1872
static
1873
intr_ret_t acornscsi_sbicintr (AS_Host *host, int in_irq)
1874
{
1875
    unsigned int asr, ssr;
1876
 
1877
    asr = sbic_arm_read (host->scsi.io_port, ASR);
1878
    if (!(asr & ASR_INT))
1879
        return INTR_IDLE;
1880
 
1881
    ssr = sbic_arm_read (host->scsi.io_port, SSR);
1882
 
1883
#if (DEBUG & DEBUG_PHASES)
1884
    print_sbic_status(asr, ssr, host->scsi.phase);
1885
#endif
1886
 
1887
    ADD_STATUS(8, ssr, host->scsi.phase, in_irq);
1888
 
1889
    if (host->SCpnt && !host->scsi.disconnectable)
1890
        ADD_STATUS(host->SCpnt->target, ssr, host->scsi.phase, in_irq);
1891
 
1892
    switch (ssr) {
1893
    case 0x00:                          /* reset state - not advanced                   */
1894
        printk (KERN_ERR "scsi%d: reset in standard mode but wanted advanced mode.\n",
1895
                host->host->host_no);
1896
        /* setup sbic - WD33C93A */
1897
        sbic_arm_write (host->scsi.io_port, OWNID, OWNID_EAF | host->host->this_id);
1898
        sbic_arm_write (host->scsi.io_port, CMND, CMND_RESET);
1899
        return INTR_IDLE;
1900
 
1901
    case 0x01:                          /* reset state - advanced                       */
1902
        sbic_arm_write (host->scsi.io_port, CTRL, INIT_SBICDMA | CTRL_IDI);
1903
        sbic_arm_write (host->scsi.io_port, TIMEOUT, TIMEOUT_TIME);
1904
        sbic_arm_write (host->scsi.io_port, SYNCHTRANSFER, SYNCHTRANSFER_2DBA);
1905
        sbic_arm_write (host->scsi.io_port, SOURCEID, SOURCEID_ER | SOURCEID_DSP);
1906
        msgqueue_flush (&host->scsi.msgs);
1907
        return INTR_IDLE;
1908
 
1909
    case 0x41:                          /* unexpected disconnect aborted command        */
1910
        acornscsi_disconnect_unexpected (host);
1911
        return INTR_NEXT_COMMAND;
1912
    }
1913
 
1914
    switch (host->scsi.phase) {
1915
    case PHASE_CONNECTING:              /* STATE: command removed from issue queue      */
1916
        switch (ssr) {
1917
        case 0x11:                      /* -> PHASE_CONNECTED                           */
1918
            /* BUS FREE -> SELECTION */
1919
            host->scsi.phase = PHASE_CONNECTED;
1920
            msgqueue_flush (&host->scsi.msgs);
1921
            host->dma.transferred = host->scsi.SCp.have_data_in;
1922
            /* 33C93 gives next interrupt indicating bus phase */
1923
            asr = sbic_arm_read (host->scsi.io_port, ASR);
1924
            if (!(asr & ASR_INT))
1925
                break;
1926
            ssr = sbic_arm_read (host->scsi.io_port, SSR);
1927
            ADD_STATUS(8, ssr, host->scsi.phase, 1);
1928
            ADD_STATUS(host->SCpnt->target, ssr, host->scsi.phase, 1);
1929
            goto connected;
1930
 
1931
        case 0x42:                      /* select timed out                             */
1932
                                        /* -> PHASE_IDLE                                */
1933
            acornscsi_done (host, &host->SCpnt, DID_NO_CONNECT);
1934
            return INTR_NEXT_COMMAND;
1935
 
1936
        case 0x81:                      /* -> PHASE_RECONNECTED or PHASE_ABORTED        */
1937
            /* BUS FREE -> RESELECTION */
1938
            host->origSCpnt = host->SCpnt;
1939
            host->SCpnt = NULL;
1940
            msgqueue_flush (&host->scsi.msgs);
1941
            acornscsi_reconnect (host);
1942
            break;
1943
 
1944
        default:
1945
            printk (KERN_ERR "scsi%d.%c: PHASE_CONNECTING, SSR %02X?\n",
1946
                    host->host->host_no, acornscsi_target (host), ssr);
1947
            acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
1948
            acornscsi_abortcmd (host, host->SCpnt->tag);
1949
        }
1950
        return INTR_PROCESSING;
1951
 
1952
    connected:
1953
    case PHASE_CONNECTED:               /* STATE: device selected ok                    */
1954
        switch (ssr) {
1955
#ifdef NONSTANDARD
1956
        case 0x8a:                      /* -> PHASE_COMMAND, PHASE_COMMANDPAUSED        */
1957
            /* SELECTION -> COMMAND */
1958
            acornscsi_sendcommand (host);
1959
            break;
1960
 
1961
        case 0x8b:                      /* -> PHASE_STATUS                              */
1962
            /* SELECTION -> STATUS */
1963
            acornscsi_readstatusbyte (host);
1964
            host->scsi.phase = PHASE_STATUSIN;
1965
            break;
1966
#endif
1967
 
1968
        case 0x8e:                      /* -> PHASE_MSGOUT                              */
1969
            /* SELECTION ->MESSAGE OUT */
1970
            host->scsi.phase = PHASE_MSGOUT;
1971
            acornscsi_buildmessages (host);
1972
            acornscsi_sendmessage (host);
1973
            break;
1974
 
1975
        /* these should not happen */
1976
        case 0x85:                      /* target disconnected                          */
1977
            acornscsi_done (host, &host->SCpnt, DID_ERROR);
1978
            break;
1979
 
1980
        default:
1981
            printk (KERN_ERR "scsi%d.%c: PHASE_CONNECTED, SSR %02X?\n",
1982
                    host->host->host_no, acornscsi_target (host), ssr);
1983
            acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
1984
            acornscsi_abortcmd (host, host->SCpnt->tag);
1985
        }
1986
        return INTR_PROCESSING;
1987
 
1988
    case PHASE_MSGOUT:                  /* STATE: connected & sent IDENTIFY message     */
1989
        /*
1990
         * SCSI standard says th at a MESSAGE OUT phases can be followed by a DATA phase
1991
         */
1992
        switch (ssr) {
1993
        case 0x8a:
1994
        case 0x1a:                      /* -> PHASE_COMMAND, PHASE_COMMANDPAUSED        */
1995
            /* MESSAGE OUT -> COMMAND */
1996
            acornscsi_sendcommand (host);
1997
            break;
1998
 
1999
        case 0x1b:                      /* -> PHASE_STATUS                              */
2000
            /* MESSAGE OUT -> STATUS */
2001
            acornscsi_readstatusbyte (host);
2002
            host->scsi.phase = PHASE_STATUSIN;
2003
            break;
2004
 
2005
        case 0x8e:                      /* -> PHASE_MSGOUT                              */
2006
            /* MESSAGE_OUT(MESSAGE_IN) ->MESSAGE OUT */
2007
            acornscsi_sendmessage (host);
2008
            break;
2009
 
2010
        case 0x4f:
2011
        case 0x1f:                      /* -> PHASE_MSGIN, PHASE_DISCONNECT             */
2012
            /* MESSAGE OUT -> MESSAGE IN */
2013
            acornscsi_message (host);
2014
            break;
2015
 
2016
        default:
2017
            printk (KERN_ERR "scsi%d.%c: PHASE_MSGOUT, SSR %02X?\n",
2018
                    host->host->host_no, acornscsi_target (host), ssr);
2019
            acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
2020
        }
2021
        return INTR_PROCESSING;
2022
 
2023
    case PHASE_COMMAND:                 /* STATE: connected & command sent              */
2024
        switch (ssr) {
2025
        case 0x18:                      /* -> PHASE_DATAOUT                             */
2026
            /* COMMAND -> DATA OUT */
2027
            if (host->scsi.SCp.sent_command != host->SCpnt->cmd_len)
2028
                acornscsi_abortcmd (host, host->SCpnt->tag);
2029
            acornscsi_dma_setup (host, DMA_OUT);
2030
            if (!acornscsi_starttransfer (host))
2031
                acornscsi_abortcmd (host, host->SCpnt->tag);
2032
            host->scsi.phase = PHASE_DATAOUT;
2033
            return INTR_IDLE;
2034
 
2035
        case 0x19:                      /* -> PHASE_DATAIN                              */
2036
            /* COMMAND -> DATA IN */
2037
            if (host->scsi.SCp.sent_command != host->SCpnt->cmd_len)
2038
                acornscsi_abortcmd (host, host->SCpnt->tag);
2039
            acornscsi_dma_setup (host, DMA_IN);
2040
            if (!acornscsi_starttransfer (host))
2041
                acornscsi_abortcmd (host, host->SCpnt->tag);
2042
            host->scsi.phase = PHASE_DATAIN;
2043
            return INTR_IDLE;
2044
 
2045
        case 0x1b:                      /* -> PHASE_STATUS                              */
2046
            /* COMMAND -> STATUS */
2047
            acornscsi_readstatusbyte (host);
2048
            host->scsi.phase = PHASE_STATUSIN;
2049
            break;
2050
 
2051
        case 0x1e:                      /* -> PHASE_MSGOUT                              */
2052
            /* COMMAND -> MESSAGE OUT */
2053
            acornscsi_sendmessage (host);
2054
            break;
2055
 
2056
        case 0x1f:                      /* -> PHASE_MSGIN, PHASE_DISCONNECT             */
2057
            /* COMMAND -> MESSAGE IN */
2058
            acornscsi_message (host);
2059
            break;
2060
 
2061
        default:
2062
            printk (KERN_ERR "scsi%d.%c: PHASE_COMMAND, SSR %02X?\n",
2063
                    host->host->host_no, acornscsi_target (host), ssr);
2064
            acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
2065
        }
2066
        return INTR_PROCESSING;
2067
 
2068
    case PHASE_DISCONNECT:              /* STATE: connected, received DISCONNECT msg    */
2069
        if (ssr == 0x85) {              /* -> PHASE_IDLE                                */
2070
            host->scsi.disconnectable = 1;
2071
            host->scsi.reconnected.tag = 0;
2072
            host->scsi.phase = PHASE_IDLE;
2073
            host->stats.disconnects += 1;
2074
        } else {
2075
            printk (KERN_ERR "scsi%d.%c: PHASE_DISCONNECT, SSR %02X instead of disconnect?\n",
2076
                    host->host->host_no, acornscsi_target (host), ssr);
2077
            acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
2078
        }
2079
        return INTR_NEXT_COMMAND;
2080
 
2081
    case PHASE_IDLE:                    /* STATE: disconnected                          */
2082
        if (ssr == 0x81)                /* -> PHASE_RECONNECTED or PHASE_ABORTED        */
2083
            acornscsi_reconnect (host);
2084
        else {
2085
            printk (KERN_ERR "scsi%d.%c: PHASE_IDLE, SSR %02X while idle?\n",
2086
                    host->host->host_no, acornscsi_target (host), ssr);
2087
            acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
2088
        }
2089
        return INTR_PROCESSING;
2090
 
2091
    case PHASE_RECONNECTED:             /* STATE: device reconnected to initiator       */
2092
        /*
2093
         * Command reconnected - if MESGIN, get message - it may be
2094
         * the tag.  If not, get command out of disconnected queue
2095
         */
2096
        /*
2097
         * If we reconnected and we're not in MESSAGE IN phase after IDENTIFY,
2098
         * reconnect I_T_L command
2099
         */
2100
        if (ssr != 0x8f && !acornscsi_reconnect_finish (host))
2101
            return INTR_IDLE;
2102
        ADD_STATUS(host->SCpnt->target, ssr, host->scsi.phase, in_irq);
2103
        switch (ssr) {
2104
        case 0x88:                      /* data out phase                               */
2105
                                        /* -> PHASE_DATAOUT                             */
2106
            /* MESSAGE IN -> DATA OUT */
2107
            acornscsi_dma_setup (host, DMA_OUT);
2108
            if (!acornscsi_starttransfer (host))
2109
                acornscsi_abortcmd (host, host->SCpnt->tag);
2110
            host->scsi.phase = PHASE_DATAOUT;
2111
            return INTR_IDLE;
2112
 
2113
        case 0x89:                      /* data in phase                                */
2114
                                        /* -> PHASE_DATAIN                              */
2115
            /* MESSAGE IN -> DATA IN */
2116
            acornscsi_dma_setup (host, DMA_IN);
2117
            if (!acornscsi_starttransfer (host))
2118
                acornscsi_abortcmd (host, host->SCpnt->tag);
2119
            host->scsi.phase = PHASE_DATAIN;
2120
            return INTR_IDLE;
2121
 
2122
        case 0x8a:                      /* command out                                  */
2123
            /* MESSAGE IN -> COMMAND */
2124
            acornscsi_sendcommand (host);/* -> PHASE_COMMAND, PHASE_COMMANDPAUSED       */
2125
            break;
2126
 
2127
        case 0x8b:                      /* status in                                    */
2128
                                        /* -> PHASE_STATUSIN                            */
2129
            /* MESSAGE IN -> STATUS */
2130
            acornscsi_readstatusbyte (host);
2131
            host->scsi.phase = PHASE_STATUSIN;
2132
            break;
2133
 
2134
        case 0x8e:                      /* message out                                  */
2135
                                        /* -> PHASE_MSGOUT                              */
2136
            /* MESSAGE IN -> MESSAGE OUT */
2137
            acornscsi_sendmessage (host);
2138
            break;
2139
 
2140
        case 0x8f:                      /* message in                                   */
2141
            acornscsi_message (host);   /* -> PHASE_MSGIN, PHASE_DISCONNECT             */
2142
            break;
2143
 
2144
        default:
2145
            printk (KERN_ERR "scsi%d.%c: PHASE_RECONNECTED, SSR %02X after reconnect?\n",
2146
                    host->host->host_no, acornscsi_target (host), ssr);
2147
            acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
2148
        }
2149
        return INTR_PROCESSING;
2150
 
2151
    case PHASE_DATAIN:                  /* STATE: transferred data in                   */
2152
        /*
2153
         * This is simple - if we disconnect then the DMA address & count is
2154
         * correct.
2155
         */
2156
        switch (ssr) {
2157
        case 0x19:                      /* -> PHASE_DATAIN                              */
2158
            acornscsi_abortcmd (host, host->SCpnt->tag);
2159
            return INTR_IDLE;
2160
 
2161
        case 0x4b:                      /* -> PHASE_STATUSIN                            */
2162
        case 0x1b:                      /* -> PHASE_STATUSIN                            */
2163
            /* DATA IN -> STATUS */
2164
            host->scsi.SCp.have_data_in = host->SCpnt->request_bufflen -
2165
                                          acornscsi_sbic_xfcount (host);
2166
            acornscsi_dma_stop (host);
2167
            acornscsi_readstatusbyte (host);
2168
            host->scsi.phase = PHASE_STATUSIN;
2169
            break;
2170
 
2171
        case 0x1e:                      /* -> PHASE_MSGOUT                              */
2172
        case 0x4e:                      /* -> PHASE_MSGOUT                              */
2173
            /* DATA IN -> MESSAGE OUT */
2174
            host->scsi.SCp.have_data_in = host->SCpnt->request_bufflen -
2175
                                          acornscsi_sbic_xfcount (host);
2176
            acornscsi_dma_stop (host);
2177
            acornscsi_sendmessage (host);
2178
            break;
2179
 
2180
        case 0x1f:                      /* message in                                   */
2181
        case 0x4f:                      /* message in                                   */
2182
            /* DATA IN -> MESSAGE IN */
2183
            host->scsi.SCp.have_data_in = host->SCpnt->request_bufflen -
2184
                                          acornscsi_sbic_xfcount (host);
2185
            acornscsi_dma_stop (host);
2186
            acornscsi_message (host);   /* -> PHASE_MSGIN, PHASE_DISCONNECT             */
2187
            break;
2188
 
2189
        default:
2190
            printk (KERN_ERR "scsi%d.%c: PHASE_DATAIN, SSR %02X?\n",
2191
                    host->host->host_no, acornscsi_target (host), ssr);
2192
            acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
2193
        }
2194
        return INTR_PROCESSING;
2195
 
2196
    case PHASE_DATAOUT:                 /* STATE: transferred data out                  */
2197
        /*
2198
         * This is more complicated - if we disconnect, the DMA could be 12
2199
         * bytes ahead of us.  We need to correct this.
2200
         */
2201
        switch (ssr) {
2202
        case 0x18:                      /* -> PHASE_DATAOUT                             */
2203
            acornscsi_abortcmd (host, host->SCpnt->tag);
2204
            return INTR_IDLE;
2205
 
2206
        case 0x4b:                      /* -> PHASE_STATUSIN                            */
2207
        case 0x1b:                      /* -> PHASE_STATUSIN                            */
2208
            /* DATA OUT -> STATUS */
2209
            host->scsi.SCp.have_data_in = host->SCpnt->request_bufflen -
2210
                                          acornscsi_sbic_xfcount (host);
2211
            acornscsi_dma_stop (host);
2212
            acornscsi_dma_adjust (host);
2213
            acornscsi_readstatusbyte (host);
2214
            host->scsi.phase = PHASE_STATUSIN;
2215
            break;
2216
 
2217
        case 0x1e:                      /* -> PHASE_MSGOUT                              */
2218
        case 0x4e:                      /* -> PHASE_MSGOUT                              */
2219
            /* DATA OUT -> MESSAGE OUT */
2220
            host->scsi.SCp.have_data_in = host->SCpnt->request_bufflen -
2221
                                          acornscsi_sbic_xfcount (host);
2222
            acornscsi_dma_stop (host);
2223
            acornscsi_dma_adjust (host);
2224
            acornscsi_sendmessage (host);
2225
            break;
2226
 
2227
        case 0x1f:                      /* message in                                   */
2228
        case 0x4f:                      /* message in                                   */
2229
            /* DATA OUT -> MESSAGE IN */
2230
            host->scsi.SCp.have_data_in = host->SCpnt->request_bufflen -
2231
                                          acornscsi_sbic_xfcount (host);
2232
            acornscsi_dma_stop (host);
2233
            acornscsi_dma_adjust (host);
2234
            acornscsi_message (host);   /* -> PHASE_MSGIN, PHASE_DISCONNECT             */
2235
            break;
2236
 
2237
        default:
2238
            printk (KERN_ERR "scsi%d.%c: PHASE_DATAOUT, SSR %02X?\n",
2239
                    host->host->host_no, acornscsi_target (host), ssr);
2240
            acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
2241
        }
2242
        return INTR_PROCESSING;
2243
 
2244
    case PHASE_STATUSIN:                /* STATE: status in complete                    */
2245
        if (ssr == 0x1f)                /* -> PHASE_MSGIN, PHASE_DONE, PHASE_DISCONNECT */
2246
            /* STATUS -> MESSAGE IN */
2247
            acornscsi_message (host);
2248
        else if (ssr == 0x1e)           /* -> PHASE_MSGOUT                              */
2249
            /* STATUS -> MESSAGE OUT */
2250
            acornscsi_sendmessage (host);
2251
        else {
2252
            printk (KERN_ERR "scsi%d.%c: PHASE_STATUSIN, SSR %02X instead of MESSAGE_IN?\n",
2253
                    host->host->host_no, acornscsi_target (host), ssr);
2254
            acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
2255
        }
2256
        return INTR_PROCESSING;
2257
 
2258
    case PHASE_MSGIN:                   /* STATE: message in                            */
2259
        switch (ssr) {
2260
        case 0x1e:                      /* -> PHASE_MSGOUT                              */
2261
        case 0x4e:                      /* -> PHASE_MSGOUT                              */
2262
            /* MESSAGE IN -> MESSAGE OUT */
2263
            acornscsi_sendmessage (host);
2264
            break;
2265
 
2266
        case 0x1f:                      /* -> PHASE_MSGIN, PHASE_DONE, PHASE_DISCONNECT */
2267
        case 0x2f:
2268
        case 0x4f:
2269
        case 0x8f:
2270
            acornscsi_message (host);
2271
            break;
2272
 
2273
        default:
2274
            printk (KERN_ERR "scsi%d.%c: PHASE_MSGIN, SSR %02X after message in?\n",
2275
                    host->host->host_no, acornscsi_target (host), ssr);
2276
            acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
2277
        }
2278
        return INTR_PROCESSING;
2279
 
2280
    case PHASE_DONE:                    /* STATE: received status & message             */
2281
        switch (ssr) {
2282
        case 0x85:                      /* -> PHASE_IDLE                                */
2283
            acornscsi_done (host, &host->SCpnt, DID_OK);
2284
            return INTR_NEXT_COMMAND;
2285
 
2286
        case 0x8e:
2287
            acornscsi_sendmessage (host);
2288
            break;
2289
 
2290
        default:
2291
            printk (KERN_ERR "scsi%d.%c: PHASE_DONE, SSR %02X instead of disconnect?\n",
2292
                    host->host->host_no, acornscsi_target (host), ssr);
2293
            acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
2294
        }
2295
        return INTR_PROCESSING;
2296
 
2297
    case PHASE_ABORTED:
2298
        switch (ssr) {
2299
        case 0x85:
2300
            acornscsi_done (host, &host->SCpnt, DID_ABORT);
2301
            return INTR_NEXT_COMMAND;
2302
 
2303
        case 0x1e:
2304
        case 0x2e:
2305
        case 0x4e:
2306
        case 0x8e:
2307
            acornscsi_sendmessage (host);
2308
            break;
2309
 
2310
        default:
2311
            printk (KERN_ERR "scsi%d.%c: PHASE_ABORTED, SSR %02X?\n",
2312
                    host->host->host_no, acornscsi_target (host), ssr);
2313
            acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
2314
        }
2315
        return INTR_PROCESSING;
2316
 
2317
    default:
2318
        printk (KERN_ERR "scsi%d.%c: unknown driver phase %d\n",
2319
                host->host->host_no, acornscsi_target (host), ssr);
2320
        acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
2321
    }
2322
    return INTR_PROCESSING;
2323
}
2324
 
2325
/*
2326
 * Prototype: void acornscsi_intr (int irq, void *dev_id, struct pt_regs *regs)
2327
 * Purpose  : handle interrupts from Acorn SCSI card
2328
 * Params   : irq    - interrupt number
2329
 *            dev_id - device specific data (AS_Host structure)
2330
 *            regs   - processor registers when interrupt occurred
2331
 */
2332
static
2333
void acornscsi_intr (int irq, void *dev_id, struct pt_regs *regs)
2334
{
2335
    AS_Host *host = (AS_Host *)dev_id;
2336
    intr_ret_t ret;
2337
    int iostatus;
2338
    int in_irq = 0;
2339
 
2340
    if (host->scsi.interrupt)
2341
        printk ("scsi%d: interrupt re-entered\n", host->host->host_no);
2342
    host->scsi.interrupt = 1;
2343
 
2344
    do {
2345
        ret = INTR_IDLE;
2346
 
2347
        iostatus = inb (host->card.io_intr);
2348
 
2349
        if (iostatus & 2) {
2350
            acornscsi_dma_intr (host);
2351
            iostatus = inb (host->card.io_intr);
2352
        }
2353
 
2354
        if (iostatus & 8)
2355
            ret = acornscsi_sbicintr (host, in_irq);
2356
 
2357
        /*
2358
         * If we have a transfer pending, start it.
2359
         * Only start it if the interface has already started transferring
2360
         * it's data
2361
         */
2362
        if (host->dma.xfer_required)
2363
            acornscsi_dma_xfer (host);
2364
 
2365
        if (ret == INTR_NEXT_COMMAND)
2366
            ret = acornscsi_kick (host);
2367
 
2368
        in_irq = 1;
2369
    } while (ret != INTR_IDLE);
2370
 
2371
    host->scsi.interrupt = 0;
2372
}
2373
 
2374
/*=============================================================================================
2375
 * Interfaces between interrupt handler and rest of scsi code
2376
 */
2377
 
2378
/*
2379
 * Function : acornscsi_queuecmd (Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
2380
 * Purpose  : queues a SCSI command
2381
 * Params   : cmd  - SCSI command
2382
 *            done - function called on completion, with pointer to command descriptor
2383
 * Returns  : 0, or < 0 on error.
2384
 */
2385
int acornscsi_queuecmd (Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
2386
{
2387
    AS_Host *host = (AS_Host *)SCpnt->host->hostdata;
2388
 
2389
    if (!done) {
2390
        /* there should be some way of rejecting errors like this without panicing... */
2391
        panic ("scsi%d: queuecommand called with NULL done function [cmd=%p]",
2392
                SCpnt->host->host_no, SCpnt);
2393
        return -EINVAL;
2394
    }
2395
 
2396
#if (DEBUG & DEBUG_NO_WRITE)
2397
    if (acornscsi_cmdtype (SCpnt->cmnd[0]) == CMD_WRITE && (NO_WRITE & (1 << SCpnt->target))) {
2398
        printk (KERN_CRIT "scsi%d.%c: WRITE attempted with NO_WRITE flag set\n",
2399
            SCpnt->host->host_no, '0' + SCpnt->target);
2400
        SCpnt->result = DID_NO_CONNECT << 16;
2401
        done (SCpnt);
2402
        return 0;
2403
    }
2404
#endif
2405
 
2406
    SCpnt->scsi_done = done;
2407
    SCpnt->host_scribble = NULL;
2408
    SCpnt->result = 0;
2409
    SCpnt->tag = 0;
2410
    SCpnt->SCp.phase = (int)acornscsi_datadirection (SCpnt->cmnd[0]);
2411
    SCpnt->SCp.sent_command = 0;
2412
    SCpnt->SCp.have_data_in = 0;
2413
    SCpnt->SCp.Status = 0;
2414
    SCpnt->SCp.Message = 0;
2415
 
2416
    if (SCpnt->use_sg) {
2417
        SCpnt->SCp.buffer = (struct scatterlist *) SCpnt->buffer;
2418
        SCpnt->SCp.buffers_residual = SCpnt->use_sg - 1;
2419
        SCpnt->SCp.ptr = (char *) SCpnt->SCp.buffer->address;
2420
        SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length;
2421
    } else {
2422
        SCpnt->SCp.buffer = NULL;
2423
        SCpnt->SCp.buffers_residual = 0;
2424
        SCpnt->SCp.ptr = (char *) SCpnt->request_buffer;
2425
        SCpnt->SCp.this_residual = SCpnt->request_bufflen;
2426
    }
2427
 
2428
    host->stats.queues += 1;
2429
 
2430
    {
2431
        unsigned long flags;
2432
 
2433
        if (!queue_add_cmd_ordered (&host->queues.issue, SCpnt)) {
2434
            SCpnt->result = DID_ERROR << 16;
2435
            done (SCpnt);
2436
            return 0;
2437
        }
2438
        save_flags_cli (flags);
2439
        if (host->scsi.phase == PHASE_IDLE)
2440
            acornscsi_kick (host);
2441
        restore_flags (flags);
2442
    }
2443
    return 0;
2444
}
2445
 
2446
/*
2447
 * Prototype: void acornscsi_reportstatus (Scsi_Cmnd **SCpntp1, Scsi_Cmnd **SCpntp2, int result)
2448
 * Purpose  : pass a result to *SCpntp1, and check if *SCpntp1 = *SCpntp2
2449
 * Params   : SCpntp1 - pointer to command to return
2450
 *            SCpntp2 - pointer to command to check
2451
 *            result  - result to pass back to mid-level done function
2452
 * Returns  : *SCpntp2 = NULL if *SCpntp1 is the same command structure as *SCpntp2.
2453
 */
2454
static inline
2455
void acornscsi_reportstatus (Scsi_Cmnd **SCpntp1, Scsi_Cmnd **SCpntp2, int result)
2456
{
2457
    Scsi_Cmnd *SCpnt = *SCpntp1;
2458
 
2459
    if (SCpnt) {
2460
        *SCpntp1 = NULL;
2461
 
2462
        SCpnt->result = result;
2463
        SCpnt->scsi_done (SCpnt);
2464
    }
2465
 
2466
    if (SCpnt == *SCpntp2)
2467
        *SCpntp2 = NULL;
2468
}
2469
 
2470
/*
2471
 * Prototype: int acornscsi_abort (Scsi_Cmnd *SCpnt)
2472
 * Purpose  : abort a command on this host
2473
 * Params   : SCpnt - command to abort
2474
 * Returns  : one of SCSI_ABORT_ macros
2475
 */
2476
int acornscsi_abort (Scsi_Cmnd *SCpnt)
2477
{
2478
    AS_Host *host = (AS_Host *) SCpnt->host->hostdata;
2479
    int result = SCSI_ABORT_NOT_RUNNING;
2480
 
2481
    host->stats.aborts += 1;
2482
 
2483
#if (DEBUG & DEBUG_ABORT)
2484
    {
2485
        int asr, ssr;
2486
        asr = sbic_arm_read (host->scsi.io_port, ASR);
2487
        ssr = sbic_arm_read (host->scsi.io_port, SSR);
2488
 
2489
        printk (KERN_WARNING "acornscsi_abort: ");
2490
        print_sbic_status(asr, ssr, host->scsi.phase);
2491
        acornscsi_dumplog (host, SCpnt->target);
2492
    }
2493
#endif
2494
 
2495
    if (queue_removecmd (&host->queues.issue, SCpnt)) {
2496
        SCpnt->result = DID_ABORT << 16;
2497
        SCpnt->scsi_done (SCpnt);
2498
#if (DEBUG & DEBUG_ABORT)
2499
        printk ("scsi%d: command on issue queue\n", host->host->host_no);
2500
#endif
2501
        result = SCSI_ABORT_SUCCESS;
2502
    } else if (queue_cmdonqueue (&host->queues.disconnected, SCpnt)) {
2503
        printk ("scsi%d: command on disconnected queue\n", host->host->host_no);
2504
        result = SCSI_ABORT_SNOOZE;
2505
    } else if (host->SCpnt == SCpnt) {
2506
        acornscsi_abortcmd (host, host->SCpnt->tag);
2507
        printk ("scsi%d: command executing\n", host->host->host_no);
2508
        result = SCSI_ABORT_SNOOZE;
2509
    } else if (host->origSCpnt == SCpnt) {
2510
        host->origSCpnt = NULL;
2511
        SCpnt->result = DID_ABORT << 16;
2512
        SCpnt->scsi_done (SCpnt);
2513
#if (DEBUG & DEBUG_ABORT)
2514
        printk ("scsi%d: command waiting for execution\n", host->host->host_no);
2515
#endif
2516
        result = SCSI_ABORT_SUCCESS;
2517
    }
2518
 
2519
    if (result == SCSI_ABORT_NOT_RUNNING) {
2520
        printk ("scsi%d: abort(): command not running\n", host->host->host_no);
2521
        acornscsi_dumplog (host, SCpnt->target);
2522
#if (DEBUG & DEBUG_ABORT)
2523
        result = SCSI_ABORT_SNOOZE;
2524
#endif
2525
    }
2526
    return result;
2527
}
2528
 
2529
/*
2530
 * Prototype: int acornscsi_reset (Scsi_Cmnd *SCpnt, unsigned int reset_flags)
2531
 * Purpose  : reset a command on this host/reset this host
2532
 * Params   : SCpnt  - command causing reset
2533
 *            result - what type of reset to perform
2534
 * Returns  : one of SCSI_RESET_ macros
2535
 */
2536
int acornscsi_reset (Scsi_Cmnd *SCpnt, unsigned int reset_flags)
2537
{
2538
    AS_Host *host = (AS_Host *)SCpnt->host->hostdata;
2539
    Scsi_Cmnd *SCptr;
2540
 
2541
    host->stats.resets += 1;
2542
 
2543
#if (DEBUG & DEBUG_RESET)
2544
    {
2545
        int asr, ssr;
2546
 
2547
        asr = sbic_arm_read (host->scsi.io_port, ASR);
2548
        ssr = sbic_arm_read (host->scsi.io_port, SSR);
2549
 
2550
        printk (KERN_WARNING "acornscsi_reset: ");
2551
        print_sbic_status(asr, ssr, host->scsi.phase);
2552
        acornscsi_dumplog (host, SCpnt->target);
2553
    }
2554
#endif
2555
 
2556
    acornscsi_dma_stop (host);
2557
 
2558
    SCptr = host->SCpnt;
2559
 
2560
    /*
2561
     * do hard reset.  This resets all devices on this host, and so we
2562
     * must set the reset status on all commands.
2563
     */
2564
    acornscsi_resetcard (host);
2565
 
2566
    /*
2567
     * report reset on commands current connected/disconnected
2568
     */
2569
    acornscsi_reportstatus (&host->SCpnt, &SCptr, DID_RESET);
2570
 
2571
    while ((SCptr = queue_remove (&host->queues.disconnected)) != NULL)
2572
        acornscsi_reportstatus (&SCptr, &SCpnt, DID_RESET);
2573
 
2574
    if (SCpnt) {
2575
        SCpnt->result = DID_RESET << 16;
2576
        SCpnt->scsi_done (SCpnt);
2577
    }
2578
while (1);
2579
    return SCSI_RESET_BUS_RESET | SCSI_RESET_HOST_RESET | SCSI_RESET_SUCCESS;
2580
}
2581
 
2582
/*==============================================================================================
2583
 * initialisation & miscellaneous support
2584
 */
2585
static struct expansion_card *ecs[MAX_ECARDS];
2586
 
2587
/*
2588
 * Prototype: void acornscsi_init (AS_Host *host)
2589
 * Purpose  : initialise the AS_Host structure for one interface & setup hardware
2590
 * Params   : host - host to setup
2591
 */
2592
static
2593
void acornscsi_init (AS_Host *host)
2594
{
2595
    memset (&host->stats, 0, sizeof (host->stats));
2596
    queue_initialise (&host->queues.issue);
2597
    queue_initialise (&host->queues.disconnected);
2598
    msgqueue_initialise (&host->scsi.msgs);
2599
 
2600
    acornscsi_resetcard (host);
2601
}
2602
 
2603
int acornscsi_detect(Scsi_Host_Template * tpnt)
2604
{
2605
    static const card_ids acornscsi_cids[] = { ACORNSCSI_LIST, { 0xffff, 0xffff } };
2606
    int i, count = 0;
2607
    struct Scsi_Host *instance;
2608
    AS_Host *host;
2609
 
2610
    tpnt->proc_dir = &proc_scsi_acornscsi;
2611
 
2612
    for (i = 0; i < MAX_ECARDS; i++)
2613
        ecs[i] = NULL;
2614
 
2615
    ecard_startfind ();
2616
 
2617
    while(1) {
2618
        ecs[count] = ecard_find(0, acornscsi_cids);
2619
        if (!ecs[count])
2620
            break;
2621
 
2622
        if (ecs[count]->irq == 0xff) {
2623
            printk ("scsi: WD33C93 does not have IRQ enabled - ignoring\n");
2624
            continue;
2625
        }
2626
 
2627
        ecard_claim(ecs[count]); /* Must claim here - card produces irq on reset */
2628
 
2629
        instance = scsi_register (tpnt, sizeof(AS_Host));
2630
        host = (AS_Host *)instance->hostdata;
2631
 
2632
        instance->io_port = ecard_address (ecs[count], ECARD_MEMC, 0);
2633
        instance->irq = ecs[count]->irq;
2634
 
2635
        host->host              = instance;
2636
        host->scsi.io_port      = ioaddr (instance->io_port + 0x800);
2637
        host->scsi.irq          = instance->irq;
2638
        host->card.io_intr      = POD_SPACE(instance->io_port) + 0x800;
2639
        host->card.io_page      = POD_SPACE(instance->io_port) + 0xc00;
2640
        host->card.io_ram       = ioaddr (instance->io_port);
2641
        host->dma.io_port       = instance->io_port + 0xc00;
2642
        host->dma.io_intr_clear = POD_SPACE(instance->io_port) + 0x800;
2643
 
2644
        request_region (instance->io_port + 0x800,  2, "acornscsi(sbic)");
2645
        request_region (host->card.io_intr,  1, "acornscsi(intr)");
2646
        request_region (host->card.io_page,  1, "acornscsi(page)");
2647
        request_region (host->dma.io_port, 256, "acornscsi(dmac)");
2648
        request_region (instance->io_port, 2048, "acornscsi(ram)");
2649
 
2650
        if (request_irq(host->scsi.irq, acornscsi_intr, SA_INTERRUPT, "acornscsi", host)) {
2651
            printk(KERN_CRIT "scsi%d: IRQ%d not free, interrupts disabled\n",
2652
                instance->host_no, host->scsi.irq);
2653
            host->scsi.irq = NO_IRQ;
2654
        }
2655
 
2656
        acornscsi_init (host);
2657
 
2658
        ++count;
2659
    }
2660
    return count;
2661
}
2662
 
2663
/*
2664
 * Function: int acornscsi_release (struct Scsi_Host *host)
2665
 * Purpose : release all resources used by this adapter
2666
 * Params  : host - driver structure to release
2667
 * Returns : nothing of any consequence
2668
 */
2669
int acornscsi_release (struct Scsi_Host *instance)
2670
{
2671
    AS_Host *host = (AS_Host *)instance->hostdata;
2672
    int i;
2673
 
2674
    /*
2675
     * Put card into RESET state
2676
     */
2677
    outb (0x80, host->card.io_page);
2678
 
2679
    if (host->scsi.irq != NO_IRQ)
2680
        free_irq (host->scsi.irq, host);
2681
 
2682
    release_region (instance->io_port + 0x800, 2);
2683
    release_region (host->card.io_intr, 1);
2684
    release_region (host->card.io_page, 1);
2685
    release_region (host->dma.io_port, 256);
2686
    release_region (instance->io_port, 2048);
2687
 
2688
    for (i = 0; i < MAX_ECARDS; i++)
2689
        if (ecs[i] && instance->io_port == ecard_address (ecs[i], ECARD_MEMC, 0))
2690
            ecard_release (ecs[i]);
2691
 
2692
    msgqueue_free (&host->scsi.msgs);
2693
    queue_free (&host->queues.disconnected);
2694
    queue_free (&host->queues.issue);
2695
 
2696
    return 0;
2697
}
2698
 
2699
/*
2700
 * Function: char *acornscsi_info (struct Scsi_Host *host)
2701
 * Purpose : return a string describing this interface
2702
 * Params  : host - host to give information on
2703
 * Returns : a constant string
2704
 */
2705
const
2706
char *acornscsi_info(struct Scsi_Host *host)
2707
{
2708
    static char string[100], *p;
2709
 
2710
    p = string;
2711
 
2712
    p += sprintf (string, "%s at port %X irq %d v%d.%d.%d"
2713
#ifdef SCSI2_SYNC
2714
    " SYNC"
2715
#endif
2716
#ifdef SCSI2_TAG
2717
    " TAG"
2718
#endif
2719
#ifdef SCSI2_LINK
2720
    " LINK"
2721
#endif
2722
#if (DEBUG & DEBUG_NO_WRITE)
2723
    " NOWRITE ("NO_WRITE_STR")"
2724
#endif
2725
                , host->hostt->name, host->io_port, host->irq,
2726
                VER_MAJOR, VER_MINOR, VER_PATCH);
2727
    return string;
2728
}
2729
 
2730
int acornscsi_proc_info(char *buffer, char **start, off_t offset,
2731
                        int length, int host_no, int inout)
2732
{
2733
    int pos, begin = 0, first;
2734
    struct Scsi_Host *instance = scsi_hostlist;
2735
    Scsi_Device *scd = scsi_devices;
2736
    AS_Host *host;
2737
    char *p = buffer;
2738
 
2739
    for (instance = scsi_hostlist;
2740
            instance && instance->host_no != host_no;
2741
                instance = instance->next);
2742
 
2743
    if (inout == 1 || !instance)
2744
        return -EINVAL;
2745
 
2746
    host  = (AS_Host *)instance->hostdata;
2747
 
2748
    p += sprintf (p, "AcornSCSI driver v%d.%d.%d"
2749
#ifdef SCSI2_SYNC
2750
    " SYNC"
2751
#endif
2752
#ifdef SCSI2_TAG
2753
    " TAG"
2754
#endif
2755
#ifdef SCSI2_LINK
2756
    " LINK"
2757
#endif
2758
#if (DEBUG & DEBUG_NO_WRITE)
2759
    " NOWRITE ("NO_WRITE_STR")"
2760
#endif
2761
                "\n\n", VER_MAJOR, VER_MINOR, VER_PATCH);
2762
 
2763
    p += sprintf (p,    "SBIC: WD33C93A  Address: %08X  IRQ : %d\n"
2764
                        "DMAC: uPC71071  Address: %08X  IRQ : %d\n\n"
2765
                        "Statistics:\n",
2766
                        host->scsi.io_port, host->scsi.irq,
2767
                        host->dma.io_port, host->scsi.irq);
2768
 
2769
    p += sprintf (p,    "Queued commands: %-10ld    Issued commands: %-10ld\n"
2770
                        "Done commands  : %-10ld    Reads          : %-10ld\n"
2771
                        "Writes         : %-10ld    Others         : %-10ld\n"
2772
                        "Disconnects    : %-10ld    Aborts         : %-10ld\n"
2773
                        "Resets         : %-10ld\n\nLast phases:",
2774
                        host->stats.queues,             host->stats.removes,
2775
                        host->stats.fins,               host->stats.reads,
2776
                        host->stats.writes,             host->stats.miscs,
2777
                        host->stats.disconnects,        host->stats.aborts,
2778
                        host->stats.resets);
2779
 
2780
    for (first = 0; first < 9; first ++) {
2781
        unsigned int statptr, prev;
2782
 
2783
        p += sprintf (p, "\n%c:", first == 8 ? 'H' : ('0' + first));
2784
        statptr = status_ptr[first] - 10;
2785
 
2786
        if ((signed int)statptr < 0)
2787
            statptr += 16;
2788
 
2789
        prev = status[first][statptr].when;
2790
 
2791
        for (; statptr != status_ptr[first]; statptr = (statptr + 1) & 15) {
2792
            if (status[first][statptr].when) {
2793
                p += sprintf (p, "%c%02X:%02X+%2ld",
2794
                        status[first][statptr].irq ? '-' : ' ',
2795
                        status[first][statptr].ph,
2796
                        status[first][statptr].ssr,
2797
                        (status[first][statptr].when - prev) < 100 ?
2798
                                (status[first][statptr].when - prev) : 99);
2799
                prev = status[first][statptr].when;
2800
            }
2801
        }
2802
    }
2803
 
2804
    first = 1;
2805
    p += sprintf (p, "\nAttached devices:");
2806
    while (scd) {
2807
        if (scd->host == instance) {
2808
            int len;
2809
            if (first) {
2810
                p += sprintf (p, "\n");
2811
                first = 0;
2812
            }
2813
 
2814
            proc_print_scsidevice (scd, p, &len, 0);
2815
            p += len;
2816
 
2817
            p += sprintf (p, "Extensions: ");
2818
 
2819
            if (scd->tagged_supported)
2820
                p += sprintf (p, "TAG %sabled [%d] ",
2821
                        scd->tagged_queue ? "en" : "dis", scd->current_tag);
2822
            p += sprintf (p, "\nTransfers: ");
2823
            if (host->device[scd->id].sync_xfer & 15)
2824
                p += sprintf (p, "sync, offset %d, %d ns\n",
2825
                              host->device[scd->id].sync_xfer & 15,
2826
                              acornscsi_getperiod (host->device[scd->id].sync_xfer));
2827
            else
2828
                p += sprintf (p, "async\n");
2829
 
2830
            pos = p - buffer;
2831
            if (pos + begin < offset) {
2832
                begin += pos;
2833
                p = buffer;
2834
            }
2835
            pos = p - buffer;
2836
            if (pos + begin > offset + length)
2837
                break;
2838
        }
2839
        scd = scd->next;
2840
    }
2841
 
2842
    if (first)
2843
        p += sprintf(p, " none\n");
2844
 
2845
    pos = p - buffer;
2846
 
2847
    *start = buffer + (offset - begin);
2848
    pos -= offset - begin;
2849
 
2850
    if (pos > length)
2851
        pos = length;
2852
 
2853
    return pos;
2854
}
2855
 
2856
#ifdef MODULE
2857
 
2858
Scsi_Host_Template driver_template = ACORNSCSI_3;
2859
 
2860
#include "scsi_module.c"
2861
#endif

powered by: WebSVN 2.1.0

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