Linux Audio

Check our new training course

Linux debugging, profiling, tracing and performance analysis training

Mar 24-27, 2025, special US time zones
Register
Loading...
v4.10.11
 
  1/*
  2 * Oak Generic NCR5380 driver
  3 *
  4 * Copyright 1995-2002, Russell King
  5 */
  6
  7#include <linux/module.h>
  8#include <linux/ioport.h>
  9#include <linux/blkdev.h>
 10#include <linux/init.h>
 11
 12#include <asm/ecard.h>
 13#include <asm/io.h>
 14
 15#include <scsi/scsi_host.h>
 16
 17#define priv(host)			((struct NCR5380_hostdata *)(host)->hostdata)
 18
 19#define NCR5380_read(reg)           readb(hostdata->io + ((reg) << 2))
 20#define NCR5380_write(reg, value)   writeb(value, hostdata->io + ((reg) << 2))
 21
 22#define NCR5380_dma_xfer_len		NCR5380_dma_xfer_none
 23#define NCR5380_dma_recv_setup		oakscsi_pread
 24#define NCR5380_dma_send_setup		oakscsi_pwrite
 25#define NCR5380_dma_residual		NCR5380_dma_residual_none
 26
 27#define NCR5380_queue_command		oakscsi_queue_command
 28#define NCR5380_info			oakscsi_info
 29
 30#define NCR5380_implementation_fields	/* none */
 31
 32#include "../NCR5380.h"
 33
 34#undef START_DMA_INITIATOR_RECEIVE_REG
 35#define START_DMA_INITIATOR_RECEIVE_REG	(128 + 7)
 36
 37#define STAT	((128 + 16) << 2)
 38#define DATA	((128 + 8) << 2)
 39
 40static inline int oakscsi_pwrite(struct NCR5380_hostdata *hostdata,
 41                                 unsigned char *addr, int len)
 42{
 43  u8 __iomem *base = hostdata->io;
 44
 45printk("writing %p len %d\n",addr, len);
 46
 47  while(1)
 48  {
 49    int status;
 50    while (((status = readw(base + STAT)) & 0x100)==0);
 51  }
 52  return 0;
 53}
 54
 55static inline int oakscsi_pread(struct NCR5380_hostdata *hostdata,
 56                                unsigned char *addr, int len)
 57{
 58  u8 __iomem *base = hostdata->io;
 59
 60printk("reading %p len %d\n", addr, len);
 61  while(len > 0)
 62  {
 63    unsigned int status, timeout;
 64    unsigned long b;
 65    
 66    timeout = 0x01FFFFFF;
 67    
 68    while (((status = readw(base + STAT)) & 0x100)==0)
 69    {
 70      timeout--;
 71      if(status & 0x200 || !timeout)
 72      {
 73        printk("status = %08X\n", status);
 74        return -1;
 75      }
 76    }
 77
 78    if(len >= 128)
 79    {
 80      readsw(base + DATA, addr, 128);
 81      addr += 128;
 82      len -= 128;
 83    }
 84    else
 85    {
 86      b = (unsigned long) readw(base + DATA);
 87      *addr ++ = b;
 88      len -= 1;
 89      if(len)
 90        *addr ++ = b>>8;
 91      len -= 1;
 92    }
 93  }
 94  return 0;
 95}
 96
 97#undef STAT
 98#undef DATA
 99
100#include "../NCR5380.c"
101
102static struct scsi_host_template oakscsi_template = {
103	.module			= THIS_MODULE,
104	.name			= "Oak 16-bit SCSI",
105	.info			= oakscsi_info,
106	.queuecommand		= oakscsi_queue_command,
107	.eh_abort_handler	= NCR5380_abort,
108	.eh_bus_reset_handler	= NCR5380_bus_reset,
109	.can_queue		= 16,
110	.this_id		= 7,
111	.sg_tablesize		= SG_ALL,
112	.cmd_per_lun		= 2,
113	.use_clustering		= DISABLE_CLUSTERING,
114	.proc_name		= "oakscsi",
115	.cmd_size		= NCR5380_CMD_SIZE,
116	.max_sectors		= 128,
117};
118
119static int oakscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
120{
121	struct Scsi_Host *host;
122	int ret = -ENOMEM;
123
124	ret = ecard_request_resources(ec);
125	if (ret)
126		goto out;
127
128	host = scsi_host_alloc(&oakscsi_template, sizeof(struct NCR5380_hostdata));
129	if (!host) {
130		ret = -ENOMEM;
131		goto release;
132	}
133
134	priv(host)->io = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC),
135	                         ecard_resource_len(ec, ECARD_RES_MEMC));
136	if (!priv(host)->io) {
137		ret = -ENOMEM;
138		goto unreg;
139	}
140
141	host->irq = NO_IRQ;
142
143	ret = NCR5380_init(host, FLAG_DMA_FIXUP | FLAG_LATE_DMA_SETUP);
144	if (ret)
145		goto out_unmap;
146
147	NCR5380_maybe_reset_bus(host);
148
149	ret = scsi_add_host(host, &ec->dev);
150	if (ret)
151		goto out_exit;
152
153	scsi_scan_host(host);
154	goto out;
155
156 out_exit:
157	NCR5380_exit(host);
158 out_unmap:
159	iounmap(priv(host)->io);
160 unreg:
161	scsi_host_put(host);
162 release:
163	ecard_release_resources(ec);
164 out:
165	return ret;
166}
167
168static void oakscsi_remove(struct expansion_card *ec)
169{
170	struct Scsi_Host *host = ecard_get_drvdata(ec);
171	void __iomem *base = priv(host)->io;
172
173	ecard_set_drvdata(ec, NULL);
174	scsi_remove_host(host);
175
176	NCR5380_exit(host);
177	scsi_host_put(host);
178	iounmap(base);
179	ecard_release_resources(ec);
180}
181
182static const struct ecard_id oakscsi_cids[] = {
183	{ MANU_OAK, PROD_OAK_SCSI },
184	{ 0xffff, 0xffff }
185};
186
187static struct ecard_driver oakscsi_driver = {
188	.probe		= oakscsi_probe,
189	.remove		= oakscsi_remove,
190	.id_table	= oakscsi_cids,
191	.drv = {
192		.name		= "oakscsi",
193	},
194};
195
196static int __init oakscsi_init(void)
197{
198	return ecard_register_driver(&oakscsi_driver);
199}
200
201static void __exit oakscsi_exit(void)
202{
203	ecard_remove_driver(&oakscsi_driver);
204}
205
206module_init(oakscsi_init);
207module_exit(oakscsi_exit);
208
209MODULE_AUTHOR("Russell King");
210MODULE_DESCRIPTION("Oak SCSI driver");
211MODULE_LICENSE("GPL");
212
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Oak Generic NCR5380 driver
  4 *
  5 * Copyright 1995-2002, Russell King
  6 */
  7
  8#include <linux/module.h>
  9#include <linux/ioport.h>
 10#include <linux/blkdev.h>
 11#include <linux/init.h>
 12
 13#include <asm/ecard.h>
 14#include <asm/io.h>
 15
 16#include <scsi/scsi_host.h>
 17
 18#define priv(host)			((struct NCR5380_hostdata *)(host)->hostdata)
 19
 20#define NCR5380_read(reg)           readb(hostdata->io + ((reg) << 2))
 21#define NCR5380_write(reg, value)   writeb(value, hostdata->io + ((reg) << 2))
 22
 23#define NCR5380_dma_xfer_len		NCR5380_dma_xfer_none
 24#define NCR5380_dma_recv_setup		oakscsi_pread
 25#define NCR5380_dma_send_setup		oakscsi_pwrite
 26#define NCR5380_dma_residual		NCR5380_dma_residual_none
 27
 28#define NCR5380_queue_command		oakscsi_queue_command
 29#define NCR5380_info			oakscsi_info
 30
 31#define NCR5380_implementation_fields	/* none */
 32
 33#include "../NCR5380.h"
 34
 35#undef START_DMA_INITIATOR_RECEIVE_REG
 36#define START_DMA_INITIATOR_RECEIVE_REG	(128 + 7)
 37
 38#define STAT	((128 + 16) << 2)
 39#define DATA	((128 + 8) << 2)
 40
 41static inline int oakscsi_pwrite(struct NCR5380_hostdata *hostdata,
 42                                 unsigned char *addr, int len)
 43{
 44  u8 __iomem *base = hostdata->io;
 45
 46printk("writing %p len %d\n",addr, len);
 47
 48  while(1)
 49  {
 50    int status;
 51    while (((status = readw(base + STAT)) & 0x100)==0);
 52  }
 53  return 0;
 54}
 55
 56static inline int oakscsi_pread(struct NCR5380_hostdata *hostdata,
 57                                unsigned char *addr, int len)
 58{
 59  u8 __iomem *base = hostdata->io;
 60
 61printk("reading %p len %d\n", addr, len);
 62  while(len > 0)
 63  {
 64    unsigned int status, timeout;
 65    unsigned long b;
 66    
 67    timeout = 0x01FFFFFF;
 68    
 69    while (((status = readw(base + STAT)) & 0x100)==0)
 70    {
 71      timeout--;
 72      if(status & 0x200 || !timeout)
 73      {
 74        printk("status = %08X\n", status);
 75        return -1;
 76      }
 77    }
 78
 79    if(len >= 128)
 80    {
 81      readsw(base + DATA, addr, 128);
 82      addr += 128;
 83      len -= 128;
 84    }
 85    else
 86    {
 87      b = (unsigned long) readw(base + DATA);
 88      *addr ++ = b;
 89      len -= 1;
 90      if(len)
 91        *addr ++ = b>>8;
 92      len -= 1;
 93    }
 94  }
 95  return 0;
 96}
 97
 98#undef STAT
 99#undef DATA
100
101#include "../NCR5380.c"
102
103static const struct scsi_host_template oakscsi_template = {
104	.module			= THIS_MODULE,
105	.name			= "Oak 16-bit SCSI",
106	.info			= oakscsi_info,
107	.queuecommand		= oakscsi_queue_command,
108	.eh_abort_handler	= NCR5380_abort,
109	.eh_host_reset_handler	= NCR5380_host_reset,
110	.can_queue		= 16,
111	.this_id		= 7,
112	.sg_tablesize		= SG_ALL,
113	.cmd_per_lun		= 2,
114	.dma_boundary		= PAGE_SIZE - 1,
115	.proc_name		= "oakscsi",
116	.cmd_size		= sizeof(struct NCR5380_cmd),
117	.max_sectors		= 128,
118};
119
120static int oakscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
121{
122	struct Scsi_Host *host;
123	int ret;
124
125	ret = ecard_request_resources(ec);
126	if (ret)
127		goto out;
128
129	host = scsi_host_alloc(&oakscsi_template, sizeof(struct NCR5380_hostdata));
130	if (!host) {
131		ret = -ENOMEM;
132		goto release;
133	}
134
135	priv(host)->io = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC),
136	                         ecard_resource_len(ec, ECARD_RES_MEMC));
137	if (!priv(host)->io) {
138		ret = -ENOMEM;
139		goto unreg;
140	}
141
142	host->irq = NO_IRQ;
143
144	ret = NCR5380_init(host, FLAG_DMA_FIXUP | FLAG_LATE_DMA_SETUP);
145	if (ret)
146		goto out_unmap;
147
148	NCR5380_maybe_reset_bus(host);
149
150	ret = scsi_add_host(host, &ec->dev);
151	if (ret)
152		goto out_exit;
153
154	scsi_scan_host(host);
155	goto out;
156
157 out_exit:
158	NCR5380_exit(host);
159 out_unmap:
160	iounmap(priv(host)->io);
161 unreg:
162	scsi_host_put(host);
163 release:
164	ecard_release_resources(ec);
165 out:
166	return ret;
167}
168
169static void oakscsi_remove(struct expansion_card *ec)
170{
171	struct Scsi_Host *host = ecard_get_drvdata(ec);
172	void __iomem *base = priv(host)->io;
173
174	ecard_set_drvdata(ec, NULL);
175	scsi_remove_host(host);
176
177	NCR5380_exit(host);
178	scsi_host_put(host);
179	iounmap(base);
180	ecard_release_resources(ec);
181}
182
183static const struct ecard_id oakscsi_cids[] = {
184	{ MANU_OAK, PROD_OAK_SCSI },
185	{ 0xffff, 0xffff }
186};
187
188static struct ecard_driver oakscsi_driver = {
189	.probe		= oakscsi_probe,
190	.remove		= oakscsi_remove,
191	.id_table	= oakscsi_cids,
192	.drv = {
193		.name		= "oakscsi",
194	},
195};
196
197static int __init oakscsi_init(void)
198{
199	return ecard_register_driver(&oakscsi_driver);
200}
201
202static void __exit oakscsi_exit(void)
203{
204	ecard_remove_driver(&oakscsi_driver);
205}
206
207module_init(oakscsi_init);
208module_exit(oakscsi_exit);
209
210MODULE_AUTHOR("Russell King");
211MODULE_DESCRIPTION("Oak SCSI driver");
212MODULE_LICENSE("GPL");
213