Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /************************************************************************ |
| 2 | * Linux driver for * |
| 3 | * ICP vortex GmbH: GDT ISA/EISA/PCI Disk Array Controllers * |
| 4 | * Intel Corporation: Storage RAID Controllers * |
| 5 | * * |
| 6 | * gdth.c * |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 7 | * Copyright (C) 1995-06 ICP vortex GmbH, Achim Leubner * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * Copyright (C) 2002-04 Intel Corporation * |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 9 | * Copyright (C) 2003-06 Adaptec Inc. * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * <achim_leubner@adaptec.com> * |
| 11 | * * |
| 12 | * Additions/Fixes: * |
| 13 | * Boji Tony Kannanthanam <boji.t.kannanthanam@intel.com> * |
| 14 | * Johannes Dinner <johannes_dinner@adaptec.com> * |
| 15 | * * |
| 16 | * This program is free software; you can redistribute it and/or modify * |
| 17 | * it under the terms of the GNU General Public License as published * |
| 18 | * by the Free Software Foundation; either version 2 of the License, * |
| 19 | * or (at your option) any later version. * |
| 20 | * * |
| 21 | * This program is distributed in the hope that it will be useful, * |
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 24 | * GNU General Public License for more details. * |
| 25 | * * |
| 26 | * You should have received a copy of the GNU General Public License * |
| 27 | * along with this kernel; if not, write to the Free Software * |
| 28 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * |
| 29 | * * |
Jeff Garzik | 8d7a5da | 2007-10-02 22:54:28 +0200 | [diff] [blame] | 30 | * Linux kernel 2.6.x supported * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | * * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | ************************************************************************/ |
| 33 | |
| 34 | /* All GDT Disk Array Controllers are fully supported by this driver. |
| 35 | * This includes the PCI/EISA/ISA SCSI Disk Array Controllers and the |
| 36 | * PCI Fibre Channel Disk Array Controllers. See gdth.h for a complete |
| 37 | * list of all controller types. |
| 38 | * |
| 39 | * If you have one or more GDT3000/3020 EISA controllers with |
| 40 | * controller BIOS disabled, you have to set the IRQ values with the |
| 41 | * command line option "gdth=irq1,irq2,...", where the irq1,irq2,... are |
| 42 | * the IRQ values for the EISA controllers. |
| 43 | * |
| 44 | * After the optional list of IRQ values, other possible |
| 45 | * command line options are: |
| 46 | * disable:Y disable driver |
| 47 | * disable:N enable driver |
| 48 | * reserve_mode:0 reserve no drives for the raw service |
| 49 | * reserve_mode:1 reserve all not init., removable drives |
| 50 | * reserve_mode:2 reserve all not init. drives |
| 51 | * reserve_list:h,b,t,l,h,b,t,l,... reserve particular drive(s) with |
| 52 | * h- controller no., b- channel no., |
| 53 | * t- target ID, l- LUN |
| 54 | * reverse_scan:Y reverse scan order for PCI controllers |
| 55 | * reverse_scan:N scan PCI controllers like BIOS |
| 56 | * max_ids:x x - target ID count per channel (1..MAXID) |
| 57 | * rescan:Y rescan all channels/IDs |
| 58 | * rescan:N use all devices found until now |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | * hdr_channel:x x - number of virtual bus for host drives |
| 60 | * shared_access:Y disable driver reserve/release protocol to |
| 61 | * access a shared resource from several nodes, |
Adrian Bunk | 575c968 | 2006-01-15 02:00:17 +0100 | [diff] [blame] | 62 | * appropriate controller firmware required |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | * shared_access:N enable driver reserve/release protocol |
| 64 | * probe_eisa_isa:Y scan for EISA/ISA controllers |
| 65 | * probe_eisa_isa:N do not scan for EISA/ISA controllers |
| 66 | * force_dma32:Y use only 32 bit DMA mode |
| 67 | * force_dma32:N use 64 bit DMA mode, if supported |
| 68 | * |
| 69 | * The default values are: "gdth=disable:N,reserve_mode:1,reverse_scan:N, |
Christoph Hellwig | 52759e6 | 2007-10-02 22:59:53 +0200 | [diff] [blame] | 70 | * max_ids:127,rescan:N,hdr_channel:0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | * shared_access:Y,probe_eisa_isa:N,force_dma32:N". |
| 72 | * Here is another example: "gdth=reserve_list:0,1,2,0,0,1,3,0,rescan:Y". |
| 73 | * |
| 74 | * When loading the gdth driver as a module, the same options are available. |
| 75 | * You can set the IRQs with "IRQ=...". However, the syntax to specify the |
| 76 | * options changes slightly. You must replace all ',' between options |
| 77 | * with ' ' and all ':' with '=' and you must use |
| 78 | * '1' in place of 'Y' and '0' in place of 'N'. |
| 79 | * |
| 80 | * Default: "modprobe gdth disable=0 reserve_mode=1 reverse_scan=0 |
Christoph Hellwig | 52759e6 | 2007-10-02 22:59:53 +0200 | [diff] [blame] | 81 | * max_ids=127 rescan=0 hdr_channel=0 shared_access=0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | * probe_eisa_isa=0 force_dma32=0" |
| 83 | * The other example: "modprobe gdth reserve_list=0,1,2,0,0,1,3,0 rescan=1". |
| 84 | */ |
| 85 | |
| 86 | /* The meaning of the Scsi_Pointer members in this driver is as follows: |
| 87 | * ptr: Chaining |
Boaz Harrosh | d35055a | 2008-02-27 15:31:20 -0800 | [diff] [blame] | 88 | * this_residual: unused |
| 89 | * buffer: unused |
Boaz Harrosh | 3892d88 | 2007-10-02 23:18:03 +0200 | [diff] [blame] | 90 | * dma_handle: unused |
Boaz Harrosh | d35055a | 2008-02-27 15:31:20 -0800 | [diff] [blame] | 91 | * buffers_residual: unused |
Boaz Harrosh | 3892d88 | 2007-10-02 23:18:03 +0200 | [diff] [blame] | 92 | * Status: unused |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 93 | * Message: unused |
| 94 | * have_data_in: unused |
| 95 | * sent_command: unused |
| 96 | * phase: unused |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | */ |
| 98 | |
| 99 | |
| 100 | /* interrupt coalescing */ |
| 101 | /* #define INT_COAL */ |
| 102 | |
| 103 | /* statistics */ |
| 104 | #define GDTH_STATISTICS |
| 105 | |
| 106 | #include <linux/module.h> |
| 107 | |
| 108 | #include <linux/version.h> |
| 109 | #include <linux/kernel.h> |
| 110 | #include <linux/types.h> |
| 111 | #include <linux/pci.h> |
| 112 | #include <linux/string.h> |
| 113 | #include <linux/ctype.h> |
| 114 | #include <linux/ioport.h> |
| 115 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | #include <linux/interrupt.h> |
| 117 | #include <linux/in.h> |
| 118 | #include <linux/proc_fs.h> |
| 119 | #include <linux/time.h> |
| 120 | #include <linux/timer.h> |
Matthias Gehre | 910638a | 2006-03-28 01:56:48 -0800 | [diff] [blame] | 121 | #include <linux/dma-mapping.h> |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 122 | #include <linux/list.h> |
Jonathan Corbet | 46787b4 | 2008-05-15 16:09:48 -0600 | [diff] [blame] | 123 | #include <linux/smp_lock.h> |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | #ifdef GDTH_RTC |
| 126 | #include <linux/mc146818rtc.h> |
| 127 | #endif |
| 128 | #include <linux/reboot.h> |
| 129 | |
| 130 | #include <asm/dma.h> |
| 131 | #include <asm/system.h> |
| 132 | #include <asm/io.h> |
| 133 | #include <asm/uaccess.h> |
| 134 | #include <linux/spinlock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | #include <linux/blkdev.h> |
Boaz Harrosh | 3892d88 | 2007-10-02 23:18:03 +0200 | [diff] [blame] | 136 | #include <linux/scatterlist.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
| 138 | #include "scsi.h" |
| 139 | #include <scsi/scsi_host.h> |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 140 | #include "gdth.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
| 142 | static void gdth_delay(int milliseconds); |
| 143 | static void gdth_eval_mapping(ulong32 size, ulong32 *cyls, int *heads, int *secs); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 144 | static irqreturn_t gdth_interrupt(int irq, void *dev_id); |
Jeff Garzik | 230e886 | 2007-12-13 16:14:12 -0800 | [diff] [blame] | 145 | static irqreturn_t __gdth_interrupt(gdth_ha_str *ha, |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 146 | int gdth_from_wait, int* pIndex); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 147 | static int gdth_sync_event(gdth_ha_str *ha, int service, unchar index, |
| 148 | Scsi_Cmnd *scp); |
| 149 | static int gdth_async_event(gdth_ha_str *ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | static void gdth_log_event(gdth_evt_data *dvr, char *buffer); |
| 151 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 152 | static void gdth_putq(gdth_ha_str *ha, Scsi_Cmnd *scp, unchar priority); |
| 153 | static void gdth_next(gdth_ha_str *ha); |
| 154 | static int gdth_fill_raw_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, unchar b); |
| 155 | static int gdth_special_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, ushort source, |
| 157 | ushort idx, gdth_evt_data *evt); |
| 158 | static int gdth_read_event(gdth_ha_str *ha, int handle, gdth_evt_str *estr); |
| 159 | static void gdth_readapp_event(gdth_ha_str *ha, unchar application, |
| 160 | gdth_evt_str *estr); |
| 161 | static void gdth_clear_events(void); |
| 162 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 163 | static void gdth_copy_internal_data(gdth_ha_str *ha, Scsi_Cmnd *scp, |
Boaz Harrosh | ee54cc6 | 2008-02-27 15:29:15 -0800 | [diff] [blame] | 164 | char *buffer, ushort count); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 165 | static int gdth_internal_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp); |
| 166 | static int gdth_fill_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, ushort hdrive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 168 | static void gdth_enable_int(gdth_ha_str *ha); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 169 | static int gdth_test_busy(gdth_ha_str *ha); |
| 170 | static int gdth_get_cmd_index(gdth_ha_str *ha); |
| 171 | static void gdth_release_event(gdth_ha_str *ha); |
| 172 | static int gdth_wait(gdth_ha_str *ha, int index,ulong32 time); |
| 173 | static int gdth_internal_cmd(gdth_ha_str *ha, unchar service, ushort opcode, |
| 174 | ulong32 p1, ulong64 p2,ulong64 p3); |
| 175 | static int gdth_search_drives(gdth_ha_str *ha); |
| 176 | static int gdth_analyse_hdrive(gdth_ha_str *ha, ushort hdrive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 178 | static const char *gdth_ctr_name(gdth_ha_str *ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
| 180 | static int gdth_open(struct inode *inode, struct file *filep); |
| 181 | static int gdth_close(struct inode *inode, struct file *filep); |
| 182 | static int gdth_ioctl(struct inode *inode, struct file *filep, |
| 183 | unsigned int cmd, unsigned long arg); |
| 184 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 185 | static void gdth_flush(gdth_ha_str *ha); |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 186 | static int gdth_queuecommand(Scsi_Cmnd *scp,void (*done)(Scsi_Cmnd *)); |
Boaz Harrosh | 3058d5d | 2007-10-02 23:14:39 +0200 | [diff] [blame] | 187 | static int __gdth_queuecommand(gdth_ha_str *ha, struct scsi_cmnd *scp, |
| 188 | struct gdth_cmndinfo *cmndinfo); |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 189 | static void gdth_scsi_done(struct scsi_cmnd *scp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
| 191 | #ifdef DEBUG_GDTH |
| 192 | static unchar DebugState = DEBUG_GDTH; |
| 193 | |
| 194 | #ifdef __SERIAL__ |
| 195 | #define MAX_SERBUF 160 |
| 196 | static void ser_init(void); |
| 197 | static void ser_puts(char *str); |
| 198 | static void ser_putc(char c); |
| 199 | static int ser_printk(const char *fmt, ...); |
| 200 | static char strbuf[MAX_SERBUF+1]; |
| 201 | #ifdef __COM2__ |
| 202 | #define COM_BASE 0x2f8 |
| 203 | #else |
| 204 | #define COM_BASE 0x3f8 |
| 205 | #endif |
| 206 | static void ser_init() |
| 207 | { |
| 208 | unsigned port=COM_BASE; |
| 209 | |
| 210 | outb(0x80,port+3); |
| 211 | outb(0,port+1); |
| 212 | /* 19200 Baud, if 9600: outb(12,port) */ |
| 213 | outb(6, port); |
| 214 | outb(3,port+3); |
| 215 | outb(0,port+1); |
| 216 | /* |
| 217 | ser_putc('I'); |
| 218 | ser_putc(' '); |
| 219 | */ |
| 220 | } |
| 221 | |
| 222 | static void ser_puts(char *str) |
| 223 | { |
| 224 | char *ptr; |
| 225 | |
| 226 | ser_init(); |
| 227 | for (ptr=str;*ptr;++ptr) |
| 228 | ser_putc(*ptr); |
| 229 | } |
| 230 | |
| 231 | static void ser_putc(char c) |
| 232 | { |
| 233 | unsigned port=COM_BASE; |
| 234 | |
| 235 | while ((inb(port+5) & 0x20)==0); |
| 236 | outb(c,port); |
| 237 | if (c==0x0a) |
| 238 | { |
| 239 | while ((inb(port+5) & 0x20)==0); |
| 240 | outb(0x0d,port); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | static int ser_printk(const char *fmt, ...) |
| 245 | { |
| 246 | va_list args; |
| 247 | int i; |
| 248 | |
| 249 | va_start(args,fmt); |
| 250 | i = vsprintf(strbuf,fmt,args); |
| 251 | ser_puts(strbuf); |
| 252 | va_end(args); |
| 253 | return i; |
| 254 | } |
| 255 | |
| 256 | #define TRACE(a) {if (DebugState==1) {ser_printk a;}} |
| 257 | #define TRACE2(a) {if (DebugState==1 || DebugState==2) {ser_printk a;}} |
| 258 | #define TRACE3(a) {if (DebugState!=0) {ser_printk a;}} |
| 259 | |
| 260 | #else /* !__SERIAL__ */ |
| 261 | #define TRACE(a) {if (DebugState==1) {printk a;}} |
| 262 | #define TRACE2(a) {if (DebugState==1 || DebugState==2) {printk a;}} |
| 263 | #define TRACE3(a) {if (DebugState!=0) {printk a;}} |
| 264 | #endif |
| 265 | |
| 266 | #else /* !DEBUG */ |
| 267 | #define TRACE(a) |
| 268 | #define TRACE2(a) |
| 269 | #define TRACE3(a) |
| 270 | #endif |
| 271 | |
| 272 | #ifdef GDTH_STATISTICS |
| 273 | static ulong32 max_rq=0, max_index=0, max_sg=0; |
| 274 | #ifdef INT_COAL |
| 275 | static ulong32 max_int_coal=0; |
| 276 | #endif |
| 277 | static ulong32 act_ints=0, act_ios=0, act_stats=0, act_rq=0; |
| 278 | static struct timer_list gdth_timer; |
| 279 | #endif |
| 280 | |
| 281 | #define PTR2USHORT(a) (ushort)(ulong)(a) |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 282 | #define GDTOFFSOF(a,b) (size_t)&(((a*)0)->b) |
| 283 | #define INDEX_OK(i,t) ((i)<ARRAY_SIZE(t)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | #define BUS_L2P(a,b) ((b)>(a)->virt_bus ? (b-1):(b)) |
| 286 | |
Christoph Hellwig | aed91cb | 2007-10-02 22:48:16 +0200 | [diff] [blame] | 287 | #ifdef CONFIG_ISA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | static unchar gdth_drq_tab[4] = {5,6,7,7}; /* DRQ table */ |
Christoph Hellwig | aed91cb | 2007-10-02 22:48:16 +0200 | [diff] [blame] | 289 | #endif |
Dhaval Giani | c8e91b0 | 2007-10-12 15:12:31 +0530 | [diff] [blame] | 290 | #if defined(CONFIG_EISA) || defined(CONFIG_ISA) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | static unchar gdth_irq_tab[6] = {0,10,11,12,14,0}; /* IRQ table */ |
Christoph Hellwig | 706a5d4 | 2007-10-02 22:49:35 +0200 | [diff] [blame] | 292 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | static unchar gdth_polling; /* polling if TRUE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | static int gdth_ctr_count = 0; /* controller count */ |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 295 | static LIST_HEAD(gdth_instances); /* controller list */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | static unchar gdth_write_through = FALSE; /* write through */ |
| 297 | static gdth_evt_str ebuffer[MAX_EVENTS]; /* event buffer */ |
| 298 | static int elastidx; |
| 299 | static int eoldidx; |
| 300 | static int major; |
| 301 | |
| 302 | #define DIN 1 /* IN data direction */ |
| 303 | #define DOU 2 /* OUT data direction */ |
| 304 | #define DNO DIN /* no data transfer */ |
| 305 | #define DUN DIN /* unknown data direction */ |
| 306 | static unchar gdth_direction_tab[0x100] = { |
| 307 | DNO,DNO,DIN,DIN,DOU,DIN,DIN,DOU,DIN,DUN,DOU,DOU,DUN,DUN,DUN,DIN, |
| 308 | DNO,DIN,DIN,DOU,DIN,DOU,DNO,DNO,DOU,DNO,DIN,DNO,DIN,DOU,DNO,DUN, |
| 309 | DIN,DUN,DIN,DUN,DOU,DIN,DUN,DUN,DIN,DIN,DOU,DNO,DUN,DIN,DOU,DOU, |
| 310 | DOU,DOU,DOU,DNO,DIN,DNO,DNO,DIN,DOU,DOU,DOU,DOU,DIN,DOU,DIN,DOU, |
| 311 | DOU,DOU,DIN,DIN,DIN,DNO,DUN,DNO,DNO,DNO,DUN,DNO,DOU,DIN,DUN,DUN, |
| 312 | DUN,DUN,DUN,DUN,DUN,DOU,DUN,DUN,DUN,DUN,DIN,DUN,DUN,DUN,DUN,DUN, |
| 313 | DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN, |
| 314 | DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN, |
| 315 | DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DIN,DUN,DOU,DUN,DUN,DUN,DUN,DUN, |
| 316 | DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DIN,DUN, |
| 317 | DUN,DUN,DUN,DUN,DUN,DNO,DNO,DUN,DIN,DNO,DOU,DUN,DNO,DUN,DOU,DOU, |
| 318 | DOU,DOU,DOU,DNO,DUN,DIN,DOU,DIN,DIN,DUN,DUN,DUN,DUN,DUN,DUN,DUN, |
| 319 | DUN,DUN,DOU,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN, |
| 320 | DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN, |
| 321 | DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DOU,DUN,DUN,DUN,DUN,DUN, |
| 322 | DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN |
| 323 | }; |
| 324 | |
| 325 | /* LILO and modprobe/insmod parameters */ |
| 326 | /* IRQ list for GDT3000/3020 EISA controllers */ |
| 327 | static int irq[MAXHA] __initdata = |
| 328 | {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, |
| 329 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}; |
| 330 | /* disable driver flag */ |
| 331 | static int disable __initdata = 0; |
| 332 | /* reserve flag */ |
| 333 | static int reserve_mode = 1; |
| 334 | /* reserve list */ |
| 335 | static int reserve_list[MAX_RES_ARGS] = |
| 336 | {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, |
| 337 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, |
| 338 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}; |
| 339 | /* scan order for PCI controllers */ |
| 340 | static int reverse_scan = 0; |
| 341 | /* virtual channel for the host drives */ |
| 342 | static int hdr_channel = 0; |
| 343 | /* max. IDs per channel */ |
| 344 | static int max_ids = MAXID; |
| 345 | /* rescan all IDs */ |
| 346 | static int rescan = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | /* shared access */ |
| 348 | static int shared_access = 1; |
| 349 | /* enable support for EISA and ISA controllers */ |
| 350 | static int probe_eisa_isa = 0; |
| 351 | /* 64 bit DMA mode, support for drives > 2 TB, if force_dma32 = 0 */ |
| 352 | static int force_dma32 = 0; |
| 353 | |
| 354 | /* parameters for modprobe/insmod */ |
| 355 | module_param_array(irq, int, NULL, 0); |
| 356 | module_param(disable, int, 0); |
| 357 | module_param(reserve_mode, int, 0); |
| 358 | module_param_array(reserve_list, int, NULL, 0); |
| 359 | module_param(reverse_scan, int, 0); |
| 360 | module_param(hdr_channel, int, 0); |
| 361 | module_param(max_ids, int, 0); |
| 362 | module_param(rescan, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | module_param(shared_access, int, 0); |
| 364 | module_param(probe_eisa_isa, int, 0); |
| 365 | module_param(force_dma32, int, 0); |
| 366 | MODULE_AUTHOR("Achim Leubner"); |
| 367 | MODULE_LICENSE("GPL"); |
| 368 | |
| 369 | /* ioctl interface */ |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 370 | static const struct file_operations gdth_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | .ioctl = gdth_ioctl, |
| 372 | .open = gdth_open, |
| 373 | .release = gdth_close, |
| 374 | }; |
| 375 | |
| 376 | #include "gdth_proc.h" |
| 377 | #include "gdth_proc.c" |
| 378 | |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 379 | static gdth_ha_str *gdth_find_ha(int hanum) |
| 380 | { |
| 381 | gdth_ha_str *ha; |
| 382 | |
| 383 | list_for_each_entry(ha, &gdth_instances, list) |
| 384 | if (hanum == ha->hanum) |
| 385 | return ha; |
| 386 | |
| 387 | return NULL; |
| 388 | } |
| 389 | |
Boaz Harrosh | 3058d5d | 2007-10-02 23:14:39 +0200 | [diff] [blame] | 390 | static struct gdth_cmndinfo *gdth_get_cmndinfo(gdth_ha_str *ha) |
| 391 | { |
| 392 | struct gdth_cmndinfo *priv = NULL; |
| 393 | ulong flags; |
| 394 | int i; |
| 395 | |
| 396 | spin_lock_irqsave(&ha->smp_lock, flags); |
| 397 | |
| 398 | for (i=0; i<GDTH_MAXCMDS; ++i) { |
| 399 | if (ha->cmndinfo[i].index == 0) { |
| 400 | priv = &ha->cmndinfo[i]; |
Boaz Harrosh | 3058d5d | 2007-10-02 23:14:39 +0200 | [diff] [blame] | 401 | memset(priv, 0, sizeof(*priv)); |
Boaz Harrosh | ee54cc6 | 2008-02-27 15:29:15 -0800 | [diff] [blame] | 402 | priv->index = i+1; |
Boaz Harrosh | 3058d5d | 2007-10-02 23:14:39 +0200 | [diff] [blame] | 403 | break; |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
| 408 | |
| 409 | return priv; |
| 410 | } |
| 411 | |
| 412 | static void gdth_put_cmndinfo(struct gdth_cmndinfo *priv) |
| 413 | { |
| 414 | BUG_ON(!priv); |
| 415 | priv->index = 0; |
| 416 | } |
| 417 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | static void gdth_delay(int milliseconds) |
| 419 | { |
| 420 | if (milliseconds == 0) { |
| 421 | udelay(1); |
| 422 | } else { |
| 423 | mdelay(milliseconds); |
| 424 | } |
| 425 | } |
| 426 | |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 427 | static void gdth_scsi_done(struct scsi_cmnd *scp) |
| 428 | { |
Boaz Harrosh | 3058d5d | 2007-10-02 23:14:39 +0200 | [diff] [blame] | 429 | struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp); |
| 430 | int internal_command = cmndinfo->internal_command; |
| 431 | |
Matthew Wilcox | b8bff2a | 2007-10-02 22:40:22 +0200 | [diff] [blame] | 432 | TRACE2(("gdth_scsi_done()\n")); |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 433 | |
Boaz Harrosh | 3058d5d | 2007-10-02 23:14:39 +0200 | [diff] [blame] | 434 | gdth_put_cmndinfo(cmndinfo); |
| 435 | scp->host_scribble = NULL; |
| 436 | |
| 437 | if (internal_command) |
Matthew Wilcox | b8bff2a | 2007-10-02 22:40:22 +0200 | [diff] [blame] | 438 | complete((struct completion *)scp->request); |
| 439 | else |
| 440 | scp->scsi_done(scp); |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | int __gdth_execute(struct scsi_device *sdev, gdth_cmd_str *gdtcmd, char *cmnd, |
| 444 | int timeout, u32 *info) |
| 445 | { |
Boaz Harrosh | 3058d5d | 2007-10-02 23:14:39 +0200 | [diff] [blame] | 446 | gdth_ha_str *ha = shost_priv(sdev->host); |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 447 | Scsi_Cmnd *scp; |
Boaz Harrosh | 3058d5d | 2007-10-02 23:14:39 +0200 | [diff] [blame] | 448 | struct gdth_cmndinfo cmndinfo; |
Peter Zijlstra | 6e9a473 | 2006-09-30 23:28:10 -0700 | [diff] [blame] | 449 | DECLARE_COMPLETION_ONSTACK(wait); |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 450 | int rval; |
| 451 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 452 | scp = kzalloc(sizeof(*scp), GFP_KERNEL); |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 453 | if (!scp) |
| 454 | return -ENOMEM; |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 455 | |
Sven Schnelle | 1b96f89 | 2008-03-10 22:50:04 +0100 | [diff] [blame] | 456 | scp->sense_buffer = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL); |
| 457 | if (!scp->sense_buffer) { |
| 458 | kfree(scp); |
| 459 | return -ENOMEM; |
| 460 | } |
| 461 | |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 462 | scp->device = sdev; |
Boaz Harrosh | 3058d5d | 2007-10-02 23:14:39 +0200 | [diff] [blame] | 463 | memset(&cmndinfo, 0, sizeof(cmndinfo)); |
| 464 | |
Christoph Hellwig | beb4048 | 2006-06-10 18:01:03 +0200 | [diff] [blame] | 465 | /* use request field to save the ptr. to completion struct. */ |
| 466 | scp->request = (struct request *)&wait; |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 467 | scp->timeout_per_command = timeout*HZ; |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 468 | scp->cmd_len = 12; |
Boaz Harrosh | 64a87b2 | 2008-04-30 11:19:47 +0300 | [diff] [blame] | 469 | scp->cmnd = cmnd; |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 470 | cmndinfo.priority = IOCTL_PRI; |
Boaz Harrosh | ee54cc6 | 2008-02-27 15:29:15 -0800 | [diff] [blame] | 471 | cmndinfo.internal_cmd_str = gdtcmd; |
Boaz Harrosh | 3058d5d | 2007-10-02 23:14:39 +0200 | [diff] [blame] | 472 | cmndinfo.internal_command = 1; |
| 473 | |
| 474 | TRACE(("__gdth_execute() cmd 0x%x\n", scp->cmnd[0])); |
| 475 | __gdth_queuecommand(ha, scp, &cmndinfo); |
| 476 | |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 477 | wait_for_completion(&wait); |
| 478 | |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 479 | rval = cmndinfo.status; |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 480 | if (info) |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 481 | *info = cmndinfo.info; |
Sven Schnelle | 1b96f89 | 2008-03-10 22:50:04 +0100 | [diff] [blame] | 482 | kfree(scp->sense_buffer); |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 483 | kfree(scp); |
| 484 | return rval; |
| 485 | } |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 486 | |
| 487 | int gdth_execute(struct Scsi_Host *shost, gdth_cmd_str *gdtcmd, char *cmnd, |
| 488 | int timeout, u32 *info) |
| 489 | { |
| 490 | struct scsi_device *sdev = scsi_get_host_dev(shost); |
| 491 | int rval = __gdth_execute(sdev, gdtcmd, cmnd, timeout, info); |
| 492 | |
| 493 | scsi_free_host_dev(sdev); |
| 494 | return rval; |
| 495 | } |
| 496 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | static void gdth_eval_mapping(ulong32 size, ulong32 *cyls, int *heads, int *secs) |
| 498 | { |
| 499 | *cyls = size /HEADS/SECS; |
| 500 | if (*cyls <= MAXCYLS) { |
| 501 | *heads = HEADS; |
| 502 | *secs = SECS; |
| 503 | } else { /* too high for 64*32 */ |
| 504 | *cyls = size /MEDHEADS/MEDSECS; |
| 505 | if (*cyls <= MAXCYLS) { |
| 506 | *heads = MEDHEADS; |
| 507 | *secs = MEDSECS; |
| 508 | } else { /* too high for 127*63 */ |
| 509 | *cyls = size /BIGHEADS/BIGSECS; |
| 510 | *heads = BIGHEADS; |
| 511 | *secs = BIGSECS; |
| 512 | } |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | /* controller search and initialization functions */ |
Christoph Hellwig | 706a5d4 | 2007-10-02 22:49:35 +0200 | [diff] [blame] | 517 | #ifdef CONFIG_EISA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | static int __init gdth_search_eisa(ushort eisa_adr) |
| 519 | { |
| 520 | ulong32 id; |
| 521 | |
| 522 | TRACE(("gdth_search_eisa() adr. %x\n",eisa_adr)); |
| 523 | id = inl(eisa_adr+ID0REG); |
| 524 | if (id == GDT3A_ID || id == GDT3B_ID) { /* GDT3000A or GDT3000B */ |
| 525 | if ((inb(eisa_adr+EISAREG) & 8) == 0) |
| 526 | return 0; /* not EISA configured */ |
| 527 | return 1; |
| 528 | } |
| 529 | if (id == GDT3_ID) /* GDT3000 */ |
| 530 | return 1; |
| 531 | |
| 532 | return 0; |
| 533 | } |
Christoph Hellwig | 706a5d4 | 2007-10-02 22:49:35 +0200 | [diff] [blame] | 534 | #endif /* CONFIG_EISA */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | |
Christoph Hellwig | aed91cb | 2007-10-02 22:48:16 +0200 | [diff] [blame] | 536 | #ifdef CONFIG_ISA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | static int __init gdth_search_isa(ulong32 bios_adr) |
| 538 | { |
| 539 | void __iomem *addr; |
| 540 | ulong32 id; |
| 541 | |
| 542 | TRACE(("gdth_search_isa() bios adr. %x\n",bios_adr)); |
| 543 | if ((addr = ioremap(bios_adr+BIOS_ID_OFFS, sizeof(ulong32))) != NULL) { |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 544 | id = readl(addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | iounmap(addr); |
| 546 | if (id == GDT2_ID) /* GDT2000 */ |
| 547 | return 1; |
| 548 | } |
| 549 | return 0; |
| 550 | } |
Christoph Hellwig | aed91cb | 2007-10-02 22:48:16 +0200 | [diff] [blame] | 551 | #endif /* CONFIG_ISA */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | |
Christoph Hellwig | 8514ef2 | 2007-10-02 22:51:06 +0200 | [diff] [blame] | 553 | #ifdef CONFIG_PCI |
Christoph Hellwig | 8514ef2 | 2007-10-02 22:51:06 +0200 | [diff] [blame] | 554 | |
Jeff Garzik | cff2680 | 2008-02-15 22:20:09 -0500 | [diff] [blame] | 555 | static bool gdth_search_vortex(ushort device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | { |
Jeff Garzik | cff2680 | 2008-02-15 22:20:09 -0500 | [diff] [blame] | 557 | if (device <= PCI_DEVICE_ID_VORTEX_GDT6555) |
| 558 | return true; |
| 559 | if (device >= PCI_DEVICE_ID_VORTEX_GDT6x17RP && |
| 560 | device <= PCI_DEVICE_ID_VORTEX_GDTMAXRP) |
| 561 | return true; |
| 562 | if (device == PCI_DEVICE_ID_VORTEX_GDTNEWRX || |
| 563 | device == PCI_DEVICE_ID_VORTEX_GDTNEWRX2) |
| 564 | return true; |
| 565 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | } |
| 567 | |
Jeff Garzik | cff2680 | 2008-02-15 22:20:09 -0500 | [diff] [blame] | 568 | static int gdth_pci_probe_one(gdth_pci_str *pcistr, gdth_ha_str **ha_out); |
| 569 | static int gdth_pci_init_one(struct pci_dev *pdev, |
| 570 | const struct pci_device_id *ent); |
| 571 | static void gdth_pci_remove_one(struct pci_dev *pdev); |
| 572 | static void gdth_remove_one(gdth_ha_str *ha); |
| 573 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | /* Vortex only makes RAID controllers. |
| 575 | * We do not really want to specify all 550 ids here, so wildcard match. |
| 576 | */ |
Jeff Garzik | cff2680 | 2008-02-15 22:20:09 -0500 | [diff] [blame] | 577 | static const struct pci_device_id gdthtable[] = { |
| 578 | { PCI_VDEVICE(VORTEX, PCI_ANY_ID) }, |
| 579 | { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_SRC) }, |
| 580 | { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_SRC_XSCALE) }, |
| 581 | { } /* terminate list */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | }; |
Jeff Garzik | cff2680 | 2008-02-15 22:20:09 -0500 | [diff] [blame] | 583 | MODULE_DEVICE_TABLE(pci, gdthtable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | |
Jeff Garzik | cff2680 | 2008-02-15 22:20:09 -0500 | [diff] [blame] | 585 | static struct pci_driver gdth_pci_driver = { |
| 586 | .name = "gdth", |
| 587 | .id_table = gdthtable, |
| 588 | .probe = gdth_pci_init_one, |
| 589 | .remove = gdth_pci_remove_one, |
| 590 | }; |
| 591 | |
| 592 | static void gdth_pci_remove_one(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | { |
Jeff Garzik | cff2680 | 2008-02-15 22:20:09 -0500 | [diff] [blame] | 594 | gdth_ha_str *ha = pci_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | |
Jeff Garzik | cff2680 | 2008-02-15 22:20:09 -0500 | [diff] [blame] | 596 | pci_set_drvdata(pdev, NULL); |
| 597 | |
| 598 | list_del(&ha->list); |
| 599 | gdth_remove_one(ha); |
| 600 | |
| 601 | pci_disable_device(pdev); |
| 602 | } |
| 603 | |
| 604 | static int gdth_pci_init_one(struct pci_dev *pdev, |
| 605 | const struct pci_device_id *ent) |
| 606 | { |
| 607 | ushort vendor = pdev->vendor; |
| 608 | ushort device = pdev->device; |
| 609 | ulong base0, base1, base2; |
| 610 | int rc; |
| 611 | gdth_pci_str gdth_pcistr; |
| 612 | gdth_ha_str *ha = NULL; |
| 613 | |
| 614 | TRACE(("gdth_search_dev() cnt %d vendor %x device %x\n", |
| 615 | gdth_ctr_count, vendor, device)); |
| 616 | |
| 617 | memset(&gdth_pcistr, 0, sizeof(gdth_pcistr)); |
| 618 | |
| 619 | if (vendor == PCI_VENDOR_ID_VORTEX && !gdth_search_vortex(device)) |
| 620 | return -ENODEV; |
| 621 | |
| 622 | rc = pci_enable_device(pdev); |
| 623 | if (rc) |
| 624 | return rc; |
| 625 | |
| 626 | if (gdth_ctr_count >= MAXHA) |
| 627 | return -EBUSY; |
Sergio Luis | 9910930 | 2008-02-12 20:48:03 -0300 | [diff] [blame] | 628 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | /* GDT PCI controller found, resources are already in pdev */ |
Jeff Garzik | cff2680 | 2008-02-15 22:20:09 -0500 | [diff] [blame] | 630 | gdth_pcistr.pdev = pdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | base0 = pci_resource_flags(pdev, 0); |
| 632 | base1 = pci_resource_flags(pdev, 1); |
| 633 | base2 = pci_resource_flags(pdev, 2); |
| 634 | if (device <= PCI_DEVICE_ID_VORTEX_GDT6000B || /* GDT6000/B */ |
| 635 | device >= PCI_DEVICE_ID_VORTEX_GDT6x17RP) { /* MPR */ |
| 636 | if (!(base0 & IORESOURCE_MEM)) |
Jeff Garzik | cff2680 | 2008-02-15 22:20:09 -0500 | [diff] [blame] | 637 | return -ENODEV; |
| 638 | gdth_pcistr.dpmem = pci_resource_start(pdev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | } else { /* GDT6110, GDT6120, .. */ |
| 640 | if (!(base0 & IORESOURCE_MEM) || |
| 641 | !(base2 & IORESOURCE_MEM) || |
| 642 | !(base1 & IORESOURCE_IO)) |
Jeff Garzik | cff2680 | 2008-02-15 22:20:09 -0500 | [diff] [blame] | 643 | return -ENODEV; |
| 644 | gdth_pcistr.dpmem = pci_resource_start(pdev, 2); |
| 645 | gdth_pcistr.io = pci_resource_start(pdev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | } |
| 647 | TRACE2(("Controller found at %d/%d, irq %d, dpmem 0x%lx\n", |
Jeff Garzik | cff2680 | 2008-02-15 22:20:09 -0500 | [diff] [blame] | 648 | gdth_pcistr.pdev->bus->number, |
| 649 | PCI_SLOT(gdth_pcistr.pdev->devfn), |
| 650 | gdth_pcistr.irq, |
| 651 | gdth_pcistr.dpmem)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
Jeff Garzik | cff2680 | 2008-02-15 22:20:09 -0500 | [diff] [blame] | 653 | rc = gdth_pci_probe_one(&gdth_pcistr, &ha); |
| 654 | if (rc) |
| 655 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | |
Jeff Garzik | cff2680 | 2008-02-15 22:20:09 -0500 | [diff] [blame] | 657 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | } |
Christoph Hellwig | 8514ef2 | 2007-10-02 22:51:06 +0200 | [diff] [blame] | 659 | #endif /* CONFIG_PCI */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | |
Christoph Hellwig | 706a5d4 | 2007-10-02 22:49:35 +0200 | [diff] [blame] | 661 | #ifdef CONFIG_EISA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | static int __init gdth_init_eisa(ushort eisa_adr,gdth_ha_str *ha) |
| 663 | { |
| 664 | ulong32 retries,id; |
| 665 | unchar prot_ver,eisacf,i,irq_found; |
| 666 | |
| 667 | TRACE(("gdth_init_eisa() adr. %x\n",eisa_adr)); |
| 668 | |
| 669 | /* disable board interrupts, deinitialize services */ |
| 670 | outb(0xff,eisa_adr+EDOORREG); |
| 671 | outb(0x00,eisa_adr+EDENABREG); |
| 672 | outb(0x00,eisa_adr+EINTENABREG); |
| 673 | |
| 674 | outb(0xff,eisa_adr+LDOORREG); |
| 675 | retries = INIT_RETRIES; |
| 676 | gdth_delay(20); |
| 677 | while (inb(eisa_adr+EDOORREG) != 0xff) { |
| 678 | if (--retries == 0) { |
| 679 | printk("GDT-EISA: Initialization error (DEINIT failed)\n"); |
| 680 | return 0; |
| 681 | } |
| 682 | gdth_delay(1); |
| 683 | TRACE2(("wait for DEINIT: retries=%d\n",retries)); |
| 684 | } |
| 685 | prot_ver = inb(eisa_adr+MAILBOXREG); |
| 686 | outb(0xff,eisa_adr+EDOORREG); |
| 687 | if (prot_ver != PROTOCOL_VERSION) { |
| 688 | printk("GDT-EISA: Illegal protocol version\n"); |
| 689 | return 0; |
| 690 | } |
| 691 | ha->bmic = eisa_adr; |
| 692 | ha->brd_phys = (ulong32)eisa_adr >> 12; |
| 693 | |
| 694 | outl(0,eisa_adr+MAILBOXREG); |
| 695 | outl(0,eisa_adr+MAILBOXREG+4); |
| 696 | outl(0,eisa_adr+MAILBOXREG+8); |
| 697 | outl(0,eisa_adr+MAILBOXREG+12); |
| 698 | |
| 699 | /* detect IRQ */ |
| 700 | if ((id = inl(eisa_adr+ID0REG)) == GDT3_ID) { |
| 701 | ha->oem_id = OEM_ID_ICP; |
| 702 | ha->type = GDT_EISA; |
| 703 | ha->stype = id; |
| 704 | outl(1,eisa_adr+MAILBOXREG+8); |
| 705 | outb(0xfe,eisa_adr+LDOORREG); |
| 706 | retries = INIT_RETRIES; |
| 707 | gdth_delay(20); |
| 708 | while (inb(eisa_adr+EDOORREG) != 0xfe) { |
| 709 | if (--retries == 0) { |
| 710 | printk("GDT-EISA: Initialization error (get IRQ failed)\n"); |
| 711 | return 0; |
| 712 | } |
| 713 | gdth_delay(1); |
| 714 | } |
| 715 | ha->irq = inb(eisa_adr+MAILBOXREG); |
| 716 | outb(0xff,eisa_adr+EDOORREG); |
| 717 | TRACE2(("GDT3000/3020: IRQ=%d\n",ha->irq)); |
| 718 | /* check the result */ |
| 719 | if (ha->irq == 0) { |
| 720 | TRACE2(("Unknown IRQ, use IRQ table from cmd line !\n")); |
| 721 | for (i = 0, irq_found = FALSE; |
| 722 | i < MAXHA && irq[i] != 0xff; ++i) { |
| 723 | if (irq[i]==10 || irq[i]==11 || irq[i]==12 || irq[i]==14) { |
| 724 | irq_found = TRUE; |
| 725 | break; |
| 726 | } |
| 727 | } |
| 728 | if (irq_found) { |
| 729 | ha->irq = irq[i]; |
| 730 | irq[i] = 0; |
| 731 | printk("GDT-EISA: Can not detect controller IRQ,\n"); |
| 732 | printk("Use IRQ setting from command line (IRQ = %d)\n", |
| 733 | ha->irq); |
| 734 | } else { |
| 735 | printk("GDT-EISA: Initialization error (unknown IRQ), Enable\n"); |
| 736 | printk("the controller BIOS or use command line parameters\n"); |
| 737 | return 0; |
| 738 | } |
| 739 | } |
| 740 | } else { |
| 741 | eisacf = inb(eisa_adr+EISAREG) & 7; |
| 742 | if (eisacf > 4) /* level triggered */ |
| 743 | eisacf -= 4; |
| 744 | ha->irq = gdth_irq_tab[eisacf]; |
| 745 | ha->oem_id = OEM_ID_ICP; |
| 746 | ha->type = GDT_EISA; |
| 747 | ha->stype = id; |
| 748 | } |
| 749 | |
| 750 | ha->dma64_support = 0; |
| 751 | return 1; |
| 752 | } |
Christoph Hellwig | 706a5d4 | 2007-10-02 22:49:35 +0200 | [diff] [blame] | 753 | #endif /* CONFIG_EISA */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | |
Christoph Hellwig | aed91cb | 2007-10-02 22:48:16 +0200 | [diff] [blame] | 755 | #ifdef CONFIG_ISA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | static int __init gdth_init_isa(ulong32 bios_adr,gdth_ha_str *ha) |
| 757 | { |
| 758 | register gdt2_dpram_str __iomem *dp2_ptr; |
| 759 | int i; |
| 760 | unchar irq_drq,prot_ver; |
| 761 | ulong32 retries; |
| 762 | |
| 763 | TRACE(("gdth_init_isa() bios adr. %x\n",bios_adr)); |
| 764 | |
| 765 | ha->brd = ioremap(bios_adr, sizeof(gdt2_dpram_str)); |
| 766 | if (ha->brd == NULL) { |
| 767 | printk("GDT-ISA: Initialization error (DPMEM remap error)\n"); |
| 768 | return 0; |
| 769 | } |
| 770 | dp2_ptr = ha->brd; |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 771 | writeb(1, &dp2_ptr->io.memlock); /* switch off write protection */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | /* reset interface area */ |
| 773 | memset_io(&dp2_ptr->u, 0, sizeof(dp2_ptr->u)); |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 774 | if (readl(&dp2_ptr->u) != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | printk("GDT-ISA: Initialization error (DPMEM write error)\n"); |
| 776 | iounmap(ha->brd); |
| 777 | return 0; |
| 778 | } |
| 779 | |
| 780 | /* disable board interrupts, read DRQ and IRQ */ |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 781 | writeb(0xff, &dp2_ptr->io.irqdel); |
| 782 | writeb(0x00, &dp2_ptr->io.irqen); |
| 783 | writeb(0x00, &dp2_ptr->u.ic.S_Status); |
| 784 | writeb(0x00, &dp2_ptr->u.ic.Cmd_Index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 786 | irq_drq = readb(&dp2_ptr->io.rq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | for (i=0; i<3; ++i) { |
| 788 | if ((irq_drq & 1)==0) |
| 789 | break; |
| 790 | irq_drq >>= 1; |
| 791 | } |
| 792 | ha->drq = gdth_drq_tab[i]; |
| 793 | |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 794 | irq_drq = readb(&dp2_ptr->io.rq) >> 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | for (i=1; i<5; ++i) { |
| 796 | if ((irq_drq & 1)==0) |
| 797 | break; |
| 798 | irq_drq >>= 1; |
| 799 | } |
| 800 | ha->irq = gdth_irq_tab[i]; |
| 801 | |
| 802 | /* deinitialize services */ |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 803 | writel(bios_adr, &dp2_ptr->u.ic.S_Info[0]); |
| 804 | writeb(0xff, &dp2_ptr->u.ic.S_Cmd_Indx); |
| 805 | writeb(0, &dp2_ptr->io.event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | retries = INIT_RETRIES; |
| 807 | gdth_delay(20); |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 808 | while (readb(&dp2_ptr->u.ic.S_Status) != 0xff) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | if (--retries == 0) { |
| 810 | printk("GDT-ISA: Initialization error (DEINIT failed)\n"); |
| 811 | iounmap(ha->brd); |
| 812 | return 0; |
| 813 | } |
| 814 | gdth_delay(1); |
| 815 | } |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 816 | prot_ver = (unchar)readl(&dp2_ptr->u.ic.S_Info[0]); |
| 817 | writeb(0, &dp2_ptr->u.ic.Status); |
| 818 | writeb(0xff, &dp2_ptr->io.irqdel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | if (prot_ver != PROTOCOL_VERSION) { |
| 820 | printk("GDT-ISA: Illegal protocol version\n"); |
| 821 | iounmap(ha->brd); |
| 822 | return 0; |
| 823 | } |
| 824 | |
| 825 | ha->oem_id = OEM_ID_ICP; |
| 826 | ha->type = GDT_ISA; |
| 827 | ha->ic_all_size = sizeof(dp2_ptr->u); |
| 828 | ha->stype= GDT2_ID; |
| 829 | ha->brd_phys = bios_adr >> 4; |
| 830 | |
| 831 | /* special request to controller BIOS */ |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 832 | writel(0x00, &dp2_ptr->u.ic.S_Info[0]); |
| 833 | writel(0x00, &dp2_ptr->u.ic.S_Info[1]); |
| 834 | writel(0x01, &dp2_ptr->u.ic.S_Info[2]); |
| 835 | writel(0x00, &dp2_ptr->u.ic.S_Info[3]); |
| 836 | writeb(0xfe, &dp2_ptr->u.ic.S_Cmd_Indx); |
| 837 | writeb(0, &dp2_ptr->io.event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | retries = INIT_RETRIES; |
| 839 | gdth_delay(20); |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 840 | while (readb(&dp2_ptr->u.ic.S_Status) != 0xfe) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | if (--retries == 0) { |
| 842 | printk("GDT-ISA: Initialization error\n"); |
| 843 | iounmap(ha->brd); |
| 844 | return 0; |
| 845 | } |
| 846 | gdth_delay(1); |
| 847 | } |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 848 | writeb(0, &dp2_ptr->u.ic.Status); |
| 849 | writeb(0xff, &dp2_ptr->io.irqdel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | |
| 851 | ha->dma64_support = 0; |
| 852 | return 1; |
| 853 | } |
Christoph Hellwig | aed91cb | 2007-10-02 22:48:16 +0200 | [diff] [blame] | 854 | #endif /* CONFIG_ISA */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | |
Christoph Hellwig | 8514ef2 | 2007-10-02 22:51:06 +0200 | [diff] [blame] | 856 | #ifdef CONFIG_PCI |
Jeff Garzik | cff2680 | 2008-02-15 22:20:09 -0500 | [diff] [blame] | 857 | static int gdth_init_pci(struct pci_dev *pdev, gdth_pci_str *pcistr, |
| 858 | gdth_ha_str *ha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | { |
| 860 | register gdt6_dpram_str __iomem *dp6_ptr; |
| 861 | register gdt6c_dpram_str __iomem *dp6c_ptr; |
| 862 | register gdt6m_dpram_str __iomem *dp6m_ptr; |
| 863 | ulong32 retries; |
| 864 | unchar prot_ver; |
| 865 | ushort command; |
| 866 | int i, found = FALSE; |
| 867 | |
| 868 | TRACE(("gdth_init_pci()\n")); |
| 869 | |
Jeff Garzik | 4c9c8d7 | 2008-02-15 21:35:26 -0500 | [diff] [blame] | 870 | if (pdev->vendor == PCI_VENDOR_ID_INTEL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | ha->oem_id = OEM_ID_INTEL; |
| 872 | else |
| 873 | ha->oem_id = OEM_ID_ICP; |
Jeff Garzik | 4c9c8d7 | 2008-02-15 21:35:26 -0500 | [diff] [blame] | 874 | ha->brd_phys = (pdev->bus->number << 8) | (pdev->devfn & 0xf8); |
| 875 | ha->stype = (ulong32)pdev->device; |
| 876 | ha->irq = pdev->irq; |
| 877 | ha->pdev = pdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | |
Jeff Garzik | 8e9a8a0 | 2007-07-17 05:25:17 -0400 | [diff] [blame] | 879 | if (ha->pdev->device <= PCI_DEVICE_ID_VORTEX_GDT6000B) { /* GDT6000/B */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | TRACE2(("init_pci() dpmem %lx irq %d\n",pcistr->dpmem,ha->irq)); |
| 881 | ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6_dpram_str)); |
| 882 | if (ha->brd == NULL) { |
| 883 | printk("GDT-PCI: Initialization error (DPMEM remap error)\n"); |
| 884 | return 0; |
| 885 | } |
| 886 | /* check and reset interface area */ |
| 887 | dp6_ptr = ha->brd; |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 888 | writel(DPMEM_MAGIC, &dp6_ptr->u); |
| 889 | if (readl(&dp6_ptr->u) != DPMEM_MAGIC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n", |
| 891 | pcistr->dpmem); |
| 892 | found = FALSE; |
| 893 | for (i = 0xC8000; i < 0xE8000; i += 0x4000) { |
| 894 | iounmap(ha->brd); |
| 895 | ha->brd = ioremap(i, sizeof(ushort)); |
| 896 | if (ha->brd == NULL) { |
| 897 | printk("GDT-PCI: Initialization error (DPMEM remap error)\n"); |
| 898 | return 0; |
| 899 | } |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 900 | if (readw(ha->brd) != 0xffff) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | TRACE2(("init_pci_old() address 0x%x busy\n", i)); |
| 902 | continue; |
| 903 | } |
| 904 | iounmap(ha->brd); |
Jeff Garzik | 4c9c8d7 | 2008-02-15 21:35:26 -0500 | [diff] [blame] | 905 | pci_write_config_dword(pdev, PCI_BASE_ADDRESS_0, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | ha->brd = ioremap(i, sizeof(gdt6_dpram_str)); |
| 907 | if (ha->brd == NULL) { |
| 908 | printk("GDT-PCI: Initialization error (DPMEM remap error)\n"); |
| 909 | return 0; |
| 910 | } |
| 911 | dp6_ptr = ha->brd; |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 912 | writel(DPMEM_MAGIC, &dp6_ptr->u); |
| 913 | if (readl(&dp6_ptr->u) == DPMEM_MAGIC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | printk("GDT-PCI: Use free address at 0x%x\n", i); |
| 915 | found = TRUE; |
| 916 | break; |
| 917 | } |
| 918 | } |
| 919 | if (!found) { |
| 920 | printk("GDT-PCI: No free address found!\n"); |
| 921 | iounmap(ha->brd); |
| 922 | return 0; |
| 923 | } |
| 924 | } |
| 925 | memset_io(&dp6_ptr->u, 0, sizeof(dp6_ptr->u)); |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 926 | if (readl(&dp6_ptr->u) != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | printk("GDT-PCI: Initialization error (DPMEM write error)\n"); |
| 928 | iounmap(ha->brd); |
| 929 | return 0; |
| 930 | } |
| 931 | |
| 932 | /* disable board interrupts, deinit services */ |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 933 | writeb(0xff, &dp6_ptr->io.irqdel); |
| 934 | writeb(0x00, &dp6_ptr->io.irqen); |
| 935 | writeb(0x00, &dp6_ptr->u.ic.S_Status); |
| 936 | writeb(0x00, &dp6_ptr->u.ic.Cmd_Index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 938 | writel(pcistr->dpmem, &dp6_ptr->u.ic.S_Info[0]); |
| 939 | writeb(0xff, &dp6_ptr->u.ic.S_Cmd_Indx); |
| 940 | writeb(0, &dp6_ptr->io.event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | retries = INIT_RETRIES; |
| 942 | gdth_delay(20); |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 943 | while (readb(&dp6_ptr->u.ic.S_Status) != 0xff) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | if (--retries == 0) { |
| 945 | printk("GDT-PCI: Initialization error (DEINIT failed)\n"); |
| 946 | iounmap(ha->brd); |
| 947 | return 0; |
| 948 | } |
| 949 | gdth_delay(1); |
| 950 | } |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 951 | prot_ver = (unchar)readl(&dp6_ptr->u.ic.S_Info[0]); |
| 952 | writeb(0, &dp6_ptr->u.ic.S_Status); |
| 953 | writeb(0xff, &dp6_ptr->io.irqdel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | if (prot_ver != PROTOCOL_VERSION) { |
| 955 | printk("GDT-PCI: Illegal protocol version\n"); |
| 956 | iounmap(ha->brd); |
| 957 | return 0; |
| 958 | } |
| 959 | |
| 960 | ha->type = GDT_PCI; |
| 961 | ha->ic_all_size = sizeof(dp6_ptr->u); |
| 962 | |
| 963 | /* special command to controller BIOS */ |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 964 | writel(0x00, &dp6_ptr->u.ic.S_Info[0]); |
| 965 | writel(0x00, &dp6_ptr->u.ic.S_Info[1]); |
| 966 | writel(0x00, &dp6_ptr->u.ic.S_Info[2]); |
| 967 | writel(0x00, &dp6_ptr->u.ic.S_Info[3]); |
| 968 | writeb(0xfe, &dp6_ptr->u.ic.S_Cmd_Indx); |
| 969 | writeb(0, &dp6_ptr->io.event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | retries = INIT_RETRIES; |
| 971 | gdth_delay(20); |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 972 | while (readb(&dp6_ptr->u.ic.S_Status) != 0xfe) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | if (--retries == 0) { |
| 974 | printk("GDT-PCI: Initialization error\n"); |
| 975 | iounmap(ha->brd); |
| 976 | return 0; |
| 977 | } |
| 978 | gdth_delay(1); |
| 979 | } |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 980 | writeb(0, &dp6_ptr->u.ic.S_Status); |
| 981 | writeb(0xff, &dp6_ptr->io.irqdel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | |
| 983 | ha->dma64_support = 0; |
| 984 | |
Jeff Garzik | 8e9a8a0 | 2007-07-17 05:25:17 -0400 | [diff] [blame] | 985 | } else if (ha->pdev->device <= PCI_DEVICE_ID_VORTEX_GDT6555) { /* GDT6110, ... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | ha->plx = (gdt6c_plx_regs *)pcistr->io; |
| 987 | TRACE2(("init_pci_new() dpmem %lx irq %d\n", |
| 988 | pcistr->dpmem,ha->irq)); |
| 989 | ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6c_dpram_str)); |
| 990 | if (ha->brd == NULL) { |
| 991 | printk("GDT-PCI: Initialization error (DPMEM remap error)\n"); |
| 992 | iounmap(ha->brd); |
| 993 | return 0; |
| 994 | } |
| 995 | /* check and reset interface area */ |
| 996 | dp6c_ptr = ha->brd; |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 997 | writel(DPMEM_MAGIC, &dp6c_ptr->u); |
| 998 | if (readl(&dp6c_ptr->u) != DPMEM_MAGIC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n", |
| 1000 | pcistr->dpmem); |
| 1001 | found = FALSE; |
| 1002 | for (i = 0xC8000; i < 0xE8000; i += 0x4000) { |
| 1003 | iounmap(ha->brd); |
| 1004 | ha->brd = ioremap(i, sizeof(ushort)); |
| 1005 | if (ha->brd == NULL) { |
| 1006 | printk("GDT-PCI: Initialization error (DPMEM remap error)\n"); |
| 1007 | return 0; |
| 1008 | } |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1009 | if (readw(ha->brd) != 0xffff) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | TRACE2(("init_pci_plx() address 0x%x busy\n", i)); |
| 1011 | continue; |
| 1012 | } |
| 1013 | iounmap(ha->brd); |
Jeff Garzik | 4c9c8d7 | 2008-02-15 21:35:26 -0500 | [diff] [blame] | 1014 | pci_write_config_dword(pdev, PCI_BASE_ADDRESS_2, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | ha->brd = ioremap(i, sizeof(gdt6c_dpram_str)); |
| 1016 | if (ha->brd == NULL) { |
| 1017 | printk("GDT-PCI: Initialization error (DPMEM remap error)\n"); |
| 1018 | return 0; |
| 1019 | } |
| 1020 | dp6c_ptr = ha->brd; |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1021 | writel(DPMEM_MAGIC, &dp6c_ptr->u); |
| 1022 | if (readl(&dp6c_ptr->u) == DPMEM_MAGIC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | printk("GDT-PCI: Use free address at 0x%x\n", i); |
| 1024 | found = TRUE; |
| 1025 | break; |
| 1026 | } |
| 1027 | } |
| 1028 | if (!found) { |
| 1029 | printk("GDT-PCI: No free address found!\n"); |
| 1030 | iounmap(ha->brd); |
| 1031 | return 0; |
| 1032 | } |
| 1033 | } |
| 1034 | memset_io(&dp6c_ptr->u, 0, sizeof(dp6c_ptr->u)); |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1035 | if (readl(&dp6c_ptr->u) != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | printk("GDT-PCI: Initialization error (DPMEM write error)\n"); |
| 1037 | iounmap(ha->brd); |
| 1038 | return 0; |
| 1039 | } |
| 1040 | |
| 1041 | /* disable board interrupts, deinit services */ |
| 1042 | outb(0x00,PTR2USHORT(&ha->plx->control1)); |
| 1043 | outb(0xff,PTR2USHORT(&ha->plx->edoor_reg)); |
| 1044 | |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1045 | writeb(0x00, &dp6c_ptr->u.ic.S_Status); |
| 1046 | writeb(0x00, &dp6c_ptr->u.ic.Cmd_Index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1048 | writel(pcistr->dpmem, &dp6c_ptr->u.ic.S_Info[0]); |
| 1049 | writeb(0xff, &dp6c_ptr->u.ic.S_Cmd_Indx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | |
| 1051 | outb(1,PTR2USHORT(&ha->plx->ldoor_reg)); |
| 1052 | |
| 1053 | retries = INIT_RETRIES; |
| 1054 | gdth_delay(20); |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1055 | while (readb(&dp6c_ptr->u.ic.S_Status) != 0xff) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | if (--retries == 0) { |
| 1057 | printk("GDT-PCI: Initialization error (DEINIT failed)\n"); |
| 1058 | iounmap(ha->brd); |
| 1059 | return 0; |
| 1060 | } |
| 1061 | gdth_delay(1); |
| 1062 | } |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1063 | prot_ver = (unchar)readl(&dp6c_ptr->u.ic.S_Info[0]); |
| 1064 | writeb(0, &dp6c_ptr->u.ic.Status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | if (prot_ver != PROTOCOL_VERSION) { |
| 1066 | printk("GDT-PCI: Illegal protocol version\n"); |
| 1067 | iounmap(ha->brd); |
| 1068 | return 0; |
| 1069 | } |
| 1070 | |
| 1071 | ha->type = GDT_PCINEW; |
| 1072 | ha->ic_all_size = sizeof(dp6c_ptr->u); |
| 1073 | |
| 1074 | /* special command to controller BIOS */ |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1075 | writel(0x00, &dp6c_ptr->u.ic.S_Info[0]); |
| 1076 | writel(0x00, &dp6c_ptr->u.ic.S_Info[1]); |
| 1077 | writel(0x00, &dp6c_ptr->u.ic.S_Info[2]); |
| 1078 | writel(0x00, &dp6c_ptr->u.ic.S_Info[3]); |
| 1079 | writeb(0xfe, &dp6c_ptr->u.ic.S_Cmd_Indx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | |
| 1081 | outb(1,PTR2USHORT(&ha->plx->ldoor_reg)); |
| 1082 | |
| 1083 | retries = INIT_RETRIES; |
| 1084 | gdth_delay(20); |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1085 | while (readb(&dp6c_ptr->u.ic.S_Status) != 0xfe) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | if (--retries == 0) { |
| 1087 | printk("GDT-PCI: Initialization error\n"); |
| 1088 | iounmap(ha->brd); |
| 1089 | return 0; |
| 1090 | } |
| 1091 | gdth_delay(1); |
| 1092 | } |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1093 | writeb(0, &dp6c_ptr->u.ic.S_Status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | |
| 1095 | ha->dma64_support = 0; |
| 1096 | |
| 1097 | } else { /* MPR */ |
| 1098 | TRACE2(("init_pci_mpr() dpmem %lx irq %d\n",pcistr->dpmem,ha->irq)); |
| 1099 | ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6m_dpram_str)); |
| 1100 | if (ha->brd == NULL) { |
| 1101 | printk("GDT-PCI: Initialization error (DPMEM remap error)\n"); |
| 1102 | return 0; |
| 1103 | } |
| 1104 | |
| 1105 | /* manipulate config. space to enable DPMEM, start RP controller */ |
Jeff Garzik | 4c9c8d7 | 2008-02-15 21:35:26 -0500 | [diff] [blame] | 1106 | pci_read_config_word(pdev, PCI_COMMAND, &command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | command |= 6; |
Jeff Garzik | 4c9c8d7 | 2008-02-15 21:35:26 -0500 | [diff] [blame] | 1108 | pci_write_config_word(pdev, PCI_COMMAND, command); |
| 1109 | if (pci_resource_start(pdev, 8) == 1UL) |
| 1110 | pci_resource_start(pdev, 8) = 0UL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | i = 0xFEFF0001UL; |
Jeff Garzik | 4c9c8d7 | 2008-02-15 21:35:26 -0500 | [diff] [blame] | 1112 | pci_write_config_dword(pdev, PCI_ROM_ADDRESS, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | gdth_delay(1); |
Jeff Garzik | 4c9c8d7 | 2008-02-15 21:35:26 -0500 | [diff] [blame] | 1114 | pci_write_config_dword(pdev, PCI_ROM_ADDRESS, |
| 1115 | pci_resource_start(pdev, 8)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | |
| 1117 | dp6m_ptr = ha->brd; |
| 1118 | |
| 1119 | /* Ensure that it is safe to access the non HW portions of DPMEM. |
| 1120 | * Aditional check needed for Xscale based RAID controllers */ |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1121 | while( ((int)readb(&dp6m_ptr->i960r.sema0_reg) ) & 3 ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | gdth_delay(1); |
| 1123 | |
| 1124 | /* check and reset interface area */ |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1125 | writel(DPMEM_MAGIC, &dp6m_ptr->u); |
| 1126 | if (readl(&dp6m_ptr->u) != DPMEM_MAGIC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n", |
| 1128 | pcistr->dpmem); |
| 1129 | found = FALSE; |
| 1130 | for (i = 0xC8000; i < 0xE8000; i += 0x4000) { |
| 1131 | iounmap(ha->brd); |
| 1132 | ha->brd = ioremap(i, sizeof(ushort)); |
| 1133 | if (ha->brd == NULL) { |
| 1134 | printk("GDT-PCI: Initialization error (DPMEM remap error)\n"); |
| 1135 | return 0; |
| 1136 | } |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1137 | if (readw(ha->brd) != 0xffff) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | TRACE2(("init_pci_mpr() address 0x%x busy\n", i)); |
| 1139 | continue; |
| 1140 | } |
| 1141 | iounmap(ha->brd); |
Jeff Garzik | 4c9c8d7 | 2008-02-15 21:35:26 -0500 | [diff] [blame] | 1142 | pci_write_config_dword(pdev, PCI_BASE_ADDRESS_0, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | ha->brd = ioremap(i, sizeof(gdt6m_dpram_str)); |
| 1144 | if (ha->brd == NULL) { |
| 1145 | printk("GDT-PCI: Initialization error (DPMEM remap error)\n"); |
| 1146 | return 0; |
| 1147 | } |
| 1148 | dp6m_ptr = ha->brd; |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1149 | writel(DPMEM_MAGIC, &dp6m_ptr->u); |
| 1150 | if (readl(&dp6m_ptr->u) == DPMEM_MAGIC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | printk("GDT-PCI: Use free address at 0x%x\n", i); |
| 1152 | found = TRUE; |
| 1153 | break; |
| 1154 | } |
| 1155 | } |
| 1156 | if (!found) { |
| 1157 | printk("GDT-PCI: No free address found!\n"); |
| 1158 | iounmap(ha->brd); |
| 1159 | return 0; |
| 1160 | } |
| 1161 | } |
| 1162 | memset_io(&dp6m_ptr->u, 0, sizeof(dp6m_ptr->u)); |
| 1163 | |
| 1164 | /* disable board interrupts, deinit services */ |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1165 | writeb(readb(&dp6m_ptr->i960r.edoor_en_reg) | 4, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | &dp6m_ptr->i960r.edoor_en_reg); |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1167 | writeb(0xff, &dp6m_ptr->i960r.edoor_reg); |
| 1168 | writeb(0x00, &dp6m_ptr->u.ic.S_Status); |
| 1169 | writeb(0x00, &dp6m_ptr->u.ic.Cmd_Index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1171 | writel(pcistr->dpmem, &dp6m_ptr->u.ic.S_Info[0]); |
| 1172 | writeb(0xff, &dp6m_ptr->u.ic.S_Cmd_Indx); |
| 1173 | writeb(1, &dp6m_ptr->i960r.ldoor_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | retries = INIT_RETRIES; |
| 1175 | gdth_delay(20); |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1176 | while (readb(&dp6m_ptr->u.ic.S_Status) != 0xff) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | if (--retries == 0) { |
| 1178 | printk("GDT-PCI: Initialization error (DEINIT failed)\n"); |
| 1179 | iounmap(ha->brd); |
| 1180 | return 0; |
| 1181 | } |
| 1182 | gdth_delay(1); |
| 1183 | } |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1184 | prot_ver = (unchar)readl(&dp6m_ptr->u.ic.S_Info[0]); |
| 1185 | writeb(0, &dp6m_ptr->u.ic.S_Status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | if (prot_ver != PROTOCOL_VERSION) { |
| 1187 | printk("GDT-PCI: Illegal protocol version\n"); |
| 1188 | iounmap(ha->brd); |
| 1189 | return 0; |
| 1190 | } |
| 1191 | |
| 1192 | ha->type = GDT_PCIMPR; |
| 1193 | ha->ic_all_size = sizeof(dp6m_ptr->u); |
| 1194 | |
| 1195 | /* special command to controller BIOS */ |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1196 | writel(0x00, &dp6m_ptr->u.ic.S_Info[0]); |
| 1197 | writel(0x00, &dp6m_ptr->u.ic.S_Info[1]); |
| 1198 | writel(0x00, &dp6m_ptr->u.ic.S_Info[2]); |
| 1199 | writel(0x00, &dp6m_ptr->u.ic.S_Info[3]); |
| 1200 | writeb(0xfe, &dp6m_ptr->u.ic.S_Cmd_Indx); |
| 1201 | writeb(1, &dp6m_ptr->i960r.ldoor_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | retries = INIT_RETRIES; |
| 1203 | gdth_delay(20); |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1204 | while (readb(&dp6m_ptr->u.ic.S_Status) != 0xfe) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | if (--retries == 0) { |
| 1206 | printk("GDT-PCI: Initialization error\n"); |
| 1207 | iounmap(ha->brd); |
| 1208 | return 0; |
| 1209 | } |
| 1210 | gdth_delay(1); |
| 1211 | } |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1212 | writeb(0, &dp6m_ptr->u.ic.S_Status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | |
| 1214 | /* read FW version to detect 64-bit DMA support */ |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1215 | writeb(0xfd, &dp6m_ptr->u.ic.S_Cmd_Indx); |
| 1216 | writeb(1, &dp6m_ptr->i960r.ldoor_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | retries = INIT_RETRIES; |
| 1218 | gdth_delay(20); |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1219 | while (readb(&dp6m_ptr->u.ic.S_Status) != 0xfd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | if (--retries == 0) { |
| 1221 | printk("GDT-PCI: Initialization error (DEINIT failed)\n"); |
| 1222 | iounmap(ha->brd); |
| 1223 | return 0; |
| 1224 | } |
| 1225 | gdth_delay(1); |
| 1226 | } |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1227 | prot_ver = (unchar)(readl(&dp6m_ptr->u.ic.S_Info[0]) >> 16); |
| 1228 | writeb(0, &dp6m_ptr->u.ic.S_Status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | if (prot_ver < 0x2b) /* FW < x.43: no 64-bit DMA support */ |
| 1230 | ha->dma64_support = 0; |
| 1231 | else |
| 1232 | ha->dma64_support = 1; |
| 1233 | } |
| 1234 | |
| 1235 | return 1; |
| 1236 | } |
Christoph Hellwig | 8514ef2 | 2007-10-02 22:51:06 +0200 | [diff] [blame] | 1237 | #endif /* CONFIG_PCI */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | |
| 1239 | /* controller protocol functions */ |
| 1240 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1241 | static void __init gdth_enable_int(gdth_ha_str *ha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | ulong flags; |
| 1244 | gdt2_dpram_str __iomem *dp2_ptr; |
| 1245 | gdt6_dpram_str __iomem *dp6_ptr; |
| 1246 | gdt6m_dpram_str __iomem *dp6m_ptr; |
| 1247 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1248 | TRACE(("gdth_enable_int() hanum %d\n",ha->hanum)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | spin_lock_irqsave(&ha->smp_lock, flags); |
| 1250 | |
| 1251 | if (ha->type == GDT_EISA) { |
| 1252 | outb(0xff, ha->bmic + EDOORREG); |
| 1253 | outb(0xff, ha->bmic + EDENABREG); |
| 1254 | outb(0x01, ha->bmic + EINTENABREG); |
| 1255 | } else if (ha->type == GDT_ISA) { |
| 1256 | dp2_ptr = ha->brd; |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1257 | writeb(1, &dp2_ptr->io.irqdel); |
| 1258 | writeb(0, &dp2_ptr->u.ic.Cmd_Index); |
| 1259 | writeb(1, &dp2_ptr->io.irqen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | } else if (ha->type == GDT_PCI) { |
| 1261 | dp6_ptr = ha->brd; |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1262 | writeb(1, &dp6_ptr->io.irqdel); |
| 1263 | writeb(0, &dp6_ptr->u.ic.Cmd_Index); |
| 1264 | writeb(1, &dp6_ptr->io.irqen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | } else if (ha->type == GDT_PCINEW) { |
| 1266 | outb(0xff, PTR2USHORT(&ha->plx->edoor_reg)); |
| 1267 | outb(0x03, PTR2USHORT(&ha->plx->control1)); |
| 1268 | } else if (ha->type == GDT_PCIMPR) { |
| 1269 | dp6m_ptr = ha->brd; |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1270 | writeb(0xff, &dp6m_ptr->i960r.edoor_reg); |
| 1271 | writeb(readb(&dp6m_ptr->i960r.edoor_en_reg) & ~4, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | &dp6m_ptr->i960r.edoor_en_reg); |
| 1273 | } |
| 1274 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
| 1275 | } |
| 1276 | |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 1277 | /* return IStatus if interrupt was from this card else 0 */ |
Jeff Garzik | 230e886 | 2007-12-13 16:14:12 -0800 | [diff] [blame] | 1278 | static unchar gdth_get_status(gdth_ha_str *ha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | { |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 1280 | unchar IStatus = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | |
Jeff Garzik | 230e886 | 2007-12-13 16:14:12 -0800 | [diff] [blame] | 1282 | TRACE(("gdth_get_status() irq %d ctr_count %d\n", ha->irq, gdth_ctr_count)); |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 1283 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | if (ha->type == GDT_EISA) |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 1285 | IStatus = inb((ushort)ha->bmic + EDOORREG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | else if (ha->type == GDT_ISA) |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 1287 | IStatus = |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1288 | readb(&((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Cmd_Index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | else if (ha->type == GDT_PCI) |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 1290 | IStatus = |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1291 | readb(&((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Cmd_Index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | else if (ha->type == GDT_PCINEW) |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 1293 | IStatus = inb(PTR2USHORT(&ha->plx->edoor_reg)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | else if (ha->type == GDT_PCIMPR) |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 1295 | IStatus = |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1296 | readb(&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.edoor_reg); |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 1297 | |
| 1298 | return IStatus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | } |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 1300 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1301 | static int gdth_test_busy(gdth_ha_str *ha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | register int gdtsema0 = 0; |
| 1304 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1305 | TRACE(("gdth_test_busy() hanum %d\n", ha->hanum)); |
| 1306 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | if (ha->type == GDT_EISA) |
| 1308 | gdtsema0 = (int)inb(ha->bmic + SEMA0REG); |
| 1309 | else if (ha->type == GDT_ISA) |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1310 | gdtsema0 = (int)readb(&((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Sema0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | else if (ha->type == GDT_PCI) |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1312 | gdtsema0 = (int)readb(&((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Sema0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | else if (ha->type == GDT_PCINEW) |
| 1314 | gdtsema0 = (int)inb(PTR2USHORT(&ha->plx->sema0_reg)); |
| 1315 | else if (ha->type == GDT_PCIMPR) |
| 1316 | gdtsema0 = |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1317 | (int)readb(&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.sema0_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | |
| 1319 | return (gdtsema0 & 1); |
| 1320 | } |
| 1321 | |
| 1322 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1323 | static int gdth_get_cmd_index(gdth_ha_str *ha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | int i; |
| 1326 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1327 | TRACE(("gdth_get_cmd_index() hanum %d\n", ha->hanum)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | for (i=0; i<GDTH_MAXCMDS; ++i) { |
| 1330 | if (ha->cmd_tab[i].cmnd == UNUSED_CMND) { |
| 1331 | ha->cmd_tab[i].cmnd = ha->pccb->RequestBuffer; |
| 1332 | ha->cmd_tab[i].service = ha->pccb->Service; |
| 1333 | ha->pccb->CommandIndex = (ulong32)i+2; |
| 1334 | return (i+2); |
| 1335 | } |
| 1336 | } |
| 1337 | return 0; |
| 1338 | } |
| 1339 | |
| 1340 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1341 | static void gdth_set_sema0(gdth_ha_str *ha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1343 | TRACE(("gdth_set_sema0() hanum %d\n", ha->hanum)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | if (ha->type == GDT_EISA) { |
| 1346 | outb(1, ha->bmic + SEMA0REG); |
| 1347 | } else if (ha->type == GDT_ISA) { |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1348 | writeb(1, &((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Sema0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | } else if (ha->type == GDT_PCI) { |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1350 | writeb(1, &((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Sema0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | } else if (ha->type == GDT_PCINEW) { |
| 1352 | outb(1, PTR2USHORT(&ha->plx->sema0_reg)); |
| 1353 | } else if (ha->type == GDT_PCIMPR) { |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1354 | writeb(1, &((gdt6m_dpram_str __iomem *)ha->brd)->i960r.sema0_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | } |
| 1356 | } |
| 1357 | |
| 1358 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1359 | static void gdth_copy_command(gdth_ha_str *ha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | register gdth_cmd_str *cmd_ptr; |
| 1362 | register gdt6m_dpram_str __iomem *dp6m_ptr; |
| 1363 | register gdt6c_dpram_str __iomem *dp6c_ptr; |
| 1364 | gdt6_dpram_str __iomem *dp6_ptr; |
| 1365 | gdt2_dpram_str __iomem *dp2_ptr; |
| 1366 | ushort cp_count,dp_offset,cmd_no; |
| 1367 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1368 | TRACE(("gdth_copy_command() hanum %d\n", ha->hanum)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | cp_count = ha->cmd_len; |
| 1371 | dp_offset= ha->cmd_offs_dpmem; |
| 1372 | cmd_no = ha->cmd_cnt; |
| 1373 | cmd_ptr = ha->pccb; |
| 1374 | |
| 1375 | ++ha->cmd_cnt; |
| 1376 | if (ha->type == GDT_EISA) |
| 1377 | return; /* no DPMEM, no copy */ |
| 1378 | |
| 1379 | /* set cpcount dword aligned */ |
| 1380 | if (cp_count & 3) |
| 1381 | cp_count += (4 - (cp_count & 3)); |
| 1382 | |
| 1383 | ha->cmd_offs_dpmem += cp_count; |
| 1384 | |
| 1385 | /* set offset and service, copy command to DPMEM */ |
| 1386 | if (ha->type == GDT_ISA) { |
| 1387 | dp2_ptr = ha->brd; |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1388 | writew(dp_offset + DPMEM_COMMAND_OFFSET, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | &dp2_ptr->u.ic.comm_queue[cmd_no].offset); |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1390 | writew((ushort)cmd_ptr->Service, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | &dp2_ptr->u.ic.comm_queue[cmd_no].serv_id); |
| 1392 | memcpy_toio(&dp2_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count); |
| 1393 | } else if (ha->type == GDT_PCI) { |
| 1394 | dp6_ptr = ha->brd; |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1395 | writew(dp_offset + DPMEM_COMMAND_OFFSET, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | &dp6_ptr->u.ic.comm_queue[cmd_no].offset); |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1397 | writew((ushort)cmd_ptr->Service, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | &dp6_ptr->u.ic.comm_queue[cmd_no].serv_id); |
| 1399 | memcpy_toio(&dp6_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count); |
| 1400 | } else if (ha->type == GDT_PCINEW) { |
| 1401 | dp6c_ptr = ha->brd; |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1402 | writew(dp_offset + DPMEM_COMMAND_OFFSET, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | &dp6c_ptr->u.ic.comm_queue[cmd_no].offset); |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1404 | writew((ushort)cmd_ptr->Service, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | &dp6c_ptr->u.ic.comm_queue[cmd_no].serv_id); |
| 1406 | memcpy_toio(&dp6c_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count); |
| 1407 | } else if (ha->type == GDT_PCIMPR) { |
| 1408 | dp6m_ptr = ha->brd; |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1409 | writew(dp_offset + DPMEM_COMMAND_OFFSET, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | &dp6m_ptr->u.ic.comm_queue[cmd_no].offset); |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1411 | writew((ushort)cmd_ptr->Service, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | &dp6m_ptr->u.ic.comm_queue[cmd_no].serv_id); |
| 1413 | memcpy_toio(&dp6m_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count); |
| 1414 | } |
| 1415 | } |
| 1416 | |
| 1417 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1418 | static void gdth_release_event(gdth_ha_str *ha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1420 | TRACE(("gdth_release_event() hanum %d\n", ha->hanum)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | |
| 1422 | #ifdef GDTH_STATISTICS |
| 1423 | { |
| 1424 | ulong32 i,j; |
| 1425 | for (i=0,j=0; j<GDTH_MAXCMDS; ++j) { |
| 1426 | if (ha->cmd_tab[j].cmnd != UNUSED_CMND) |
| 1427 | ++i; |
| 1428 | } |
| 1429 | if (max_index < i) { |
| 1430 | max_index = i; |
| 1431 | TRACE3(("GDT: max_index = %d\n",(ushort)i)); |
| 1432 | } |
| 1433 | } |
| 1434 | #endif |
| 1435 | |
| 1436 | if (ha->pccb->OpCode == GDT_INIT) |
| 1437 | ha->pccb->Service |= 0x80; |
| 1438 | |
| 1439 | if (ha->type == GDT_EISA) { |
| 1440 | if (ha->pccb->OpCode == GDT_INIT) /* store DMA buffer */ |
| 1441 | outl(ha->ccb_phys, ha->bmic + MAILBOXREG); |
| 1442 | outb(ha->pccb->Service, ha->bmic + LDOORREG); |
| 1443 | } else if (ha->type == GDT_ISA) { |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1444 | writeb(0, &((gdt2_dpram_str __iomem *)ha->brd)->io.event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | } else if (ha->type == GDT_PCI) { |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1446 | writeb(0, &((gdt6_dpram_str __iomem *)ha->brd)->io.event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | } else if (ha->type == GDT_PCINEW) { |
| 1448 | outb(1, PTR2USHORT(&ha->plx->ldoor_reg)); |
| 1449 | } else if (ha->type == GDT_PCIMPR) { |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 1450 | writeb(1, &((gdt6m_dpram_str __iomem *)ha->brd)->i960r.ldoor_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | } |
| 1452 | } |
| 1453 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1454 | static int gdth_wait(gdth_ha_str *ha, int index, ulong32 time) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | int answer_found = FALSE; |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 1457 | int wait_index = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1459 | TRACE(("gdth_wait() hanum %d index %d time %d\n", ha->hanum, index, time)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | if (index == 0) |
| 1462 | return 1; /* no wait required */ |
| 1463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | do { |
Jeff Garzik | 230e886 | 2007-12-13 16:14:12 -0800 | [diff] [blame] | 1465 | __gdth_interrupt(ha, true, &wait_index); |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 1466 | if (wait_index == index) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | answer_found = TRUE; |
| 1468 | break; |
| 1469 | } |
| 1470 | gdth_delay(1); |
| 1471 | } while (--time); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1472 | |
| 1473 | while (gdth_test_busy(ha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | gdth_delay(0); |
| 1475 | |
| 1476 | return (answer_found); |
| 1477 | } |
| 1478 | |
| 1479 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1480 | static int gdth_internal_cmd(gdth_ha_str *ha, unchar service, ushort opcode, |
| 1481 | ulong32 p1, ulong64 p2, ulong64 p3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | register gdth_cmd_str *cmd_ptr; |
| 1484 | int retries,index; |
| 1485 | |
| 1486 | TRACE2(("gdth_internal_cmd() service %d opcode %d\n",service,opcode)); |
| 1487 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | cmd_ptr = ha->pccb; |
| 1489 | memset((char*)cmd_ptr,0,sizeof(gdth_cmd_str)); |
| 1490 | |
| 1491 | /* make command */ |
| 1492 | for (retries = INIT_RETRIES;;) { |
| 1493 | cmd_ptr->Service = service; |
| 1494 | cmd_ptr->RequestBuffer = INTERNAL_CMND; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1495 | if (!(index=gdth_get_cmd_index(ha))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | TRACE(("GDT: No free command index found\n")); |
| 1497 | return 0; |
| 1498 | } |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1499 | gdth_set_sema0(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | cmd_ptr->OpCode = opcode; |
| 1501 | cmd_ptr->BoardNode = LOCALBOARD; |
| 1502 | if (service == CACHESERVICE) { |
| 1503 | if (opcode == GDT_IOCTL) { |
| 1504 | cmd_ptr->u.ioctl.subfunc = p1; |
| 1505 | cmd_ptr->u.ioctl.channel = (ulong32)p2; |
| 1506 | cmd_ptr->u.ioctl.param_size = (ushort)p3; |
| 1507 | cmd_ptr->u.ioctl.p_param = ha->scratch_phys; |
| 1508 | } else { |
| 1509 | if (ha->cache_feat & GDT_64BIT) { |
| 1510 | cmd_ptr->u.cache64.DeviceNo = (ushort)p1; |
| 1511 | cmd_ptr->u.cache64.BlockNo = p2; |
| 1512 | } else { |
| 1513 | cmd_ptr->u.cache.DeviceNo = (ushort)p1; |
| 1514 | cmd_ptr->u.cache.BlockNo = (ulong32)p2; |
| 1515 | } |
| 1516 | } |
| 1517 | } else if (service == SCSIRAWSERVICE) { |
| 1518 | if (ha->raw_feat & GDT_64BIT) { |
| 1519 | cmd_ptr->u.raw64.direction = p1; |
| 1520 | cmd_ptr->u.raw64.bus = (unchar)p2; |
| 1521 | cmd_ptr->u.raw64.target = (unchar)p3; |
| 1522 | cmd_ptr->u.raw64.lun = (unchar)(p3 >> 8); |
| 1523 | } else { |
| 1524 | cmd_ptr->u.raw.direction = p1; |
| 1525 | cmd_ptr->u.raw.bus = (unchar)p2; |
| 1526 | cmd_ptr->u.raw.target = (unchar)p3; |
| 1527 | cmd_ptr->u.raw.lun = (unchar)(p3 >> 8); |
| 1528 | } |
| 1529 | } else if (service == SCREENSERVICE) { |
| 1530 | if (opcode == GDT_REALTIME) { |
| 1531 | *(ulong32 *)&cmd_ptr->u.screen.su.data[0] = p1; |
| 1532 | *(ulong32 *)&cmd_ptr->u.screen.su.data[4] = (ulong32)p2; |
| 1533 | *(ulong32 *)&cmd_ptr->u.screen.su.data[8] = (ulong32)p3; |
| 1534 | } |
| 1535 | } |
| 1536 | ha->cmd_len = sizeof(gdth_cmd_str); |
| 1537 | ha->cmd_offs_dpmem = 0; |
| 1538 | ha->cmd_cnt = 0; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1539 | gdth_copy_command(ha); |
| 1540 | gdth_release_event(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | gdth_delay(20); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1542 | if (!gdth_wait(ha, index, INIT_TIMEOUT)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | printk("GDT: Initialization error (timeout service %d)\n",service); |
| 1544 | return 0; |
| 1545 | } |
| 1546 | if (ha->status != S_BSY || --retries == 0) |
| 1547 | break; |
| 1548 | gdth_delay(1); |
| 1549 | } |
| 1550 | |
| 1551 | return (ha->status != S_OK ? 0:1); |
| 1552 | } |
| 1553 | |
| 1554 | |
| 1555 | /* search for devices */ |
| 1556 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1557 | static int __init gdth_search_drives(gdth_ha_str *ha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1559 | ushort cdev_cnt, i; |
| 1560 | int ok; |
| 1561 | ulong32 bus_no, drv_cnt, drv_no, j; |
| 1562 | gdth_getch_str *chn; |
| 1563 | gdth_drlist_str *drl; |
| 1564 | gdth_iochan_str *ioc; |
| 1565 | gdth_raw_iochan_str *iocr; |
| 1566 | gdth_arcdl_str *alst; |
| 1567 | gdth_alist_str *alst2; |
| 1568 | gdth_oem_str_ioctl *oemstr; |
| 1569 | #ifdef INT_COAL |
| 1570 | gdth_perf_modes *pmod; |
| 1571 | #endif |
| 1572 | |
| 1573 | #ifdef GDTH_RTC |
| 1574 | unchar rtc[12]; |
| 1575 | ulong flags; |
| 1576 | #endif |
| 1577 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1578 | TRACE(("gdth_search_drives() hanum %d\n", ha->hanum)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | ok = 0; |
| 1580 | |
| 1581 | /* initialize controller services, at first: screen service */ |
| 1582 | ha->screen_feat = 0; |
| 1583 | if (!force_dma32) { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1584 | ok = gdth_internal_cmd(ha, SCREENSERVICE, GDT_X_INIT_SCR, 0, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | if (ok) |
| 1586 | ha->screen_feat = GDT_64BIT; |
| 1587 | } |
| 1588 | if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC)) |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1589 | ok = gdth_internal_cmd(ha, SCREENSERVICE, GDT_INIT, 0, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | if (!ok) { |
| 1591 | printk("GDT-HA %d: Initialization error screen service (code %d)\n", |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1592 | ha->hanum, ha->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | return 0; |
| 1594 | } |
| 1595 | TRACE2(("gdth_search_drives(): SCREENSERVICE initialized\n")); |
| 1596 | |
| 1597 | #ifdef GDTH_RTC |
| 1598 | /* read realtime clock info, send to controller */ |
| 1599 | /* 1. wait for the falling edge of update flag */ |
| 1600 | spin_lock_irqsave(&rtc_lock, flags); |
| 1601 | for (j = 0; j < 1000000; ++j) |
| 1602 | if (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) |
| 1603 | break; |
| 1604 | for (j = 0; j < 1000000; ++j) |
| 1605 | if (!(CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP)) |
| 1606 | break; |
| 1607 | /* 2. read info */ |
| 1608 | do { |
| 1609 | for (j = 0; j < 12; ++j) |
| 1610 | rtc[j] = CMOS_READ(j); |
| 1611 | } while (rtc[0] != CMOS_READ(0)); |
Robert P. J. Day | 7a960b7 | 2007-05-23 14:41:40 -0700 | [diff] [blame] | 1612 | spin_unlock_irqrestore(&rtc_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | TRACE2(("gdth_search_drives(): RTC: %x/%x/%x\n",*(ulong32 *)&rtc[0], |
| 1614 | *(ulong32 *)&rtc[4], *(ulong32 *)&rtc[8])); |
| 1615 | /* 3. send to controller firmware */ |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1616 | gdth_internal_cmd(ha, SCREENSERVICE, GDT_REALTIME, *(ulong32 *)&rtc[0], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | *(ulong32 *)&rtc[4], *(ulong32 *)&rtc[8]); |
| 1618 | #endif |
| 1619 | |
| 1620 | /* unfreeze all IOs */ |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1621 | gdth_internal_cmd(ha, CACHESERVICE, GDT_UNFREEZE_IO, 0, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | |
| 1623 | /* initialize cache service */ |
| 1624 | ha->cache_feat = 0; |
| 1625 | if (!force_dma32) { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1626 | ok = gdth_internal_cmd(ha, CACHESERVICE, GDT_X_INIT_HOST, LINUX_OS, |
| 1627 | 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | if (ok) |
| 1629 | ha->cache_feat = GDT_64BIT; |
| 1630 | } |
| 1631 | if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC)) |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1632 | ok = gdth_internal_cmd(ha, CACHESERVICE, GDT_INIT, LINUX_OS, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | if (!ok) { |
| 1634 | printk("GDT-HA %d: Initialization error cache service (code %d)\n", |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1635 | ha->hanum, ha->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | return 0; |
| 1637 | } |
| 1638 | TRACE2(("gdth_search_drives(): CACHESERVICE initialized\n")); |
| 1639 | cdev_cnt = (ushort)ha->info; |
| 1640 | ha->fw_vers = ha->service; |
| 1641 | |
| 1642 | #ifdef INT_COAL |
| 1643 | if (ha->type == GDT_PCIMPR) { |
| 1644 | /* set perf. modes */ |
| 1645 | pmod = (gdth_perf_modes *)ha->pscratch; |
| 1646 | pmod->version = 1; |
| 1647 | pmod->st_mode = 1; /* enable one status buffer */ |
| 1648 | *((ulong64 *)&pmod->st_buff_addr1) = ha->coal_stat_phys; |
| 1649 | pmod->st_buff_indx1 = COALINDEX; |
| 1650 | pmod->st_buff_addr2 = 0; |
| 1651 | pmod->st_buff_u_addr2 = 0; |
| 1652 | pmod->st_buff_indx2 = 0; |
| 1653 | pmod->st_buff_size = sizeof(gdth_coal_status) * MAXOFFSETS; |
| 1654 | pmod->cmd_mode = 0; // disable all cmd buffers |
| 1655 | pmod->cmd_buff_addr1 = 0; |
| 1656 | pmod->cmd_buff_u_addr1 = 0; |
| 1657 | pmod->cmd_buff_indx1 = 0; |
| 1658 | pmod->cmd_buff_addr2 = 0; |
| 1659 | pmod->cmd_buff_u_addr2 = 0; |
| 1660 | pmod->cmd_buff_indx2 = 0; |
| 1661 | pmod->cmd_buff_size = 0; |
| 1662 | pmod->reserved1 = 0; |
| 1663 | pmod->reserved2 = 0; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1664 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, SET_PERF_MODES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | INVALID_CHANNEL,sizeof(gdth_perf_modes))) { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1666 | printk("GDT-HA %d: Interrupt coalescing activated\n", ha->hanum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1667 | } |
| 1668 | } |
| 1669 | #endif |
| 1670 | |
| 1671 | /* detect number of buses - try new IOCTL */ |
| 1672 | iocr = (gdth_raw_iochan_str *)ha->pscratch; |
| 1673 | iocr->hdr.version = 0xffffffff; |
| 1674 | iocr->hdr.list_entries = MAXBUS; |
| 1675 | iocr->hdr.first_chan = 0; |
| 1676 | iocr->hdr.last_chan = MAXBUS-1; |
| 1677 | iocr->hdr.list_offset = GDTOFFSOF(gdth_raw_iochan_str, list[0]); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1678 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, IOCHAN_RAW_DESC, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | INVALID_CHANNEL,sizeof(gdth_raw_iochan_str))) { |
| 1680 | TRACE2(("IOCHAN_RAW_DESC supported!\n")); |
| 1681 | ha->bus_cnt = iocr->hdr.chan_count; |
| 1682 | for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) { |
| 1683 | if (iocr->list[bus_no].proc_id < MAXID) |
| 1684 | ha->bus_id[bus_no] = iocr->list[bus_no].proc_id; |
| 1685 | else |
| 1686 | ha->bus_id[bus_no] = 0xff; |
| 1687 | } |
| 1688 | } else { |
| 1689 | /* old method */ |
| 1690 | chn = (gdth_getch_str *)ha->pscratch; |
| 1691 | for (bus_no = 0; bus_no < MAXBUS; ++bus_no) { |
| 1692 | chn->channel_no = bus_no; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1693 | if (!gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | SCSI_CHAN_CNT | L_CTRL_PATTERN, |
| 1695 | IO_CHANNEL | INVALID_CHANNEL, |
| 1696 | sizeof(gdth_getch_str))) { |
| 1697 | if (bus_no == 0) { |
| 1698 | printk("GDT-HA %d: Error detecting channel count (0x%x)\n", |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1699 | ha->hanum, ha->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | return 0; |
| 1701 | } |
| 1702 | break; |
| 1703 | } |
| 1704 | if (chn->siop_id < MAXID) |
| 1705 | ha->bus_id[bus_no] = chn->siop_id; |
| 1706 | else |
| 1707 | ha->bus_id[bus_no] = 0xff; |
| 1708 | } |
| 1709 | ha->bus_cnt = (unchar)bus_no; |
| 1710 | } |
| 1711 | TRACE2(("gdth_search_drives() %d channels\n",ha->bus_cnt)); |
| 1712 | |
| 1713 | /* read cache configuration */ |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1714 | if (!gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, CACHE_INFO, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | INVALID_CHANNEL,sizeof(gdth_cinfo_str))) { |
| 1716 | printk("GDT-HA %d: Initialization error cache service (code %d)\n", |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1717 | ha->hanum, ha->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | return 0; |
| 1719 | } |
| 1720 | ha->cpar = ((gdth_cinfo_str *)ha->pscratch)->cpar; |
| 1721 | TRACE2(("gdth_search_drives() cinfo: vs %x sta %d str %d dw %d b %d\n", |
| 1722 | ha->cpar.version,ha->cpar.state,ha->cpar.strategy, |
| 1723 | ha->cpar.write_back,ha->cpar.block_size)); |
| 1724 | |
| 1725 | /* read board info and features */ |
| 1726 | ha->more_proc = FALSE; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1727 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, BOARD_INFO, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | INVALID_CHANNEL,sizeof(gdth_binfo_str))) { |
| 1729 | memcpy(&ha->binfo, (gdth_binfo_str *)ha->pscratch, |
| 1730 | sizeof(gdth_binfo_str)); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1731 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, BOARD_FEATURES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | INVALID_CHANNEL,sizeof(gdth_bfeat_str))) { |
| 1733 | TRACE2(("BOARD_INFO/BOARD_FEATURES supported\n")); |
| 1734 | ha->bfeat = *(gdth_bfeat_str *)ha->pscratch; |
| 1735 | ha->more_proc = TRUE; |
| 1736 | } |
| 1737 | } else { |
| 1738 | TRACE2(("BOARD_INFO requires firmware >= 1.10/2.08\n")); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1739 | strcpy(ha->binfo.type_string, gdth_ctr_name(ha)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 | } |
| 1741 | TRACE2(("Controller name: %s\n",ha->binfo.type_string)); |
| 1742 | |
| 1743 | /* read more informations */ |
| 1744 | if (ha->more_proc) { |
| 1745 | /* physical drives, channel addresses */ |
| 1746 | ioc = (gdth_iochan_str *)ha->pscratch; |
| 1747 | ioc->hdr.version = 0xffffffff; |
| 1748 | ioc->hdr.list_entries = MAXBUS; |
| 1749 | ioc->hdr.first_chan = 0; |
| 1750 | ioc->hdr.last_chan = MAXBUS-1; |
| 1751 | ioc->hdr.list_offset = GDTOFFSOF(gdth_iochan_str, list[0]); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1752 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, IOCHAN_DESC, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | INVALID_CHANNEL,sizeof(gdth_iochan_str))) { |
| 1754 | for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) { |
| 1755 | ha->raw[bus_no].address = ioc->list[bus_no].address; |
| 1756 | ha->raw[bus_no].local_no = ioc->list[bus_no].local_no; |
| 1757 | } |
| 1758 | } else { |
| 1759 | for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) { |
| 1760 | ha->raw[bus_no].address = IO_CHANNEL; |
| 1761 | ha->raw[bus_no].local_no = bus_no; |
| 1762 | } |
| 1763 | } |
| 1764 | for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) { |
| 1765 | chn = (gdth_getch_str *)ha->pscratch; |
| 1766 | chn->channel_no = ha->raw[bus_no].local_no; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1767 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 | SCSI_CHAN_CNT | L_CTRL_PATTERN, |
| 1769 | ha->raw[bus_no].address | INVALID_CHANNEL, |
| 1770 | sizeof(gdth_getch_str))) { |
| 1771 | ha->raw[bus_no].pdev_cnt = chn->drive_cnt; |
| 1772 | TRACE2(("Channel %d: %d phys. drives\n", |
| 1773 | bus_no,chn->drive_cnt)); |
| 1774 | } |
| 1775 | if (ha->raw[bus_no].pdev_cnt > 0) { |
| 1776 | drl = (gdth_drlist_str *)ha->pscratch; |
| 1777 | drl->sc_no = ha->raw[bus_no].local_no; |
| 1778 | drl->sc_cnt = ha->raw[bus_no].pdev_cnt; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1779 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | SCSI_DR_LIST | L_CTRL_PATTERN, |
| 1781 | ha->raw[bus_no].address | INVALID_CHANNEL, |
| 1782 | sizeof(gdth_drlist_str))) { |
| 1783 | for (j = 0; j < ha->raw[bus_no].pdev_cnt; ++j) |
| 1784 | ha->raw[bus_no].id_list[j] = drl->sc_list[j]; |
| 1785 | } else { |
| 1786 | ha->raw[bus_no].pdev_cnt = 0; |
| 1787 | } |
| 1788 | } |
| 1789 | } |
| 1790 | |
| 1791 | /* logical drives */ |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1792 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, CACHE_DRV_CNT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | INVALID_CHANNEL,sizeof(ulong32))) { |
| 1794 | drv_cnt = *(ulong32 *)ha->pscratch; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1795 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, CACHE_DRV_LIST, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1796 | INVALID_CHANNEL,drv_cnt * sizeof(ulong32))) { |
| 1797 | for (j = 0; j < drv_cnt; ++j) { |
| 1798 | drv_no = ((ulong32 *)ha->pscratch)[j]; |
| 1799 | if (drv_no < MAX_LDRIVES) { |
| 1800 | ha->hdr[drv_no].is_logdrv = TRUE; |
| 1801 | TRACE2(("Drive %d is log. drive\n",drv_no)); |
| 1802 | } |
| 1803 | } |
| 1804 | } |
| 1805 | alst = (gdth_arcdl_str *)ha->pscratch; |
| 1806 | alst->entries_avail = MAX_LDRIVES; |
| 1807 | alst->first_entry = 0; |
| 1808 | alst->list_offset = GDTOFFSOF(gdth_arcdl_str, list[0]); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1809 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | ARRAY_DRV_LIST2 | LA_CTRL_PATTERN, |
| 1811 | INVALID_CHANNEL, sizeof(gdth_arcdl_str) + |
| 1812 | (alst->entries_avail-1) * sizeof(gdth_alist_str))) { |
| 1813 | for (j = 0; j < alst->entries_init; ++j) { |
| 1814 | ha->hdr[j].is_arraydrv = alst->list[j].is_arrayd; |
| 1815 | ha->hdr[j].is_master = alst->list[j].is_master; |
| 1816 | ha->hdr[j].is_parity = alst->list[j].is_parity; |
| 1817 | ha->hdr[j].is_hotfix = alst->list[j].is_hotfix; |
| 1818 | ha->hdr[j].master_no = alst->list[j].cd_handle; |
| 1819 | } |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1820 | } else if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | ARRAY_DRV_LIST | LA_CTRL_PATTERN, |
| 1822 | 0, 35 * sizeof(gdth_alist_str))) { |
| 1823 | for (j = 0; j < 35; ++j) { |
| 1824 | alst2 = &((gdth_alist_str *)ha->pscratch)[j]; |
| 1825 | ha->hdr[j].is_arraydrv = alst2->is_arrayd; |
| 1826 | ha->hdr[j].is_master = alst2->is_master; |
| 1827 | ha->hdr[j].is_parity = alst2->is_parity; |
| 1828 | ha->hdr[j].is_hotfix = alst2->is_hotfix; |
| 1829 | ha->hdr[j].master_no = alst2->cd_handle; |
| 1830 | } |
| 1831 | } |
| 1832 | } |
| 1833 | } |
| 1834 | |
| 1835 | /* initialize raw service */ |
| 1836 | ha->raw_feat = 0; |
| 1837 | if (!force_dma32) { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1838 | ok = gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_X_INIT_RAW, 0, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1839 | if (ok) |
| 1840 | ha->raw_feat = GDT_64BIT; |
| 1841 | } |
| 1842 | if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC)) |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1843 | ok = gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_INIT, 0, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | if (!ok) { |
| 1845 | printk("GDT-HA %d: Initialization error raw service (code %d)\n", |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1846 | ha->hanum, ha->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | return 0; |
| 1848 | } |
| 1849 | TRACE2(("gdth_search_drives(): RAWSERVICE initialized\n")); |
| 1850 | |
| 1851 | /* set/get features raw service (scatter/gather) */ |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1852 | if (gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_SET_FEAT, SCATTER_GATHER, |
| 1853 | 0, 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | TRACE2(("gdth_search_drives(): set features RAWSERVICE OK\n")); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1855 | if (gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_GET_FEAT, 0, 0, 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | TRACE2(("gdth_search_dr(): get feat RAWSERVICE %d\n", |
| 1857 | ha->info)); |
| 1858 | ha->raw_feat |= (ushort)ha->info; |
| 1859 | } |
| 1860 | } |
| 1861 | |
| 1862 | /* set/get features cache service (equal to raw service) */ |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1863 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_SET_FEAT, 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | SCATTER_GATHER,0)) { |
| 1865 | TRACE2(("gdth_search_drives(): set features CACHESERVICE OK\n")); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1866 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_GET_FEAT, 0, 0, 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | TRACE2(("gdth_search_dr(): get feat CACHESERV. %d\n", |
| 1868 | ha->info)); |
| 1869 | ha->cache_feat |= (ushort)ha->info; |
| 1870 | } |
| 1871 | } |
| 1872 | |
| 1873 | /* reserve drives for raw service */ |
| 1874 | if (reserve_mode != 0) { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1875 | gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_RESERVE_ALL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | reserve_mode == 1 ? 1 : 3, 0, 0); |
| 1877 | TRACE2(("gdth_search_drives(): RESERVE_ALL code %d\n", |
| 1878 | ha->status)); |
| 1879 | } |
| 1880 | for (i = 0; i < MAX_RES_ARGS; i += 4) { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1881 | if (reserve_list[i] == ha->hanum && reserve_list[i+1] < ha->bus_cnt && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | reserve_list[i+2] < ha->tid_cnt && reserve_list[i+3] < MAXLUN) { |
| 1883 | TRACE2(("gdth_search_drives(): reserve ha %d bus %d id %d lun %d\n", |
| 1884 | reserve_list[i], reserve_list[i+1], |
| 1885 | reserve_list[i+2], reserve_list[i+3])); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1886 | if (!gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_RESERVE, 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | reserve_list[i+1], reserve_list[i+2] | |
| 1888 | (reserve_list[i+3] << 8))) { |
| 1889 | printk("GDT-HA %d: Error raw service (RESERVE, code %d)\n", |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1890 | ha->hanum, ha->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | } |
| 1892 | } |
| 1893 | } |
| 1894 | |
| 1895 | /* Determine OEM string using IOCTL */ |
| 1896 | oemstr = (gdth_oem_str_ioctl *)ha->pscratch; |
| 1897 | oemstr->params.ctl_version = 0x01; |
| 1898 | oemstr->params.buffer_size = sizeof(oemstr->text); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1899 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | CACHE_READ_OEM_STRING_RECORD,INVALID_CHANNEL, |
| 1901 | sizeof(gdth_oem_str_ioctl))) { |
| 1902 | TRACE2(("gdth_search_drives(): CACHE_READ_OEM_STRING_RECORD OK\n")); |
| 1903 | printk("GDT-HA %d: Vendor: %s Name: %s\n", |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1904 | ha->hanum, oemstr->text.oem_company_name, ha->binfo.type_string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | /* Save the Host Drive inquiry data */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | strlcpy(ha->oem_name,oemstr->text.scsi_host_drive_inquiry_vendor_id, |
| 1907 | sizeof(ha->oem_name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | } else { |
| 1909 | /* Old method, based on PCI ID */ |
| 1910 | TRACE2(("gdth_search_drives(): CACHE_READ_OEM_STRING_RECORD failed\n")); |
| 1911 | printk("GDT-HA %d: Name: %s\n", |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1912 | ha->hanum, ha->binfo.type_string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | if (ha->oem_id == OEM_ID_INTEL) |
| 1914 | strlcpy(ha->oem_name,"Intel ", sizeof(ha->oem_name)); |
| 1915 | else |
| 1916 | strlcpy(ha->oem_name,"ICP ", sizeof(ha->oem_name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | } |
| 1918 | |
| 1919 | /* scanning for host drives */ |
| 1920 | for (i = 0; i < cdev_cnt; ++i) |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1921 | gdth_analyse_hdrive(ha, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | |
| 1923 | TRACE(("gdth_search_drives() OK\n")); |
| 1924 | return 1; |
| 1925 | } |
| 1926 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1927 | static int gdth_analyse_hdrive(gdth_ha_str *ha, ushort hdrive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | ulong32 drv_cyls; |
| 1930 | int drv_hds, drv_secs; |
| 1931 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1932 | TRACE(("gdth_analyse_hdrive() hanum %d drive %d\n", ha->hanum, hdrive)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | if (hdrive >= MAX_HDRIVES) |
| 1934 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1936 | if (!gdth_internal_cmd(ha, CACHESERVICE, GDT_INFO, hdrive, 0, 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | return 0; |
| 1938 | ha->hdr[hdrive].present = TRUE; |
| 1939 | ha->hdr[hdrive].size = ha->info; |
| 1940 | |
| 1941 | /* evaluate mapping (sectors per head, heads per cylinder) */ |
| 1942 | ha->hdr[hdrive].size &= ~SECS32; |
| 1943 | if (ha->info2 == 0) { |
| 1944 | gdth_eval_mapping(ha->hdr[hdrive].size,&drv_cyls,&drv_hds,&drv_secs); |
| 1945 | } else { |
| 1946 | drv_hds = ha->info2 & 0xff; |
| 1947 | drv_secs = (ha->info2 >> 8) & 0xff; |
| 1948 | drv_cyls = (ulong32)ha->hdr[hdrive].size / drv_hds / drv_secs; |
| 1949 | } |
| 1950 | ha->hdr[hdrive].heads = (unchar)drv_hds; |
| 1951 | ha->hdr[hdrive].secs = (unchar)drv_secs; |
| 1952 | /* round size */ |
| 1953 | ha->hdr[hdrive].size = drv_cyls * drv_hds * drv_secs; |
| 1954 | |
| 1955 | if (ha->cache_feat & GDT_64BIT) { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1956 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_X_INFO, hdrive, 0, 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | && ha->info2 != 0) { |
| 1958 | ha->hdr[hdrive].size = ((ulong64)ha->info2 << 32) | ha->info; |
| 1959 | } |
| 1960 | } |
| 1961 | TRACE2(("gdth_search_dr() cdr. %d size %d hds %d scs %d\n", |
| 1962 | hdrive,ha->hdr[hdrive].size,drv_hds,drv_secs)); |
| 1963 | |
| 1964 | /* get informations about device */ |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1965 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_DEVTYPE, hdrive, 0, 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | TRACE2(("gdth_search_dr() cache drive %d devtype %d\n", |
| 1967 | hdrive,ha->info)); |
| 1968 | ha->hdr[hdrive].devtype = (ushort)ha->info; |
| 1969 | } |
| 1970 | |
| 1971 | /* cluster info */ |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1972 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_CLUST_INFO, hdrive, 0, 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | TRACE2(("gdth_search_dr() cache drive %d cluster info %d\n", |
| 1974 | hdrive,ha->info)); |
| 1975 | if (!shared_access) |
| 1976 | ha->hdr[hdrive].cluster_type = (unchar)ha->info; |
| 1977 | } |
| 1978 | |
| 1979 | /* R/W attributes */ |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1980 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_RW_ATTRIBS, hdrive, 0, 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1981 | TRACE2(("gdth_search_dr() cache drive %d r/w attrib. %d\n", |
| 1982 | hdrive,ha->info)); |
| 1983 | ha->hdr[hdrive].rw_attribs = (unchar)ha->info; |
| 1984 | } |
| 1985 | |
| 1986 | return 1; |
| 1987 | } |
| 1988 | |
| 1989 | |
| 1990 | /* command queueing/sending functions */ |
| 1991 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 1992 | static void gdth_putq(gdth_ha_str *ha, Scsi_Cmnd *scp, unchar priority) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | { |
Boaz Harrosh | 3058d5d | 2007-10-02 23:14:39 +0200 | [diff] [blame] | 1994 | struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | register Scsi_Cmnd *pscp; |
| 1996 | register Scsi_Cmnd *nscp; |
| 1997 | ulong flags; |
| 1998 | unchar b, t; |
| 1999 | |
| 2000 | TRACE(("gdth_putq() priority %d\n",priority)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 | spin_lock_irqsave(&ha->smp_lock, flags); |
| 2002 | |
Boaz Harrosh | 3058d5d | 2007-10-02 23:14:39 +0200 | [diff] [blame] | 2003 | if (!cmndinfo->internal_command) { |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2004 | cmndinfo->priority = priority; |
Christoph Hellwig | 52759e6 | 2007-10-02 22:59:53 +0200 | [diff] [blame] | 2005 | b = scp->device->channel; |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 2006 | t = scp->device->id; |
| 2007 | if (priority >= DEFAULT_PRI) { |
| 2008 | if ((b != ha->virt_bus && ha->raw[BUS_L2P(ha,b)].lock) || |
| 2009 | (b==ha->virt_bus && t<MAX_HDRIVES && ha->hdr[t].lock)) { |
| 2010 | TRACE2(("gdth_putq(): locked IO ->update_timeout()\n")); |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2011 | cmndinfo->timeout = gdth_update_timeout(scp, 0); |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 2012 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | } |
| 2014 | } |
| 2015 | |
| 2016 | if (ha->req_first==NULL) { |
| 2017 | ha->req_first = scp; /* queue was empty */ |
| 2018 | scp->SCp.ptr = NULL; |
| 2019 | } else { /* queue not empty */ |
| 2020 | pscp = ha->req_first; |
| 2021 | nscp = (Scsi_Cmnd *)pscp->SCp.ptr; |
| 2022 | /* priority: 0-highest,..,0xff-lowest */ |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2023 | while (nscp && gdth_cmnd_priv(nscp)->priority <= priority) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | pscp = nscp; |
| 2025 | nscp = (Scsi_Cmnd *)pscp->SCp.ptr; |
| 2026 | } |
| 2027 | pscp->SCp.ptr = (char *)scp; |
| 2028 | scp->SCp.ptr = (char *)nscp; |
| 2029 | } |
| 2030 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
| 2031 | |
| 2032 | #ifdef GDTH_STATISTICS |
| 2033 | flags = 0; |
| 2034 | for (nscp=ha->req_first; nscp; nscp=(Scsi_Cmnd*)nscp->SCp.ptr) |
| 2035 | ++flags; |
| 2036 | if (max_rq < flags) { |
| 2037 | max_rq = flags; |
| 2038 | TRACE3(("GDT: max_rq = %d\n",(ushort)max_rq)); |
| 2039 | } |
| 2040 | #endif |
| 2041 | } |
| 2042 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2043 | static void gdth_next(gdth_ha_str *ha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | register Scsi_Cmnd *pscp; |
| 2046 | register Scsi_Cmnd *nscp; |
| 2047 | unchar b, t, l, firsttime; |
| 2048 | unchar this_cmd, next_cmd; |
| 2049 | ulong flags = 0; |
| 2050 | int cmd_index; |
| 2051 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2052 | TRACE(("gdth_next() hanum %d\n", ha->hanum)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2053 | if (!gdth_polling) |
| 2054 | spin_lock_irqsave(&ha->smp_lock, flags); |
| 2055 | |
| 2056 | ha->cmd_cnt = ha->cmd_offs_dpmem = 0; |
| 2057 | this_cmd = firsttime = TRUE; |
| 2058 | next_cmd = gdth_polling ? FALSE:TRUE; |
| 2059 | cmd_index = 0; |
| 2060 | |
| 2061 | for (nscp = pscp = ha->req_first; nscp; nscp = (Scsi_Cmnd *)nscp->SCp.ptr) { |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2062 | struct gdth_cmndinfo *nscp_cmndinfo = gdth_cmnd_priv(nscp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | if (nscp != pscp && nscp != (Scsi_Cmnd *)pscp->SCp.ptr) |
| 2064 | pscp = (Scsi_Cmnd *)pscp->SCp.ptr; |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2065 | if (!nscp_cmndinfo->internal_command) { |
Christoph Hellwig | 52759e6 | 2007-10-02 22:59:53 +0200 | [diff] [blame] | 2066 | b = nscp->device->channel; |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 2067 | t = nscp->device->id; |
| 2068 | l = nscp->device->lun; |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2069 | if (nscp_cmndinfo->priority >= DEFAULT_PRI) { |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 2070 | if ((b != ha->virt_bus && ha->raw[BUS_L2P(ha,b)].lock) || |
| 2071 | (b == ha->virt_bus && t < MAX_HDRIVES && ha->hdr[t].lock)) |
| 2072 | continue; |
| 2073 | } |
| 2074 | } else |
| 2075 | b = t = l = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | |
| 2077 | if (firsttime) { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2078 | if (gdth_test_busy(ha)) { /* controller busy ? */ |
| 2079 | TRACE(("gdth_next() controller %d busy !\n", ha->hanum)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | if (!gdth_polling) { |
| 2081 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
| 2082 | return; |
| 2083 | } |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2084 | while (gdth_test_busy(ha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | gdth_delay(1); |
| 2086 | } |
| 2087 | firsttime = FALSE; |
| 2088 | } |
| 2089 | |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2090 | if (!nscp_cmndinfo->internal_command) { |
| 2091 | if (nscp_cmndinfo->phase == -1) { |
| 2092 | nscp_cmndinfo->phase = CACHESERVICE; /* default: cache svc. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | if (nscp->cmnd[0] == TEST_UNIT_READY) { |
| 2094 | TRACE2(("TEST_UNIT_READY Bus %d Id %d LUN %d\n", |
| 2095 | b, t, l)); |
| 2096 | /* TEST_UNIT_READY -> set scan mode */ |
| 2097 | if ((ha->scan_mode & 0x0f) == 0) { |
| 2098 | if (b == 0 && t == 0 && l == 0) { |
| 2099 | ha->scan_mode |= 1; |
| 2100 | TRACE2(("Scan mode: 0x%x\n", ha->scan_mode)); |
| 2101 | } |
| 2102 | } else if ((ha->scan_mode & 0x0f) == 1) { |
| 2103 | if (b == 0 && ((t == 0 && l == 1) || |
| 2104 | (t == 1 && l == 0))) { |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2105 | nscp_cmndinfo->OpCode = GDT_SCAN_START; |
| 2106 | nscp_cmndinfo->phase = ((ha->scan_mode & 0x10 ? 1:0) << 8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | | SCSIRAWSERVICE; |
| 2108 | ha->scan_mode = 0x12; |
| 2109 | TRACE2(("Scan mode: 0x%x (SCAN_START)\n", |
| 2110 | ha->scan_mode)); |
| 2111 | } else { |
| 2112 | ha->scan_mode &= 0x10; |
| 2113 | TRACE2(("Scan mode: 0x%x\n", ha->scan_mode)); |
| 2114 | } |
| 2115 | } else if (ha->scan_mode == 0x12) { |
| 2116 | if (b == ha->bus_cnt && t == ha->tid_cnt-1) { |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2117 | nscp_cmndinfo->phase = SCSIRAWSERVICE; |
| 2118 | nscp_cmndinfo->OpCode = GDT_SCAN_END; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2119 | ha->scan_mode &= 0x10; |
| 2120 | TRACE2(("Scan mode: 0x%x (SCAN_END)\n", |
| 2121 | ha->scan_mode)); |
| 2122 | } |
| 2123 | } |
| 2124 | } |
| 2125 | if (b == ha->virt_bus && nscp->cmnd[0] != INQUIRY && |
| 2126 | nscp->cmnd[0] != READ_CAPACITY && nscp->cmnd[0] != MODE_SENSE && |
| 2127 | (ha->hdr[t].cluster_type & CLUSTER_DRIVE)) { |
| 2128 | /* always GDT_CLUST_INFO! */ |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2129 | nscp_cmndinfo->OpCode = GDT_CLUST_INFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2130 | } |
| 2131 | } |
| 2132 | } |
| 2133 | |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2134 | if (nscp_cmndinfo->OpCode != -1) { |
| 2135 | if ((nscp_cmndinfo->phase & 0xff) == CACHESERVICE) { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2136 | if (!(cmd_index=gdth_fill_cache_cmd(ha, nscp, t))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | this_cmd = FALSE; |
| 2138 | next_cmd = FALSE; |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2139 | } else if ((nscp_cmndinfo->phase & 0xff) == SCSIRAWSERVICE) { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2140 | if (!(cmd_index=gdth_fill_raw_cmd(ha, nscp, BUS_L2P(ha, b)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2141 | this_cmd = FALSE; |
| 2142 | next_cmd = FALSE; |
| 2143 | } else { |
| 2144 | memset((char*)nscp->sense_buffer,0,16); |
| 2145 | nscp->sense_buffer[0] = 0x70; |
| 2146 | nscp->sense_buffer[2] = NOT_READY; |
| 2147 | nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1); |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2148 | if (!nscp_cmndinfo->wait_for_completion) |
| 2149 | nscp_cmndinfo->wait_for_completion++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2150 | else |
Matthew Wilcox | b8bff2a | 2007-10-02 22:40:22 +0200 | [diff] [blame] | 2151 | gdth_scsi_done(nscp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2152 | } |
Boaz Harrosh | 3058d5d | 2007-10-02 23:14:39 +0200 | [diff] [blame] | 2153 | } else if (gdth_cmnd_priv(nscp)->internal_command) { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2154 | if (!(cmd_index=gdth_special_cmd(ha, nscp))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2155 | this_cmd = FALSE; |
| 2156 | next_cmd = FALSE; |
| 2157 | } else if (b != ha->virt_bus) { |
| 2158 | if (ha->raw[BUS_L2P(ha,b)].io_cnt[t] >= GDTH_MAX_RAW || |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2159 | !(cmd_index=gdth_fill_raw_cmd(ha, nscp, BUS_L2P(ha, b)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | this_cmd = FALSE; |
| 2161 | else |
| 2162 | ha->raw[BUS_L2P(ha,b)].io_cnt[t]++; |
| 2163 | } else if (t >= MAX_HDRIVES || !ha->hdr[t].present || l != 0) { |
| 2164 | TRACE2(("Command 0x%x to bus %d id %d lun %d -> IGNORE\n", |
| 2165 | nscp->cmnd[0], b, t, l)); |
| 2166 | nscp->result = DID_BAD_TARGET << 16; |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2167 | if (!nscp_cmndinfo->wait_for_completion) |
| 2168 | nscp_cmndinfo->wait_for_completion++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | else |
Matthew Wilcox | b8bff2a | 2007-10-02 22:40:22 +0200 | [diff] [blame] | 2170 | gdth_scsi_done(nscp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | } else { |
| 2172 | switch (nscp->cmnd[0]) { |
| 2173 | case TEST_UNIT_READY: |
| 2174 | case INQUIRY: |
| 2175 | case REQUEST_SENSE: |
| 2176 | case READ_CAPACITY: |
| 2177 | case VERIFY: |
| 2178 | case START_STOP: |
| 2179 | case MODE_SENSE: |
| 2180 | case SERVICE_ACTION_IN: |
| 2181 | TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0], |
| 2182 | nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3], |
| 2183 | nscp->cmnd[4],nscp->cmnd[5])); |
| 2184 | if (ha->hdr[t].media_changed && nscp->cmnd[0] != INQUIRY) { |
| 2185 | /* return UNIT_ATTENTION */ |
| 2186 | TRACE2(("cmd 0x%x target %d: UNIT_ATTENTION\n", |
| 2187 | nscp->cmnd[0], t)); |
| 2188 | ha->hdr[t].media_changed = FALSE; |
| 2189 | memset((char*)nscp->sense_buffer,0,16); |
| 2190 | nscp->sense_buffer[0] = 0x70; |
| 2191 | nscp->sense_buffer[2] = UNIT_ATTENTION; |
| 2192 | nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1); |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2193 | if (!nscp_cmndinfo->wait_for_completion) |
| 2194 | nscp_cmndinfo->wait_for_completion++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | else |
Matthew Wilcox | b8bff2a | 2007-10-02 22:40:22 +0200 | [diff] [blame] | 2196 | gdth_scsi_done(nscp); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2197 | } else if (gdth_internal_cache_cmd(ha, nscp)) |
Matthew Wilcox | b8bff2a | 2007-10-02 22:40:22 +0200 | [diff] [blame] | 2198 | gdth_scsi_done(nscp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2199 | break; |
| 2200 | |
| 2201 | case ALLOW_MEDIUM_REMOVAL: |
| 2202 | TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0], |
| 2203 | nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3], |
| 2204 | nscp->cmnd[4],nscp->cmnd[5])); |
| 2205 | if ( (nscp->cmnd[4]&1) && !(ha->hdr[t].devtype&1) ) { |
| 2206 | TRACE(("Prevent r. nonremov. drive->do nothing\n")); |
| 2207 | nscp->result = DID_OK << 16; |
| 2208 | nscp->sense_buffer[0] = 0; |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2209 | if (!nscp_cmndinfo->wait_for_completion) |
| 2210 | nscp_cmndinfo->wait_for_completion++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2211 | else |
Matthew Wilcox | b8bff2a | 2007-10-02 22:40:22 +0200 | [diff] [blame] | 2212 | gdth_scsi_done(nscp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2213 | } else { |
| 2214 | nscp->cmnd[3] = (ha->hdr[t].devtype&1) ? 1:0; |
| 2215 | TRACE(("Prevent/allow r. %d rem. drive %d\n", |
| 2216 | nscp->cmnd[4],nscp->cmnd[3])); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2217 | if (!(cmd_index=gdth_fill_cache_cmd(ha, nscp, t))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2218 | this_cmd = FALSE; |
| 2219 | } |
| 2220 | break; |
| 2221 | |
| 2222 | case RESERVE: |
| 2223 | case RELEASE: |
| 2224 | TRACE2(("cache cmd %s\n",nscp->cmnd[0] == RESERVE ? |
| 2225 | "RESERVE" : "RELEASE")); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2226 | if (!(cmd_index=gdth_fill_cache_cmd(ha, nscp, t))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | this_cmd = FALSE; |
| 2228 | break; |
| 2229 | |
| 2230 | case READ_6: |
| 2231 | case WRITE_6: |
| 2232 | case READ_10: |
| 2233 | case WRITE_10: |
| 2234 | case READ_16: |
| 2235 | case WRITE_16: |
| 2236 | if (ha->hdr[t].media_changed) { |
| 2237 | /* return UNIT_ATTENTION */ |
| 2238 | TRACE2(("cmd 0x%x target %d: UNIT_ATTENTION\n", |
| 2239 | nscp->cmnd[0], t)); |
| 2240 | ha->hdr[t].media_changed = FALSE; |
| 2241 | memset((char*)nscp->sense_buffer,0,16); |
| 2242 | nscp->sense_buffer[0] = 0x70; |
| 2243 | nscp->sense_buffer[2] = UNIT_ATTENTION; |
| 2244 | nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1); |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2245 | if (!nscp_cmndinfo->wait_for_completion) |
| 2246 | nscp_cmndinfo->wait_for_completion++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2247 | else |
Matthew Wilcox | b8bff2a | 2007-10-02 22:40:22 +0200 | [diff] [blame] | 2248 | gdth_scsi_done(nscp); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2249 | } else if (!(cmd_index=gdth_fill_cache_cmd(ha, nscp, t))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2250 | this_cmd = FALSE; |
| 2251 | break; |
| 2252 | |
| 2253 | default: |
| 2254 | TRACE2(("cache cmd %x/%x/%x/%x/%x/%x unknown\n",nscp->cmnd[0], |
| 2255 | nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3], |
| 2256 | nscp->cmnd[4],nscp->cmnd[5])); |
| 2257 | printk("GDT-HA %d: Unknown SCSI command 0x%x to cache service !\n", |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2258 | ha->hanum, nscp->cmnd[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2259 | nscp->result = DID_ABORT << 16; |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2260 | if (!nscp_cmndinfo->wait_for_completion) |
| 2261 | nscp_cmndinfo->wait_for_completion++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2262 | else |
Matthew Wilcox | b8bff2a | 2007-10-02 22:40:22 +0200 | [diff] [blame] | 2263 | gdth_scsi_done(nscp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2264 | break; |
| 2265 | } |
| 2266 | } |
| 2267 | |
| 2268 | if (!this_cmd) |
| 2269 | break; |
| 2270 | if (nscp == ha->req_first) |
| 2271 | ha->req_first = pscp = (Scsi_Cmnd *)nscp->SCp.ptr; |
| 2272 | else |
| 2273 | pscp->SCp.ptr = nscp->SCp.ptr; |
| 2274 | if (!next_cmd) |
| 2275 | break; |
| 2276 | } |
| 2277 | |
| 2278 | if (ha->cmd_cnt > 0) { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2279 | gdth_release_event(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | } |
| 2281 | |
| 2282 | if (!gdth_polling) |
| 2283 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
| 2284 | |
| 2285 | if (gdth_polling && ha->cmd_cnt > 0) { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2286 | if (!gdth_wait(ha, cmd_index, POLL_TIMEOUT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2287 | printk("GDT-HA %d: Command %d timed out !\n", |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2288 | ha->hanum, cmd_index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2289 | } |
| 2290 | } |
Boaz Harrosh | 3892d88 | 2007-10-02 23:18:03 +0200 | [diff] [blame] | 2291 | |
| 2292 | /* |
| 2293 | * gdth_copy_internal_data() - copy to/from a buffer onto a scsi_cmnd's |
| 2294 | * buffers, kmap_atomic() as needed. |
| 2295 | */ |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2296 | static void gdth_copy_internal_data(gdth_ha_str *ha, Scsi_Cmnd *scp, |
Boaz Harrosh | ee54cc6 | 2008-02-27 15:29:15 -0800 | [diff] [blame] | 2297 | char *buffer, ushort count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | { |
Boaz Harrosh | d35055a | 2008-02-27 15:31:20 -0800 | [diff] [blame] | 2299 | ushort cpcount,i, max_sg = scsi_sg_count(scp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2300 | ushort cpsum,cpnow; |
| 2301 | struct scatterlist *sl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | char *address; |
| 2303 | |
Boaz Harrosh | d35055a | 2008-02-27 15:31:20 -0800 | [diff] [blame] | 2304 | cpcount = min_t(ushort, count, scsi_bufflen(scp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2305 | |
Boaz Harrosh | 3892d88 | 2007-10-02 23:18:03 +0200 | [diff] [blame] | 2306 | if (cpcount) { |
| 2307 | cpsum=0; |
| 2308 | scsi_for_each_sg(scp, sl, max_sg, i) { |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 2309 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2310 | cpnow = (ushort)sl->length; |
| 2311 | TRACE(("copy_internal() now %d sum %d count %d %d\n", |
Boaz Harrosh | d35055a | 2008-02-27 15:31:20 -0800 | [diff] [blame] | 2312 | cpnow, cpsum, cpcount, scsi_bufflen(scp))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | if (cpsum+cpnow > cpcount) |
| 2314 | cpnow = cpcount - cpsum; |
| 2315 | cpsum += cpnow; |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 2316 | if (!sg_page(sl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | printk("GDT-HA %d: invalid sc/gt element in gdth_copy_internal_data()\n", |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2318 | ha->hanum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2319 | return; |
| 2320 | } |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 2321 | local_irq_save(flags); |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 2322 | address = kmap_atomic(sg_page(sl), KM_BIO_SRC_IRQ) + sl->offset; |
Boaz Harrosh | ee54cc6 | 2008-02-27 15:29:15 -0800 | [diff] [blame] | 2323 | memcpy(address, buffer, cpnow); |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 2324 | flush_dcache_page(sg_page(sl)); |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 2325 | kunmap_atomic(address, KM_BIO_SRC_IRQ); |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 2326 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | if (cpsum == cpcount) |
| 2328 | break; |
| 2329 | buffer += cpnow; |
| 2330 | } |
Boaz Harrosh | 3892d88 | 2007-10-02 23:18:03 +0200 | [diff] [blame] | 2331 | } else if (count) { |
| 2332 | printk("GDT-HA %d: SCSI command with no buffers but data transfer expected!\n", |
| 2333 | ha->hanum); |
| 2334 | WARN_ON(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2335 | } |
| 2336 | } |
| 2337 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2338 | static int gdth_internal_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2339 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2340 | unchar t; |
| 2341 | gdth_inq_data inq; |
| 2342 | gdth_rdcap_data rdc; |
| 2343 | gdth_sense_data sd; |
| 2344 | gdth_modep_data mpd; |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2345 | struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | t = scp->device->id; |
| 2348 | TRACE(("gdth_internal_cache_cmd() cmd 0x%x hdrive %d\n", |
| 2349 | scp->cmnd[0],t)); |
| 2350 | |
| 2351 | scp->result = DID_OK << 16; |
| 2352 | scp->sense_buffer[0] = 0; |
| 2353 | |
| 2354 | switch (scp->cmnd[0]) { |
| 2355 | case TEST_UNIT_READY: |
| 2356 | case VERIFY: |
| 2357 | case START_STOP: |
| 2358 | TRACE2(("Test/Verify/Start hdrive %d\n",t)); |
| 2359 | break; |
| 2360 | |
| 2361 | case INQUIRY: |
| 2362 | TRACE2(("Inquiry hdrive %d devtype %d\n", |
| 2363 | t,ha->hdr[t].devtype)); |
| 2364 | inq.type_qual = (ha->hdr[t].devtype&4) ? TYPE_ROM:TYPE_DISK; |
| 2365 | /* you can here set all disks to removable, if you want to do |
| 2366 | a flush using the ALLOW_MEDIUM_REMOVAL command */ |
| 2367 | inq.modif_rmb = 0x00; |
| 2368 | if ((ha->hdr[t].devtype & 1) || |
| 2369 | (ha->hdr[t].cluster_type & CLUSTER_DRIVE)) |
| 2370 | inq.modif_rmb = 0x80; |
| 2371 | inq.version = 2; |
| 2372 | inq.resp_aenc = 2; |
| 2373 | inq.add_length= 32; |
| 2374 | strcpy(inq.vendor,ha->oem_name); |
| 2375 | sprintf(inq.product,"Host Drive #%02d",t); |
| 2376 | strcpy(inq.revision," "); |
Boaz Harrosh | ee54cc6 | 2008-02-27 15:29:15 -0800 | [diff] [blame] | 2377 | gdth_copy_internal_data(ha, scp, (char*)&inq, sizeof(gdth_inq_data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2378 | break; |
| 2379 | |
| 2380 | case REQUEST_SENSE: |
| 2381 | TRACE2(("Request sense hdrive %d\n",t)); |
| 2382 | sd.errorcode = 0x70; |
| 2383 | sd.segno = 0x00; |
| 2384 | sd.key = NO_SENSE; |
| 2385 | sd.info = 0; |
| 2386 | sd.add_length= 0; |
Boaz Harrosh | ee54cc6 | 2008-02-27 15:29:15 -0800 | [diff] [blame] | 2387 | gdth_copy_internal_data(ha, scp, (char*)&sd, sizeof(gdth_sense_data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2388 | break; |
| 2389 | |
| 2390 | case MODE_SENSE: |
| 2391 | TRACE2(("Mode sense hdrive %d\n",t)); |
| 2392 | memset((char*)&mpd,0,sizeof(gdth_modep_data)); |
| 2393 | mpd.hd.data_length = sizeof(gdth_modep_data); |
| 2394 | mpd.hd.dev_par = (ha->hdr[t].devtype&2) ? 0x80:0; |
| 2395 | mpd.hd.bd_length = sizeof(mpd.bd); |
| 2396 | mpd.bd.block_length[0] = (SECTOR_SIZE & 0x00ff0000) >> 16; |
| 2397 | mpd.bd.block_length[1] = (SECTOR_SIZE & 0x0000ff00) >> 8; |
| 2398 | mpd.bd.block_length[2] = (SECTOR_SIZE & 0x000000ff); |
Boaz Harrosh | ee54cc6 | 2008-02-27 15:29:15 -0800 | [diff] [blame] | 2399 | gdth_copy_internal_data(ha, scp, (char*)&mpd, sizeof(gdth_modep_data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2400 | break; |
| 2401 | |
| 2402 | case READ_CAPACITY: |
| 2403 | TRACE2(("Read capacity hdrive %d\n",t)); |
| 2404 | if (ha->hdr[t].size > (ulong64)0xffffffff) |
| 2405 | rdc.last_block_no = 0xffffffff; |
| 2406 | else |
| 2407 | rdc.last_block_no = cpu_to_be32(ha->hdr[t].size-1); |
| 2408 | rdc.block_length = cpu_to_be32(SECTOR_SIZE); |
Boaz Harrosh | ee54cc6 | 2008-02-27 15:29:15 -0800 | [diff] [blame] | 2409 | gdth_copy_internal_data(ha, scp, (char*)&rdc, sizeof(gdth_rdcap_data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | break; |
| 2411 | |
| 2412 | case SERVICE_ACTION_IN: |
| 2413 | if ((scp->cmnd[1] & 0x1f) == SAI_READ_CAPACITY_16 && |
| 2414 | (ha->cache_feat & GDT_64BIT)) { |
| 2415 | gdth_rdcap16_data rdc16; |
| 2416 | |
| 2417 | TRACE2(("Read capacity (16) hdrive %d\n",t)); |
| 2418 | rdc16.last_block_no = cpu_to_be64(ha->hdr[t].size-1); |
| 2419 | rdc16.block_length = cpu_to_be32(SECTOR_SIZE); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2420 | gdth_copy_internal_data(ha, scp, (char*)&rdc16, |
Boaz Harrosh | ee54cc6 | 2008-02-27 15:29:15 -0800 | [diff] [blame] | 2421 | sizeof(gdth_rdcap16_data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2422 | } else { |
| 2423 | scp->result = DID_ABORT << 16; |
| 2424 | } |
| 2425 | break; |
| 2426 | |
| 2427 | default: |
| 2428 | TRACE2(("Internal cache cmd 0x%x unknown\n",scp->cmnd[0])); |
| 2429 | break; |
| 2430 | } |
| 2431 | |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2432 | if (!cmndinfo->wait_for_completion) |
| 2433 | cmndinfo->wait_for_completion++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | else |
| 2435 | return 1; |
| 2436 | |
| 2437 | return 0; |
| 2438 | } |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2439 | |
| 2440 | static int gdth_fill_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, ushort hdrive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2441 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | register gdth_cmd_str *cmdp; |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2443 | struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2444 | ulong32 cnt, blockcnt; |
| 2445 | ulong64 no, blockno; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2446 | int i, cmd_index, read_write, sgcnt, mode64; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2448 | cmdp = ha->pccb; |
| 2449 | TRACE(("gdth_fill_cache_cmd() cmd 0x%x cmdsize %d hdrive %d\n", |
| 2450 | scp->cmnd[0],scp->cmd_len,hdrive)); |
| 2451 | |
| 2452 | if (ha->type==GDT_EISA && ha->cmd_cnt>0) |
| 2453 | return 0; |
| 2454 | |
| 2455 | mode64 = (ha->cache_feat & GDT_64BIT) ? TRUE : FALSE; |
| 2456 | /* test for READ_16, WRITE_16 if !mode64 ? --- |
| 2457 | not required, should not occur due to error return on |
| 2458 | READ_CAPACITY_16 */ |
| 2459 | |
| 2460 | cmdp->Service = CACHESERVICE; |
| 2461 | cmdp->RequestBuffer = scp; |
| 2462 | /* search free command index */ |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2463 | if (!(cmd_index=gdth_get_cmd_index(ha))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | TRACE(("GDT: No free command index found\n")); |
| 2465 | return 0; |
| 2466 | } |
| 2467 | /* if it's the first command, set command semaphore */ |
| 2468 | if (ha->cmd_cnt == 0) |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2469 | gdth_set_sema0(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | |
| 2471 | /* fill command */ |
| 2472 | read_write = 0; |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2473 | if (cmndinfo->OpCode != -1) |
| 2474 | cmdp->OpCode = cmndinfo->OpCode; /* special cache cmd. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2475 | else if (scp->cmnd[0] == RESERVE) |
| 2476 | cmdp->OpCode = GDT_RESERVE_DRV; |
| 2477 | else if (scp->cmnd[0] == RELEASE) |
| 2478 | cmdp->OpCode = GDT_RELEASE_DRV; |
| 2479 | else if (scp->cmnd[0] == ALLOW_MEDIUM_REMOVAL) { |
| 2480 | if (scp->cmnd[4] & 1) /* prevent ? */ |
| 2481 | cmdp->OpCode = GDT_MOUNT; |
| 2482 | else if (scp->cmnd[3] & 1) /* removable drive ? */ |
| 2483 | cmdp->OpCode = GDT_UNMOUNT; |
| 2484 | else |
| 2485 | cmdp->OpCode = GDT_FLUSH; |
| 2486 | } else if (scp->cmnd[0] == WRITE_6 || scp->cmnd[0] == WRITE_10 || |
| 2487 | scp->cmnd[0] == WRITE_12 || scp->cmnd[0] == WRITE_16 |
| 2488 | ) { |
| 2489 | read_write = 1; |
| 2490 | if (gdth_write_through || ((ha->hdr[hdrive].rw_attribs & 1) && |
| 2491 | (ha->cache_feat & GDT_WR_THROUGH))) |
| 2492 | cmdp->OpCode = GDT_WRITE_THR; |
| 2493 | else |
| 2494 | cmdp->OpCode = GDT_WRITE; |
| 2495 | } else { |
| 2496 | read_write = 2; |
| 2497 | cmdp->OpCode = GDT_READ; |
| 2498 | } |
| 2499 | |
| 2500 | cmdp->BoardNode = LOCALBOARD; |
| 2501 | if (mode64) { |
| 2502 | cmdp->u.cache64.DeviceNo = hdrive; |
| 2503 | cmdp->u.cache64.BlockNo = 1; |
| 2504 | cmdp->u.cache64.sg_canz = 0; |
| 2505 | } else { |
| 2506 | cmdp->u.cache.DeviceNo = hdrive; |
| 2507 | cmdp->u.cache.BlockNo = 1; |
| 2508 | cmdp->u.cache.sg_canz = 0; |
| 2509 | } |
| 2510 | |
| 2511 | if (read_write) { |
| 2512 | if (scp->cmd_len == 16) { |
| 2513 | memcpy(&no, &scp->cmnd[2], sizeof(ulong64)); |
| 2514 | blockno = be64_to_cpu(no); |
| 2515 | memcpy(&cnt, &scp->cmnd[10], sizeof(ulong32)); |
| 2516 | blockcnt = be32_to_cpu(cnt); |
| 2517 | } else if (scp->cmd_len == 10) { |
| 2518 | memcpy(&no, &scp->cmnd[2], sizeof(ulong32)); |
| 2519 | blockno = be32_to_cpu(no); |
| 2520 | memcpy(&cnt, &scp->cmnd[7], sizeof(ushort)); |
| 2521 | blockcnt = be16_to_cpu(cnt); |
| 2522 | } else { |
| 2523 | memcpy(&no, &scp->cmnd[0], sizeof(ulong32)); |
| 2524 | blockno = be32_to_cpu(no) & 0x001fffffUL; |
| 2525 | blockcnt= scp->cmnd[4]==0 ? 0x100 : scp->cmnd[4]; |
| 2526 | } |
| 2527 | if (mode64) { |
| 2528 | cmdp->u.cache64.BlockNo = blockno; |
| 2529 | cmdp->u.cache64.BlockCnt = blockcnt; |
| 2530 | } else { |
| 2531 | cmdp->u.cache.BlockNo = (ulong32)blockno; |
| 2532 | cmdp->u.cache.BlockCnt = blockcnt; |
| 2533 | } |
| 2534 | |
Boaz Harrosh | d35055a | 2008-02-27 15:31:20 -0800 | [diff] [blame] | 2535 | if (scsi_bufflen(scp)) { |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2536 | cmndinfo->dma_dir = (read_write == 1 ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE); |
Boaz Harrosh | d35055a | 2008-02-27 15:31:20 -0800 | [diff] [blame] | 2538 | sgcnt = pci_map_sg(ha->pdev, scsi_sglist(scp), scsi_sg_count(scp), |
Boaz Harrosh | 3892d88 | 2007-10-02 23:18:03 +0200 | [diff] [blame] | 2539 | cmndinfo->dma_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2540 | if (mode64) { |
Boaz Harrosh | 3892d88 | 2007-10-02 23:18:03 +0200 | [diff] [blame] | 2541 | struct scatterlist *sl; |
| 2542 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2543 | cmdp->u.cache64.DestAddr= (ulong64)-1; |
| 2544 | cmdp->u.cache64.sg_canz = sgcnt; |
Boaz Harrosh | 3892d88 | 2007-10-02 23:18:03 +0200 | [diff] [blame] | 2545 | scsi_for_each_sg(scp, sl, sgcnt, i) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2546 | cmdp->u.cache64.sg_lst[i].sg_ptr = sg_dma_address(sl); |
| 2547 | #ifdef GDTH_DMA_STATISTICS |
| 2548 | if (cmdp->u.cache64.sg_lst[i].sg_ptr > (ulong64)0xffffffff) |
| 2549 | ha->dma64_cnt++; |
| 2550 | else |
| 2551 | ha->dma32_cnt++; |
| 2552 | #endif |
| 2553 | cmdp->u.cache64.sg_lst[i].sg_len = sg_dma_len(sl); |
| 2554 | } |
| 2555 | } else { |
Boaz Harrosh | 3892d88 | 2007-10-02 23:18:03 +0200 | [diff] [blame] | 2556 | struct scatterlist *sl; |
| 2557 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2558 | cmdp->u.cache.DestAddr= 0xffffffff; |
| 2559 | cmdp->u.cache.sg_canz = sgcnt; |
Boaz Harrosh | 3892d88 | 2007-10-02 23:18:03 +0200 | [diff] [blame] | 2560 | scsi_for_each_sg(scp, sl, sgcnt, i) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2561 | cmdp->u.cache.sg_lst[i].sg_ptr = sg_dma_address(sl); |
| 2562 | #ifdef GDTH_DMA_STATISTICS |
| 2563 | ha->dma32_cnt++; |
| 2564 | #endif |
| 2565 | cmdp->u.cache.sg_lst[i].sg_len = sg_dma_len(sl); |
| 2566 | } |
| 2567 | } |
| 2568 | |
| 2569 | #ifdef GDTH_STATISTICS |
| 2570 | if (max_sg < (ulong32)sgcnt) { |
| 2571 | max_sg = (ulong32)sgcnt; |
| 2572 | TRACE3(("GDT: max_sg = %d\n",max_sg)); |
| 2573 | } |
| 2574 | #endif |
| 2575 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2576 | } |
| 2577 | } |
| 2578 | /* evaluate command size, check space */ |
| 2579 | if (mode64) { |
| 2580 | TRACE(("cache cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n", |
| 2581 | cmdp->u.cache64.DestAddr,cmdp->u.cache64.sg_canz, |
| 2582 | cmdp->u.cache64.sg_lst[0].sg_ptr, |
| 2583 | cmdp->u.cache64.sg_lst[0].sg_len)); |
| 2584 | TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n", |
| 2585 | cmdp->OpCode,cmdp->u.cache64.BlockNo,cmdp->u.cache64.BlockCnt)); |
| 2586 | ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.cache64.sg_lst) + |
| 2587 | (ushort)cmdp->u.cache64.sg_canz * sizeof(gdth_sg64_str); |
| 2588 | } else { |
| 2589 | TRACE(("cache cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n", |
| 2590 | cmdp->u.cache.DestAddr,cmdp->u.cache.sg_canz, |
| 2591 | cmdp->u.cache.sg_lst[0].sg_ptr, |
| 2592 | cmdp->u.cache.sg_lst[0].sg_len)); |
| 2593 | TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n", |
| 2594 | cmdp->OpCode,cmdp->u.cache.BlockNo,cmdp->u.cache.BlockCnt)); |
| 2595 | ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.cache.sg_lst) + |
| 2596 | (ushort)cmdp->u.cache.sg_canz * sizeof(gdth_sg_str); |
| 2597 | } |
| 2598 | if (ha->cmd_len & 3) |
| 2599 | ha->cmd_len += (4 - (ha->cmd_len & 3)); |
| 2600 | |
| 2601 | if (ha->cmd_cnt > 0) { |
| 2602 | if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) > |
| 2603 | ha->ic_all_size) { |
| 2604 | TRACE2(("gdth_fill_cache() DPMEM overflow\n")); |
| 2605 | ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND; |
| 2606 | return 0; |
| 2607 | } |
| 2608 | } |
| 2609 | |
| 2610 | /* copy command */ |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2611 | gdth_copy_command(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2612 | return cmd_index; |
| 2613 | } |
| 2614 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2615 | static int gdth_fill_raw_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, unchar b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2616 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2617 | register gdth_cmd_str *cmdp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2618 | ushort i; |
Boaz Harrosh | 3892d88 | 2007-10-02 23:18:03 +0200 | [diff] [blame] | 2619 | dma_addr_t sense_paddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2620 | int cmd_index, sgcnt, mode64; |
| 2621 | unchar t,l; |
| 2622 | struct page *page; |
| 2623 | ulong offset; |
Boaz Harrosh | 3058d5d | 2007-10-02 23:14:39 +0200 | [diff] [blame] | 2624 | struct gdth_cmndinfo *cmndinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2625 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2626 | t = scp->device->id; |
| 2627 | l = scp->device->lun; |
| 2628 | cmdp = ha->pccb; |
| 2629 | TRACE(("gdth_fill_raw_cmd() cmd 0x%x bus %d ID %d LUN %d\n", |
| 2630 | scp->cmnd[0],b,t,l)); |
| 2631 | |
| 2632 | if (ha->type==GDT_EISA && ha->cmd_cnt>0) |
| 2633 | return 0; |
| 2634 | |
| 2635 | mode64 = (ha->raw_feat & GDT_64BIT) ? TRUE : FALSE; |
| 2636 | |
| 2637 | cmdp->Service = SCSIRAWSERVICE; |
| 2638 | cmdp->RequestBuffer = scp; |
| 2639 | /* search free command index */ |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2640 | if (!(cmd_index=gdth_get_cmd_index(ha))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2641 | TRACE(("GDT: No free command index found\n")); |
| 2642 | return 0; |
| 2643 | } |
| 2644 | /* if it's the first command, set command semaphore */ |
| 2645 | if (ha->cmd_cnt == 0) |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2646 | gdth_set_sema0(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2647 | |
Boaz Harrosh | 3058d5d | 2007-10-02 23:14:39 +0200 | [diff] [blame] | 2648 | cmndinfo = gdth_cmnd_priv(scp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2649 | /* fill command */ |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2650 | if (cmndinfo->OpCode != -1) { |
| 2651 | cmdp->OpCode = cmndinfo->OpCode; /* special raw cmd. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2652 | cmdp->BoardNode = LOCALBOARD; |
| 2653 | if (mode64) { |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2654 | cmdp->u.raw64.direction = (cmndinfo->phase >> 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2655 | TRACE2(("special raw cmd 0x%x param 0x%x\n", |
| 2656 | cmdp->OpCode, cmdp->u.raw64.direction)); |
| 2657 | /* evaluate command size */ |
| 2658 | ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst); |
| 2659 | } else { |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2660 | cmdp->u.raw.direction = (cmndinfo->phase >> 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2661 | TRACE2(("special raw cmd 0x%x param 0x%x\n", |
| 2662 | cmdp->OpCode, cmdp->u.raw.direction)); |
| 2663 | /* evaluate command size */ |
| 2664 | ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst); |
| 2665 | } |
| 2666 | |
| 2667 | } else { |
| 2668 | page = virt_to_page(scp->sense_buffer); |
| 2669 | offset = (ulong)scp->sense_buffer & ~PAGE_MASK; |
| 2670 | sense_paddr = pci_map_page(ha->pdev,page,offset, |
| 2671 | 16,PCI_DMA_FROMDEVICE); |
Boaz Harrosh | 3058d5d | 2007-10-02 23:14:39 +0200 | [diff] [blame] | 2672 | |
| 2673 | cmndinfo->sense_paddr = sense_paddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2674 | cmdp->OpCode = GDT_WRITE; /* always */ |
| 2675 | cmdp->BoardNode = LOCALBOARD; |
| 2676 | if (mode64) { |
| 2677 | cmdp->u.raw64.reserved = 0; |
| 2678 | cmdp->u.raw64.mdisc_time = 0; |
| 2679 | cmdp->u.raw64.mcon_time = 0; |
| 2680 | cmdp->u.raw64.clen = scp->cmd_len; |
| 2681 | cmdp->u.raw64.target = t; |
| 2682 | cmdp->u.raw64.lun = l; |
| 2683 | cmdp->u.raw64.bus = b; |
| 2684 | cmdp->u.raw64.priority = 0; |
Boaz Harrosh | d35055a | 2008-02-27 15:31:20 -0800 | [diff] [blame] | 2685 | cmdp->u.raw64.sdlen = scsi_bufflen(scp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2686 | cmdp->u.raw64.sense_len = 16; |
| 2687 | cmdp->u.raw64.sense_data = sense_paddr; |
| 2688 | cmdp->u.raw64.direction = |
| 2689 | gdth_direction_tab[scp->cmnd[0]]==DOU ? GDTH_DATA_OUT:GDTH_DATA_IN; |
| 2690 | memcpy(cmdp->u.raw64.cmd,scp->cmnd,16); |
Joerg Dorchain | bb9ba31 | 2007-03-06 02:46:54 -0800 | [diff] [blame] | 2691 | cmdp->u.raw64.sg_ranz = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2692 | } else { |
| 2693 | cmdp->u.raw.reserved = 0; |
| 2694 | cmdp->u.raw.mdisc_time = 0; |
| 2695 | cmdp->u.raw.mcon_time = 0; |
| 2696 | cmdp->u.raw.clen = scp->cmd_len; |
| 2697 | cmdp->u.raw.target = t; |
| 2698 | cmdp->u.raw.lun = l; |
| 2699 | cmdp->u.raw.bus = b; |
| 2700 | cmdp->u.raw.priority = 0; |
| 2701 | cmdp->u.raw.link_p = 0; |
Boaz Harrosh | d35055a | 2008-02-27 15:31:20 -0800 | [diff] [blame] | 2702 | cmdp->u.raw.sdlen = scsi_bufflen(scp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2703 | cmdp->u.raw.sense_len = 16; |
| 2704 | cmdp->u.raw.sense_data = sense_paddr; |
| 2705 | cmdp->u.raw.direction = |
| 2706 | gdth_direction_tab[scp->cmnd[0]]==DOU ? GDTH_DATA_OUT:GDTH_DATA_IN; |
| 2707 | memcpy(cmdp->u.raw.cmd,scp->cmnd,12); |
Joerg Dorchain | bb9ba31 | 2007-03-06 02:46:54 -0800 | [diff] [blame] | 2708 | cmdp->u.raw.sg_ranz = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2709 | } |
| 2710 | |
Boaz Harrosh | d35055a | 2008-02-27 15:31:20 -0800 | [diff] [blame] | 2711 | if (scsi_bufflen(scp)) { |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 2712 | cmndinfo->dma_dir = PCI_DMA_BIDIRECTIONAL; |
Boaz Harrosh | d35055a | 2008-02-27 15:31:20 -0800 | [diff] [blame] | 2713 | sgcnt = pci_map_sg(ha->pdev, scsi_sglist(scp), scsi_sg_count(scp), |
Boaz Harrosh | 3892d88 | 2007-10-02 23:18:03 +0200 | [diff] [blame] | 2714 | cmndinfo->dma_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2715 | if (mode64) { |
Boaz Harrosh | 3892d88 | 2007-10-02 23:18:03 +0200 | [diff] [blame] | 2716 | struct scatterlist *sl; |
| 2717 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2718 | cmdp->u.raw64.sdata = (ulong64)-1; |
| 2719 | cmdp->u.raw64.sg_ranz = sgcnt; |
Boaz Harrosh | 3892d88 | 2007-10-02 23:18:03 +0200 | [diff] [blame] | 2720 | scsi_for_each_sg(scp, sl, sgcnt, i) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2721 | cmdp->u.raw64.sg_lst[i].sg_ptr = sg_dma_address(sl); |
| 2722 | #ifdef GDTH_DMA_STATISTICS |
| 2723 | if (cmdp->u.raw64.sg_lst[i].sg_ptr > (ulong64)0xffffffff) |
| 2724 | ha->dma64_cnt++; |
| 2725 | else |
| 2726 | ha->dma32_cnt++; |
| 2727 | #endif |
| 2728 | cmdp->u.raw64.sg_lst[i].sg_len = sg_dma_len(sl); |
| 2729 | } |
| 2730 | } else { |
Boaz Harrosh | 3892d88 | 2007-10-02 23:18:03 +0200 | [diff] [blame] | 2731 | struct scatterlist *sl; |
| 2732 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2733 | cmdp->u.raw.sdata = 0xffffffff; |
| 2734 | cmdp->u.raw.sg_ranz = sgcnt; |
Boaz Harrosh | 3892d88 | 2007-10-02 23:18:03 +0200 | [diff] [blame] | 2735 | scsi_for_each_sg(scp, sl, sgcnt, i) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2736 | cmdp->u.raw.sg_lst[i].sg_ptr = sg_dma_address(sl); |
| 2737 | #ifdef GDTH_DMA_STATISTICS |
| 2738 | ha->dma32_cnt++; |
| 2739 | #endif |
| 2740 | cmdp->u.raw.sg_lst[i].sg_len = sg_dma_len(sl); |
| 2741 | } |
| 2742 | } |
| 2743 | |
| 2744 | #ifdef GDTH_STATISTICS |
| 2745 | if (max_sg < sgcnt) { |
| 2746 | max_sg = sgcnt; |
| 2747 | TRACE3(("GDT: max_sg = %d\n",sgcnt)); |
| 2748 | } |
| 2749 | #endif |
| 2750 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2751 | } |
| 2752 | if (mode64) { |
| 2753 | TRACE(("raw cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n", |
| 2754 | cmdp->u.raw64.sdata,cmdp->u.raw64.sg_ranz, |
| 2755 | cmdp->u.raw64.sg_lst[0].sg_ptr, |
| 2756 | cmdp->u.raw64.sg_lst[0].sg_len)); |
| 2757 | /* evaluate command size */ |
| 2758 | ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst) + |
| 2759 | (ushort)cmdp->u.raw64.sg_ranz * sizeof(gdth_sg64_str); |
| 2760 | } else { |
| 2761 | TRACE(("raw cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n", |
| 2762 | cmdp->u.raw.sdata,cmdp->u.raw.sg_ranz, |
| 2763 | cmdp->u.raw.sg_lst[0].sg_ptr, |
| 2764 | cmdp->u.raw.sg_lst[0].sg_len)); |
| 2765 | /* evaluate command size */ |
| 2766 | ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst) + |
| 2767 | (ushort)cmdp->u.raw.sg_ranz * sizeof(gdth_sg_str); |
| 2768 | } |
| 2769 | } |
| 2770 | /* check space */ |
| 2771 | if (ha->cmd_len & 3) |
| 2772 | ha->cmd_len += (4 - (ha->cmd_len & 3)); |
| 2773 | |
| 2774 | if (ha->cmd_cnt > 0) { |
| 2775 | if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) > |
| 2776 | ha->ic_all_size) { |
| 2777 | TRACE2(("gdth_fill_raw() DPMEM overflow\n")); |
| 2778 | ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND; |
| 2779 | return 0; |
| 2780 | } |
| 2781 | } |
| 2782 | |
| 2783 | /* copy command */ |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2784 | gdth_copy_command(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2785 | return cmd_index; |
| 2786 | } |
| 2787 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2788 | static int gdth_special_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2789 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2790 | register gdth_cmd_str *cmdp; |
Boaz Harrosh | ee54cc6 | 2008-02-27 15:29:15 -0800 | [diff] [blame] | 2791 | struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | int cmd_index; |
| 2793 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2794 | cmdp= ha->pccb; |
| 2795 | TRACE2(("gdth_special_cmd(): ")); |
| 2796 | |
| 2797 | if (ha->type==GDT_EISA && ha->cmd_cnt>0) |
| 2798 | return 0; |
| 2799 | |
Boaz Harrosh | ee54cc6 | 2008-02-27 15:29:15 -0800 | [diff] [blame] | 2800 | *cmdp = *cmndinfo->internal_cmd_str; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2801 | cmdp->RequestBuffer = scp; |
| 2802 | |
| 2803 | /* search free command index */ |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2804 | if (!(cmd_index=gdth_get_cmd_index(ha))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2805 | TRACE(("GDT: No free command index found\n")); |
| 2806 | return 0; |
| 2807 | } |
| 2808 | |
| 2809 | /* if it's the first command, set command semaphore */ |
| 2810 | if (ha->cmd_cnt == 0) |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2811 | gdth_set_sema0(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | |
| 2813 | /* evaluate command size, check space */ |
| 2814 | if (cmdp->OpCode == GDT_IOCTL) { |
| 2815 | TRACE2(("IOCTL\n")); |
| 2816 | ha->cmd_len = |
| 2817 | GDTOFFSOF(gdth_cmd_str,u.ioctl.p_param) + sizeof(ulong64); |
| 2818 | } else if (cmdp->Service == CACHESERVICE) { |
| 2819 | TRACE2(("cache command %d\n",cmdp->OpCode)); |
| 2820 | if (ha->cache_feat & GDT_64BIT) |
| 2821 | ha->cmd_len = |
| 2822 | GDTOFFSOF(gdth_cmd_str,u.cache64.sg_lst) + sizeof(gdth_sg64_str); |
| 2823 | else |
| 2824 | ha->cmd_len = |
| 2825 | GDTOFFSOF(gdth_cmd_str,u.cache.sg_lst) + sizeof(gdth_sg_str); |
| 2826 | } else if (cmdp->Service == SCSIRAWSERVICE) { |
| 2827 | TRACE2(("raw command %d\n",cmdp->OpCode)); |
| 2828 | if (ha->raw_feat & GDT_64BIT) |
| 2829 | ha->cmd_len = |
| 2830 | GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst) + sizeof(gdth_sg64_str); |
| 2831 | else |
| 2832 | ha->cmd_len = |
| 2833 | GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst) + sizeof(gdth_sg_str); |
| 2834 | } |
| 2835 | |
| 2836 | if (ha->cmd_len & 3) |
| 2837 | ha->cmd_len += (4 - (ha->cmd_len & 3)); |
| 2838 | |
| 2839 | if (ha->cmd_cnt > 0) { |
| 2840 | if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) > |
| 2841 | ha->ic_all_size) { |
| 2842 | TRACE2(("gdth_special_cmd() DPMEM overflow\n")); |
| 2843 | ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND; |
| 2844 | return 0; |
| 2845 | } |
| 2846 | } |
| 2847 | |
| 2848 | /* copy command */ |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 2849 | gdth_copy_command(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2850 | return cmd_index; |
| 2851 | } |
| 2852 | |
| 2853 | |
| 2854 | /* Controller event handling functions */ |
| 2855 | static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, ushort source, |
| 2856 | ushort idx, gdth_evt_data *evt) |
| 2857 | { |
| 2858 | gdth_evt_str *e; |
| 2859 | struct timeval tv; |
| 2860 | |
| 2861 | /* no GDTH_LOCK_HA() ! */ |
| 2862 | TRACE2(("gdth_store_event() source %d idx %d\n", source, idx)); |
| 2863 | if (source == 0) /* no source -> no event */ |
| 2864 | return NULL; |
| 2865 | |
| 2866 | if (ebuffer[elastidx].event_source == source && |
| 2867 | ebuffer[elastidx].event_idx == idx && |
| 2868 | ((evt->size != 0 && ebuffer[elastidx].event_data.size != 0 && |
| 2869 | !memcmp((char *)&ebuffer[elastidx].event_data.eu, |
| 2870 | (char *)&evt->eu, evt->size)) || |
| 2871 | (evt->size == 0 && ebuffer[elastidx].event_data.size == 0 && |
| 2872 | !strcmp((char *)&ebuffer[elastidx].event_data.event_string, |
| 2873 | (char *)&evt->event_string)))) { |
| 2874 | e = &ebuffer[elastidx]; |
| 2875 | do_gettimeofday(&tv); |
| 2876 | e->last_stamp = tv.tv_sec; |
| 2877 | ++e->same_count; |
| 2878 | } else { |
| 2879 | if (ebuffer[elastidx].event_source != 0) { /* entry not free ? */ |
| 2880 | ++elastidx; |
| 2881 | if (elastidx == MAX_EVENTS) |
| 2882 | elastidx = 0; |
| 2883 | if (elastidx == eoldidx) { /* reached mark ? */ |
| 2884 | ++eoldidx; |
| 2885 | if (eoldidx == MAX_EVENTS) |
| 2886 | eoldidx = 0; |
| 2887 | } |
| 2888 | } |
| 2889 | e = &ebuffer[elastidx]; |
| 2890 | e->event_source = source; |
| 2891 | e->event_idx = idx; |
| 2892 | do_gettimeofday(&tv); |
| 2893 | e->first_stamp = e->last_stamp = tv.tv_sec; |
| 2894 | e->same_count = 1; |
| 2895 | e->event_data = *evt; |
| 2896 | e->application = 0; |
| 2897 | } |
| 2898 | return e; |
| 2899 | } |
| 2900 | |
| 2901 | static int gdth_read_event(gdth_ha_str *ha, int handle, gdth_evt_str *estr) |
| 2902 | { |
| 2903 | gdth_evt_str *e; |
| 2904 | int eindex; |
| 2905 | ulong flags; |
| 2906 | |
| 2907 | TRACE2(("gdth_read_event() handle %d\n", handle)); |
| 2908 | spin_lock_irqsave(&ha->smp_lock, flags); |
| 2909 | if (handle == -1) |
| 2910 | eindex = eoldidx; |
| 2911 | else |
| 2912 | eindex = handle; |
| 2913 | estr->event_source = 0; |
| 2914 | |
| 2915 | if (eindex >= MAX_EVENTS) { |
| 2916 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
| 2917 | return eindex; |
| 2918 | } |
| 2919 | e = &ebuffer[eindex]; |
| 2920 | if (e->event_source != 0) { |
| 2921 | if (eindex != elastidx) { |
| 2922 | if (++eindex == MAX_EVENTS) |
| 2923 | eindex = 0; |
| 2924 | } else { |
| 2925 | eindex = -1; |
| 2926 | } |
| 2927 | memcpy(estr, e, sizeof(gdth_evt_str)); |
| 2928 | } |
| 2929 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
| 2930 | return eindex; |
| 2931 | } |
| 2932 | |
| 2933 | static void gdth_readapp_event(gdth_ha_str *ha, |
| 2934 | unchar application, gdth_evt_str *estr) |
| 2935 | { |
| 2936 | gdth_evt_str *e; |
| 2937 | int eindex; |
| 2938 | ulong flags; |
| 2939 | unchar found = FALSE; |
| 2940 | |
| 2941 | TRACE2(("gdth_readapp_event() app. %d\n", application)); |
| 2942 | spin_lock_irqsave(&ha->smp_lock, flags); |
| 2943 | eindex = eoldidx; |
| 2944 | for (;;) { |
| 2945 | e = &ebuffer[eindex]; |
| 2946 | if (e->event_source == 0) |
| 2947 | break; |
| 2948 | if ((e->application & application) == 0) { |
| 2949 | e->application |= application; |
| 2950 | found = TRUE; |
| 2951 | break; |
| 2952 | } |
| 2953 | if (eindex == elastidx) |
| 2954 | break; |
| 2955 | if (++eindex == MAX_EVENTS) |
| 2956 | eindex = 0; |
| 2957 | } |
| 2958 | if (found) |
| 2959 | memcpy(estr, e, sizeof(gdth_evt_str)); |
| 2960 | else |
| 2961 | estr->event_source = 0; |
| 2962 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
| 2963 | } |
| 2964 | |
| 2965 | static void gdth_clear_events(void) |
| 2966 | { |
| 2967 | TRACE(("gdth_clear_events()")); |
| 2968 | |
| 2969 | eoldidx = elastidx = 0; |
| 2970 | ebuffer[0].event_source = 0; |
| 2971 | } |
| 2972 | |
| 2973 | |
| 2974 | /* SCSI interface functions */ |
| 2975 | |
Jeff Garzik | 230e886 | 2007-12-13 16:14:12 -0800 | [diff] [blame] | 2976 | static irqreturn_t __gdth_interrupt(gdth_ha_str *ha, |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 2977 | int gdth_from_wait, int* pIndex) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2979 | gdt6m_dpram_str __iomem *dp6m_ptr = NULL; |
| 2980 | gdt6_dpram_str __iomem *dp6_ptr; |
| 2981 | gdt2_dpram_str __iomem *dp2_ptr; |
| 2982 | Scsi_Cmnd *scp; |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 2983 | int rval, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2984 | unchar IStatus; |
| 2985 | ushort Service; |
| 2986 | ulong flags = 0; |
| 2987 | #ifdef INT_COAL |
| 2988 | int coalesced = FALSE; |
| 2989 | int next = FALSE; |
| 2990 | gdth_coal_status *pcs = NULL; |
| 2991 | int act_int_coal = 0; |
| 2992 | #endif |
| 2993 | |
Jeff Garzik | 230e886 | 2007-12-13 16:14:12 -0800 | [diff] [blame] | 2994 | TRACE(("gdth_interrupt() IRQ %d\n", ha->irq)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | |
| 2996 | /* if polling and not from gdth_wait() -> return */ |
| 2997 | if (gdth_polling) { |
| 2998 | if (!gdth_from_wait) { |
| 2999 | return IRQ_HANDLED; |
| 3000 | } |
| 3001 | } |
| 3002 | |
| 3003 | if (!gdth_polling) |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 3004 | spin_lock_irqsave(&ha->smp_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3005 | |
| 3006 | /* search controller */ |
Jeff Garzik | 230e886 | 2007-12-13 16:14:12 -0800 | [diff] [blame] | 3007 | IStatus = gdth_get_status(ha); |
| 3008 | if (IStatus == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3009 | /* spurious interrupt */ |
| 3010 | if (!gdth_polling) |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 3011 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
| 3012 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3013 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3014 | |
| 3015 | #ifdef GDTH_STATISTICS |
| 3016 | ++act_ints; |
| 3017 | #endif |
| 3018 | |
| 3019 | #ifdef INT_COAL |
| 3020 | /* See if the fw is returning coalesced status */ |
| 3021 | if (IStatus == COALINDEX) { |
| 3022 | /* Coalesced status. Setup the initial status |
| 3023 | buffer pointer and flags */ |
| 3024 | pcs = ha->coal_stat; |
| 3025 | coalesced = TRUE; |
| 3026 | next = TRUE; |
| 3027 | } |
| 3028 | |
| 3029 | do { |
| 3030 | if (coalesced) { |
| 3031 | /* For coalesced requests all status |
| 3032 | information is found in the status buffer */ |
| 3033 | IStatus = (unchar)(pcs->status & 0xff); |
| 3034 | } |
| 3035 | #endif |
| 3036 | |
| 3037 | if (ha->type == GDT_EISA) { |
| 3038 | if (IStatus & 0x80) { /* error flag */ |
| 3039 | IStatus &= ~0x80; |
| 3040 | ha->status = inw(ha->bmic + MAILBOXREG+8); |
| 3041 | TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status)); |
| 3042 | } else /* no error */ |
| 3043 | ha->status = S_OK; |
| 3044 | ha->info = inl(ha->bmic + MAILBOXREG+12); |
| 3045 | ha->service = inw(ha->bmic + MAILBOXREG+10); |
| 3046 | ha->info2 = inl(ha->bmic + MAILBOXREG+4); |
| 3047 | |
| 3048 | outb(0xff, ha->bmic + EDOORREG); /* acknowledge interrupt */ |
| 3049 | outb(0x00, ha->bmic + SEMA1REG); /* reset status semaphore */ |
| 3050 | } else if (ha->type == GDT_ISA) { |
| 3051 | dp2_ptr = ha->brd; |
| 3052 | if (IStatus & 0x80) { /* error flag */ |
| 3053 | IStatus &= ~0x80; |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 3054 | ha->status = readw(&dp2_ptr->u.ic.Status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status)); |
| 3056 | } else /* no error */ |
| 3057 | ha->status = S_OK; |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 3058 | ha->info = readl(&dp2_ptr->u.ic.Info[0]); |
| 3059 | ha->service = readw(&dp2_ptr->u.ic.Service); |
| 3060 | ha->info2 = readl(&dp2_ptr->u.ic.Info[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 3062 | writeb(0xff, &dp2_ptr->io.irqdel); /* acknowledge interrupt */ |
| 3063 | writeb(0, &dp2_ptr->u.ic.Cmd_Index);/* reset command index */ |
| 3064 | writeb(0, &dp2_ptr->io.Sema1); /* reset status semaphore */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3065 | } else if (ha->type == GDT_PCI) { |
| 3066 | dp6_ptr = ha->brd; |
| 3067 | if (IStatus & 0x80) { /* error flag */ |
| 3068 | IStatus &= ~0x80; |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 3069 | ha->status = readw(&dp6_ptr->u.ic.Status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status)); |
| 3071 | } else /* no error */ |
| 3072 | ha->status = S_OK; |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 3073 | ha->info = readl(&dp6_ptr->u.ic.Info[0]); |
| 3074 | ha->service = readw(&dp6_ptr->u.ic.Service); |
| 3075 | ha->info2 = readl(&dp6_ptr->u.ic.Info[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 3077 | writeb(0xff, &dp6_ptr->io.irqdel); /* acknowledge interrupt */ |
| 3078 | writeb(0, &dp6_ptr->u.ic.Cmd_Index);/* reset command index */ |
| 3079 | writeb(0, &dp6_ptr->io.Sema1); /* reset status semaphore */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3080 | } else if (ha->type == GDT_PCINEW) { |
| 3081 | if (IStatus & 0x80) { /* error flag */ |
| 3082 | IStatus &= ~0x80; |
| 3083 | ha->status = inw(PTR2USHORT(&ha->plx->status)); |
| 3084 | TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status)); |
| 3085 | } else |
| 3086 | ha->status = S_OK; |
| 3087 | ha->info = inl(PTR2USHORT(&ha->plx->info[0])); |
| 3088 | ha->service = inw(PTR2USHORT(&ha->plx->service)); |
| 3089 | ha->info2 = inl(PTR2USHORT(&ha->plx->info[1])); |
| 3090 | |
| 3091 | outb(0xff, PTR2USHORT(&ha->plx->edoor_reg)); |
| 3092 | outb(0x00, PTR2USHORT(&ha->plx->sema1_reg)); |
| 3093 | } else if (ha->type == GDT_PCIMPR) { |
| 3094 | dp6m_ptr = ha->brd; |
| 3095 | if (IStatus & 0x80) { /* error flag */ |
| 3096 | IStatus &= ~0x80; |
| 3097 | #ifdef INT_COAL |
| 3098 | if (coalesced) |
Jean Delvare | 107e716 | 2006-11-09 21:45:09 +0100 | [diff] [blame] | 3099 | ha->status = pcs->ext_status & 0xffff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3100 | else |
| 3101 | #endif |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 3102 | ha->status = readw(&dp6m_ptr->i960r.status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status)); |
| 3104 | } else /* no error */ |
| 3105 | ha->status = S_OK; |
| 3106 | #ifdef INT_COAL |
| 3107 | /* get information */ |
| 3108 | if (coalesced) { |
| 3109 | ha->info = pcs->info0; |
| 3110 | ha->info2 = pcs->info1; |
Jean Delvare | 107e716 | 2006-11-09 21:45:09 +0100 | [diff] [blame] | 3111 | ha->service = (pcs->ext_status >> 16) & 0xffff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3112 | } else |
| 3113 | #endif |
| 3114 | { |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 3115 | ha->info = readl(&dp6m_ptr->i960r.info[0]); |
| 3116 | ha->service = readw(&dp6m_ptr->i960r.service); |
| 3117 | ha->info2 = readl(&dp6m_ptr->i960r.info[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3118 | } |
| 3119 | /* event string */ |
| 3120 | if (IStatus == ASYNCINDEX) { |
| 3121 | if (ha->service != SCREENSERVICE && |
| 3122 | (ha->fw_vers & 0xff) >= 0x1a) { |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 3123 | ha->dvr.severity = readb |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3124 | (&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.severity); |
| 3125 | for (i = 0; i < 256; ++i) { |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 3126 | ha->dvr.event_string[i] = readb |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3127 | (&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.evt_str[i]); |
| 3128 | if (ha->dvr.event_string[i] == 0) |
| 3129 | break; |
| 3130 | } |
| 3131 | } |
| 3132 | } |
| 3133 | #ifdef INT_COAL |
| 3134 | /* Make sure that non coalesced interrupts get cleared |
| 3135 | before being handled by gdth_async_event/gdth_sync_event */ |
| 3136 | if (!coalesced) |
| 3137 | #endif |
| 3138 | { |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 3139 | writeb(0xff, &dp6m_ptr->i960r.edoor_reg); |
| 3140 | writeb(0, &dp6m_ptr->i960r.sema1_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3141 | } |
| 3142 | } else { |
| 3143 | TRACE2(("gdth_interrupt() unknown controller type\n")); |
| 3144 | if (!gdth_polling) |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 3145 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3146 | return IRQ_HANDLED; |
| 3147 | } |
| 3148 | |
| 3149 | TRACE(("gdth_interrupt() index %d stat %d info %d\n", |
| 3150 | IStatus,ha->status,ha->info)); |
| 3151 | |
| 3152 | if (gdth_from_wait) { |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 3153 | *pIndex = (int)IStatus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3154 | } |
| 3155 | |
| 3156 | if (IStatus == ASYNCINDEX) { |
| 3157 | TRACE2(("gdth_interrupt() async. event\n")); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3158 | gdth_async_event(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | if (!gdth_polling) |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 3160 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3161 | gdth_next(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3162 | return IRQ_HANDLED; |
| 3163 | } |
| 3164 | |
| 3165 | if (IStatus == SPEZINDEX) { |
| 3166 | TRACE2(("Service unknown or not initialized !\n")); |
| 3167 | ha->dvr.size = sizeof(ha->dvr.eu.driver); |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 3168 | ha->dvr.eu.driver.ionode = ha->hanum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3169 | gdth_store_event(ha, ES_DRIVER, 4, &ha->dvr); |
| 3170 | if (!gdth_polling) |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 3171 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3172 | return IRQ_HANDLED; |
| 3173 | } |
| 3174 | scp = ha->cmd_tab[IStatus-2].cmnd; |
| 3175 | Service = ha->cmd_tab[IStatus-2].service; |
| 3176 | ha->cmd_tab[IStatus-2].cmnd = UNUSED_CMND; |
| 3177 | if (scp == UNUSED_CMND) { |
| 3178 | TRACE2(("gdth_interrupt() index to unused command (%d)\n",IStatus)); |
| 3179 | ha->dvr.size = sizeof(ha->dvr.eu.driver); |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 3180 | ha->dvr.eu.driver.ionode = ha->hanum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3181 | ha->dvr.eu.driver.index = IStatus; |
| 3182 | gdth_store_event(ha, ES_DRIVER, 1, &ha->dvr); |
| 3183 | if (!gdth_polling) |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 3184 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | return IRQ_HANDLED; |
| 3186 | } |
| 3187 | if (scp == INTERNAL_CMND) { |
| 3188 | TRACE(("gdth_interrupt() answer to internal command\n")); |
| 3189 | if (!gdth_polling) |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 3190 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3191 | return IRQ_HANDLED; |
| 3192 | } |
| 3193 | |
| 3194 | TRACE(("gdth_interrupt() sync. status\n")); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3195 | rval = gdth_sync_event(ha,Service,IStatus,scp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | if (!gdth_polling) |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 3197 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | if (rval == 2) { |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 3199 | gdth_putq(ha, scp, gdth_cmnd_priv(scp)->priority); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3200 | } else if (rval == 1) { |
Matthew Wilcox | b8bff2a | 2007-10-02 22:40:22 +0200 | [diff] [blame] | 3201 | gdth_scsi_done(scp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3202 | } |
| 3203 | |
| 3204 | #ifdef INT_COAL |
| 3205 | if (coalesced) { |
| 3206 | /* go to the next status in the status buffer */ |
| 3207 | ++pcs; |
| 3208 | #ifdef GDTH_STATISTICS |
| 3209 | ++act_int_coal; |
| 3210 | if (act_int_coal > max_int_coal) { |
| 3211 | max_int_coal = act_int_coal; |
| 3212 | printk("GDT: max_int_coal = %d\n",(ushort)max_int_coal); |
| 3213 | } |
| 3214 | #endif |
| 3215 | /* see if there is another status */ |
| 3216 | if (pcs->status == 0) |
| 3217 | /* Stop the coalesce loop */ |
| 3218 | next = FALSE; |
| 3219 | } |
| 3220 | } while (next); |
| 3221 | |
| 3222 | /* coalescing only for new GDT_PCIMPR controllers available */ |
| 3223 | if (ha->type == GDT_PCIMPR && coalesced) { |
Jeff Garzik | a52667f | 2007-10-02 22:55:53 +0200 | [diff] [blame] | 3224 | writeb(0xff, &dp6m_ptr->i960r.edoor_reg); |
| 3225 | writeb(0, &dp6m_ptr->i960r.sema1_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | } |
| 3227 | #endif |
| 3228 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3229 | gdth_next(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3230 | return IRQ_HANDLED; |
| 3231 | } |
| 3232 | |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 3233 | static irqreturn_t gdth_interrupt(int irq, void *dev_id) |
| 3234 | { |
Jeff Garzik | 230e886 | 2007-12-13 16:14:12 -0800 | [diff] [blame] | 3235 | gdth_ha_str *ha = dev_id; |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 3236 | |
Jeff Garzik | 230e886 | 2007-12-13 16:14:12 -0800 | [diff] [blame] | 3237 | return __gdth_interrupt(ha, false, NULL); |
Boaz Harrosh | 10e1b4b | 2007-10-02 23:08:10 +0200 | [diff] [blame] | 3238 | } |
| 3239 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3240 | static int gdth_sync_event(gdth_ha_str *ha, int service, unchar index, |
| 3241 | Scsi_Cmnd *scp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3242 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3243 | gdth_msg_str *msg; |
| 3244 | gdth_cmd_str *cmdp; |
| 3245 | unchar b, t; |
Boaz Harrosh | 3058d5d | 2007-10-02 23:14:39 +0200 | [diff] [blame] | 3246 | struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3248 | cmdp = ha->pccb; |
| 3249 | TRACE(("gdth_sync_event() serv %d status %d\n", |
| 3250 | service,ha->status)); |
| 3251 | |
| 3252 | if (service == SCREENSERVICE) { |
| 3253 | msg = ha->pmsg; |
| 3254 | TRACE(("len: %d, answer: %d, ext: %d, alen: %d\n", |
| 3255 | msg->msg_len,msg->msg_answer,msg->msg_ext,msg->msg_alen)); |
| 3256 | if (msg->msg_len > MSGLEN+1) |
| 3257 | msg->msg_len = MSGLEN+1; |
| 3258 | if (msg->msg_len) |
| 3259 | if (!(msg->msg_answer && msg->msg_ext)) { |
| 3260 | msg->msg_text[msg->msg_len] = '\0'; |
| 3261 | printk("%s",msg->msg_text); |
| 3262 | } |
| 3263 | |
| 3264 | if (msg->msg_ext && !msg->msg_answer) { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3265 | while (gdth_test_busy(ha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3266 | gdth_delay(0); |
| 3267 | cmdp->Service = SCREENSERVICE; |
| 3268 | cmdp->RequestBuffer = SCREEN_CMND; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3269 | gdth_get_cmd_index(ha); |
| 3270 | gdth_set_sema0(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3271 | cmdp->OpCode = GDT_READ; |
| 3272 | cmdp->BoardNode = LOCALBOARD; |
| 3273 | cmdp->u.screen.reserved = 0; |
| 3274 | cmdp->u.screen.su.msg.msg_handle= msg->msg_handle; |
| 3275 | cmdp->u.screen.su.msg.msg_addr = ha->msg_phys; |
| 3276 | ha->cmd_offs_dpmem = 0; |
| 3277 | ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr) |
| 3278 | + sizeof(ulong64); |
| 3279 | ha->cmd_cnt = 0; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3280 | gdth_copy_command(ha); |
| 3281 | gdth_release_event(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3282 | return 0; |
| 3283 | } |
| 3284 | |
| 3285 | if (msg->msg_answer && msg->msg_alen) { |
| 3286 | /* default answers (getchar() not possible) */ |
| 3287 | if (msg->msg_alen == 1) { |
| 3288 | msg->msg_alen = 0; |
| 3289 | msg->msg_len = 1; |
| 3290 | msg->msg_text[0] = 0; |
| 3291 | } else { |
| 3292 | msg->msg_alen -= 2; |
| 3293 | msg->msg_len = 2; |
| 3294 | msg->msg_text[0] = 1; |
| 3295 | msg->msg_text[1] = 0; |
| 3296 | } |
| 3297 | msg->msg_ext = 0; |
| 3298 | msg->msg_answer = 0; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3299 | while (gdth_test_busy(ha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3300 | gdth_delay(0); |
| 3301 | cmdp->Service = SCREENSERVICE; |
| 3302 | cmdp->RequestBuffer = SCREEN_CMND; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3303 | gdth_get_cmd_index(ha); |
| 3304 | gdth_set_sema0(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3305 | cmdp->OpCode = GDT_WRITE; |
| 3306 | cmdp->BoardNode = LOCALBOARD; |
| 3307 | cmdp->u.screen.reserved = 0; |
| 3308 | cmdp->u.screen.su.msg.msg_handle= msg->msg_handle; |
| 3309 | cmdp->u.screen.su.msg.msg_addr = ha->msg_phys; |
| 3310 | ha->cmd_offs_dpmem = 0; |
| 3311 | ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr) |
| 3312 | + sizeof(ulong64); |
| 3313 | ha->cmd_cnt = 0; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3314 | gdth_copy_command(ha); |
| 3315 | gdth_release_event(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3316 | return 0; |
| 3317 | } |
| 3318 | printk("\n"); |
| 3319 | |
| 3320 | } else { |
Christoph Hellwig | 52759e6 | 2007-10-02 22:59:53 +0200 | [diff] [blame] | 3321 | b = scp->device->channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3322 | t = scp->device->id; |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 3323 | if (cmndinfo->OpCode == -1 && b != ha->virt_bus) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3324 | ha->raw[BUS_L2P(ha,b)].io_cnt[t]--; |
| 3325 | } |
| 3326 | /* cache or raw service */ |
| 3327 | if (ha->status == S_BSY) { |
| 3328 | TRACE2(("Controller busy -> retry !\n")); |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 3329 | if (cmndinfo->OpCode == GDT_MOUNT) |
| 3330 | cmndinfo->OpCode = GDT_CLUST_INFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3331 | /* retry */ |
| 3332 | return 2; |
| 3333 | } |
Boaz Harrosh | d35055a | 2008-02-27 15:31:20 -0800 | [diff] [blame] | 3334 | if (scsi_bufflen(scp)) |
| 3335 | pci_unmap_sg(ha->pdev, scsi_sglist(scp), scsi_sg_count(scp), |
Boaz Harrosh | 3892d88 | 2007-10-02 23:18:03 +0200 | [diff] [blame] | 3336 | cmndinfo->dma_dir); |
| 3337 | |
Boaz Harrosh | 3058d5d | 2007-10-02 23:14:39 +0200 | [diff] [blame] | 3338 | if (cmndinfo->sense_paddr) |
| 3339 | pci_unmap_page(ha->pdev, cmndinfo->sense_paddr, 16, |
| 3340 | PCI_DMA_FROMDEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3341 | |
| 3342 | if (ha->status == S_OK) { |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 3343 | cmndinfo->status = S_OK; |
| 3344 | cmndinfo->info = ha->info; |
| 3345 | if (cmndinfo->OpCode != -1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3346 | TRACE2(("gdth_sync_event(): special cmd 0x%x OK\n", |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 3347 | cmndinfo->OpCode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3348 | /* special commands GDT_CLUST_INFO/GDT_MOUNT ? */ |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 3349 | if (cmndinfo->OpCode == GDT_CLUST_INFO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | ha->hdr[t].cluster_type = (unchar)ha->info; |
| 3351 | if (!(ha->hdr[t].cluster_type & |
| 3352 | CLUSTER_MOUNTED)) { |
| 3353 | /* NOT MOUNTED -> MOUNT */ |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 3354 | cmndinfo->OpCode = GDT_MOUNT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3355 | if (ha->hdr[t].cluster_type & |
| 3356 | CLUSTER_RESERVED) { |
| 3357 | /* cluster drive RESERVED (on the other node) */ |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 3358 | cmndinfo->phase = -2; /* reservation conflict */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3359 | } |
| 3360 | } else { |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 3361 | cmndinfo->OpCode = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3362 | } |
| 3363 | } else { |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 3364 | if (cmndinfo->OpCode == GDT_MOUNT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3365 | ha->hdr[t].cluster_type |= CLUSTER_MOUNTED; |
| 3366 | ha->hdr[t].media_changed = TRUE; |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 3367 | } else if (cmndinfo->OpCode == GDT_UNMOUNT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3368 | ha->hdr[t].cluster_type &= ~CLUSTER_MOUNTED; |
| 3369 | ha->hdr[t].media_changed = TRUE; |
| 3370 | } |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 3371 | cmndinfo->OpCode = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3372 | } |
| 3373 | /* retry */ |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 3374 | cmndinfo->priority = HIGH_PRI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | return 2; |
| 3376 | } else { |
| 3377 | /* RESERVE/RELEASE ? */ |
| 3378 | if (scp->cmnd[0] == RESERVE) { |
| 3379 | ha->hdr[t].cluster_type |= CLUSTER_RESERVED; |
| 3380 | } else if (scp->cmnd[0] == RELEASE) { |
| 3381 | ha->hdr[t].cluster_type &= ~CLUSTER_RESERVED; |
| 3382 | } |
| 3383 | scp->result = DID_OK << 16; |
| 3384 | scp->sense_buffer[0] = 0; |
| 3385 | } |
| 3386 | } else { |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 3387 | cmndinfo->status = ha->status; |
| 3388 | cmndinfo->info = ha->info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3389 | |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 3390 | if (cmndinfo->OpCode != -1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3391 | TRACE2(("gdth_sync_event(): special cmd 0x%x error 0x%x\n", |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 3392 | cmndinfo->OpCode, ha->status)); |
| 3393 | if (cmndinfo->OpCode == GDT_SCAN_START || |
| 3394 | cmndinfo->OpCode == GDT_SCAN_END) { |
| 3395 | cmndinfo->OpCode = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3396 | /* retry */ |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 3397 | cmndinfo->priority = HIGH_PRI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3398 | return 2; |
| 3399 | } |
| 3400 | memset((char*)scp->sense_buffer,0,16); |
| 3401 | scp->sense_buffer[0] = 0x70; |
| 3402 | scp->sense_buffer[2] = NOT_READY; |
| 3403 | scp->result = (DID_OK << 16) | (CHECK_CONDITION << 1); |
| 3404 | } else if (service == CACHESERVICE) { |
| 3405 | if (ha->status == S_CACHE_UNKNOWN && |
| 3406 | (ha->hdr[t].cluster_type & |
| 3407 | CLUSTER_RESERVE_STATE) == CLUSTER_RESERVE_STATE) { |
| 3408 | /* bus reset -> force GDT_CLUST_INFO */ |
| 3409 | ha->hdr[t].cluster_type &= ~CLUSTER_RESERVED; |
| 3410 | } |
| 3411 | memset((char*)scp->sense_buffer,0,16); |
| 3412 | if (ha->status == (ushort)S_CACHE_RESERV) { |
| 3413 | scp->result = (DID_OK << 16) | (RESERVATION_CONFLICT << 1); |
| 3414 | } else { |
| 3415 | scp->sense_buffer[0] = 0x70; |
| 3416 | scp->sense_buffer[2] = NOT_READY; |
| 3417 | scp->result = (DID_OK << 16) | (CHECK_CONDITION << 1); |
| 3418 | } |
Boaz Harrosh | 3058d5d | 2007-10-02 23:14:39 +0200 | [diff] [blame] | 3419 | if (!cmndinfo->internal_command) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3420 | ha->dvr.size = sizeof(ha->dvr.eu.sync); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3421 | ha->dvr.eu.sync.ionode = ha->hanum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3422 | ha->dvr.eu.sync.service = service; |
| 3423 | ha->dvr.eu.sync.status = ha->status; |
| 3424 | ha->dvr.eu.sync.info = ha->info; |
| 3425 | ha->dvr.eu.sync.hostdrive = t; |
| 3426 | if (ha->status >= 0x8000) |
| 3427 | gdth_store_event(ha, ES_SYNC, 0, &ha->dvr); |
| 3428 | else |
| 3429 | gdth_store_event(ha, ES_SYNC, service, &ha->dvr); |
| 3430 | } |
| 3431 | } else { |
| 3432 | /* sense buffer filled from controller firmware (DMA) */ |
| 3433 | if (ha->status != S_RAW_SCSI || ha->info >= 0x100) { |
| 3434 | scp->result = DID_BAD_TARGET << 16; |
| 3435 | } else { |
| 3436 | scp->result = (DID_OK << 16) | ha->info; |
| 3437 | } |
| 3438 | } |
| 3439 | } |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 3440 | if (!cmndinfo->wait_for_completion) |
| 3441 | cmndinfo->wait_for_completion++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3442 | else |
| 3443 | return 1; |
| 3444 | } |
| 3445 | |
| 3446 | return 0; |
| 3447 | } |
| 3448 | |
| 3449 | static char *async_cache_tab[] = { |
| 3450 | /* 0*/ "\011\000\002\002\002\004\002\006\004" |
| 3451 | "GDT HA %u, service %u, async. status %u/%lu unknown", |
| 3452 | /* 1*/ "\011\000\002\002\002\004\002\006\004" |
| 3453 | "GDT HA %u, service %u, async. status %u/%lu unknown", |
| 3454 | /* 2*/ "\005\000\002\006\004" |
| 3455 | "GDT HA %u, Host Drive %lu not ready", |
| 3456 | /* 3*/ "\005\000\002\006\004" |
| 3457 | "GDT HA %u, Host Drive %lu: REASSIGN not successful and/or data error on reassigned blocks. Drive may crash in the future and should be replaced", |
| 3458 | /* 4*/ "\005\000\002\006\004" |
| 3459 | "GDT HA %u, mirror update on Host Drive %lu failed", |
| 3460 | /* 5*/ "\005\000\002\006\004" |
| 3461 | "GDT HA %u, Mirror Drive %lu failed", |
| 3462 | /* 6*/ "\005\000\002\006\004" |
| 3463 | "GDT HA %u, Mirror Drive %lu: REASSIGN not successful and/or data error on reassigned blocks. Drive may crash in the future and should be replaced", |
| 3464 | /* 7*/ "\005\000\002\006\004" |
| 3465 | "GDT HA %u, Host Drive %lu write protected", |
| 3466 | /* 8*/ "\005\000\002\006\004" |
| 3467 | "GDT HA %u, media changed in Host Drive %lu", |
| 3468 | /* 9*/ "\005\000\002\006\004" |
| 3469 | "GDT HA %u, Host Drive %lu is offline", |
| 3470 | /*10*/ "\005\000\002\006\004" |
| 3471 | "GDT HA %u, media change of Mirror Drive %lu", |
| 3472 | /*11*/ "\005\000\002\006\004" |
| 3473 | "GDT HA %u, Mirror Drive %lu is write protected", |
| 3474 | /*12*/ "\005\000\002\006\004" |
| 3475 | "GDT HA %u, general error on Host Drive %lu. Please check the devices of this drive!", |
| 3476 | /*13*/ "\007\000\002\006\002\010\002" |
| 3477 | "GDT HA %u, Array Drive %u: Cache Drive %u failed", |
| 3478 | /*14*/ "\005\000\002\006\002" |
| 3479 | "GDT HA %u, Array Drive %u: FAIL state entered", |
| 3480 | /*15*/ "\005\000\002\006\002" |
| 3481 | "GDT HA %u, Array Drive %u: error", |
| 3482 | /*16*/ "\007\000\002\006\002\010\002" |
| 3483 | "GDT HA %u, Array Drive %u: failed drive replaced by Cache Drive %u", |
| 3484 | /*17*/ "\005\000\002\006\002" |
| 3485 | "GDT HA %u, Array Drive %u: parity build failed", |
| 3486 | /*18*/ "\005\000\002\006\002" |
| 3487 | "GDT HA %u, Array Drive %u: drive rebuild failed", |
| 3488 | /*19*/ "\005\000\002\010\002" |
| 3489 | "GDT HA %u, Test of Hot Fix %u failed", |
| 3490 | /*20*/ "\005\000\002\006\002" |
| 3491 | "GDT HA %u, Array Drive %u: drive build finished successfully", |
| 3492 | /*21*/ "\005\000\002\006\002" |
| 3493 | "GDT HA %u, Array Drive %u: drive rebuild finished successfully", |
| 3494 | /*22*/ "\007\000\002\006\002\010\002" |
| 3495 | "GDT HA %u, Array Drive %u: Hot Fix %u activated", |
| 3496 | /*23*/ "\005\000\002\006\002" |
| 3497 | "GDT HA %u, Host Drive %u: processing of i/o aborted due to serious drive error", |
| 3498 | /*24*/ "\005\000\002\010\002" |
| 3499 | "GDT HA %u, mirror update on Cache Drive %u completed", |
| 3500 | /*25*/ "\005\000\002\010\002" |
| 3501 | "GDT HA %u, mirror update on Cache Drive %lu failed", |
| 3502 | /*26*/ "\005\000\002\006\002" |
| 3503 | "GDT HA %u, Array Drive %u: drive rebuild started", |
| 3504 | /*27*/ "\005\000\002\012\001" |
| 3505 | "GDT HA %u, Fault bus %u: SHELF OK detected", |
| 3506 | /*28*/ "\005\000\002\012\001" |
| 3507 | "GDT HA %u, Fault bus %u: SHELF not OK detected", |
| 3508 | /*29*/ "\007\000\002\012\001\013\001" |
| 3509 | "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug started", |
| 3510 | /*30*/ "\007\000\002\012\001\013\001" |
| 3511 | "GDT HA %u, Fault bus %u, ID %u: new disk detected", |
| 3512 | /*31*/ "\007\000\002\012\001\013\001" |
| 3513 | "GDT HA %u, Fault bus %u, ID %u: old disk detected", |
| 3514 | /*32*/ "\007\000\002\012\001\013\001" |
| 3515 | "GDT HA %u, Fault bus %u, ID %u: plugging an active disk is invalid", |
| 3516 | /*33*/ "\007\000\002\012\001\013\001" |
| 3517 | "GDT HA %u, Fault bus %u, ID %u: invalid device detected", |
| 3518 | /*34*/ "\011\000\002\012\001\013\001\006\004" |
| 3519 | "GDT HA %u, Fault bus %u, ID %u: insufficient disk capacity (%lu MB required)", |
| 3520 | /*35*/ "\007\000\002\012\001\013\001" |
| 3521 | "GDT HA %u, Fault bus %u, ID %u: disk write protected", |
| 3522 | /*36*/ "\007\000\002\012\001\013\001" |
| 3523 | "GDT HA %u, Fault bus %u, ID %u: disk not available", |
| 3524 | /*37*/ "\007\000\002\012\001\006\004" |
| 3525 | "GDT HA %u, Fault bus %u: swap detected (%lu)", |
| 3526 | /*38*/ "\007\000\002\012\001\013\001" |
| 3527 | "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug finished successfully", |
| 3528 | /*39*/ "\007\000\002\012\001\013\001" |
| 3529 | "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug aborted due to user Hot Plug", |
| 3530 | /*40*/ "\007\000\002\012\001\013\001" |
| 3531 | "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug aborted", |
| 3532 | /*41*/ "\007\000\002\012\001\013\001" |
| 3533 | "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug for Hot Fix started", |
| 3534 | /*42*/ "\005\000\002\006\002" |
| 3535 | "GDT HA %u, Array Drive %u: drive build started", |
| 3536 | /*43*/ "\003\000\002" |
| 3537 | "GDT HA %u, DRAM parity error detected", |
| 3538 | /*44*/ "\005\000\002\006\002" |
| 3539 | "GDT HA %u, Mirror Drive %u: update started", |
| 3540 | /*45*/ "\007\000\002\006\002\010\002" |
| 3541 | "GDT HA %u, Mirror Drive %u: Hot Fix %u activated", |
| 3542 | /*46*/ "\005\000\002\006\002" |
| 3543 | "GDT HA %u, Array Drive %u: no matching Pool Hot Fix Drive available", |
| 3544 | /*47*/ "\005\000\002\006\002" |
| 3545 | "GDT HA %u, Array Drive %u: Pool Hot Fix Drive available", |
| 3546 | /*48*/ "\005\000\002\006\002" |
| 3547 | "GDT HA %u, Mirror Drive %u: no matching Pool Hot Fix Drive available", |
| 3548 | /*49*/ "\005\000\002\006\002" |
| 3549 | "GDT HA %u, Mirror Drive %u: Pool Hot Fix Drive available", |
| 3550 | /*50*/ "\007\000\002\012\001\013\001" |
| 3551 | "GDT HA %u, SCSI bus %u, ID %u: IGNORE_WIDE_RESIDUE message received", |
| 3552 | /*51*/ "\005\000\002\006\002" |
| 3553 | "GDT HA %u, Array Drive %u: expand started", |
| 3554 | /*52*/ "\005\000\002\006\002" |
| 3555 | "GDT HA %u, Array Drive %u: expand finished successfully", |
| 3556 | /*53*/ "\005\000\002\006\002" |
| 3557 | "GDT HA %u, Array Drive %u: expand failed", |
| 3558 | /*54*/ "\003\000\002" |
| 3559 | "GDT HA %u, CPU temperature critical", |
| 3560 | /*55*/ "\003\000\002" |
| 3561 | "GDT HA %u, CPU temperature OK", |
| 3562 | /*56*/ "\005\000\002\006\004" |
| 3563 | "GDT HA %u, Host drive %lu created", |
| 3564 | /*57*/ "\005\000\002\006\002" |
| 3565 | "GDT HA %u, Array Drive %u: expand restarted", |
| 3566 | /*58*/ "\005\000\002\006\002" |
| 3567 | "GDT HA %u, Array Drive %u: expand stopped", |
| 3568 | /*59*/ "\005\000\002\010\002" |
| 3569 | "GDT HA %u, Mirror Drive %u: drive build quited", |
| 3570 | /*60*/ "\005\000\002\006\002" |
| 3571 | "GDT HA %u, Array Drive %u: parity build quited", |
| 3572 | /*61*/ "\005\000\002\006\002" |
| 3573 | "GDT HA %u, Array Drive %u: drive rebuild quited", |
| 3574 | /*62*/ "\005\000\002\006\002" |
| 3575 | "GDT HA %u, Array Drive %u: parity verify started", |
| 3576 | /*63*/ "\005\000\002\006\002" |
| 3577 | "GDT HA %u, Array Drive %u: parity verify done", |
| 3578 | /*64*/ "\005\000\002\006\002" |
| 3579 | "GDT HA %u, Array Drive %u: parity verify failed", |
| 3580 | /*65*/ "\005\000\002\006\002" |
| 3581 | "GDT HA %u, Array Drive %u: parity error detected", |
| 3582 | /*66*/ "\005\000\002\006\002" |
| 3583 | "GDT HA %u, Array Drive %u: parity verify quited", |
| 3584 | /*67*/ "\005\000\002\006\002" |
| 3585 | "GDT HA %u, Host Drive %u reserved", |
| 3586 | /*68*/ "\005\000\002\006\002" |
| 3587 | "GDT HA %u, Host Drive %u mounted and released", |
| 3588 | /*69*/ "\005\000\002\006\002" |
| 3589 | "GDT HA %u, Host Drive %u released", |
| 3590 | /*70*/ "\003\000\002" |
| 3591 | "GDT HA %u, DRAM error detected and corrected with ECC", |
| 3592 | /*71*/ "\003\000\002" |
| 3593 | "GDT HA %u, Uncorrectable DRAM error detected with ECC", |
| 3594 | /*72*/ "\011\000\002\012\001\013\001\014\001" |
| 3595 | "GDT HA %u, SCSI bus %u, ID %u, LUN %u: reassigning block", |
| 3596 | /*73*/ "\005\000\002\006\002" |
| 3597 | "GDT HA %u, Host drive %u resetted locally", |
| 3598 | /*74*/ "\005\000\002\006\002" |
| 3599 | "GDT HA %u, Host drive %u resetted remotely", |
| 3600 | /*75*/ "\003\000\002" |
| 3601 | "GDT HA %u, async. status 75 unknown", |
| 3602 | }; |
| 3603 | |
| 3604 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3605 | static int gdth_async_event(gdth_ha_str *ha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3606 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3607 | gdth_cmd_str *cmdp; |
| 3608 | int cmd_index; |
| 3609 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3610 | cmdp= ha->pccb; |
| 3611 | TRACE2(("gdth_async_event() ha %d serv %d\n", |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3612 | ha->hanum, ha->service)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3613 | |
| 3614 | if (ha->service == SCREENSERVICE) { |
| 3615 | if (ha->status == MSG_REQUEST) { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3616 | while (gdth_test_busy(ha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3617 | gdth_delay(0); |
| 3618 | cmdp->Service = SCREENSERVICE; |
| 3619 | cmdp->RequestBuffer = SCREEN_CMND; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3620 | cmd_index = gdth_get_cmd_index(ha); |
| 3621 | gdth_set_sema0(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3622 | cmdp->OpCode = GDT_READ; |
| 3623 | cmdp->BoardNode = LOCALBOARD; |
| 3624 | cmdp->u.screen.reserved = 0; |
| 3625 | cmdp->u.screen.su.msg.msg_handle= MSG_INV_HANDLE; |
| 3626 | cmdp->u.screen.su.msg.msg_addr = ha->msg_phys; |
| 3627 | ha->cmd_offs_dpmem = 0; |
| 3628 | ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr) |
| 3629 | + sizeof(ulong64); |
| 3630 | ha->cmd_cnt = 0; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3631 | gdth_copy_command(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3632 | if (ha->type == GDT_EISA) |
| 3633 | printk("[EISA slot %d] ",(ushort)ha->brd_phys); |
| 3634 | else if (ha->type == GDT_ISA) |
| 3635 | printk("[DPMEM 0x%4X] ",(ushort)ha->brd_phys); |
| 3636 | else |
| 3637 | printk("[PCI %d/%d] ",(ushort)(ha->brd_phys>>8), |
| 3638 | (ushort)((ha->brd_phys>>3)&0x1f)); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3639 | gdth_release_event(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3640 | } |
| 3641 | |
| 3642 | } else { |
| 3643 | if (ha->type == GDT_PCIMPR && |
| 3644 | (ha->fw_vers & 0xff) >= 0x1a) { |
| 3645 | ha->dvr.size = 0; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3646 | ha->dvr.eu.async.ionode = ha->hanum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3647 | ha->dvr.eu.async.status = ha->status; |
| 3648 | /* severity and event_string already set! */ |
| 3649 | } else { |
| 3650 | ha->dvr.size = sizeof(ha->dvr.eu.async); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3651 | ha->dvr.eu.async.ionode = ha->hanum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3652 | ha->dvr.eu.async.service = ha->service; |
| 3653 | ha->dvr.eu.async.status = ha->status; |
| 3654 | ha->dvr.eu.async.info = ha->info; |
| 3655 | *(ulong32 *)ha->dvr.eu.async.scsi_coord = ha->info2; |
| 3656 | } |
| 3657 | gdth_store_event( ha, ES_ASYNC, ha->service, &ha->dvr ); |
| 3658 | gdth_log_event( &ha->dvr, NULL ); |
| 3659 | |
| 3660 | /* new host drive from expand? */ |
| 3661 | if (ha->service == CACHESERVICE && ha->status == 56) { |
| 3662 | TRACE2(("gdth_async_event(): new host drive %d created\n", |
| 3663 | (ushort)ha->info)); |
| 3664 | /* gdth_analyse_hdrive(hanum, (ushort)ha->info); */ |
| 3665 | } |
| 3666 | } |
| 3667 | return 1; |
| 3668 | } |
| 3669 | |
| 3670 | static void gdth_log_event(gdth_evt_data *dvr, char *buffer) |
| 3671 | { |
| 3672 | gdth_stackframe stack; |
| 3673 | char *f = NULL; |
| 3674 | int i,j; |
| 3675 | |
| 3676 | TRACE2(("gdth_log_event()\n")); |
| 3677 | if (dvr->size == 0) { |
| 3678 | if (buffer == NULL) { |
| 3679 | printk("Adapter %d: %s\n",dvr->eu.async.ionode,dvr->event_string); |
| 3680 | } else { |
| 3681 | sprintf(buffer,"Adapter %d: %s\n", |
| 3682 | dvr->eu.async.ionode,dvr->event_string); |
| 3683 | } |
| 3684 | } else if (dvr->eu.async.service == CACHESERVICE && |
| 3685 | INDEX_OK(dvr->eu.async.status, async_cache_tab)) { |
| 3686 | TRACE2(("GDT: Async. event cache service, event no.: %d\n", |
| 3687 | dvr->eu.async.status)); |
| 3688 | |
| 3689 | f = async_cache_tab[dvr->eu.async.status]; |
| 3690 | |
| 3691 | /* i: parameter to push, j: stack element to fill */ |
| 3692 | for (j=0,i=1; i < f[0]; i+=2) { |
| 3693 | switch (f[i+1]) { |
| 3694 | case 4: |
| 3695 | stack.b[j++] = *(ulong32*)&dvr->eu.stream[(int)f[i]]; |
| 3696 | break; |
| 3697 | case 2: |
| 3698 | stack.b[j++] = *(ushort*)&dvr->eu.stream[(int)f[i]]; |
| 3699 | break; |
| 3700 | case 1: |
| 3701 | stack.b[j++] = *(unchar*)&dvr->eu.stream[(int)f[i]]; |
| 3702 | break; |
| 3703 | default: |
| 3704 | break; |
| 3705 | } |
| 3706 | } |
| 3707 | |
| 3708 | if (buffer == NULL) { |
| 3709 | printk(&f[(int)f[0]],stack); |
| 3710 | printk("\n"); |
| 3711 | } else { |
| 3712 | sprintf(buffer,&f[(int)f[0]],stack); |
| 3713 | } |
| 3714 | |
| 3715 | } else { |
| 3716 | if (buffer == NULL) { |
| 3717 | printk("GDT HA %u, Unknown async. event service %d event no. %d\n", |
| 3718 | dvr->eu.async.ionode,dvr->eu.async.service,dvr->eu.async.status); |
| 3719 | } else { |
| 3720 | sprintf(buffer,"GDT HA %u, Unknown async. event service %d event no. %d", |
| 3721 | dvr->eu.async.ionode,dvr->eu.async.service,dvr->eu.async.status); |
| 3722 | } |
| 3723 | } |
| 3724 | } |
| 3725 | |
| 3726 | #ifdef GDTH_STATISTICS |
James Bottomley | 2d6f0d0 | 2008-05-04 22:34:49 -0500 | [diff] [blame] | 3727 | static unchar gdth_timer_running; |
| 3728 | |
| 8e87904 | 2005-04-17 15:28:39 -0500 | [diff] [blame] | 3729 | static void gdth_timeout(ulong data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3730 | { |
| 3731 | ulong32 i; |
| 3732 | Scsi_Cmnd *nscp; |
| 3733 | gdth_ha_str *ha; |
| 3734 | ulong flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3735 | |
James Bottomley | 2d6f0d0 | 2008-05-04 22:34:49 -0500 | [diff] [blame] | 3736 | if(unlikely(list_empty(&gdth_instances))) { |
| 3737 | gdth_timer_running = 0; |
| 3738 | return; |
| 3739 | } |
Boaz Harrosh | b31ddd3 | 2008-02-27 15:27:16 -0800 | [diff] [blame] | 3740 | |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 3741 | ha = list_first_entry(&gdth_instances, gdth_ha_str, list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3742 | spin_lock_irqsave(&ha->smp_lock, flags); |
| 3743 | |
| 3744 | for (act_stats=0,i=0; i<GDTH_MAXCMDS; ++i) |
| 3745 | if (ha->cmd_tab[i].cmnd != UNUSED_CMND) |
| 3746 | ++act_stats; |
| 3747 | |
| 3748 | for (act_rq=0,nscp=ha->req_first; nscp; nscp=(Scsi_Cmnd*)nscp->SCp.ptr) |
| 3749 | ++act_rq; |
| 3750 | |
| 3751 | TRACE2(("gdth_to(): ints %d, ios %d, act_stats %d, act_rq %d\n", |
| 3752 | act_ints, act_ios, act_stats, act_rq)); |
| 3753 | act_ints = act_ios = 0; |
| 3754 | |
| 3755 | gdth_timer.expires = jiffies + 30 * HZ; |
| 3756 | add_timer(&gdth_timer); |
| 3757 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
| 3758 | } |
James Bottomley | 2d6f0d0 | 2008-05-04 22:34:49 -0500 | [diff] [blame] | 3759 | |
| 3760 | static void gdth_timer_init(void) |
| 3761 | { |
| 3762 | if (gdth_timer_running) |
| 3763 | return; |
| 3764 | gdth_timer_running = 1; |
| 3765 | TRACE2(("gdth_detect(): Initializing timer !\n")); |
| 3766 | gdth_timer.expires = jiffies + HZ; |
| 3767 | gdth_timer.data = 0L; |
| 3768 | gdth_timer.function = gdth_timeout; |
| 3769 | add_timer(&gdth_timer); |
| 3770 | } |
| 3771 | #else |
| 3772 | static inline void gdth_timer_init(void) |
| 3773 | { |
| 3774 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3775 | #endif |
| 3776 | |
| 8e87904 | 2005-04-17 15:28:39 -0500 | [diff] [blame] | 3777 | static void __init internal_setup(char *str,int *ints) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3778 | { |
| 3779 | int i, argc; |
| 3780 | char *cur_str, *argv; |
| 3781 | |
| 3782 | TRACE2(("internal_setup() str %s ints[0] %d\n", |
| 3783 | str ? str:"NULL", ints ? ints[0]:0)); |
| 3784 | |
| 3785 | /* read irq[] from ints[] */ |
| 3786 | if (ints) { |
| 3787 | argc = ints[0]; |
| 3788 | if (argc > 0) { |
| 3789 | if (argc > MAXHA) |
| 3790 | argc = MAXHA; |
| 3791 | for (i = 0; i < argc; ++i) |
| 3792 | irq[i] = ints[i+1]; |
| 3793 | } |
| 3794 | } |
| 3795 | |
| 3796 | /* analyse string */ |
| 3797 | argv = str; |
| 3798 | while (argv && (cur_str = strchr(argv, ':'))) { |
| 3799 | int val = 0, c = *++cur_str; |
| 3800 | |
| 3801 | if (c == 'n' || c == 'N') |
| 3802 | val = 0; |
| 3803 | else if (c == 'y' || c == 'Y') |
| 3804 | val = 1; |
| 3805 | else |
| 3806 | val = (int)simple_strtoul(cur_str, NULL, 0); |
| 3807 | |
| 3808 | if (!strncmp(argv, "disable:", 8)) |
| 3809 | disable = val; |
| 3810 | else if (!strncmp(argv, "reserve_mode:", 13)) |
| 3811 | reserve_mode = val; |
| 3812 | else if (!strncmp(argv, "reverse_scan:", 13)) |
| 3813 | reverse_scan = val; |
| 3814 | else if (!strncmp(argv, "hdr_channel:", 12)) |
| 3815 | hdr_channel = val; |
| 3816 | else if (!strncmp(argv, "max_ids:", 8)) |
| 3817 | max_ids = val; |
| 3818 | else if (!strncmp(argv, "rescan:", 7)) |
| 3819 | rescan = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3820 | else if (!strncmp(argv, "shared_access:", 14)) |
| 3821 | shared_access = val; |
| 3822 | else if (!strncmp(argv, "probe_eisa_isa:", 15)) |
| 3823 | probe_eisa_isa = val; |
| 3824 | else if (!strncmp(argv, "reserve_list:", 13)) { |
| 3825 | reserve_list[0] = val; |
| 3826 | for (i = 1; i < MAX_RES_ARGS; i++) { |
| 3827 | cur_str = strchr(cur_str, ','); |
| 3828 | if (!cur_str) |
| 3829 | break; |
| 3830 | if (!isdigit((int)*++cur_str)) { |
| 3831 | --cur_str; |
| 3832 | break; |
| 3833 | } |
| 3834 | reserve_list[i] = |
| 3835 | (int)simple_strtoul(cur_str, NULL, 0); |
| 3836 | } |
| 3837 | if (!cur_str) |
| 3838 | break; |
| 3839 | argv = ++cur_str; |
| 3840 | continue; |
| 3841 | } |
| 3842 | |
| 3843 | if ((argv = strchr(argv, ','))) |
| 3844 | ++argv; |
| 3845 | } |
| 3846 | } |
| 3847 | |
| 3848 | int __init option_setup(char *str) |
| 3849 | { |
| 3850 | int ints[MAXHA]; |
| 3851 | char *cur = str; |
| 3852 | int i = 1; |
| 3853 | |
| 3854 | TRACE2(("option_setup() str %s\n", str ? str:"NULL")); |
| 3855 | |
| 3856 | while (cur && isdigit(*cur) && i <= MAXHA) { |
| 3857 | ints[i++] = simple_strtoul(cur, NULL, 0); |
| 3858 | if ((cur = strchr(cur, ',')) != NULL) cur++; |
| 3859 | } |
| 3860 | |
| 3861 | ints[0] = i - 1; |
| 3862 | internal_setup(cur, ints); |
| 3863 | return 1; |
| 3864 | } |
| 3865 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3866 | static const char *gdth_ctr_name(gdth_ha_str *ha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3867 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3868 | TRACE2(("gdth_ctr_name()\n")); |
| 3869 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3870 | if (ha->type == GDT_EISA) { |
| 3871 | switch (ha->stype) { |
| 3872 | case GDT3_ID: |
| 3873 | return("GDT3000/3020"); |
| 3874 | case GDT3A_ID: |
| 3875 | return("GDT3000A/3020A/3050A"); |
| 3876 | case GDT3B_ID: |
| 3877 | return("GDT3000B/3010A"); |
| 3878 | } |
| 3879 | } else if (ha->type == GDT_ISA) { |
| 3880 | return("GDT2000/2020"); |
| 3881 | } else if (ha->type == GDT_PCI) { |
Jeff Garzik | 8e9a8a0 | 2007-07-17 05:25:17 -0400 | [diff] [blame] | 3882 | switch (ha->pdev->device) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3883 | case PCI_DEVICE_ID_VORTEX_GDT60x0: |
| 3884 | return("GDT6000/6020/6050"); |
| 3885 | case PCI_DEVICE_ID_VORTEX_GDT6000B: |
| 3886 | return("GDT6000B/6010"); |
| 3887 | } |
| 3888 | } |
| 3889 | /* new controllers (GDT_PCINEW, GDT_PCIMPR, ..) use board_info IOCTL! */ |
| 3890 | |
| 3891 | return(""); |
| 3892 | } |
| 3893 | |
| 8e87904 | 2005-04-17 15:28:39 -0500 | [diff] [blame] | 3894 | static const char *gdth_info(struct Scsi_Host *shp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3895 | { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3896 | gdth_ha_str *ha = shost_priv(shp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3897 | |
| 3898 | TRACE2(("gdth_info()\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3899 | return ((const char *)ha->binfo.type_string); |
| 3900 | } |
| 3901 | |
| 8e87904 | 2005-04-17 15:28:39 -0500 | [diff] [blame] | 3902 | static int gdth_eh_bus_reset(Scsi_Cmnd *scp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3903 | { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3904 | gdth_ha_str *ha = shost_priv(scp->device->host); |
| 3905 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3906 | ulong flags; |
| 3907 | Scsi_Cmnd *cmnd; |
| 3908 | unchar b; |
| 3909 | |
| 3910 | TRACE2(("gdth_eh_bus_reset()\n")); |
| 3911 | |
Christoph Hellwig | 52759e6 | 2007-10-02 22:59:53 +0200 | [diff] [blame] | 3912 | b = scp->device->channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3913 | |
| 3914 | /* clear command tab */ |
| 3915 | spin_lock_irqsave(&ha->smp_lock, flags); |
| 3916 | for (i = 0; i < GDTH_MAXCMDS; ++i) { |
| 3917 | cmnd = ha->cmd_tab[i].cmnd; |
| 3918 | if (!SPECIAL_SCP(cmnd) && cmnd->device->channel == b) |
| 3919 | ha->cmd_tab[i].cmnd = UNUSED_CMND; |
| 3920 | } |
| 3921 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
| 3922 | |
| 3923 | if (b == ha->virt_bus) { |
| 3924 | /* host drives */ |
| 3925 | for (i = 0; i < MAX_HDRIVES; ++i) { |
| 3926 | if (ha->hdr[i].present) { |
| 3927 | spin_lock_irqsave(&ha->smp_lock, flags); |
| 3928 | gdth_polling = TRUE; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3929 | while (gdth_test_busy(ha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3930 | gdth_delay(0); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3931 | if (gdth_internal_cmd(ha, CACHESERVICE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3932 | GDT_CLUST_RESET, i, 0, 0)) |
| 3933 | ha->hdr[i].cluster_type &= ~CLUSTER_RESERVED; |
| 3934 | gdth_polling = FALSE; |
| 3935 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
| 3936 | } |
| 3937 | } |
| 3938 | } else { |
| 3939 | /* raw devices */ |
| 3940 | spin_lock_irqsave(&ha->smp_lock, flags); |
| 3941 | for (i = 0; i < MAXID; ++i) |
| 3942 | ha->raw[BUS_L2P(ha,b)].io_cnt[i] = 0; |
| 3943 | gdth_polling = TRUE; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3944 | while (gdth_test_busy(ha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3945 | gdth_delay(0); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3946 | gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_RESET_BUS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3947 | BUS_L2P(ha,b), 0, 0); |
| 3948 | gdth_polling = FALSE; |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 3949 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3950 | } |
| 3951 | return SUCCESS; |
| 3952 | } |
| 3953 | |
| 8e87904 | 2005-04-17 15:28:39 -0500 | [diff] [blame] | 3954 | static int gdth_bios_param(struct scsi_device *sdev,struct block_device *bdev,sector_t cap,int *ip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3955 | { |
| 3956 | unchar b, t; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3957 | gdth_ha_str *ha = shost_priv(sdev->host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3958 | struct scsi_device *sd; |
| 3959 | unsigned capacity; |
| 3960 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3961 | sd = sdev; |
| 3962 | capacity = cap; |
Christoph Hellwig | 52759e6 | 2007-10-02 22:59:53 +0200 | [diff] [blame] | 3963 | b = sd->channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3964 | t = sd->id; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3965 | TRACE2(("gdth_bios_param() ha %d bus %d target %d\n", ha->hanum, b, t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3966 | |
| 3967 | if (b != ha->virt_bus || ha->hdr[t].heads == 0) { |
| 3968 | /* raw device or host drive without mapping information */ |
| 3969 | TRACE2(("Evaluate mapping\n")); |
| 3970 | gdth_eval_mapping(capacity,&ip[2],&ip[0],&ip[1]); |
| 3971 | } else { |
| 3972 | ip[0] = ha->hdr[t].heads; |
| 3973 | ip[1] = ha->hdr[t].secs; |
| 3974 | ip[2] = capacity / ip[0] / ip[1]; |
| 3975 | } |
| 3976 | |
| 3977 | TRACE2(("gdth_bios_param(): %d heads, %d secs, %d cyls\n", |
| 3978 | ip[0],ip[1],ip[2])); |
| 3979 | return 0; |
| 3980 | } |
| 3981 | |
| 3982 | |
Matthew Wilcox | b8bff2a | 2007-10-02 22:40:22 +0200 | [diff] [blame] | 3983 | static int gdth_queuecommand(struct scsi_cmnd *scp, |
| 3984 | void (*done)(struct scsi_cmnd *)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3985 | { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 3986 | gdth_ha_str *ha = shost_priv(scp->device->host); |
Boaz Harrosh | 3058d5d | 2007-10-02 23:14:39 +0200 | [diff] [blame] | 3987 | struct gdth_cmndinfo *cmndinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3988 | |
| 3989 | TRACE(("gdth_queuecommand() cmd 0x%x\n", scp->cmnd[0])); |
Boaz Harrosh | 3058d5d | 2007-10-02 23:14:39 +0200 | [diff] [blame] | 3990 | |
| 3991 | cmndinfo = gdth_get_cmndinfo(ha); |
| 3992 | BUG_ON(!cmndinfo); |
| 3993 | |
Matthew Wilcox | b8bff2a | 2007-10-02 22:40:22 +0200 | [diff] [blame] | 3994 | scp->scsi_done = done; |
Boaz Harrosh | 3058d5d | 2007-10-02 23:14:39 +0200 | [diff] [blame] | 3995 | gdth_update_timeout(scp, scp->timeout_per_command * 6); |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 3996 | cmndinfo->priority = DEFAULT_PRI; |
Boaz Harrosh | 3892d88 | 2007-10-02 23:18:03 +0200 | [diff] [blame] | 3997 | |
Boaz Harrosh | 3058d5d | 2007-10-02 23:14:39 +0200 | [diff] [blame] | 3998 | return __gdth_queuecommand(ha, scp, cmndinfo); |
| 3999 | } |
| 4000 | |
| 4001 | static int __gdth_queuecommand(gdth_ha_str *ha, struct scsi_cmnd *scp, |
| 4002 | struct gdth_cmndinfo *cmndinfo) |
| 4003 | { |
| 4004 | scp->host_scribble = (unsigned char *)cmndinfo; |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 4005 | cmndinfo->wait_for_completion = 1; |
| 4006 | cmndinfo->phase = -1; |
| 4007 | cmndinfo->OpCode = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4008 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4009 | #ifdef GDTH_STATISTICS |
| 4010 | ++act_ios; |
| 4011 | #endif |
| 4012 | |
Boaz Harrosh | f842b64 | 2007-10-02 23:16:01 +0200 | [diff] [blame] | 4013 | gdth_putq(ha, scp, cmndinfo->priority); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4014 | gdth_next(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4015 | return 0; |
| 4016 | } |
| 4017 | |
| 4018 | |
| 4019 | static int gdth_open(struct inode *inode, struct file *filep) |
| 4020 | { |
| 4021 | gdth_ha_str *ha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4022 | |
Jonathan Corbet | 46787b4 | 2008-05-15 16:09:48 -0600 | [diff] [blame] | 4023 | lock_kernel(); |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 4024 | list_for_each_entry(ha, &gdth_instances, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4025 | if (!ha->sdev) |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 4026 | ha->sdev = scsi_get_host_dev(ha->shost); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4027 | } |
Jonathan Corbet | 46787b4 | 2008-05-15 16:09:48 -0600 | [diff] [blame] | 4028 | unlock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4029 | |
| 4030 | TRACE(("gdth_open()\n")); |
| 4031 | return 0; |
| 4032 | } |
| 4033 | |
| 4034 | static int gdth_close(struct inode *inode, struct file *filep) |
| 4035 | { |
| 4036 | TRACE(("gdth_close()\n")); |
| 4037 | return 0; |
| 4038 | } |
| 4039 | |
| 4040 | static int ioc_event(void __user *arg) |
| 4041 | { |
| 4042 | gdth_ioctl_event evt; |
| 4043 | gdth_ha_str *ha; |
| 4044 | ulong flags; |
| 4045 | |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 4046 | if (copy_from_user(&evt, arg, sizeof(gdth_ioctl_event))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 | return -EFAULT; |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 4048 | ha = gdth_find_ha(evt.ionode); |
| 4049 | if (!ha) |
| 4050 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4051 | |
| 4052 | if (evt.erase == 0xff) { |
| 4053 | if (evt.event.event_source == ES_TEST) |
| 4054 | evt.event.event_data.size=sizeof(evt.event.event_data.eu.test); |
| 4055 | else if (evt.event.event_source == ES_DRIVER) |
| 4056 | evt.event.event_data.size=sizeof(evt.event.event_data.eu.driver); |
| 4057 | else if (evt.event.event_source == ES_SYNC) |
| 4058 | evt.event.event_data.size=sizeof(evt.event.event_data.eu.sync); |
| 4059 | else |
| 4060 | evt.event.event_data.size=sizeof(evt.event.event_data.eu.async); |
| 4061 | spin_lock_irqsave(&ha->smp_lock, flags); |
| 4062 | gdth_store_event(ha, evt.event.event_source, evt.event.event_idx, |
| 4063 | &evt.event.event_data); |
| 4064 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
| 4065 | } else if (evt.erase == 0xfe) { |
| 4066 | gdth_clear_events(); |
| 4067 | } else if (evt.erase == 0) { |
| 4068 | evt.handle = gdth_read_event(ha, evt.handle, &evt.event); |
| 4069 | } else { |
| 4070 | gdth_readapp_event(ha, evt.erase, &evt.event); |
| 4071 | } |
| 4072 | if (copy_to_user(arg, &evt, sizeof(gdth_ioctl_event))) |
| 4073 | return -EFAULT; |
| 4074 | return 0; |
| 4075 | } |
| 4076 | |
| 4077 | static int ioc_lockdrv(void __user *arg) |
| 4078 | { |
| 4079 | gdth_ioctl_lockdrv ldrv; |
| 4080 | unchar i, j; |
| 4081 | ulong flags; |
| 4082 | gdth_ha_str *ha; |
| 4083 | |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 4084 | if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4085 | return -EFAULT; |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 4086 | ha = gdth_find_ha(ldrv.ionode); |
| 4087 | if (!ha) |
| 4088 | return -EFAULT; |
| 4089 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4090 | for (i = 0; i < ldrv.drive_cnt && i < MAX_HDRIVES; ++i) { |
| 4091 | j = ldrv.drives[i]; |
| 4092 | if (j >= MAX_HDRIVES || !ha->hdr[j].present) |
| 4093 | continue; |
| 4094 | if (ldrv.lock) { |
| 4095 | spin_lock_irqsave(&ha->smp_lock, flags); |
| 4096 | ha->hdr[j].lock = 1; |
| 4097 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4098 | gdth_wait_completion(ha, ha->bus_cnt, j); |
| 4099 | gdth_stop_timeout(ha, ha->bus_cnt, j); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4100 | } else { |
| 4101 | spin_lock_irqsave(&ha->smp_lock, flags); |
| 4102 | ha->hdr[j].lock = 0; |
| 4103 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4104 | gdth_start_timeout(ha, ha->bus_cnt, j); |
| 4105 | gdth_next(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4106 | } |
| 4107 | } |
| 4108 | return 0; |
| 4109 | } |
| 4110 | |
| 4111 | static int ioc_resetdrv(void __user *arg, char *cmnd) |
| 4112 | { |
| 4113 | gdth_ioctl_reset res; |
| 4114 | gdth_cmd_str cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4115 | gdth_ha_str *ha; |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 4116 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4117 | |
| 4118 | if (copy_from_user(&res, arg, sizeof(gdth_ioctl_reset)) || |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 4119 | res.number >= MAX_HDRIVES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4120 | return -EFAULT; |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 4121 | ha = gdth_find_ha(res.ionode); |
| 4122 | if (!ha) |
| 4123 | return -EFAULT; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4125 | if (!ha->hdr[res.number].present) |
| 4126 | return 0; |
| 4127 | memset(&cmd, 0, sizeof(gdth_cmd_str)); |
| 4128 | cmd.Service = CACHESERVICE; |
| 4129 | cmd.OpCode = GDT_CLUST_RESET; |
| 4130 | if (ha->cache_feat & GDT_64BIT) |
| 4131 | cmd.u.cache64.DeviceNo = res.number; |
| 4132 | else |
| 4133 | cmd.u.cache.DeviceNo = res.number; |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 4134 | |
| 4135 | rval = __gdth_execute(ha->sdev, &cmd, cmnd, 30, NULL); |
| 4136 | if (rval < 0) |
| 4137 | return rval; |
| 4138 | res.status = rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4139 | |
| 4140 | if (copy_to_user(arg, &res, sizeof(gdth_ioctl_reset))) |
| 4141 | return -EFAULT; |
| 4142 | return 0; |
| 4143 | } |
| 4144 | |
| 4145 | static int ioc_general(void __user *arg, char *cmnd) |
| 4146 | { |
| 4147 | gdth_ioctl_general gen; |
| 4148 | char *buf = NULL; |
| 4149 | ulong64 paddr; |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 4150 | gdth_ha_str *ha; |
| 4151 | int rval; |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 4152 | |
| 4153 | if (copy_from_user(&gen, arg, sizeof(gdth_ioctl_general))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4154 | return -EFAULT; |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 4155 | ha = gdth_find_ha(gen.ionode); |
| 4156 | if (!ha) |
| 4157 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4158 | if (gen.data_len + gen.sense_len != 0) { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4159 | if (!(buf = gdth_ioctl_alloc(ha, gen.data_len + gen.sense_len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4160 | FALSE, &paddr))) |
| 4161 | return -EFAULT; |
| 4162 | if (copy_from_user(buf, arg + sizeof(gdth_ioctl_general), |
| 4163 | gen.data_len + gen.sense_len)) { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4164 | gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4165 | return -EFAULT; |
| 4166 | } |
| 4167 | |
| 4168 | if (gen.command.OpCode == GDT_IOCTL) { |
| 4169 | gen.command.u.ioctl.p_param = paddr; |
| 4170 | } else if (gen.command.Service == CACHESERVICE) { |
| 4171 | if (ha->cache_feat & GDT_64BIT) { |
| 4172 | /* copy elements from 32-bit IOCTL structure */ |
| 4173 | gen.command.u.cache64.BlockCnt = gen.command.u.cache.BlockCnt; |
| 4174 | gen.command.u.cache64.BlockNo = gen.command.u.cache.BlockNo; |
| 4175 | gen.command.u.cache64.DeviceNo = gen.command.u.cache.DeviceNo; |
| 4176 | /* addresses */ |
| 4177 | if (ha->cache_feat & SCATTER_GATHER) { |
| 4178 | gen.command.u.cache64.DestAddr = (ulong64)-1; |
| 4179 | gen.command.u.cache64.sg_canz = 1; |
| 4180 | gen.command.u.cache64.sg_lst[0].sg_ptr = paddr; |
| 4181 | gen.command.u.cache64.sg_lst[0].sg_len = gen.data_len; |
| 4182 | gen.command.u.cache64.sg_lst[1].sg_len = 0; |
| 4183 | } else { |
| 4184 | gen.command.u.cache64.DestAddr = paddr; |
| 4185 | gen.command.u.cache64.sg_canz = 0; |
| 4186 | } |
| 4187 | } else { |
| 4188 | if (ha->cache_feat & SCATTER_GATHER) { |
| 4189 | gen.command.u.cache.DestAddr = 0xffffffff; |
| 4190 | gen.command.u.cache.sg_canz = 1; |
| 4191 | gen.command.u.cache.sg_lst[0].sg_ptr = (ulong32)paddr; |
| 4192 | gen.command.u.cache.sg_lst[0].sg_len = gen.data_len; |
| 4193 | gen.command.u.cache.sg_lst[1].sg_len = 0; |
| 4194 | } else { |
| 4195 | gen.command.u.cache.DestAddr = paddr; |
| 4196 | gen.command.u.cache.sg_canz = 0; |
| 4197 | } |
| 4198 | } |
| 4199 | } else if (gen.command.Service == SCSIRAWSERVICE) { |
| 4200 | if (ha->raw_feat & GDT_64BIT) { |
| 4201 | /* copy elements from 32-bit IOCTL structure */ |
| 4202 | char cmd[16]; |
| 4203 | gen.command.u.raw64.sense_len = gen.command.u.raw.sense_len; |
| 4204 | gen.command.u.raw64.bus = gen.command.u.raw.bus; |
| 4205 | gen.command.u.raw64.lun = gen.command.u.raw.lun; |
| 4206 | gen.command.u.raw64.target = gen.command.u.raw.target; |
| 4207 | memcpy(cmd, gen.command.u.raw.cmd, 16); |
| 4208 | memcpy(gen.command.u.raw64.cmd, cmd, 16); |
| 4209 | gen.command.u.raw64.clen = gen.command.u.raw.clen; |
| 4210 | gen.command.u.raw64.sdlen = gen.command.u.raw.sdlen; |
| 4211 | gen.command.u.raw64.direction = gen.command.u.raw.direction; |
| 4212 | /* addresses */ |
| 4213 | if (ha->raw_feat & SCATTER_GATHER) { |
| 4214 | gen.command.u.raw64.sdata = (ulong64)-1; |
| 4215 | gen.command.u.raw64.sg_ranz = 1; |
| 4216 | gen.command.u.raw64.sg_lst[0].sg_ptr = paddr; |
| 4217 | gen.command.u.raw64.sg_lst[0].sg_len = gen.data_len; |
| 4218 | gen.command.u.raw64.sg_lst[1].sg_len = 0; |
| 4219 | } else { |
| 4220 | gen.command.u.raw64.sdata = paddr; |
| 4221 | gen.command.u.raw64.sg_ranz = 0; |
| 4222 | } |
| 4223 | gen.command.u.raw64.sense_data = paddr + gen.data_len; |
| 4224 | } else { |
| 4225 | if (ha->raw_feat & SCATTER_GATHER) { |
| 4226 | gen.command.u.raw.sdata = 0xffffffff; |
| 4227 | gen.command.u.raw.sg_ranz = 1; |
| 4228 | gen.command.u.raw.sg_lst[0].sg_ptr = (ulong32)paddr; |
| 4229 | gen.command.u.raw.sg_lst[0].sg_len = gen.data_len; |
| 4230 | gen.command.u.raw.sg_lst[1].sg_len = 0; |
| 4231 | } else { |
| 4232 | gen.command.u.raw.sdata = paddr; |
| 4233 | gen.command.u.raw.sg_ranz = 0; |
| 4234 | } |
| 4235 | gen.command.u.raw.sense_data = (ulong32)paddr + gen.data_len; |
| 4236 | } |
| 4237 | } else { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4238 | gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4239 | return -EFAULT; |
| 4240 | } |
| 4241 | } |
| 4242 | |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 4243 | rval = __gdth_execute(ha->sdev, &gen.command, cmnd, gen.timeout, &gen.info); |
| 4244 | if (rval < 0) |
| 4245 | return rval; |
| 4246 | gen.status = rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4247 | |
| 4248 | if (copy_to_user(arg + sizeof(gdth_ioctl_general), buf, |
| 4249 | gen.data_len + gen.sense_len)) { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4250 | gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4251 | return -EFAULT; |
| 4252 | } |
| 4253 | if (copy_to_user(arg, &gen, |
| 4254 | sizeof(gdth_ioctl_general) - sizeof(gdth_cmd_str))) { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4255 | gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4256 | return -EFAULT; |
| 4257 | } |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4258 | gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4259 | return 0; |
| 4260 | } |
| 4261 | |
| 4262 | static int ioc_hdrlist(void __user *arg, char *cmnd) |
| 4263 | { |
| 4264 | gdth_ioctl_rescan *rsc; |
| 4265 | gdth_cmd_str *cmd; |
| 4266 | gdth_ha_str *ha; |
| 4267 | unchar i; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4268 | int rc = -ENOMEM; |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 4269 | u32 cluster_type = 0; |
| 4270 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4271 | rsc = kmalloc(sizeof(*rsc), GFP_KERNEL); |
| 4272 | cmd = kmalloc(sizeof(*cmd), GFP_KERNEL); |
| 4273 | if (!rsc || !cmd) |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 4274 | goto free_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4275 | |
| 4276 | if (copy_from_user(rsc, arg, sizeof(gdth_ioctl_rescan)) || |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 4277 | (NULL == (ha = gdth_find_ha(rsc->ionode)))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4278 | rc = -EFAULT; |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 4279 | goto free_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4280 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4281 | memset(cmd, 0, sizeof(gdth_cmd_str)); |
| 4282 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4283 | for (i = 0; i < MAX_HDRIVES; ++i) { |
| 4284 | if (!ha->hdr[i].present) { |
| 4285 | rsc->hdr_list[i].bus = 0xff; |
| 4286 | continue; |
| 4287 | } |
| 4288 | rsc->hdr_list[i].bus = ha->virt_bus; |
| 4289 | rsc->hdr_list[i].target = i; |
| 4290 | rsc->hdr_list[i].lun = 0; |
| 4291 | rsc->hdr_list[i].cluster_type = ha->hdr[i].cluster_type; |
| 4292 | if (ha->hdr[i].cluster_type & CLUSTER_DRIVE) { |
| 4293 | cmd->Service = CACHESERVICE; |
| 4294 | cmd->OpCode = GDT_CLUST_INFO; |
| 4295 | if (ha->cache_feat & GDT_64BIT) |
| 4296 | cmd->u.cache64.DeviceNo = i; |
| 4297 | else |
| 4298 | cmd->u.cache.DeviceNo = i; |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 4299 | if (__gdth_execute(ha->sdev, cmd, cmnd, 30, &cluster_type) == S_OK) |
| 4300 | rsc->hdr_list[i].cluster_type = cluster_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4301 | } |
| 4302 | } |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 4303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4304 | if (copy_to_user(arg, rsc, sizeof(gdth_ioctl_rescan))) |
| 4305 | rc = -EFAULT; |
| 4306 | else |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 4307 | rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4308 | |
| 4309 | free_fail: |
| 4310 | kfree(rsc); |
| 4311 | kfree(cmd); |
| 4312 | return rc; |
| 4313 | } |
| 4314 | |
| 4315 | static int ioc_rescan(void __user *arg, char *cmnd) |
| 4316 | { |
| 4317 | gdth_ioctl_rescan *rsc; |
| 4318 | gdth_cmd_str *cmd; |
| 4319 | ushort i, status, hdr_cnt; |
| 4320 | ulong32 info; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4321 | int cyls, hds, secs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4322 | int rc = -ENOMEM; |
| 4323 | ulong flags; |
| 4324 | gdth_ha_str *ha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4325 | |
| 4326 | rsc = kmalloc(sizeof(*rsc), GFP_KERNEL); |
| 4327 | cmd = kmalloc(sizeof(*cmd), GFP_KERNEL); |
| 4328 | if (!cmd || !rsc) |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 4329 | goto free_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4330 | |
| 4331 | if (copy_from_user(rsc, arg, sizeof(gdth_ioctl_rescan)) || |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 4332 | (NULL == (ha = gdth_find_ha(rsc->ionode)))) { |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 4333 | rc = -EFAULT; |
| 4334 | goto free_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4335 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4336 | memset(cmd, 0, sizeof(gdth_cmd_str)); |
| 4337 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4338 | if (rsc->flag == 0) { |
| 4339 | /* old method: re-init. cache service */ |
| 4340 | cmd->Service = CACHESERVICE; |
| 4341 | if (ha->cache_feat & GDT_64BIT) { |
| 4342 | cmd->OpCode = GDT_X_INIT_HOST; |
| 4343 | cmd->u.cache64.DeviceNo = LINUX_OS; |
| 4344 | } else { |
| 4345 | cmd->OpCode = GDT_INIT; |
| 4346 | cmd->u.cache.DeviceNo = LINUX_OS; |
| 4347 | } |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 4348 | |
| 4349 | status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4350 | i = 0; |
| 4351 | hdr_cnt = (status == S_OK ? (ushort)info : 0); |
| 4352 | } else { |
| 4353 | i = rsc->hdr_no; |
| 4354 | hdr_cnt = i + 1; |
| 4355 | } |
| 4356 | |
| 4357 | for (; i < hdr_cnt && i < MAX_HDRIVES; ++i) { |
| 4358 | cmd->Service = CACHESERVICE; |
| 4359 | cmd->OpCode = GDT_INFO; |
| 4360 | if (ha->cache_feat & GDT_64BIT) |
| 4361 | cmd->u.cache64.DeviceNo = i; |
| 4362 | else |
| 4363 | cmd->u.cache.DeviceNo = i; |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 4364 | |
| 4365 | status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info); |
| 4366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4367 | spin_lock_irqsave(&ha->smp_lock, flags); |
| 4368 | rsc->hdr_list[i].bus = ha->virt_bus; |
| 4369 | rsc->hdr_list[i].target = i; |
| 4370 | rsc->hdr_list[i].lun = 0; |
| 4371 | if (status != S_OK) { |
| 4372 | ha->hdr[i].present = FALSE; |
| 4373 | } else { |
| 4374 | ha->hdr[i].present = TRUE; |
| 4375 | ha->hdr[i].size = info; |
| 4376 | /* evaluate mapping */ |
| 4377 | ha->hdr[i].size &= ~SECS32; |
| 4378 | gdth_eval_mapping(ha->hdr[i].size,&cyls,&hds,&secs); |
| 4379 | ha->hdr[i].heads = hds; |
| 4380 | ha->hdr[i].secs = secs; |
| 4381 | /* round size */ |
| 4382 | ha->hdr[i].size = cyls * hds * secs; |
| 4383 | } |
| 4384 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
| 4385 | if (status != S_OK) |
| 4386 | continue; |
| 4387 | |
| 4388 | /* extended info, if GDT_64BIT, for drives > 2 TB */ |
| 4389 | /* but we need ha->info2, not yet stored in scp->SCp */ |
| 4390 | |
| 4391 | /* devtype, cluster info, R/W attribs */ |
| 4392 | cmd->Service = CACHESERVICE; |
| 4393 | cmd->OpCode = GDT_DEVTYPE; |
| 4394 | if (ha->cache_feat & GDT_64BIT) |
| 4395 | cmd->u.cache64.DeviceNo = i; |
| 4396 | else |
| 4397 | cmd->u.cache.DeviceNo = i; |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 4398 | |
| 4399 | status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info); |
| 4400 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4401 | spin_lock_irqsave(&ha->smp_lock, flags); |
| 4402 | ha->hdr[i].devtype = (status == S_OK ? (ushort)info : 0); |
| 4403 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
| 4404 | |
| 4405 | cmd->Service = CACHESERVICE; |
| 4406 | cmd->OpCode = GDT_CLUST_INFO; |
| 4407 | if (ha->cache_feat & GDT_64BIT) |
| 4408 | cmd->u.cache64.DeviceNo = i; |
| 4409 | else |
| 4410 | cmd->u.cache.DeviceNo = i; |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 4411 | |
| 4412 | status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info); |
| 4413 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4414 | spin_lock_irqsave(&ha->smp_lock, flags); |
| 4415 | ha->hdr[i].cluster_type = |
| 4416 | ((status == S_OK && !shared_access) ? (ushort)info : 0); |
| 4417 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
| 4418 | rsc->hdr_list[i].cluster_type = ha->hdr[i].cluster_type; |
| 4419 | |
| 4420 | cmd->Service = CACHESERVICE; |
| 4421 | cmd->OpCode = GDT_RW_ATTRIBS; |
| 4422 | if (ha->cache_feat & GDT_64BIT) |
| 4423 | cmd->u.cache64.DeviceNo = i; |
| 4424 | else |
| 4425 | cmd->u.cache.DeviceNo = i; |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 4426 | |
| 4427 | status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info); |
| 4428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4429 | spin_lock_irqsave(&ha->smp_lock, flags); |
| 4430 | ha->hdr[i].rw_attribs = (status == S_OK ? (ushort)info : 0); |
| 4431 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
| 4432 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4433 | |
| 4434 | if (copy_to_user(arg, rsc, sizeof(gdth_ioctl_rescan))) |
| 4435 | rc = -EFAULT; |
| 4436 | else |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 4437 | rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4438 | |
| 4439 | free_fail: |
| 4440 | kfree(rsc); |
| 4441 | kfree(cmd); |
| 4442 | return rc; |
| 4443 | } |
| 4444 | |
| 4445 | static int gdth_ioctl(struct inode *inode, struct file *filep, |
| 4446 | unsigned int cmd, unsigned long arg) |
| 4447 | { |
| 4448 | gdth_ha_str *ha; |
| 4449 | Scsi_Cmnd *scp; |
| 4450 | ulong flags; |
| 4451 | char cmnd[MAX_COMMAND_SIZE]; |
| 4452 | void __user *argp = (void __user *)arg; |
| 4453 | |
| 4454 | memset(cmnd, 0xff, 12); |
| 4455 | |
| 4456 | TRACE(("gdth_ioctl() cmd 0x%x\n", cmd)); |
| 4457 | |
| 4458 | switch (cmd) { |
| 4459 | case GDTIOCTL_CTRCNT: |
| 4460 | { |
| 4461 | int cnt = gdth_ctr_count; |
| 4462 | if (put_user(cnt, (int __user *)argp)) |
| 4463 | return -EFAULT; |
| 4464 | break; |
| 4465 | } |
| 4466 | |
| 4467 | case GDTIOCTL_DRVERS: |
| 4468 | { |
| 4469 | int ver = (GDTH_VERSION<<8) | GDTH_SUBVERSION; |
| 4470 | if (put_user(ver, (int __user *)argp)) |
| 4471 | return -EFAULT; |
| 4472 | break; |
| 4473 | } |
| 4474 | |
| 4475 | case GDTIOCTL_OSVERS: |
| 4476 | { |
| 4477 | gdth_ioctl_osvers osv; |
| 4478 | |
| 4479 | osv.version = (unchar)(LINUX_VERSION_CODE >> 16); |
| 4480 | osv.subversion = (unchar)(LINUX_VERSION_CODE >> 8); |
| 4481 | osv.revision = (ushort)(LINUX_VERSION_CODE & 0xff); |
| 4482 | if (copy_to_user(argp, &osv, sizeof(gdth_ioctl_osvers))) |
| 4483 | return -EFAULT; |
| 4484 | break; |
| 4485 | } |
| 4486 | |
| 4487 | case GDTIOCTL_CTRTYPE: |
| 4488 | { |
| 4489 | gdth_ioctl_ctrtype ctrt; |
| 4490 | |
| 4491 | if (copy_from_user(&ctrt, argp, sizeof(gdth_ioctl_ctrtype)) || |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 4492 | (NULL == (ha = gdth_find_ha(ctrt.ionode)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4493 | return -EFAULT; |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 4494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4495 | if (ha->type == GDT_ISA || ha->type == GDT_EISA) { |
| 4496 | ctrt.type = (unchar)((ha->stype>>20) - 0x10); |
| 4497 | } else { |
| 4498 | if (ha->type != GDT_PCIMPR) { |
| 4499 | ctrt.type = (unchar)((ha->stype<<4) + 6); |
| 4500 | } else { |
| 4501 | ctrt.type = |
| 4502 | (ha->oem_id == OEM_ID_INTEL ? 0xfd : 0xfe); |
| 4503 | if (ha->stype >= 0x300) |
Jeff Garzik | 8e9a8a0 | 2007-07-17 05:25:17 -0400 | [diff] [blame] | 4504 | ctrt.ext_type = 0x6000 | ha->pdev->subsystem_device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4505 | else |
| 4506 | ctrt.ext_type = 0x6000 | ha->stype; |
| 4507 | } |
Jeff Garzik | 8e9a8a0 | 2007-07-17 05:25:17 -0400 | [diff] [blame] | 4508 | ctrt.device_id = ha->pdev->device; |
| 4509 | ctrt.sub_device_id = ha->pdev->subsystem_device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4510 | } |
| 4511 | ctrt.info = ha->brd_phys; |
| 4512 | ctrt.oem_id = ha->oem_id; |
| 4513 | if (copy_to_user(argp, &ctrt, sizeof(gdth_ioctl_ctrtype))) |
| 4514 | return -EFAULT; |
| 4515 | break; |
| 4516 | } |
| 4517 | |
| 4518 | case GDTIOCTL_GENERAL: |
| 4519 | return ioc_general(argp, cmnd); |
| 4520 | |
| 4521 | case GDTIOCTL_EVENT: |
| 4522 | return ioc_event(argp); |
| 4523 | |
| 4524 | case GDTIOCTL_LOCKDRV: |
| 4525 | return ioc_lockdrv(argp); |
| 4526 | |
| 4527 | case GDTIOCTL_LOCKCHN: |
| 4528 | { |
| 4529 | gdth_ioctl_lockchn lchn; |
| 4530 | unchar i, j; |
| 4531 | |
| 4532 | if (copy_from_user(&lchn, argp, sizeof(gdth_ioctl_lockchn)) || |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 4533 | (NULL == (ha = gdth_find_ha(lchn.ionode)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4534 | return -EFAULT; |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 4535 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4536 | i = lchn.channel; |
| 4537 | if (i < ha->bus_cnt) { |
| 4538 | if (lchn.lock) { |
| 4539 | spin_lock_irqsave(&ha->smp_lock, flags); |
| 4540 | ha->raw[i].lock = 1; |
| 4541 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
| 4542 | for (j = 0; j < ha->tid_cnt; ++j) { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4543 | gdth_wait_completion(ha, i, j); |
| 4544 | gdth_stop_timeout(ha, i, j); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4545 | } |
| 4546 | } else { |
| 4547 | spin_lock_irqsave(&ha->smp_lock, flags); |
| 4548 | ha->raw[i].lock = 0; |
| 4549 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
| 4550 | for (j = 0; j < ha->tid_cnt; ++j) { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4551 | gdth_start_timeout(ha, i, j); |
| 4552 | gdth_next(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4553 | } |
| 4554 | } |
| 4555 | } |
| 4556 | break; |
| 4557 | } |
| 4558 | |
| 4559 | case GDTIOCTL_RESCAN: |
| 4560 | return ioc_rescan(argp, cmnd); |
| 4561 | |
| 4562 | case GDTIOCTL_HDRLIST: |
| 4563 | return ioc_hdrlist(argp, cmnd); |
| 4564 | |
| 4565 | case GDTIOCTL_RESET_BUS: |
| 4566 | { |
| 4567 | gdth_ioctl_reset res; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4568 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4569 | |
| 4570 | if (copy_from_user(&res, argp, sizeof(gdth_ioctl_reset)) || |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 4571 | (NULL == (ha = gdth_find_ha(res.ionode)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4572 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4573 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 4574 | scp = kzalloc(sizeof(*scp), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4575 | if (!scp) |
| 4576 | return -ENOMEM; |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 4577 | scp->device = ha->sdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4578 | scp->cmd_len = 12; |
Christoph Hellwig | 52759e6 | 2007-10-02 22:59:53 +0200 | [diff] [blame] | 4579 | scp->device->channel = res.number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4580 | rval = gdth_eh_bus_reset(scp); |
| 4581 | res.status = (rval == SUCCESS ? S_OK : S_GENERR); |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 4582 | kfree(scp); |
Jeff Garzik | 8d7a5da | 2007-10-02 22:54:28 +0200 | [diff] [blame] | 4583 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4584 | if (copy_to_user(argp, &res, sizeof(gdth_ioctl_reset))) |
| 4585 | return -EFAULT; |
| 4586 | break; |
| 4587 | } |
| 4588 | |
| 4589 | case GDTIOCTL_RESET_DRV: |
| 4590 | return ioc_resetdrv(argp, cmnd); |
| 4591 | |
| 4592 | default: |
| 4593 | break; |
| 4594 | } |
| 4595 | return 0; |
| 4596 | } |
| 4597 | |
| 4598 | |
| 4599 | /* flush routine */ |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4600 | static void gdth_flush(gdth_ha_str *ha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4601 | { |
| 4602 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4603 | gdth_cmd_str gdtcmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4604 | char cmnd[MAX_COMMAND_SIZE]; |
| 4605 | memset(cmnd, 0xff, MAX_COMMAND_SIZE); |
| 4606 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4607 | TRACE2(("gdth_flush() hanum %d\n", ha->hanum)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4608 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4609 | for (i = 0; i < MAX_HDRIVES; ++i) { |
| 4610 | if (ha->hdr[i].present) { |
| 4611 | gdtcmd.BoardNode = LOCALBOARD; |
| 4612 | gdtcmd.Service = CACHESERVICE; |
| 4613 | gdtcmd.OpCode = GDT_FLUSH; |
| 4614 | if (ha->cache_feat & GDT_64BIT) { |
| 4615 | gdtcmd.u.cache64.DeviceNo = i; |
| 4616 | gdtcmd.u.cache64.BlockNo = 1; |
| 4617 | gdtcmd.u.cache64.sg_canz = 0; |
| 4618 | } else { |
| 4619 | gdtcmd.u.cache.DeviceNo = i; |
| 4620 | gdtcmd.u.cache.BlockNo = 1; |
| 4621 | gdtcmd.u.cache.sg_canz = 0; |
| 4622 | } |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4623 | TRACE2(("gdth_flush(): flush ha %d drive %d\n", ha->hanum, i)); |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 4624 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4625 | gdth_execute(ha->shost, &gdtcmd, cmnd, 30, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4626 | } |
| 4627 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4628 | } |
| 4629 | |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 4630 | /* configure lun */ |
| 4631 | static int gdth_slave_configure(struct scsi_device *sdev) |
| 4632 | { |
| 4633 | scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun); |
| 4634 | sdev->skip_ms_page_3f = 1; |
| 4635 | sdev->skip_ms_page_8 = 1; |
| 4636 | return 0; |
| 4637 | } |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 4638 | |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 4639 | static struct scsi_host_template gdth_template = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4640 | .name = "GDT SCSI Disk Array Controller", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4641 | .info = gdth_info, |
| 4642 | .queuecommand = gdth_queuecommand, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4643 | .eh_bus_reset_handler = gdth_eh_bus_reset, |
Leubner, Achim | cbd5f69 | 2006-06-09 11:34:29 -0700 | [diff] [blame] | 4644 | .slave_configure = gdth_slave_configure, |
Jeff Garzik | 69916b7 | 2007-10-02 22:57:58 +0200 | [diff] [blame] | 4645 | .bios_param = gdth_bios_param, |
| 4646 | .proc_info = gdth_proc_info, |
| 4647 | .proc_name = "gdth", |
| 4648 | .can_queue = GDTH_MAXCMDS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4649 | .this_id = -1, |
| 4650 | .sg_tablesize = GDTH_MAXSG, |
| 4651 | .cmd_per_lun = GDTH_MAXC_P_L, |
| 4652 | .unchecked_isa_dma = 1, |
| 4653 | .use_clustering = ENABLE_CLUSTERING, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4654 | }; |
| 4655 | |
Christoph Hellwig | aed91cb | 2007-10-02 22:48:16 +0200 | [diff] [blame] | 4656 | #ifdef CONFIG_ISA |
Adrian Bunk | 05dd7ed | 2007-10-18 12:51:05 +0200 | [diff] [blame] | 4657 | static int __init gdth_isa_probe_one(ulong32 isa_bios) |
Christoph Hellwig | aed91cb | 2007-10-02 22:48:16 +0200 | [diff] [blame] | 4658 | { |
| 4659 | struct Scsi_Host *shp; |
| 4660 | gdth_ha_str *ha; |
| 4661 | dma_addr_t scratch_dma_handle = 0; |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 4662 | int error, i; |
Christoph Hellwig | aed91cb | 2007-10-02 22:48:16 +0200 | [diff] [blame] | 4663 | |
| 4664 | if (!gdth_search_isa(isa_bios)) |
| 4665 | return -ENXIO; |
| 4666 | |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 4667 | shp = scsi_host_alloc(&gdth_template, sizeof(gdth_ha_str)); |
Christoph Hellwig | aed91cb | 2007-10-02 22:48:16 +0200 | [diff] [blame] | 4668 | if (!shp) |
| 4669 | return -ENOMEM; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4670 | ha = shost_priv(shp); |
Christoph Hellwig | aed91cb | 2007-10-02 22:48:16 +0200 | [diff] [blame] | 4671 | |
| 4672 | error = -ENODEV; |
| 4673 | if (!gdth_init_isa(isa_bios,ha)) |
| 4674 | goto out_host_put; |
| 4675 | |
| 4676 | /* controller found and initialized */ |
| 4677 | printk("Configuring GDT-ISA HA at BIOS 0x%05X IRQ %u DRQ %u\n", |
| 4678 | isa_bios, ha->irq, ha->drq); |
| 4679 | |
| 4680 | error = request_irq(ha->irq, gdth_interrupt, IRQF_DISABLED, "gdth", ha); |
| 4681 | if (error) { |
| 4682 | printk("GDT-ISA: Unable to allocate IRQ\n"); |
| 4683 | goto out_host_put; |
| 4684 | } |
| 4685 | |
| 4686 | error = request_dma(ha->drq, "gdth"); |
| 4687 | if (error) { |
| 4688 | printk("GDT-ISA: Unable to allocate DMA channel\n"); |
| 4689 | goto out_free_irq; |
| 4690 | } |
| 4691 | |
| 4692 | set_dma_mode(ha->drq,DMA_MODE_CASCADE); |
| 4693 | enable_dma(ha->drq); |
| 4694 | shp->unchecked_isa_dma = 1; |
| 4695 | shp->irq = ha->irq; |
| 4696 | shp->dma_channel = ha->drq; |
Christoph Hellwig | aed91cb | 2007-10-02 22:48:16 +0200 | [diff] [blame] | 4697 | |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 4698 | ha->hanum = gdth_ctr_count++; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4699 | ha->shost = shp; |
Christoph Hellwig | aed91cb | 2007-10-02 22:48:16 +0200 | [diff] [blame] | 4700 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4701 | ha->pccb = &ha->cmdext; |
Christoph Hellwig | aed91cb | 2007-10-02 22:48:16 +0200 | [diff] [blame] | 4702 | ha->ccb_phys = 0L; |
| 4703 | ha->pdev = NULL; |
| 4704 | |
| 4705 | error = -ENOMEM; |
| 4706 | |
| 4707 | ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH, |
| 4708 | &scratch_dma_handle); |
| 4709 | if (!ha->pscratch) |
| 4710 | goto out_dec_counters; |
| 4711 | ha->scratch_phys = scratch_dma_handle; |
| 4712 | |
| 4713 | ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str), |
| 4714 | &scratch_dma_handle); |
| 4715 | if (!ha->pmsg) |
| 4716 | goto out_free_pscratch; |
| 4717 | ha->msg_phys = scratch_dma_handle; |
| 4718 | |
| 4719 | #ifdef INT_COAL |
| 4720 | ha->coal_stat = pci_alloc_consistent(ha->pdev, |
| 4721 | sizeof(gdth_coal_status) * MAXOFFSETS, |
| 4722 | &scratch_dma_handle); |
| 4723 | if (!ha->coal_stat) |
| 4724 | goto out_free_pmsg; |
| 4725 | ha->coal_stat_phys = scratch_dma_handle; |
| 4726 | #endif |
| 4727 | |
| 4728 | ha->scratch_busy = FALSE; |
| 4729 | ha->req_first = NULL; |
| 4730 | ha->tid_cnt = MAX_HDRIVES; |
| 4731 | if (max_ids > 0 && max_ids < ha->tid_cnt) |
| 4732 | ha->tid_cnt = max_ids; |
| 4733 | for (i = 0; i < GDTH_MAXCMDS; ++i) |
| 4734 | ha->cmd_tab[i].cmnd = UNUSED_CMND; |
| 4735 | ha->scan_mode = rescan ? 0x10 : 0; |
| 4736 | |
| 4737 | error = -ENODEV; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4738 | if (!gdth_search_drives(ha)) { |
Christoph Hellwig | aed91cb | 2007-10-02 22:48:16 +0200 | [diff] [blame] | 4739 | printk("GDT-ISA: Error during device scan\n"); |
| 4740 | goto out_free_coal_stat; |
| 4741 | } |
| 4742 | |
| 4743 | if (hdr_channel < 0 || hdr_channel > ha->bus_cnt) |
| 4744 | hdr_channel = ha->bus_cnt; |
| 4745 | ha->virt_bus = hdr_channel; |
| 4746 | |
| 4747 | if (ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT) |
| 4748 | shp->max_cmd_len = 16; |
| 4749 | |
| 4750 | shp->max_id = ha->tid_cnt; |
| 4751 | shp->max_lun = MAXLUN; |
Christoph Hellwig | 52759e6 | 2007-10-02 22:59:53 +0200 | [diff] [blame] | 4752 | shp->max_channel = ha->bus_cnt; |
Christoph Hellwig | aed91cb | 2007-10-02 22:48:16 +0200 | [diff] [blame] | 4753 | |
| 4754 | spin_lock_init(&ha->smp_lock); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4755 | gdth_enable_int(ha); |
Christoph Hellwig | aed91cb | 2007-10-02 22:48:16 +0200 | [diff] [blame] | 4756 | |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 4757 | error = scsi_add_host(shp, NULL); |
| 4758 | if (error) |
| 4759 | goto out_free_coal_stat; |
| 4760 | list_add_tail(&ha->list, &gdth_instances); |
James Bottomley | 2d6f0d0 | 2008-05-04 22:34:49 -0500 | [diff] [blame] | 4761 | gdth_timer_init(); |
Boaz Harrosh | 61c9281 | 2008-02-12 19:35:22 +0200 | [diff] [blame] | 4762 | |
| 4763 | scsi_scan_host(shp); |
| 4764 | |
Christoph Hellwig | aed91cb | 2007-10-02 22:48:16 +0200 | [diff] [blame] | 4765 | return 0; |
| 4766 | |
| 4767 | out_free_coal_stat: |
| 4768 | #ifdef INT_COAL |
| 4769 | pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) * MAXOFFSETS, |
| 4770 | ha->coal_stat, ha->coal_stat_phys); |
| 4771 | out_free_pmsg: |
| 4772 | #endif |
| 4773 | pci_free_consistent(ha->pdev, sizeof(gdth_msg_str), |
| 4774 | ha->pmsg, ha->msg_phys); |
| 4775 | out_free_pscratch: |
| 4776 | pci_free_consistent(ha->pdev, GDTH_SCRATCH, |
| 4777 | ha->pscratch, ha->scratch_phys); |
| 4778 | out_dec_counters: |
| 4779 | gdth_ctr_count--; |
Christoph Hellwig | aed91cb | 2007-10-02 22:48:16 +0200 | [diff] [blame] | 4780 | out_free_irq: |
| 4781 | free_irq(ha->irq, ha); |
| 4782 | out_host_put: |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 4783 | scsi_host_put(shp); |
Christoph Hellwig | aed91cb | 2007-10-02 22:48:16 +0200 | [diff] [blame] | 4784 | return error; |
| 4785 | } |
| 4786 | #endif /* CONFIG_ISA */ |
| 4787 | |
Christoph Hellwig | 706a5d4 | 2007-10-02 22:49:35 +0200 | [diff] [blame] | 4788 | #ifdef CONFIG_EISA |
Adrian Bunk | 05dd7ed | 2007-10-18 12:51:05 +0200 | [diff] [blame] | 4789 | static int __init gdth_eisa_probe_one(ushort eisa_slot) |
Christoph Hellwig | 706a5d4 | 2007-10-02 22:49:35 +0200 | [diff] [blame] | 4790 | { |
| 4791 | struct Scsi_Host *shp; |
| 4792 | gdth_ha_str *ha; |
| 4793 | dma_addr_t scratch_dma_handle = 0; |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 4794 | int error, i; |
Christoph Hellwig | 706a5d4 | 2007-10-02 22:49:35 +0200 | [diff] [blame] | 4795 | |
| 4796 | if (!gdth_search_eisa(eisa_slot)) |
| 4797 | return -ENXIO; |
| 4798 | |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 4799 | shp = scsi_host_alloc(&gdth_template, sizeof(gdth_ha_str)); |
Christoph Hellwig | 706a5d4 | 2007-10-02 22:49:35 +0200 | [diff] [blame] | 4800 | if (!shp) |
| 4801 | return -ENOMEM; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4802 | ha = shost_priv(shp); |
Christoph Hellwig | 706a5d4 | 2007-10-02 22:49:35 +0200 | [diff] [blame] | 4803 | |
| 4804 | error = -ENODEV; |
| 4805 | if (!gdth_init_eisa(eisa_slot,ha)) |
| 4806 | goto out_host_put; |
| 4807 | |
| 4808 | /* controller found and initialized */ |
| 4809 | printk("Configuring GDT-EISA HA at Slot %d IRQ %u\n", |
| 4810 | eisa_slot >> 12, ha->irq); |
| 4811 | |
| 4812 | error = request_irq(ha->irq, gdth_interrupt, IRQF_DISABLED, "gdth", ha); |
| 4813 | if (error) { |
| 4814 | printk("GDT-EISA: Unable to allocate IRQ\n"); |
| 4815 | goto out_host_put; |
| 4816 | } |
| 4817 | |
| 4818 | shp->unchecked_isa_dma = 0; |
| 4819 | shp->irq = ha->irq; |
| 4820 | shp->dma_channel = 0xff; |
Christoph Hellwig | 706a5d4 | 2007-10-02 22:49:35 +0200 | [diff] [blame] | 4821 | |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 4822 | ha->hanum = gdth_ctr_count++; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4823 | ha->shost = shp; |
Christoph Hellwig | 706a5d4 | 2007-10-02 22:49:35 +0200 | [diff] [blame] | 4824 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4825 | TRACE2(("EISA detect Bus 0: hanum %d\n", ha->hanum)); |
| 4826 | |
| 4827 | ha->pccb = &ha->cmdext; |
Christoph Hellwig | 706a5d4 | 2007-10-02 22:49:35 +0200 | [diff] [blame] | 4828 | ha->ccb_phys = 0L; |
| 4829 | |
| 4830 | error = -ENOMEM; |
| 4831 | |
| 4832 | ha->pdev = NULL; |
| 4833 | ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH, |
| 4834 | &scratch_dma_handle); |
| 4835 | if (!ha->pscratch) |
| 4836 | goto out_free_irq; |
| 4837 | ha->scratch_phys = scratch_dma_handle; |
| 4838 | |
| 4839 | ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str), |
| 4840 | &scratch_dma_handle); |
| 4841 | if (!ha->pmsg) |
| 4842 | goto out_free_pscratch; |
| 4843 | ha->msg_phys = scratch_dma_handle; |
| 4844 | |
| 4845 | #ifdef INT_COAL |
| 4846 | ha->coal_stat = pci_alloc_consistent(ha->pdev, |
| 4847 | sizeof(gdth_coal_status) * MAXOFFSETS, |
| 4848 | &scratch_dma_handle); |
| 4849 | if (!ha->coal_stat) |
| 4850 | goto out_free_pmsg; |
| 4851 | ha->coal_stat_phys = scratch_dma_handle; |
| 4852 | #endif |
| 4853 | |
| 4854 | ha->ccb_phys = pci_map_single(ha->pdev,ha->pccb, |
| 4855 | sizeof(gdth_cmd_str), PCI_DMA_BIDIRECTIONAL); |
| 4856 | if (!ha->ccb_phys) |
| 4857 | goto out_free_coal_stat; |
| 4858 | |
| 4859 | ha->scratch_busy = FALSE; |
| 4860 | ha->req_first = NULL; |
| 4861 | ha->tid_cnt = MAX_HDRIVES; |
| 4862 | if (max_ids > 0 && max_ids < ha->tid_cnt) |
| 4863 | ha->tid_cnt = max_ids; |
| 4864 | for (i = 0; i < GDTH_MAXCMDS; ++i) |
| 4865 | ha->cmd_tab[i].cmnd = UNUSED_CMND; |
| 4866 | ha->scan_mode = rescan ? 0x10 : 0; |
| 4867 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4868 | if (!gdth_search_drives(ha)) { |
Christoph Hellwig | 706a5d4 | 2007-10-02 22:49:35 +0200 | [diff] [blame] | 4869 | printk("GDT-EISA: Error during device scan\n"); |
| 4870 | error = -ENODEV; |
| 4871 | goto out_free_ccb_phys; |
| 4872 | } |
| 4873 | |
| 4874 | if (hdr_channel < 0 || hdr_channel > ha->bus_cnt) |
| 4875 | hdr_channel = ha->bus_cnt; |
| 4876 | ha->virt_bus = hdr_channel; |
| 4877 | |
| 4878 | if (ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT) |
| 4879 | shp->max_cmd_len = 16; |
| 4880 | |
| 4881 | shp->max_id = ha->tid_cnt; |
| 4882 | shp->max_lun = MAXLUN; |
Christoph Hellwig | 52759e6 | 2007-10-02 22:59:53 +0200 | [diff] [blame] | 4883 | shp->max_channel = ha->bus_cnt; |
Christoph Hellwig | 706a5d4 | 2007-10-02 22:49:35 +0200 | [diff] [blame] | 4884 | |
| 4885 | spin_lock_init(&ha->smp_lock); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4886 | gdth_enable_int(ha); |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 4887 | |
| 4888 | error = scsi_add_host(shp, NULL); |
| 4889 | if (error) |
| 4890 | goto out_free_coal_stat; |
| 4891 | list_add_tail(&ha->list, &gdth_instances); |
James Bottomley | 2d6f0d0 | 2008-05-04 22:34:49 -0500 | [diff] [blame] | 4892 | gdth_timer_init(); |
Boaz Harrosh | 61c9281 | 2008-02-12 19:35:22 +0200 | [diff] [blame] | 4893 | |
| 4894 | scsi_scan_host(shp); |
| 4895 | |
Christoph Hellwig | 706a5d4 | 2007-10-02 22:49:35 +0200 | [diff] [blame] | 4896 | return 0; |
| 4897 | |
| 4898 | out_free_ccb_phys: |
| 4899 | pci_unmap_single(ha->pdev,ha->ccb_phys, sizeof(gdth_cmd_str), |
| 4900 | PCI_DMA_BIDIRECTIONAL); |
| 4901 | out_free_coal_stat: |
| 4902 | #ifdef INT_COAL |
| 4903 | pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) * MAXOFFSETS, |
| 4904 | ha->coal_stat, ha->coal_stat_phys); |
| 4905 | out_free_pmsg: |
| 4906 | #endif |
| 4907 | pci_free_consistent(ha->pdev, sizeof(gdth_msg_str), |
| 4908 | ha->pmsg, ha->msg_phys); |
| 4909 | out_free_pscratch: |
| 4910 | pci_free_consistent(ha->pdev, GDTH_SCRATCH, |
| 4911 | ha->pscratch, ha->scratch_phys); |
| 4912 | out_free_irq: |
| 4913 | free_irq(ha->irq, ha); |
| 4914 | gdth_ctr_count--; |
Christoph Hellwig | 706a5d4 | 2007-10-02 22:49:35 +0200 | [diff] [blame] | 4915 | out_host_put: |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 4916 | scsi_host_put(shp); |
Christoph Hellwig | 706a5d4 | 2007-10-02 22:49:35 +0200 | [diff] [blame] | 4917 | return error; |
| 4918 | } |
| 4919 | #endif /* CONFIG_EISA */ |
Christoph Hellwig | aed91cb | 2007-10-02 22:48:16 +0200 | [diff] [blame] | 4920 | |
Christoph Hellwig | 8514ef2 | 2007-10-02 22:51:06 +0200 | [diff] [blame] | 4921 | #ifdef CONFIG_PCI |
Jeff Garzik | cff2680 | 2008-02-15 22:20:09 -0500 | [diff] [blame] | 4922 | static int gdth_pci_probe_one(gdth_pci_str *pcistr, |
| 4923 | gdth_ha_str **ha_out) |
Christoph Hellwig | 8514ef2 | 2007-10-02 22:51:06 +0200 | [diff] [blame] | 4924 | { |
| 4925 | struct Scsi_Host *shp; |
| 4926 | gdth_ha_str *ha; |
| 4927 | dma_addr_t scratch_dma_handle = 0; |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 4928 | int error, i; |
Jeff Garzik | 4c9c8d7 | 2008-02-15 21:35:26 -0500 | [diff] [blame] | 4929 | struct pci_dev *pdev = pcistr->pdev; |
Christoph Hellwig | 8514ef2 | 2007-10-02 22:51:06 +0200 | [diff] [blame] | 4930 | |
Jeff Garzik | cff2680 | 2008-02-15 22:20:09 -0500 | [diff] [blame] | 4931 | *ha_out = NULL; |
| 4932 | |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 4933 | shp = scsi_host_alloc(&gdth_template, sizeof(gdth_ha_str)); |
Christoph Hellwig | 8514ef2 | 2007-10-02 22:51:06 +0200 | [diff] [blame] | 4934 | if (!shp) |
| 4935 | return -ENOMEM; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4936 | ha = shost_priv(shp); |
Christoph Hellwig | 8514ef2 | 2007-10-02 22:51:06 +0200 | [diff] [blame] | 4937 | |
| 4938 | error = -ENODEV; |
Jeff Garzik | 4c9c8d7 | 2008-02-15 21:35:26 -0500 | [diff] [blame] | 4939 | if (!gdth_init_pci(pdev, pcistr, ha)) |
Christoph Hellwig | 8514ef2 | 2007-10-02 22:51:06 +0200 | [diff] [blame] | 4940 | goto out_host_put; |
| 4941 | |
| 4942 | /* controller found and initialized */ |
| 4943 | printk("Configuring GDT-PCI HA at %d/%d IRQ %u\n", |
Jeff Garzik | 4c9c8d7 | 2008-02-15 21:35:26 -0500 | [diff] [blame] | 4944 | pdev->bus->number, |
| 4945 | PCI_SLOT(pdev->devfn), |
Christoph Hellwig | 8514ef2 | 2007-10-02 22:51:06 +0200 | [diff] [blame] | 4946 | ha->irq); |
| 4947 | |
| 4948 | error = request_irq(ha->irq, gdth_interrupt, |
| 4949 | IRQF_DISABLED|IRQF_SHARED, "gdth", ha); |
| 4950 | if (error) { |
| 4951 | printk("GDT-PCI: Unable to allocate IRQ\n"); |
| 4952 | goto out_host_put; |
| 4953 | } |
| 4954 | |
| 4955 | shp->unchecked_isa_dma = 0; |
| 4956 | shp->irq = ha->irq; |
| 4957 | shp->dma_channel = 0xff; |
Christoph Hellwig | 8514ef2 | 2007-10-02 22:51:06 +0200 | [diff] [blame] | 4958 | |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 4959 | ha->hanum = gdth_ctr_count++; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4960 | ha->shost = shp; |
Christoph Hellwig | 8514ef2 | 2007-10-02 22:51:06 +0200 | [diff] [blame] | 4961 | |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4962 | ha->pccb = &ha->cmdext; |
Christoph Hellwig | 8514ef2 | 2007-10-02 22:51:06 +0200 | [diff] [blame] | 4963 | ha->ccb_phys = 0L; |
| 4964 | |
| 4965 | error = -ENOMEM; |
| 4966 | |
| 4967 | ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH, |
| 4968 | &scratch_dma_handle); |
| 4969 | if (!ha->pscratch) |
| 4970 | goto out_free_irq; |
| 4971 | ha->scratch_phys = scratch_dma_handle; |
| 4972 | |
| 4973 | ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str), |
| 4974 | &scratch_dma_handle); |
| 4975 | if (!ha->pmsg) |
| 4976 | goto out_free_pscratch; |
| 4977 | ha->msg_phys = scratch_dma_handle; |
| 4978 | |
| 4979 | #ifdef INT_COAL |
| 4980 | ha->coal_stat = pci_alloc_consistent(ha->pdev, |
| 4981 | sizeof(gdth_coal_status) * MAXOFFSETS, |
| 4982 | &scratch_dma_handle); |
| 4983 | if (!ha->coal_stat) |
| 4984 | goto out_free_pmsg; |
| 4985 | ha->coal_stat_phys = scratch_dma_handle; |
| 4986 | #endif |
| 4987 | |
| 4988 | ha->scratch_busy = FALSE; |
| 4989 | ha->req_first = NULL; |
Jeff Garzik | 4c9c8d7 | 2008-02-15 21:35:26 -0500 | [diff] [blame] | 4990 | ha->tid_cnt = pdev->device >= 0x200 ? MAXID : MAX_HDRIVES; |
Christoph Hellwig | 8514ef2 | 2007-10-02 22:51:06 +0200 | [diff] [blame] | 4991 | if (max_ids > 0 && max_ids < ha->tid_cnt) |
| 4992 | ha->tid_cnt = max_ids; |
| 4993 | for (i = 0; i < GDTH_MAXCMDS; ++i) |
| 4994 | ha->cmd_tab[i].cmnd = UNUSED_CMND; |
| 4995 | ha->scan_mode = rescan ? 0x10 : 0; |
| 4996 | |
| 4997 | error = -ENODEV; |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 4998 | if (!gdth_search_drives(ha)) { |
| 4999 | printk("GDT-PCI %d: Error during device scan\n", ha->hanum); |
Christoph Hellwig | 8514ef2 | 2007-10-02 22:51:06 +0200 | [diff] [blame] | 5000 | goto out_free_coal_stat; |
| 5001 | } |
| 5002 | |
| 5003 | if (hdr_channel < 0 || hdr_channel > ha->bus_cnt) |
| 5004 | hdr_channel = ha->bus_cnt; |
| 5005 | ha->virt_bus = hdr_channel; |
| 5006 | |
| 5007 | /* 64-bit DMA only supported from FW >= x.43 */ |
| 5008 | if (!(ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT) || |
| 5009 | !ha->dma64_support) { |
Jeff Garzik | 4c9c8d7 | 2008-02-15 21:35:26 -0500 | [diff] [blame] | 5010 | if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) { |
Christoph Hellwig | 8514ef2 | 2007-10-02 22:51:06 +0200 | [diff] [blame] | 5011 | printk(KERN_WARNING "GDT-PCI %d: " |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 5012 | "Unable to set 32-bit DMA\n", ha->hanum); |
Christoph Hellwig | 8514ef2 | 2007-10-02 22:51:06 +0200 | [diff] [blame] | 5013 | goto out_free_coal_stat; |
| 5014 | } |
| 5015 | } else { |
| 5016 | shp->max_cmd_len = 16; |
Jeff Garzik | 4c9c8d7 | 2008-02-15 21:35:26 -0500 | [diff] [blame] | 5017 | if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) { |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 5018 | printk("GDT-PCI %d: 64-bit DMA enabled\n", ha->hanum); |
Jeff Garzik | 4c9c8d7 | 2008-02-15 21:35:26 -0500 | [diff] [blame] | 5019 | } else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) { |
Christoph Hellwig | 8514ef2 | 2007-10-02 22:51:06 +0200 | [diff] [blame] | 5020 | printk(KERN_WARNING "GDT-PCI %d: " |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 5021 | "Unable to set 64/32-bit DMA\n", ha->hanum); |
Christoph Hellwig | 8514ef2 | 2007-10-02 22:51:06 +0200 | [diff] [blame] | 5022 | goto out_free_coal_stat; |
| 5023 | } |
| 5024 | } |
| 5025 | |
| 5026 | shp->max_id = ha->tid_cnt; |
| 5027 | shp->max_lun = MAXLUN; |
Christoph Hellwig | 52759e6 | 2007-10-02 22:59:53 +0200 | [diff] [blame] | 5028 | shp->max_channel = ha->bus_cnt; |
Christoph Hellwig | 8514ef2 | 2007-10-02 22:51:06 +0200 | [diff] [blame] | 5029 | |
| 5030 | spin_lock_init(&ha->smp_lock); |
Boaz Harrosh | 45f1a41 | 2007-10-02 23:05:53 +0200 | [diff] [blame] | 5031 | gdth_enable_int(ha); |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 5032 | |
Jeff Garzik | 4c9c8d7 | 2008-02-15 21:35:26 -0500 | [diff] [blame] | 5033 | error = scsi_add_host(shp, &pdev->dev); |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 5034 | if (error) |
| 5035 | goto out_free_coal_stat; |
| 5036 | list_add_tail(&ha->list, &gdth_instances); |
Boaz Harrosh | 61c9281 | 2008-02-12 19:35:22 +0200 | [diff] [blame] | 5037 | |
Jeff Garzik | cff2680 | 2008-02-15 22:20:09 -0500 | [diff] [blame] | 5038 | pci_set_drvdata(ha->pdev, ha); |
James Bottomley | 2d6f0d0 | 2008-05-04 22:34:49 -0500 | [diff] [blame] | 5039 | gdth_timer_init(); |
Jeff Garzik | cff2680 | 2008-02-15 22:20:09 -0500 | [diff] [blame] | 5040 | |
Boaz Harrosh | 61c9281 | 2008-02-12 19:35:22 +0200 | [diff] [blame] | 5041 | scsi_scan_host(shp); |
| 5042 | |
Jeff Garzik | cff2680 | 2008-02-15 22:20:09 -0500 | [diff] [blame] | 5043 | *ha_out = ha; |
| 5044 | |
Christoph Hellwig | 8514ef2 | 2007-10-02 22:51:06 +0200 | [diff] [blame] | 5045 | return 0; |
| 5046 | |
| 5047 | out_free_coal_stat: |
| 5048 | #ifdef INT_COAL |
| 5049 | pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) * MAXOFFSETS, |
| 5050 | ha->coal_stat, ha->coal_stat_phys); |
| 5051 | out_free_pmsg: |
| 5052 | #endif |
| 5053 | pci_free_consistent(ha->pdev, sizeof(gdth_msg_str), |
| 5054 | ha->pmsg, ha->msg_phys); |
| 5055 | out_free_pscratch: |
| 5056 | pci_free_consistent(ha->pdev, GDTH_SCRATCH, |
| 5057 | ha->pscratch, ha->scratch_phys); |
| 5058 | out_free_irq: |
| 5059 | free_irq(ha->irq, ha); |
| 5060 | gdth_ctr_count--; |
Christoph Hellwig | 8514ef2 | 2007-10-02 22:51:06 +0200 | [diff] [blame] | 5061 | out_host_put: |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 5062 | scsi_host_put(shp); |
Christoph Hellwig | 8514ef2 | 2007-10-02 22:51:06 +0200 | [diff] [blame] | 5063 | return error; |
| 5064 | } |
| 5065 | #endif /* CONFIG_PCI */ |
| 5066 | |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 5067 | static void gdth_remove_one(gdth_ha_str *ha) |
| 5068 | { |
| 5069 | struct Scsi_Host *shp = ha->shost; |
| 5070 | |
| 5071 | TRACE2(("gdth_remove_one()\n")); |
| 5072 | |
| 5073 | scsi_remove_host(shp); |
| 5074 | |
Boaz Harrosh | b31ddd3 | 2008-02-27 15:27:16 -0800 | [diff] [blame] | 5075 | gdth_flush(ha); |
| 5076 | |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 5077 | if (ha->sdev) { |
| 5078 | scsi_free_host_dev(ha->sdev); |
| 5079 | ha->sdev = NULL; |
| 5080 | } |
| 5081 | |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 5082 | if (shp->irq) |
| 5083 | free_irq(shp->irq,ha); |
| 5084 | |
| 5085 | #ifdef CONFIG_ISA |
| 5086 | if (shp->dma_channel != 0xff) |
| 5087 | free_dma(shp->dma_channel); |
| 5088 | #endif |
| 5089 | #ifdef INT_COAL |
| 5090 | if (ha->coal_stat) |
| 5091 | pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) * |
| 5092 | MAXOFFSETS, ha->coal_stat, ha->coal_stat_phys); |
| 5093 | #endif |
| 5094 | if (ha->pscratch) |
| 5095 | pci_free_consistent(ha->pdev, GDTH_SCRATCH, |
| 5096 | ha->pscratch, ha->scratch_phys); |
| 5097 | if (ha->pmsg) |
| 5098 | pci_free_consistent(ha->pdev, sizeof(gdth_msg_str), |
| 5099 | ha->pmsg, ha->msg_phys); |
| 5100 | if (ha->ccb_phys) |
| 5101 | pci_unmap_single(ha->pdev,ha->ccb_phys, |
| 5102 | sizeof(gdth_cmd_str),PCI_DMA_BIDIRECTIONAL); |
| 5103 | |
| 5104 | scsi_host_put(shp); |
| 5105 | } |
| 5106 | |
Boaz Harrosh | b31ddd3 | 2008-02-27 15:27:16 -0800 | [diff] [blame] | 5107 | static int gdth_halt(struct notifier_block *nb, ulong event, void *buf) |
| 5108 | { |
| 5109 | gdth_ha_str *ha; |
| 5110 | |
| 5111 | TRACE2(("gdth_halt() event %d\n", (int)event)); |
| 5112 | if (event != SYS_RESTART && event != SYS_HALT && event != SYS_POWER_OFF) |
| 5113 | return NOTIFY_DONE; |
| 5114 | |
| 5115 | list_for_each_entry(ha, &gdth_instances, list) |
| 5116 | gdth_flush(ha); |
| 5117 | |
| 5118 | return NOTIFY_OK; |
| 5119 | } |
| 5120 | |
| 5121 | static struct notifier_block gdth_notifier = { |
| 5122 | gdth_halt, NULL, 0 |
| 5123 | }; |
| 5124 | |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 5125 | static int __init gdth_init(void) |
| 5126 | { |
| 5127 | if (disable) { |
| 5128 | printk("GDT-HA: Controller driver disabled from" |
| 5129 | " command line !\n"); |
| 5130 | return 0; |
| 5131 | } |
| 5132 | |
| 5133 | printk("GDT-HA: Storage RAID Controller Driver. Version: %s\n", |
| 5134 | GDTH_VERSION_STR); |
| 5135 | |
| 5136 | /* initializations */ |
| 5137 | gdth_polling = TRUE; |
| 5138 | gdth_clear_events(); |
James Bottomley | 2d6f0d0 | 2008-05-04 22:34:49 -0500 | [diff] [blame] | 5139 | init_timer(&gdth_timer); |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 5140 | |
| 5141 | /* As default we do not probe for EISA or ISA controllers */ |
| 5142 | if (probe_eisa_isa) { |
| 5143 | /* scanning for controllers, at first: ISA controller */ |
| 5144 | #ifdef CONFIG_ISA |
| 5145 | ulong32 isa_bios; |
| 5146 | for (isa_bios = 0xc8000UL; isa_bios <= 0xd8000UL; |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 5147 | isa_bios += 0x8000UL) |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 5148 | gdth_isa_probe_one(isa_bios); |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 5149 | #endif |
| 5150 | #ifdef CONFIG_EISA |
| 5151 | { |
| 5152 | ushort eisa_slot; |
| 5153 | for (eisa_slot = 0x1000; eisa_slot <= 0x8000; |
Boaz Harrosh | 884f7fb | 2007-10-02 23:11:24 +0200 | [diff] [blame] | 5154 | eisa_slot += 0x1000) |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 5155 | gdth_eisa_probe_one(eisa_slot); |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 5156 | } |
| 5157 | #endif |
| 5158 | } |
| 5159 | |
| 5160 | #ifdef CONFIG_PCI |
| 5161 | /* scanning for PCI controllers */ |
James Bottomley | a85591f | 2008-05-04 22:35:58 -0500 | [diff] [blame] | 5162 | if (pci_register_driver(&gdth_pci_driver)) { |
| 5163 | gdth_ha_str *ha; |
| 5164 | |
| 5165 | list_for_each_entry(ha, &gdth_instances, list) |
| 5166 | gdth_remove_one(ha); |
| 5167 | return -ENODEV; |
| 5168 | } |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 5169 | #endif /* CONFIG_PCI */ |
| 5170 | |
| 5171 | TRACE2(("gdth_detect() %d controller detected\n", gdth_ctr_count)); |
Linus Torvalds | c596cc4 | 2007-10-15 12:46:16 -0700 | [diff] [blame] | 5172 | |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 5173 | major = register_chrdev(0,"gdth", &gdth_fops); |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 5174 | register_reboot_notifier(&gdth_notifier); |
| 5175 | gdth_polling = FALSE; |
| 5176 | return 0; |
| 5177 | } |
| 5178 | |
| 5179 | static void __exit gdth_exit(void) |
| 5180 | { |
| 5181 | gdth_ha_str *ha; |
| 5182 | |
Boaz Harrosh | b31ddd3 | 2008-02-27 15:27:16 -0800 | [diff] [blame] | 5183 | unregister_chrdev(major, "gdth"); |
| 5184 | unregister_reboot_notifier(&gdth_notifier); |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 5185 | |
| 5186 | #ifdef GDTH_STATISTICS |
Boaz Harrosh | b31ddd3 | 2008-02-27 15:27:16 -0800 | [diff] [blame] | 5187 | del_timer_sync(&gdth_timer); |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 5188 | #endif |
Boaz Harrosh | b31ddd3 | 2008-02-27 15:27:16 -0800 | [diff] [blame] | 5189 | |
Jeff Garzik | cff2680 | 2008-02-15 22:20:09 -0500 | [diff] [blame] | 5190 | #ifdef CONFIG_PCI |
James Bottomley | a85591f | 2008-05-04 22:35:58 -0500 | [diff] [blame] | 5191 | pci_unregister_driver(&gdth_pci_driver); |
Jeff Garzik | cff2680 | 2008-02-15 22:20:09 -0500 | [diff] [blame] | 5192 | #endif |
| 5193 | |
Boaz Harrosh | b31ddd3 | 2008-02-27 15:27:16 -0800 | [diff] [blame] | 5194 | list_for_each_entry(ha, &gdth_instances, list) |
| 5195 | gdth_remove_one(ha); |
Christoph Hellwig | 835cc24 | 2007-10-02 23:09:56 +0200 | [diff] [blame] | 5196 | } |
| 5197 | |
| 5198 | module_init(gdth_init); |
| 5199 | module_exit(gdth_exit); |
| 5200 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5201 | #ifndef MODULE |
| 5202 | __setup("gdth=", option_setup); |
| 5203 | #endif |