1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/drivers/scsi/arm/arxescsi.c
5 * Copyright (C) 1997-2000 Russell King, Stefan Hanske
7 * This driver is based on experimentation. Hence, it may have made
8 * assumptions about the particular card that I have available, and
12 * 30-08-1997 RMK 0.0.0 Created, READONLY version as cumana_2.c
13 * 22-01-1998 RMK 0.0.1 Updated to 2.1.80
14 * 15-04-1998 RMK 0.0.1 Only do PIO if FAS216 will allow it.
15 * 11-06-1998 SH 0.0.2 Changed to support ARXE 16-bit SCSI card
17 * 01-01-2000 SH 0.1.0 Added *real* pseudo dma writing
18 * (arxescsi_pseudo_dma_write)
19 * 02-04-2000 RMK 0.1.1 Updated for new error handling code.
20 * 22-10-2000 SH Updated for new registering scheme.
22 #include <linux/module.h>
23 #include <linux/blkdev.h>
24 #include <linux/kernel.h>
25 #include <linux/string.h>
26 #include <linux/ioport.h>
27 #include <linux/proc_fs.h>
28 #include <linux/unistd.h>
29 #include <linux/stat.h>
30 #include <linux/delay.h>
31 #include <linux/init.h>
32 #include <linux/interrupt.h>
36 #include <asm/ecard.h>
39 #include <scsi/scsi_host.h>
42 struct arxescsi_info
{
44 struct expansion_card
*ec
;
48 #define DMADATA_OFFSET (0x200)
50 #define DMASTAT_OFFSET (0x600)
51 #define DMASTAT_DRQ (1 << 0)
53 #define CSTATUS_IRQ (1 << 0)
55 #define VERSION "1.10 (23/01/2003 2.5.57)"
58 * Function: int arxescsi_dma_setup(host, SCpnt, direction, min_type)
59 * Purpose : initialises DMA/PIO
60 * Params : host - host
62 * direction - DMA on to/off of card
63 * min_type - minimum DMA support that we must have for this transfer
64 * Returns : 0 if we should not set CMD_WITHDMA for transfer info command
67 arxescsi_dma_setup(struct Scsi_Host
*host
, struct scsi_pointer
*SCp
,
68 fasdmadir_t direction
, fasdmatype_t min_type
)
71 * We don't do real DMA
76 static void arxescsi_pseudo_dma_write(unsigned char *addr
, void __iomem
*base
)
79 " stmdb sp!, {r0-r12}\n"
84 ".loop_1: ldmia r3!, {r6, r8, r10, r12}\n"
85 " mov r5, r6, lsl #16\n"
86 " mov r7, r8, lsl #16\n"
87 ".loop_2: ldrb r0, [r1, #1536]\n"
90 " stmia r2, {r5-r8}\n\t"
91 " mov r9, r10, lsl #16\n"
92 " mov r11, r12, lsl #16\n"
93 ".loop_3: ldrb r0, [r1, #1536]\n"
96 " stmia r2, {r9-r12}\n"
99 " ldmia sp!, {r0-r12}\n"
101 : "r" (addr
), "r" (base
));
105 * Function: int arxescsi_dma_pseudo(host, SCpnt, direction, transfer)
106 * Purpose : handles pseudo DMA
107 * Params : host - host
109 * direction - DMA on to/off of card
110 * transfer - minimum number of bytes we expect to transfer
113 arxescsi_dma_pseudo(struct Scsi_Host
*host
, struct scsi_pointer
*SCp
,
114 fasdmadir_t direction
, int transfer
)
116 struct arxescsi_info
*info
= (struct arxescsi_info
*)host
->hostdata
;
117 unsigned int length
, error
= 0;
118 void __iomem
*base
= info
->info
.scsi
.io_base
;
121 length
= SCp
->this_residual
;
124 if (direction
== DMA_OUT
) {
126 while (length
> 256) {
127 if (readb(base
+ 0x80) & STAT_INT
) {
131 arxescsi_pseudo_dma_write(addr
, base
);
138 if (readb(base
+ 0x80) & STAT_INT
)
141 if (!(readb(base
+ DMASTAT_OFFSET
) & DMASTAT_DRQ
))
144 word
= *addr
| *(addr
+ 1) << 8;
146 writew(word
, base
+ DMADATA_OFFSET
);
157 if (transfer
&& (transfer
& 255)) {
158 while (length
>= 256) {
159 if (readb(base
+ 0x80) & STAT_INT
) {
164 if (!(readb(base
+ DMASTAT_OFFSET
) & DMASTAT_DRQ
))
167 readsw(base
+ DMADATA_OFFSET
, addr
, 256 >> 1);
177 if (readb(base
+ 0x80) & STAT_INT
)
180 if (!(readb(base
+ DMASTAT_OFFSET
) & DMASTAT_DRQ
))
183 word
= readw(base
+ DMADATA_OFFSET
);
194 * Function: int arxescsi_dma_stop(host, SCpnt)
195 * Purpose : stops DMA/PIO
196 * Params : host - host
199 static void arxescsi_dma_stop(struct Scsi_Host
*host
, struct scsi_pointer
*SCp
)
207 * Function: const char *arxescsi_info(struct Scsi_Host * host)
208 * Purpose : returns a descriptive string about this interface,
209 * Params : host - driver host structure to return info for.
210 * Returns : pointer to a static buffer containing null terminated string.
212 static const char *arxescsi_info(struct Scsi_Host
*host
)
214 struct arxescsi_info
*info
= (struct arxescsi_info
*)host
->hostdata
;
215 static char string
[150];
217 sprintf(string
, "%s (%s) in slot %d v%s",
218 host
->hostt
->name
, info
->info
.scsi
.type
, info
->ec
->slot_no
,
225 arxescsi_show_info(struct seq_file
*m
, struct Scsi_Host
*host
)
227 struct arxescsi_info
*info
;
228 info
= (struct arxescsi_info
*)host
->hostdata
;
230 seq_printf(m
, "ARXE 16-bit SCSI driver v%s\n", VERSION
);
231 fas216_print_host(&info
->info
, m
);
232 fas216_print_stats(&info
->info
, m
);
233 fas216_print_devices(&info
->info
, m
);
237 static struct scsi_host_template arxescsi_template
= {
238 .show_info
= arxescsi_show_info
,
239 .name
= "ARXE SCSI card",
240 .info
= arxescsi_info
,
241 .queuecommand
= fas216_noqueue_command
,
242 .eh_host_reset_handler
= fas216_eh_host_reset
,
243 .eh_bus_reset_handler
= fas216_eh_bus_reset
,
244 .eh_device_reset_handler
= fas216_eh_device_reset
,
245 .eh_abort_handler
= fas216_eh_abort
,
248 .sg_tablesize
= SG_ALL
,
249 .dma_boundary
= PAGE_SIZE
- 1,
250 .proc_name
= "arxescsi",
253 static int arxescsi_probe(struct expansion_card
*ec
, const struct ecard_id
*id
)
255 struct Scsi_Host
*host
;
256 struct arxescsi_info
*info
;
260 ret
= ecard_request_resources(ec
);
264 base
= ecardm_iomap(ec
, ECARD_RES_MEMC
, 0, 0);
270 host
= scsi_host_alloc(&arxescsi_template
, sizeof(struct arxescsi_info
));
276 info
= (struct arxescsi_info
*)host
->hostdata
;
280 info
->info
.scsi
.io_base
= base
+ 0x2000;
281 info
->info
.scsi
.irq
= 0;
282 info
->info
.scsi
.dma
= NO_DMA
;
283 info
->info
.scsi
.io_shift
= 5;
284 info
->info
.ifcfg
.clockrate
= 24; /* MHz */
285 info
->info
.ifcfg
.select_timeout
= 255;
286 info
->info
.ifcfg
.asyncperiod
= 200; /* ns */
287 info
->info
.ifcfg
.sync_max_depth
= 0;
288 info
->info
.ifcfg
.cntl3
= CNTL3_FASTSCSI
| CNTL3_FASTCLK
;
289 info
->info
.ifcfg
.disconnect_ok
= 0;
290 info
->info
.ifcfg
.wide_max_size
= 0;
291 info
->info
.ifcfg
.capabilities
= FASCAP_PSEUDODMA
;
292 info
->info
.dma
.setup
= arxescsi_dma_setup
;
293 info
->info
.dma
.pseudo
= arxescsi_dma_pseudo
;
294 info
->info
.dma
.stop
= arxescsi_dma_stop
;
297 ec
->irqmask
= CSTATUS_IRQ
;
299 ret
= fas216_init(host
);
303 ret
= fas216_add(host
, &ec
->dev
);
307 fas216_release(host
);
311 ecard_release_resources(ec
);
316 static void arxescsi_remove(struct expansion_card
*ec
)
318 struct Scsi_Host
*host
= ecard_get_drvdata(ec
);
320 ecard_set_drvdata(ec
, NULL
);
323 fas216_release(host
);
325 ecard_release_resources(ec
);
328 static const struct ecard_id arxescsi_cids
[] = {
329 { MANU_ARXE
, PROD_ARXE_SCSI
},
333 static struct ecard_driver arxescsi_driver
= {
334 .probe
= arxescsi_probe
,
335 .remove
= arxescsi_remove
,
336 .id_table
= arxescsi_cids
,
342 static int __init
init_arxe_scsi_driver(void)
344 return ecard_register_driver(&arxescsi_driver
);
347 static void __exit
exit_arxe_scsi_driver(void)
349 ecard_remove_driver(&arxescsi_driver
);
352 module_init(init_arxe_scsi_driver
);
353 module_exit(exit_arxe_scsi_driver
);
355 MODULE_AUTHOR("Stefan Hanske");
356 MODULE_DESCRIPTION("ARXESCSI driver for Acorn machines");
357 MODULE_LICENSE("GPL");