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.dag2] - Blame information for rev 1622

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

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

powered by: WebSVN 2.1.0

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