Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]
  1 /*
  2  * Oak Generic NCR5380 driver
  3  *
  4  * Copyright 1995-2002, Russell King
  5  */
  6 
  7 #include <linux/module.h>
  8 #include <linux/signal.h>
  9 #include <linux/sched.h>
 10 #include <linux/ioport.h>
 11 #include <linux/delay.h>
 12 #include <linux/blkdev.h>
 13 #include <linux/init.h>
 14 
 15 #include <asm/ecard.h>
 16 #include <asm/io.h>
 17 #include <asm/system.h>
 18 
 19 #include "../scsi.h"
 20 #include <scsi/scsi_host.h>
 21 
 22 #define AUTOSENSE
 23 /*#define PSEUDO_DMA*/
 24 
 25 #define OAKSCSI_PUBLIC_RELEASE 1
 26 
 27 #define NCR5380_read(reg)               oakscsi_read(_instance, reg)
 28 #define NCR5380_write(reg, value)       oakscsi_write(_instance, reg, value)
 29 #define NCR5380_intr                    oakscsi_intr
 30 #define NCR5380_queue_command           oakscsi_queue_command
 31 #define NCR5380_proc_info               oakscsi_proc_info
 32 
 33 #define NCR5380_implementation_fields   int port, ctrl
 34 #define NCR5380_local_declare()         struct Scsi_Host *_instance
 35 #define NCR5380_setup(instance)         _instance = instance
 36 
 37 #define BOARD_NORMAL    0
 38 #define BOARD_NCR53C400 1
 39 
 40 #include "../NCR5380.h"
 41 
 42 #undef START_DMA_INITIATOR_RECEIVE_REG
 43 #define START_DMA_INITIATOR_RECEIVE_REG (7 + 128)
 44 
 45 const char * oakscsi_info (struct Scsi_Host *spnt)
 46 {
 47         return "";
 48 }
 49 
 50 #define STAT(p)   inw(p + 144)
 51 extern void inswb(int from, void *to, int len);
 52 
 53 static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *addr,
 54               int len)
 55 {
 56   int iobase = instance->io_port;
 57 printk("writing %p len %d\n",addr, len);
 58   if(!len) return -1;
 59 
 60   while(1)
 61   {
 62     int status;
 63     while(((status = STAT(iobase)) & 0x100)==0);
 64   }
 65 }
 66 
 67 static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *addr,
 68               int len)
 69 {
 70   int iobase = instance->io_port;
 71 printk("reading %p len %d\n", addr, len);
 72   while(len > 0)
 73   {
 74     int status, timeout;
 75     unsigned long b;
 76     
 77     timeout = 0x01FFFFFF;
 78     
 79     while(((status = STAT(iobase)) & 0x100)==0)
 80     {
 81       timeout--;
 82       if(status & 0x200 || !timeout)
 83       {
 84         printk("status = %08X\n",status);
 85         return 1;
 86       }
 87     }
 88     if(len >= 128)
 89     {
 90       inswb(iobase + 136, addr, 128);
 91       addr += 128;
 92       len -= 128;
 93     }
 94     else
 95     {
 96       b = (unsigned long) inw(iobase + 136);
 97       *addr ++ = b;
 98       len -= 1;
 99       if(len)
100         *addr ++ = b>>8;
101       len -= 1;
102     }
103   }
104   return 0;
105 }
106 
107 #define oakscsi_read(instance,reg)      (inb((instance)->io_port + (reg)))
108 #define oakscsi_write(instance,reg,val) (outb((val), (instance)->io_port + (reg)))
109 
110 #undef STAT
111 
112 #include "../NCR5380.c"
113 
114 static Scsi_Host_Template oakscsi_template = {
115         .module                 = THIS_MODULE,
116         .proc_info              = oakscsi_proc_info,
117         .name                   = "Oak 16-bit SCSI",
118         .info                   = oakscsi_info,
119         .queuecommand           = oakscsi_queue_command,
120         .eh_abort_handler       = NCR5380_abort,
121         .eh_device_reset_handler= NCR5380_device_reset,
122         .eh_bus_reset_handler   = NCR5380_bus_reset,
123         .eh_host_reset_handler  = NCR5380_host_reset,
124         .can_queue              = 16,
125         .this_id                = 7,
126         .sg_tablesize           = SG_ALL,
127         .cmd_per_lun            = 2,
128         .use_clustering         = DISABLE_CLUSTERING,
129         .proc_name              = "oakscsi",
130 };
131 
132 static int __devinit
133 oakscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
134 {
135         struct Scsi_Host *host;
136         int ret = -ENOMEM;
137 
138         host = scsi_host_alloc(&oakscsi_template, sizeof(struct NCR5380_hostdata));
139         if (!host)
140                 goto out;
141 
142         host->io_port = ecard_address(ec, ECARD_MEMC, 0);
143         host->irq = IRQ_NONE;
144         host->n_io_port = 255;
145 
146         ret = -EBUSY;
147         if (!request_region (host->io_port, host->n_io_port, "Oak SCSI"))
148                 goto unreg;
149 
150         NCR5380_init(host, 0);
151 
152         printk("scsi%d: at port 0x%08lx irqs disabled",
153                 host->host_no, host->io_port);
154         printk(" options CAN_QUEUE=%d  CMD_PER_LUN=%d release=%d",
155                 host->can_queue, host->cmd_per_lun, OAKSCSI_PUBLIC_RELEASE);
156         printk("\nscsi%d:", host->host_no);
157         NCR5380_print_options(host);
158         printk("\n");
159 
160         ret = scsi_add_host(host, &ec->dev);
161         if (ret)
162                 goto out_release;
163 
164         scsi_scan_host(host);
165         goto out;
166 
167  out_release:
168         release_region(host->io_port, host->n_io_port);
169  unreg:
170         scsi_host_put(host);
171  out:
172         return ret;
173 }
174 
175 static void __devexit oakscsi_remove(struct expansion_card *ec)
176 {
177         struct Scsi_Host *host = ecard_get_drvdata(ec);
178 
179         ecard_set_drvdata(ec, NULL);
180         scsi_remove_host(host);
181 
182         NCR5380_exit(host);
183         release_region(host->io_port, host->n_io_port);
184         scsi_host_put(host);
185 }
186 
187 static const struct ecard_id oakscsi_cids[] = {
188         { MANU_OAK, PROD_OAK_SCSI },
189         { 0xffff, 0xffff }
190 };
191 
192 static struct ecard_driver oakscsi_driver = {
193         .probe          = oakscsi_probe,
194         .remove         = __devexit_p(oakscsi_remove),
195         .id_table       = oakscsi_cids,
196         .drv = {
197                 .name           = "oakscsi",
198         },
199 };
200 
201 static int __init oakscsi_init(void)
202 {
203         return ecard_register_driver(&oakscsi_driver);
204 }
205 
206 static void __exit oakscsi_exit(void)
207 {
208         ecard_remove_driver(&oakscsi_driver);
209 }
210 
211 module_init(oakscsi_init);
212 module_exit(oakscsi_exit);
213 
214 MODULE_AUTHOR("Russell King");
215 MODULE_DESCRIPTION("Oak SCSI driver");
216 MODULE_LICENSE("GPL");
217 
218 
  This page was automatically generated by the LXR engine.