Blame view
drivers/scsi/a100u2w.c
36.1 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
/* * Initio A100 device driver for Linux. * * Copyright (c) 1994-1998 Initio Corporation * Copyright (c) 2003-2004 Christoph Hellwig * All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * |
1da177e4c Linux-2.6.12-rc2 |
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * Revision History: * 07/02/98 hl - v.91n Initial drivers. * 09/14/98 hl - v1.01 Support new Kernel. * 09/22/98 hl - v1.01a Support reset. * 09/24/98 hl - v1.01b Fixed reset. * 10/05/98 hl - v1.02 split the source code and release. * 12/19/98 bv - v1.02a Use spinlocks for 2.1.95 and up * 01/31/99 bv - v1.02b Use mdelay instead of waitForPause * 08/08/99 bv - v1.02c Use waitForPause again. * 06/25/02 Doug Ledford <dledford@redhat.com> - v1.02d * - Remove limit on number of controllers * - Port to DMA mapping API * - Clean up interrupt handler registration * - Fix memory leaks * - Fix allocation of scsi host structs and private data * 11/18/03 Christoph Hellwig <hch@lst.de> * - Port to new probing API * - Fix some more leaks in init failure cases * 9/28/04 Christoph Hellwig <hch@lst.de> * - merge the two source files * - remove internal queueing code |
fa195afe4 [SCSI] Clean up m... |
57 |
* 14/06/07 Alan Cox <alan@lxorguk.ukuu.org.uk> |
4023c4747 [SCSI] a100u2w: C... |
58 |
* - Grand cleanup and Linuxisation |
1da177e4c Linux-2.6.12-rc2 |
59 60 61 62 63 64 65 66 67 68 69 70 71 |
*/ #include <linux/module.h> #include <linux/errno.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/pci.h> #include <linux/init.h> #include <linux/blkdev.h> #include <linux/spinlock.h> #include <linux/kernel.h> #include <linux/string.h> #include <linux/ioport.h> |
910638ae7 [PATCH] Replace 0... |
72 |
#include <linux/dma-mapping.h> |
1da177e4c Linux-2.6.12-rc2 |
73 74 75 76 77 78 79 80 81 82 |
#include <asm/io.h> #include <asm/irq.h> #include <scsi/scsi.h> #include <scsi/scsi_cmnd.h> #include <scsi/scsi_device.h> #include <scsi/scsi_host.h> #include "a100u2w.h" |
4023c4747 [SCSI] a100u2w: C... |
83 84 |
static struct orc_scb *__orc_alloc_scb(struct orc_host * host); static void inia100_scb_handler(struct orc_host *host, struct orc_scb *scb); |
1da177e4c Linux-2.6.12-rc2 |
85 |
|
4023c4747 [SCSI] a100u2w: C... |
86 |
static struct orc_nvram nvram, *nvramp = &nvram; |
1da177e4c Linux-2.6.12-rc2 |
87 |
|
4023c4747 [SCSI] a100u2w: C... |
88 |
static u8 default_nvram[64] = |
1da177e4c Linux-2.6.12-rc2 |
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
{ /*----------header -------------*/ 0x01, /* 0x00: Sub System Vendor ID 0 */ 0x11, /* 0x01: Sub System Vendor ID 1 */ 0x60, /* 0x02: Sub System ID 0 */ 0x10, /* 0x03: Sub System ID 1 */ 0x00, /* 0x04: SubClass */ 0x01, /* 0x05: Vendor ID 0 */ 0x11, /* 0x06: Vendor ID 1 */ 0x60, /* 0x07: Device ID 0 */ 0x10, /* 0x08: Device ID 1 */ 0x00, /* 0x09: Reserved */ 0x00, /* 0x0A: Reserved */ 0x01, /* 0x0B: Revision of Data Structure */ /* -- Host Adapter Structure --- */ 0x01, /* 0x0C: Number Of SCSI Channel */ 0x01, /* 0x0D: BIOS Configuration 1 */ 0x00, /* 0x0E: BIOS Configuration 2 */ 0x00, /* 0x0F: BIOS Configuration 3 */ /* --- SCSI Channel 0 Configuration --- */ 0x07, /* 0x10: H/A ID */ 0x83, /* 0x11: Channel Configuration */ 0x20, /* 0x12: MAX TAG per target */ 0x0A, /* 0x13: SCSI Reset Recovering time */ 0x00, /* 0x14: Channel Configuration4 */ 0x00, /* 0x15: Channel Configuration5 */ /* SCSI Channel 0 Target Configuration */ /* 0x16-0x25 */ 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, /* --- SCSI Channel 1 Configuration --- */ 0x07, /* 0x26: H/A ID */ 0x83, /* 0x27: Channel Configuration */ 0x20, /* 0x28: MAX TAG per target */ 0x0A, /* 0x29: SCSI Reset Recovering time */ 0x00, /* 0x2A: Channel Configuration4 */ 0x00, /* 0x2B: Channel Configuration5 */ /* SCSI Channel 1 Target Configuration */ /* 0x2C-0x3B */ 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0x00, /* 0x3C: Reserved */ 0x00, /* 0x3D: Reserved */ 0x00, /* 0x3E: Reserved */ 0x00 /* 0x3F: Checksum */ }; |
4023c4747 [SCSI] a100u2w: C... |
135 |
static u8 wait_chip_ready(struct orc_host * host) |
1da177e4c Linux-2.6.12-rc2 |
136 137 138 139 |
{ int i; for (i = 0; i < 10; i++) { /* Wait 1 second for report timeout */ |
4023c4747 [SCSI] a100u2w: C... |
140 |
if (inb(host->base + ORC_HCTRL) & HOSTSTOP) /* Wait HOSTSTOP set */ |
1da177e4c Linux-2.6.12-rc2 |
141 |
return 1; |
4023c4747 [SCSI] a100u2w: C... |
142 |
mdelay(100); |
1da177e4c Linux-2.6.12-rc2 |
143 144 145 |
} return 0; } |
4023c4747 [SCSI] a100u2w: C... |
146 |
static u8 wait_firmware_ready(struct orc_host * host) |
1da177e4c Linux-2.6.12-rc2 |
147 148 149 150 |
{ int i; for (i = 0; i < 10; i++) { /* Wait 1 second for report timeout */ |
4023c4747 [SCSI] a100u2w: C... |
151 |
if (inb(host->base + ORC_HSTUS) & RREADY) /* Wait READY set */ |
1da177e4c Linux-2.6.12-rc2 |
152 |
return 1; |
4023c4747 [SCSI] a100u2w: C... |
153 |
mdelay(100); /* wait 100ms before try again */ |
1da177e4c Linux-2.6.12-rc2 |
154 155 156 157 158 |
} return 0; } /***************************************************************************/ |
4023c4747 [SCSI] a100u2w: C... |
159 |
static u8 wait_scsi_reset_done(struct orc_host * host) |
1da177e4c Linux-2.6.12-rc2 |
160 161 162 163 |
{ int i; for (i = 0; i < 10; i++) { /* Wait 1 second for report timeout */ |
4023c4747 [SCSI] a100u2w: C... |
164 |
if (!(inb(host->base + ORC_HCTRL) & SCSIRST)) /* Wait SCSIRST done */ |
1da177e4c Linux-2.6.12-rc2 |
165 |
return 1; |
4023c4747 [SCSI] a100u2w: C... |
166 |
mdelay(100); /* wait 100ms before try again */ |
1da177e4c Linux-2.6.12-rc2 |
167 168 169 170 171 |
} return 0; } /***************************************************************************/ |
4023c4747 [SCSI] a100u2w: C... |
172 |
static u8 wait_HDO_off(struct orc_host * host) |
1da177e4c Linux-2.6.12-rc2 |
173 174 175 176 |
{ int i; for (i = 0; i < 10; i++) { /* Wait 1 second for report timeout */ |
4023c4747 [SCSI] a100u2w: C... |
177 |
if (!(inb(host->base + ORC_HCTRL) & HDO)) /* Wait HDO off */ |
1da177e4c Linux-2.6.12-rc2 |
178 |
return 1; |
4023c4747 [SCSI] a100u2w: C... |
179 |
mdelay(100); /* wait 100ms before try again */ |
1da177e4c Linux-2.6.12-rc2 |
180 181 182 183 184 |
} return 0; } /***************************************************************************/ |
4023c4747 [SCSI] a100u2w: C... |
185 |
static u8 wait_hdi_set(struct orc_host * host, u8 * data) |
1da177e4c Linux-2.6.12-rc2 |
186 187 188 189 |
{ int i; for (i = 0; i < 10; i++) { /* Wait 1 second for report timeout */ |
4023c4747 [SCSI] a100u2w: C... |
190 |
if ((*data = inb(host->base + ORC_HSTUS)) & HDI) |
1da177e4c Linux-2.6.12-rc2 |
191 |
return 1; /* Wait HDI set */ |
4023c4747 [SCSI] a100u2w: C... |
192 |
mdelay(100); /* wait 100ms before try again */ |
1da177e4c Linux-2.6.12-rc2 |
193 194 195 196 197 |
} return 0; } /***************************************************************************/ |
4023c4747 [SCSI] a100u2w: C... |
198 |
static unsigned short orc_read_fwrev(struct orc_host * host) |
1da177e4c Linux-2.6.12-rc2 |
199 |
{ |
4023c4747 [SCSI] a100u2w: C... |
200 201 202 203 204 205 |
u16 version; u8 data; outb(ORC_CMD_VERSION, host->base + ORC_HDATA); outb(HDO, host->base + ORC_HCTRL); if (wait_HDO_off(host) == 0) /* Wait HDO off */ |
1da177e4c Linux-2.6.12-rc2 |
206 |
return 0; |
4023c4747 [SCSI] a100u2w: C... |
207 |
if (wait_hdi_set(host, &data) == 0) /* Wait HDI set */ |
1da177e4c Linux-2.6.12-rc2 |
208 |
return 0; |
4023c4747 [SCSI] a100u2w: C... |
209 210 |
version = inb(host->base + ORC_HDATA); outb(data, host->base + ORC_HSTUS); /* Clear HDI */ |
1da177e4c Linux-2.6.12-rc2 |
211 |
|
4023c4747 [SCSI] a100u2w: C... |
212 |
if (wait_hdi_set(host, &data) == 0) /* Wait HDI set */ |
1da177e4c Linux-2.6.12-rc2 |
213 |
return 0; |
4023c4747 [SCSI] a100u2w: C... |
214 215 |
version |= inb(host->base + ORC_HDATA) << 8; outb(data, host->base + ORC_HSTUS); /* Clear HDI */ |
1da177e4c Linux-2.6.12-rc2 |
216 |
|
4023c4747 [SCSI] a100u2w: C... |
217 |
return version; |
1da177e4c Linux-2.6.12-rc2 |
218 219 220 |
} /***************************************************************************/ |
4023c4747 [SCSI] a100u2w: C... |
221 |
static u8 orc_nv_write(struct orc_host * host, unsigned char address, unsigned char value) |
1da177e4c Linux-2.6.12-rc2 |
222 |
{ |
4023c4747 [SCSI] a100u2w: C... |
223 224 225 |
outb(ORC_CMD_SET_NVM, host->base + ORC_HDATA); /* Write command */ outb(HDO, host->base + ORC_HCTRL); if (wait_HDO_off(host) == 0) /* Wait HDO off */ |
1da177e4c Linux-2.6.12-rc2 |
226 |
return 0; |
4023c4747 [SCSI] a100u2w: C... |
227 228 229 |
outb(address, host->base + ORC_HDATA); /* Write address */ outb(HDO, host->base + ORC_HCTRL); if (wait_HDO_off(host) == 0) /* Wait HDO off */ |
1da177e4c Linux-2.6.12-rc2 |
230 |
return 0; |
4023c4747 [SCSI] a100u2w: C... |
231 232 233 |
outb(value, host->base + ORC_HDATA); /* Write value */ outb(HDO, host->base + ORC_HCTRL); if (wait_HDO_off(host) == 0) /* Wait HDO off */ |
1da177e4c Linux-2.6.12-rc2 |
234 235 236 237 238 239 |
return 0; return 1; } /***************************************************************************/ |
4023c4747 [SCSI] a100u2w: C... |
240 |
static u8 orc_nv_read(struct orc_host * host, u8 address, u8 *ptr) |
1da177e4c Linux-2.6.12-rc2 |
241 |
{ |
4023c4747 [SCSI] a100u2w: C... |
242 |
unsigned char data; |
1da177e4c Linux-2.6.12-rc2 |
243 |
|
4023c4747 [SCSI] a100u2w: C... |
244 245 246 |
outb(ORC_CMD_GET_NVM, host->base + ORC_HDATA); /* Write command */ outb(HDO, host->base + ORC_HCTRL); if (wait_HDO_off(host) == 0) /* Wait HDO off */ |
1da177e4c Linux-2.6.12-rc2 |
247 |
return 0; |
4023c4747 [SCSI] a100u2w: C... |
248 249 250 |
outb(address, host->base + ORC_HDATA); /* Write address */ outb(HDO, host->base + ORC_HCTRL); if (wait_HDO_off(host) == 0) /* Wait HDO off */ |
1da177e4c Linux-2.6.12-rc2 |
251 |
return 0; |
4023c4747 [SCSI] a100u2w: C... |
252 |
if (wait_hdi_set(host, &data) == 0) /* Wait HDI set */ |
1da177e4c Linux-2.6.12-rc2 |
253 |
return 0; |
4023c4747 [SCSI] a100u2w: C... |
254 255 |
*ptr = inb(host->base + ORC_HDATA); outb(data, host->base + ORC_HSTUS); /* Clear HDI */ |
1da177e4c Linux-2.6.12-rc2 |
256 257 |
return 1; |
4023c4747 [SCSI] a100u2w: C... |
258 |
|
1da177e4c Linux-2.6.12-rc2 |
259 |
} |
4023c4747 [SCSI] a100u2w: C... |
260 261 262 263 264 265 266 |
/** * orc_exec_sb - Queue an SCB with the HA * @host: host adapter the SCB belongs to * @scb: SCB to queue for execution */ static void orc_exec_scb(struct orc_host * host, struct orc_scb * scb) |
1da177e4c Linux-2.6.12-rc2 |
267 |
{ |
4023c4747 [SCSI] a100u2w: C... |
268 269 |
scb->status = ORCSCB_POST; outb(scb->scbidx, host->base + ORC_PQUEUE); |
1da177e4c Linux-2.6.12-rc2 |
270 |
} |
4023c4747 [SCSI] a100u2w: C... |
271 272 273 274 275 276 277 278 |
/** * se2_rd_all - read SCSI parameters from EEPROM * @host: Host whose EEPROM is being loaded * * Read SCSI H/A configuration parameters from serial EEPROM */ static int se2_rd_all(struct orc_host * host) |
1da177e4c Linux-2.6.12-rc2 |
279 280 |
{ int i; |
4023c4747 [SCSI] a100u2w: C... |
281 |
u8 *np, chksum = 0; |
1da177e4c Linux-2.6.12-rc2 |
282 |
|
4023c4747 [SCSI] a100u2w: C... |
283 |
np = (u8 *) nvramp; |
1da177e4c Linux-2.6.12-rc2 |
284 |
for (i = 0; i < 64; i++, np++) { /* <01> */ |
4023c4747 [SCSI] a100u2w: C... |
285 |
if (orc_nv_read(host, (u8) i, np) == 0) |
1da177e4c Linux-2.6.12-rc2 |
286 |
return -1; |
1da177e4c Linux-2.6.12-rc2 |
287 |
} |
4023c4747 [SCSI] a100u2w: C... |
288 289 |
/*------ Is ckecksum ok ? ------*/ np = (u8 *) nvramp; |
1da177e4c Linux-2.6.12-rc2 |
290 291 |
for (i = 0; i < 63; i++) chksum += *np++; |
4023c4747 [SCSI] a100u2w: C... |
292 |
if (nvramp->CheckSum != (u8) chksum) |
1da177e4c Linux-2.6.12-rc2 |
293 294 295 |
return -1; return 1; } |
4023c4747 [SCSI] a100u2w: C... |
296 297 298 299 300 301 302 303 |
/** * se2_update_all - update the EEPROM * @host: Host whose EEPROM is being updated * * Update changed bytes in the EEPROM image. */ static void se2_update_all(struct orc_host * host) |
1da177e4c Linux-2.6.12-rc2 |
304 305 |
{ /* setup default pattern */ int i; |
4023c4747 [SCSI] a100u2w: C... |
306 |
u8 *np, *np1, chksum = 0; |
1da177e4c Linux-2.6.12-rc2 |
307 308 |
/* Calculate checksum first */ |
4023c4747 [SCSI] a100u2w: C... |
309 |
np = (u8 *) default_nvram; |
1da177e4c Linux-2.6.12-rc2 |
310 311 312 |
for (i = 0; i < 63; i++) chksum += *np++; *np = chksum; |
4023c4747 [SCSI] a100u2w: C... |
313 314 |
np = (u8 *) default_nvram; np1 = (u8 *) nvramp; |
1da177e4c Linux-2.6.12-rc2 |
315 |
for (i = 0; i < 64; i++, np++, np1++) { |
4023c4747 [SCSI] a100u2w: C... |
316 317 |
if (*np != *np1) orc_nv_write(host, (u8) i, *np); |
1da177e4c Linux-2.6.12-rc2 |
318 |
} |
1da177e4c Linux-2.6.12-rc2 |
319 |
} |
4023c4747 [SCSI] a100u2w: C... |
320 321 322 323 324 325 326 327 328 |
/** * read_eeprom - load EEPROM * @host: Host EEPROM to read * * Read the EEPROM for a given host. If it is invalid or fails * the restore the defaults and use them. */ static void read_eeprom(struct orc_host * host) |
1da177e4c Linux-2.6.12-rc2 |
329 |
{ |
4023c4747 [SCSI] a100u2w: C... |
330 331 332 |
if (se2_rd_all(host) != 1) { se2_update_all(host); /* setup default pattern */ se2_rd_all(host); /* load again */ |
1da177e4c Linux-2.6.12-rc2 |
333 334 |
} } |
4023c4747 [SCSI] a100u2w: C... |
335 336 337 338 339 340 341 342 343 344 345 |
/** * orc_load_firmware - initialise firmware * @host: Host to set up * * Load the firmware from the EEPROM into controller SRAM. This * is basically a 4K block copy and then a 4K block read to check * correctness. The rest is convulted by the indirect interfaces * in the hardware */ static u8 orc_load_firmware(struct orc_host * host) |
1da177e4c Linux-2.6.12-rc2 |
346 |
{ |
4023c4747 [SCSI] a100u2w: C... |
347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
u32 data32; u16 bios_addr; u16 i; u8 *data32_ptr, data; /* Set up the EEPROM for access */ data = inb(host->base + ORC_GCFG); outb(data | EEPRG, host->base + ORC_GCFG); /* Enable EEPROM programming */ outb(0x00, host->base + ORC_EBIOSADR2); outw(0x0000, host->base + ORC_EBIOSADR0); if (inb(host->base + ORC_EBIOSDATA) != 0x55) { outb(data, host->base + ORC_GCFG); /* Disable EEPROM programming */ |
1da177e4c Linux-2.6.12-rc2 |
361 362 |
return 0; } |
4023c4747 [SCSI] a100u2w: C... |
363 364 365 |
outw(0x0001, host->base + ORC_EBIOSADR0); if (inb(host->base + ORC_EBIOSDATA) != 0xAA) { outb(data, host->base + ORC_GCFG); /* Disable EEPROM programming */ |
1da177e4c Linux-2.6.12-rc2 |
366 367 |
return 0; } |
4023c4747 [SCSI] a100u2w: C... |
368 369 370 |
outb(PRGMRST | DOWNLOAD, host->base + ORC_RISCCTL); /* Enable SRAM programming */ data32_ptr = (u8 *) & data32; |
987ff954c Fix endianity in ... |
371 |
data32 = cpu_to_le32(0); /* Initial FW address to 0 */ |
4023c4747 [SCSI] a100u2w: C... |
372 373 374 375 376 377 378 |
outw(0x0010, host->base + ORC_EBIOSADR0); *data32_ptr = inb(host->base + ORC_EBIOSDATA); /* Read from BIOS */ outw(0x0011, host->base + ORC_EBIOSADR0); *(data32_ptr + 1) = inb(host->base + ORC_EBIOSDATA); /* Read from BIOS */ outw(0x0012, host->base + ORC_EBIOSADR0); *(data32_ptr + 2) = inb(host->base + ORC_EBIOSDATA); /* Read from BIOS */ outw(*(data32_ptr + 2), host->base + ORC_EBIOSADR2); |
987ff954c Fix endianity in ... |
379 |
outl(le32_to_cpu(data32), host->base + ORC_FWBASEADR); /* Write FW address */ |
4023c4747 [SCSI] a100u2w: C... |
380 381 |
/* Copy the code from the BIOS to the SRAM */ |
56d387ec2 Add udelay to A10... |
382 |
udelay(500); /* Required on Sun Ultra 5 ... 350 -> failures */ |
987ff954c Fix endianity in ... |
383 |
bios_addr = (u16) le32_to_cpu(data32); /* FW code locate at BIOS address + ? */ |
4023c4747 [SCSI] a100u2w: C... |
384 |
for (i = 0, data32_ptr = (u8 *) & data32; /* Download the code */ |
1da177e4c Linux-2.6.12-rc2 |
385 |
i < 0x1000; /* Firmware code size = 4K */ |
4023c4747 [SCSI] a100u2w: C... |
386 387 388 |
i++, bios_addr++) { outw(bios_addr, host->base + ORC_EBIOSADR0); *data32_ptr++ = inb(host->base + ORC_EBIOSDATA); /* Read from BIOS */ |
1da177e4c Linux-2.6.12-rc2 |
389 |
if ((i % 4) == 3) { |
987ff954c Fix endianity in ... |
390 |
outl(le32_to_cpu(data32), host->base + ORC_RISCRAM); /* Write every 4 bytes */ |
4023c4747 [SCSI] a100u2w: C... |
391 |
data32_ptr = (u8 *) & data32; |
1da177e4c Linux-2.6.12-rc2 |
392 393 |
} } |
4023c4747 [SCSI] a100u2w: C... |
394 395 396 |
/* Go back and check they match */ outb(PRGMRST | DOWNLOAD, host->base + ORC_RISCCTL); /* Reset program count 0 */ |
b595076a1 tree-wide: fix co... |
397 |
bios_addr -= 0x1000; /* Reset the BIOS address */ |
4023c4747 [SCSI] a100u2w: C... |
398 |
for (i = 0, data32_ptr = (u8 *) & data32; /* Check the code */ |
1da177e4c Linux-2.6.12-rc2 |
399 |
i < 0x1000; /* Firmware code size = 4K */ |
4023c4747 [SCSI] a100u2w: C... |
400 401 402 |
i++, bios_addr++) { outw(bios_addr, host->base + ORC_EBIOSADR0); *data32_ptr++ = inb(host->base + ORC_EBIOSDATA); /* Read from BIOS */ |
1da177e4c Linux-2.6.12-rc2 |
403 |
if ((i % 4) == 3) { |
987ff954c Fix endianity in ... |
404 |
if (inl(host->base + ORC_RISCRAM) != le32_to_cpu(data32)) { |
4023c4747 [SCSI] a100u2w: C... |
405 406 |
outb(PRGMRST, host->base + ORC_RISCCTL); /* Reset program to 0 */ outb(data, host->base + ORC_GCFG); /*Disable EEPROM programming */ |
1da177e4c Linux-2.6.12-rc2 |
407 408 |
return 0; } |
4023c4747 [SCSI] a100u2w: C... |
409 |
data32_ptr = (u8 *) & data32; |
1da177e4c Linux-2.6.12-rc2 |
410 411 |
} } |
4023c4747 [SCSI] a100u2w: C... |
412 413 414 415 |
/* Success */ outb(PRGMRST, host->base + ORC_RISCCTL); /* Reset program to 0 */ outb(data, host->base + ORC_GCFG); /* Disable EEPROM programming */ |
1da177e4c Linux-2.6.12-rc2 |
416 417 418 419 |
return 1; } /***************************************************************************/ |
4023c4747 [SCSI] a100u2w: C... |
420 |
static void setup_SCBs(struct orc_host * host) |
1da177e4c Linux-2.6.12-rc2 |
421 |
{ |
4023c4747 [SCSI] a100u2w: C... |
422 |
struct orc_scb *scb; |
1da177e4c Linux-2.6.12-rc2 |
423 |
int i; |
4023c4747 [SCSI] a100u2w: C... |
424 425 |
struct orc_extended_scb *escb; dma_addr_t escb_phys; |
1da177e4c Linux-2.6.12-rc2 |
426 |
|
4023c4747 [SCSI] a100u2w: C... |
427 428 429 430 431 432 |
/* Setup SCB base and SCB Size registers */ outb(ORC_MAXQUEUE, host->base + ORC_SCBSIZE); /* Total number of SCBs */ /* SCB base address 0 */ outl(host->scb_phys, host->base + ORC_SCBBASE0); /* SCB base address 1 */ outl(host->scb_phys, host->base + ORC_SCBBASE1); |
1da177e4c Linux-2.6.12-rc2 |
433 434 |
/* setup scatter list address with one buffer */ |
4023c4747 [SCSI] a100u2w: C... |
435 436 |
scb = host->scb_virt; escb = host->escb_virt; |
1da177e4c Linux-2.6.12-rc2 |
437 438 |
for (i = 0; i < ORC_MAXQUEUE; i++) { |
4023c4747 [SCSI] a100u2w: C... |
439 |
escb_phys = (host->escb_phys + (sizeof(struct orc_extended_scb) * i)); |
987ff954c Fix endianity in ... |
440 441 |
scb->sg_addr = cpu_to_le32((u32) escb_phys); scb->sense_addr = cpu_to_le32((u32) escb_phys); |
4023c4747 [SCSI] a100u2w: C... |
442 443 444 445 |
scb->escb = escb; scb->scbidx = i; scb++; escb++; |
1da177e4c Linux-2.6.12-rc2 |
446 |
} |
1da177e4c Linux-2.6.12-rc2 |
447 |
} |
4023c4747 [SCSI] a100u2w: C... |
448 449 450 451 452 453 454 455 456 |
/** * init_alloc_map - initialise allocation map * @host: host map to configure * * Initialise the allocation maps for this device. If the device * is not quiescent the caller must hold the allocation lock */ static void init_alloc_map(struct orc_host * host) |
1da177e4c Linux-2.6.12-rc2 |
457 |
{ |
4023c4747 [SCSI] a100u2w: C... |
458 |
u8 i, j; |
1da177e4c Linux-2.6.12-rc2 |
459 460 461 |
for (i = 0; i < MAX_CHANNELS; i++) { for (j = 0; j < 8; j++) { |
4023c4747 [SCSI] a100u2w: C... |
462 |
host->allocation_map[i][j] = 0xffffffff; |
1da177e4c Linux-2.6.12-rc2 |
463 464 465 |
} } } |
4023c4747 [SCSI] a100u2w: C... |
466 467 468 469 |
/** * init_orchid - initialise the host adapter * @host:host adapter to initialise * |
3ad2f3fbb tree-wide: Assort... |
470 |
* Initialise the controller and if necessary load the firmware. |
4023c4747 [SCSI] a100u2w: C... |
471 472 473 474 475 |
* * Returns -1 if the initialisation fails. */ static int init_orchid(struct orc_host * host) |
1da177e4c Linux-2.6.12-rc2 |
476 |
{ |
4023c4747 [SCSI] a100u2w: C... |
477 478 479 480 481 482 483 484 485 |
u8 *ptr; u16 revision; u8 i; init_alloc_map(host); outb(0xFF, host->base + ORC_GIMSK); /* Disable all interrupts */ if (inb(host->base + ORC_HSTUS) & RREADY) { /* Orchid is ready */ revision = orc_read_fwrev(host); |
1da177e4c Linux-2.6.12-rc2 |
486 |
if (revision == 0xFFFF) { |
4023c4747 [SCSI] a100u2w: C... |
487 488 489 490 491 492 493 494 |
outb(DEVRST, host->base + ORC_HCTRL); /* Reset Host Adapter */ if (wait_chip_ready(host) == 0) return -1; orc_load_firmware(host); /* Download FW */ setup_SCBs(host); /* Setup SCB base and SCB Size registers */ outb(0x00, host->base + ORC_HCTRL); /* clear HOSTSTOP */ if (wait_firmware_ready(host) == 0) return -1; |
1da177e4c Linux-2.6.12-rc2 |
495 496 |
/* Wait for firmware ready */ } else { |
4023c4747 [SCSI] a100u2w: C... |
497 |
setup_SCBs(host); /* Setup SCB base and SCB Size registers */ |
1da177e4c Linux-2.6.12-rc2 |
498 499 |
} } else { /* Orchid is not Ready */ |
4023c4747 [SCSI] a100u2w: C... |
500 501 502 503 504 505 |
outb(DEVRST, host->base + ORC_HCTRL); /* Reset Host Adapter */ if (wait_chip_ready(host) == 0) return -1; orc_load_firmware(host); /* Download FW */ setup_SCBs(host); /* Setup SCB base and SCB Size registers */ outb(HDO, host->base + ORC_HCTRL); /* Do Hardware Reset & */ |
1da177e4c Linux-2.6.12-rc2 |
506 507 |
/* clear HOSTSTOP */ |
4023c4747 [SCSI] a100u2w: C... |
508 509 |
if (wait_firmware_ready(host) == 0) /* Wait for firmware ready */ return -1; |
1da177e4c Linux-2.6.12-rc2 |
510 |
} |
4023c4747 [SCSI] a100u2w: C... |
511 512 513 |
/* Load an EEProm copy into RAM */ /* Assumes single threaded at this point */ read_eeprom(host); |
1da177e4c Linux-2.6.12-rc2 |
514 |
|
4023c4747 [SCSI] a100u2w: C... |
515 516 |
if (nvramp->revision != 1) return -1; |
1da177e4c Linux-2.6.12-rc2 |
517 |
|
4023c4747 [SCSI] a100u2w: C... |
518 519 520 521 522 523 524 |
host->scsi_id = nvramp->scsi_id; host->BIOScfg = nvramp->BIOSConfig1; host->max_targets = MAX_TARGETS; ptr = (u8 *) & (nvramp->Target00Config); for (i = 0; i < 16; ptr++, i++) { host->target_flag[i] = *ptr; host->max_tags[i] = ORC_MAXTAGS; |
1da177e4c Linux-2.6.12-rc2 |
525 |
} |
4023c4747 [SCSI] a100u2w: C... |
526 527 528 529 530 |
if (nvramp->SCSI0Config & NCC_BUSRESET) host->flags |= HCF_SCSI_RESET; outb(0xFB, host->base + ORC_GIMSK); /* enable RP FIFO interrupt */ return 0; |
1da177e4c Linux-2.6.12-rc2 |
531 |
} |
4023c4747 [SCSI] a100u2w: C... |
532 533 534 535 536 537 538 539 |
/** * orc_reset_scsi_bus - perform bus reset * @host: host being reset * * Perform a full bus reset on the adapter. */ static int orc_reset_scsi_bus(struct orc_host * host) |
1da177e4c Linux-2.6.12-rc2 |
540 |
{ /* I need Host Control Block Information */ |
4023c4747 [SCSI] a100u2w: C... |
541 |
unsigned long flags; |
1da177e4c Linux-2.6.12-rc2 |
542 |
|
4023c4747 [SCSI] a100u2w: C... |
543 |
spin_lock_irqsave(&host->allocation_lock, flags); |
1da177e4c Linux-2.6.12-rc2 |
544 |
|
4023c4747 [SCSI] a100u2w: C... |
545 |
init_alloc_map(host); |
1da177e4c Linux-2.6.12-rc2 |
546 |
/* reset scsi bus */ |
4023c4747 [SCSI] a100u2w: C... |
547 548 549 550 551 |
outb(SCSIRST, host->base + ORC_HCTRL); /* FIXME: We can spend up to a second with the lock held and interrupts off here */ if (wait_scsi_reset_done(host) == 0) { spin_unlock_irqrestore(&host->allocation_lock, flags); |
1da177e4c Linux-2.6.12-rc2 |
552 553 |
return FAILED; } else { |
4023c4747 [SCSI] a100u2w: C... |
554 |
spin_unlock_irqrestore(&host->allocation_lock, flags); |
1da177e4c Linux-2.6.12-rc2 |
555 556 557 |
return SUCCESS; } } |
4023c4747 [SCSI] a100u2w: C... |
558 559 560 561 562 563 564 565 566 567 568 |
/** * orc_device_reset - device reset handler * @host: host to reset * @cmd: command causing the reset * @target; target device * * Reset registers, reset a hanging bus and kill active and disconnected * commands for target w/o soft reset */ static int orc_device_reset(struct orc_host * host, struct scsi_cmnd *cmd, unsigned int target) |
1da177e4c Linux-2.6.12-rc2 |
569 |
{ /* I need Host Control Block Information */ |
4023c4747 [SCSI] a100u2w: C... |
570 571 572 573 574 |
struct orc_scb *scb; struct orc_extended_scb *escb; struct orc_scb *host_scb; u8 i; unsigned long flags; |
1da177e4c Linux-2.6.12-rc2 |
575 |
|
4023c4747 [SCSI] a100u2w: C... |
576 577 578 |
spin_lock_irqsave(&(host->allocation_lock), flags); scb = (struct orc_scb *) NULL; escb = (struct orc_extended_scb *) NULL; |
1da177e4c Linux-2.6.12-rc2 |
579 580 |
/* setup scatter list address with one buffer */ |
4023c4747 [SCSI] a100u2w: C... |
581 |
host_scb = host->scb_virt; |
1da177e4c Linux-2.6.12-rc2 |
582 |
|
4023c4747 [SCSI] a100u2w: C... |
583 584 585 586 587 |
/* FIXME: is this safe if we then fail to issue the reset or race a completion ? */ init_alloc_map(host); /* Find the scb corresponding to the command */ |
1da177e4c Linux-2.6.12-rc2 |
588 |
for (i = 0; i < ORC_MAXQUEUE; i++) { |
4023c4747 [SCSI] a100u2w: C... |
589 590 |
escb = host_scb->escb; if (host_scb->status && escb->srb == cmd) |
1da177e4c Linux-2.6.12-rc2 |
591 |
break; |
4023c4747 [SCSI] a100u2w: C... |
592 |
host_scb++; |
1da177e4c Linux-2.6.12-rc2 |
593 594 595 |
} if (i == ORC_MAXQUEUE) { |
4023c4747 [SCSI] a100u2w: C... |
596 597 598 |
printk(KERN_ERR "Unable to Reset - No SCB Found "); spin_unlock_irqrestore(&(host->allocation_lock), flags); |
1da177e4c Linux-2.6.12-rc2 |
599 600 |
return FAILED; } |
4023c4747 [SCSI] a100u2w: C... |
601 602 603 604 605 |
/* Allocate a new SCB for the reset command to the firmware */ if ((scb = __orc_alloc_scb(host)) == NULL) { /* Can't happen.. */ spin_unlock_irqrestore(&(host->allocation_lock), flags); |
1da177e4c Linux-2.6.12-rc2 |
606 607 |
return FAILED; } |
4023c4747 [SCSI] a100u2w: C... |
608 |
|
89546deb9 trivial: Fix miss... |
609 |
/* Reset device is handled by the firmware, we fill in an SCB and |
4023c4747 [SCSI] a100u2w: C... |
610 611 612 613 614 615 616 617 618 |
fire it at the controller, it does the rest */ scb->opcode = ORC_BUSDEVRST; scb->target = target; scb->hastat = 0; scb->tastat = 0; scb->status = 0x0; scb->link = 0xFF; scb->reserved0 = 0; scb->reserved1 = 0; |
987ff954c Fix endianity in ... |
619 620 |
scb->xferlen = cpu_to_le32(0); scb->sg_len = cpu_to_le32(0); |
4023c4747 [SCSI] a100u2w: C... |
621 622 623 624 625 |
escb->srb = NULL; escb->srb = cmd; orc_exec_scb(host, scb); /* Start execute SCB */ spin_unlock_irqrestore(&host->allocation_lock, flags); |
1da177e4c Linux-2.6.12-rc2 |
626 627 |
return SUCCESS; } |
4023c4747 [SCSI] a100u2w: C... |
628 629 630 631 632 633 634 635 |
/** * __orc_alloc_scb - allocate an SCB * @host: host to allocate from * * Allocate an SCB and return a pointer to the SCB object. NULL * is returned if no SCB is free. The caller must already hold * the allocator lock at this point. */ |
1da177e4c Linux-2.6.12-rc2 |
636 |
|
4023c4747 [SCSI] a100u2w: C... |
637 638 |
static struct orc_scb *__orc_alloc_scb(struct orc_host * host) |
1da177e4c Linux-2.6.12-rc2 |
639 |
{ |
4023c4747 [SCSI] a100u2w: C... |
640 641 642 643 |
u8 channel; unsigned long idx; u8 index; u8 i; |
1da177e4c Linux-2.6.12-rc2 |
644 |
|
4023c4747 [SCSI] a100u2w: C... |
645 |
channel = host->index; |
1da177e4c Linux-2.6.12-rc2 |
646 647 |
for (i = 0; i < 8; i++) { for (index = 0; index < 32; index++) { |
4023c4747 [SCSI] a100u2w: C... |
648 649 |
if ((host->allocation_map[channel][i] >> index) & 0x01) { host->allocation_map[channel][i] &= ~(1 << index); |
28aef2f7d [SCSI] a100u2w: f... |
650 651 652 653 654 |
idx = index + 32 * i; /* * Translate the index to a structure instance */ return host->scb_virt + idx; |
1da177e4c Linux-2.6.12-rc2 |
655 656 |
} } |
1da177e4c Linux-2.6.12-rc2 |
657 |
} |
4023c4747 [SCSI] a100u2w: C... |
658 |
return NULL; |
1da177e4c Linux-2.6.12-rc2 |
659 |
} |
4023c4747 [SCSI] a100u2w: C... |
660 661 662 663 664 665 666 667 668 |
/** * orc_alloc_scb - allocate an SCB * @host: host to allocate from * * Allocate an SCB and return a pointer to the SCB object. NULL * is returned if no SCB is free. */ static struct orc_scb *orc_alloc_scb(struct orc_host * host) |
1da177e4c Linux-2.6.12-rc2 |
669 |
{ |
4023c4747 [SCSI] a100u2w: C... |
670 671 |
struct orc_scb *scb; unsigned long flags; |
1da177e4c Linux-2.6.12-rc2 |
672 |
|
4023c4747 [SCSI] a100u2w: C... |
673 674 675 676 |
spin_lock_irqsave(&host->allocation_lock, flags); scb = __orc_alloc_scb(host); spin_unlock_irqrestore(&host->allocation_lock, flags); return scb; |
1da177e4c Linux-2.6.12-rc2 |
677 |
} |
4023c4747 [SCSI] a100u2w: C... |
678 679 680 681 682 683 684 685 |
/** * orc_release_scb - release an SCB * @host: host owning the SCB * @scb: SCB that is now free * * Called to return a completed SCB to the allocation pool. Before * calling the SCB must be out of use on both the host and the HA. */ |
1da177e4c Linux-2.6.12-rc2 |
686 |
|
4023c4747 [SCSI] a100u2w: C... |
687 |
static void orc_release_scb(struct orc_host *host, struct orc_scb *scb) |
1da177e4c Linux-2.6.12-rc2 |
688 |
{ |
4023c4747 [SCSI] a100u2w: C... |
689 690 691 692 693 694 695 696 697 698 |
unsigned long flags; u8 index, i, channel; spin_lock_irqsave(&(host->allocation_lock), flags); channel = host->index; /* Channel */ index = scb->scbidx; i = index / 32; index %= 32; host->allocation_map[channel][i] |= (1 << index); spin_unlock_irqrestore(&(host->allocation_lock), flags); |
1da177e4c Linux-2.6.12-rc2 |
699 |
} |
4023c4747 [SCSI] a100u2w: C... |
700 701 702 703 704 705 706 707 708 |
/** * orchid_abort_scb - abort a command * * Abort a queued command that has been passed to the firmware layer * if possible. This is all handled by the firmware. We aks the firmware * and it either aborts the command or fails */ static int orchid_abort_scb(struct orc_host * host, struct orc_scb * scb) |
1da177e4c Linux-2.6.12-rc2 |
709 |
{ |
4023c4747 [SCSI] a100u2w: C... |
710 |
unsigned char data, status; |
1da177e4c Linux-2.6.12-rc2 |
711 |
|
4023c4747 [SCSI] a100u2w: C... |
712 713 714 |
outb(ORC_CMD_ABORT_SCB, host->base + ORC_HDATA); /* Write command */ outb(HDO, host->base + ORC_HCTRL); if (wait_HDO_off(host) == 0) /* Wait HDO off */ |
1da177e4c Linux-2.6.12-rc2 |
715 |
return 0; |
4023c4747 [SCSI] a100u2w: C... |
716 717 718 |
outb(scb->scbidx, host->base + ORC_HDATA); /* Write address */ outb(HDO, host->base + ORC_HCTRL); if (wait_HDO_off(host) == 0) /* Wait HDO off */ |
1da177e4c Linux-2.6.12-rc2 |
719 |
return 0; |
4023c4747 [SCSI] a100u2w: C... |
720 |
if (wait_hdi_set(host, &data) == 0) /* Wait HDI set */ |
1da177e4c Linux-2.6.12-rc2 |
721 |
return 0; |
4023c4747 [SCSI] a100u2w: C... |
722 723 |
status = inb(host->base + ORC_HDATA); outb(data, host->base + ORC_HSTUS); /* Clear HDI */ |
1da177e4c Linux-2.6.12-rc2 |
724 |
|
4023c4747 [SCSI] a100u2w: C... |
725 |
if (status == 1) /* 0 - Successfully */ |
1da177e4c Linux-2.6.12-rc2 |
726 727 728 |
return 0; /* 1 - Fail */ return 1; } |
4023c4747 [SCSI] a100u2w: C... |
729 |
static int inia100_abort_cmd(struct orc_host * host, struct scsi_cmnd *cmd) |
1da177e4c Linux-2.6.12-rc2 |
730 |
{ |
4023c4747 [SCSI] a100u2w: C... |
731 732 733 734 735 736 |
struct orc_extended_scb *escb; struct orc_scb *scb; u8 i; unsigned long flags; spin_lock_irqsave(&(host->allocation_lock), flags); |
1da177e4c Linux-2.6.12-rc2 |
737 |
|
4023c4747 [SCSI] a100u2w: C... |
738 |
scb = host->scb_virt; |
1da177e4c Linux-2.6.12-rc2 |
739 |
|
4023c4747 [SCSI] a100u2w: C... |
740 741 742 |
/* Walk the queue until we find the SCB that belongs to the command block. This isn't a performance critical path so a walk in the park here does no harm */ |
1da177e4c Linux-2.6.12-rc2 |
743 |
|
4023c4747 [SCSI] a100u2w: C... |
744 745 746 747 748 |
for (i = 0; i < ORC_MAXQUEUE; i++, scb++) { escb = scb->escb; if (scb->status && escb->srb == cmd) { if (scb->tag_msg == 0) { goto out; |
1da177e4c Linux-2.6.12-rc2 |
749 |
} else { |
4023c4747 [SCSI] a100u2w: C... |
750 751 752 753 |
/* Issue an ABORT to the firmware */ if (orchid_abort_scb(host, scb)) { escb->srb = NULL; spin_unlock_irqrestore(&host->allocation_lock, flags); |
1da177e4c Linux-2.6.12-rc2 |
754 |
return SUCCESS; |
4023c4747 [SCSI] a100u2w: C... |
755 756 |
} else goto out; |
1da177e4c Linux-2.6.12-rc2 |
757 758 759 |
} } } |
4023c4747 [SCSI] a100u2w: C... |
760 761 |
out: spin_unlock_irqrestore(&host->allocation_lock, flags); |
1da177e4c Linux-2.6.12-rc2 |
762 763 |
return FAILED; } |
4023c4747 [SCSI] a100u2w: C... |
764 765 766 767 768 769 770 771 772 773 774 775 776 777 |
/** * orc_interrupt - IRQ processing * @host: Host causing the interrupt * * This function is called from the IRQ handler and protected * by the host lock. While the controller reports that there are * scb's for processing we pull them off the controller, turn the * index into a host address pointer to the scb and call the scb * handler. * * Returns IRQ_HANDLED if any SCBs were processed, IRQ_NONE otherwise */ static irqreturn_t orc_interrupt(struct orc_host * host) |
1da177e4c Linux-2.6.12-rc2 |
778 |
{ |
4023c4747 [SCSI] a100u2w: C... |
779 780 |
u8 scb_index; struct orc_scb *scb; |
1da177e4c Linux-2.6.12-rc2 |
781 |
|
4023c4747 [SCSI] a100u2w: C... |
782 783 784 |
/* Check if we have an SCB queued for servicing */ if (inb(host->base + ORC_RQUEUECNT) == 0) return IRQ_NONE; |
1da177e4c Linux-2.6.12-rc2 |
785 |
|
1da177e4c Linux-2.6.12-rc2 |
786 |
do { |
4023c4747 [SCSI] a100u2w: C... |
787 788 789 790 791 792 793 794 795 796 |
/* Get the SCB index of the SCB to service */ scb_index = inb(host->base + ORC_RQUEUE); /* Translate it back to a host pointer */ scb = (struct orc_scb *) ((unsigned long) host->scb_virt + (unsigned long) (sizeof(struct orc_scb) * scb_index)); scb->status = 0x0; /* Process the SCB */ inia100_scb_handler(host, scb); } while (inb(host->base + ORC_RQUEUECNT)); return IRQ_HANDLED; |
1da177e4c Linux-2.6.12-rc2 |
797 |
} /* End of I1060Interrupt() */ |
4023c4747 [SCSI] a100u2w: C... |
798 799 800 801 802 803 804 805 |
/** * inia100_build_scb - build SCB * @host: host owing the control block * @scb: control block to use * @cmd: Mid layer command * * Build a host adapter control block from the SCSI mid layer command */ |
3a628b0fd Don't crash on IO... |
806 |
static int inia100_build_scb(struct orc_host * host, struct orc_scb * scb, struct scsi_cmnd * cmd) |
1da177e4c Linux-2.6.12-rc2 |
807 |
{ /* Create corresponding SCB */ |
985c0a727 [SCSI] a100u2w: c... |
808 |
struct scatterlist *sg; |
4023c4747 [SCSI] a100u2w: C... |
809 |
struct orc_sgent *sgent; /* Pointer to SG list */ |
1da177e4c Linux-2.6.12-rc2 |
810 |
int i, count_sg; |
4023c4747 [SCSI] a100u2w: C... |
811 812 813 814 815 816 817 818 819 820 821 822 823 824 |
struct orc_extended_scb *escb; /* Links between the escb, scb and Linux scsi midlayer cmd */ escb = scb->escb; escb->srb = cmd; sgent = NULL; /* Set up the SCB to do a SCSI command block */ scb->opcode = ORC_EXECSCSI; scb->flags = SCF_NO_DCHK; /* Clear done bit */ scb->target = cmd->device->id; scb->lun = cmd->device->lun; scb->reserved0 = 0; scb->reserved1 = 0; |
987ff954c Fix endianity in ... |
825 |
scb->sg_len = cpu_to_le32(0); |
4023c4747 [SCSI] a100u2w: C... |
826 |
|
987ff954c Fix endianity in ... |
827 |
scb->xferlen = cpu_to_le32((u32) scsi_bufflen(cmd)); |
4023c4747 [SCSI] a100u2w: C... |
828 829 830 |
sgent = (struct orc_sgent *) & escb->sglist[0]; count_sg = scsi_dma_map(cmd); |
3a628b0fd Don't crash on IO... |
831 832 |
if (count_sg < 0) return count_sg; |
a5db33411 BUG_ON on kernel ... |
833 |
BUG_ON(count_sg > TOTAL_SG_ENTRY); |
4023c4747 [SCSI] a100u2w: C... |
834 835 |
/* Build the scatter gather lists */ |
985c0a727 [SCSI] a100u2w: c... |
836 |
if (count_sg) { |
987ff954c Fix endianity in ... |
837 |
scb->sg_len = cpu_to_le32((u32) (count_sg * 8)); |
4023c4747 [SCSI] a100u2w: C... |
838 |
scsi_for_each_sg(cmd, sg, count_sg, i) { |
987ff954c Fix endianity in ... |
839 840 |
sgent->base = cpu_to_le32((u32) sg_dma_address(sg)); sgent->length = cpu_to_le32((u32) sg_dma_len(sg)); |
4023c4747 [SCSI] a100u2w: C... |
841 |
sgent++; |
1da177e4c Linux-2.6.12-rc2 |
842 |
} |
985c0a727 [SCSI] a100u2w: c... |
843 |
} else { |
987ff954c Fix endianity in ... |
844 845 846 |
scb->sg_len = cpu_to_le32(0); sgent->base = cpu_to_le32(0); sgent->length = cpu_to_le32(0); |
1da177e4c Linux-2.6.12-rc2 |
847 |
} |
987ff954c Fix endianity in ... |
848 |
scb->sg_addr = (u32) scb->sense_addr; /* sense_addr is already little endian */ |
4023c4747 [SCSI] a100u2w: C... |
849 850 851 852 853 854 855 856 |
scb->hastat = 0; scb->tastat = 0; scb->link = 0xFF; scb->sense_len = SENSE_SIZE; scb->cdb_len = cmd->cmd_len; if (scb->cdb_len >= IMAX_CDB) { printk("max cdb length= %x\b", cmd->cmd_len); scb->cdb_len = IMAX_CDB; |
1da177e4c Linux-2.6.12-rc2 |
857 |
} |
4023c4747 [SCSI] a100u2w: C... |
858 859 860 |
scb->ident = cmd->device->lun | DISC_ALLOW; if (cmd->device->tagged_supported) { /* Tag Support */ scb->tag_msg = SIMPLE_QUEUE_TAG; /* Do simple tag only */ |
1da177e4c Linux-2.6.12-rc2 |
861 |
} else { |
4023c4747 [SCSI] a100u2w: C... |
862 |
scb->tag_msg = 0; /* No tag support */ |
1da177e4c Linux-2.6.12-rc2 |
863 |
} |
64a87b244 [SCSI] Let scsi_c... |
864 |
memcpy(scb->cdb, cmd->cmnd, scb->cdb_len); |
3a628b0fd Don't crash on IO... |
865 |
return 0; |
1da177e4c Linux-2.6.12-rc2 |
866 |
} |
4023c4747 [SCSI] a100u2w: C... |
867 868 869 870 871 872 873 874 875 |
/** * inia100_queue - queue command with host * @cmd: Command block * @done: Completion function * * Called by the mid layer to queue a command. Process the command * block, build the host specific scb structures and if there is room * queue the command down to the controller */ |
f281233d3 SCSI host lock pu... |
876 |
static int inia100_queue_lck(struct scsi_cmnd * cmd, void (*done) (struct scsi_cmnd *)) |
1da177e4c Linux-2.6.12-rc2 |
877 |
{ |
4023c4747 [SCSI] a100u2w: C... |
878 879 |
struct orc_scb *scb; struct orc_host *host; /* Point to Host adapter control block */ |
1da177e4c Linux-2.6.12-rc2 |
880 |
|
4023c4747 [SCSI] a100u2w: C... |
881 882 |
host = (struct orc_host *) cmd->device->host->hostdata; cmd->scsi_done = done; |
1da177e4c Linux-2.6.12-rc2 |
883 |
/* Get free SCSI control block */ |
4023c4747 [SCSI] a100u2w: C... |
884 |
if ((scb = orc_alloc_scb(host)) == NULL) |
1da177e4c Linux-2.6.12-rc2 |
885 |
return SCSI_MLQUEUE_HOST_BUSY; |
3a628b0fd Don't crash on IO... |
886 887 888 889 |
if (inia100_build_scb(host, scb, cmd)) { orc_release_scb(host, scb); return SCSI_MLQUEUE_HOST_BUSY; } |
4023c4747 [SCSI] a100u2w: C... |
890 891 |
orc_exec_scb(host, scb); /* Start execute SCB */ return 0; |
1da177e4c Linux-2.6.12-rc2 |
892 |
} |
f281233d3 SCSI host lock pu... |
893 |
static DEF_SCSI_QCMD(inia100_queue) |
1da177e4c Linux-2.6.12-rc2 |
894 895 896 897 |
/***************************************************************************** Function name : inia100_abort Description : Abort a queued command. (commands that are on the bus can't be aborted easily) |
4023c4747 [SCSI] a100u2w: C... |
898 |
Input : host - Pointer to host adapter structure |
1da177e4c Linux-2.6.12-rc2 |
899 900 901 |
Output : None. Return : pSRB - Pointer to SCSI request block. *****************************************************************************/ |
4023c4747 [SCSI] a100u2w: C... |
902 |
static int inia100_abort(struct scsi_cmnd * cmd) |
1da177e4c Linux-2.6.12-rc2 |
903 |
{ |
4023c4747 [SCSI] a100u2w: C... |
904 |
struct orc_host *host; |
1da177e4c Linux-2.6.12-rc2 |
905 |
|
4023c4747 [SCSI] a100u2w: C... |
906 907 |
host = (struct orc_host *) cmd->device->host->hostdata; return inia100_abort_cmd(host, cmd); |
1da177e4c Linux-2.6.12-rc2 |
908 909 910 911 912 913 |
} /***************************************************************************** Function name : inia100_reset Description : Reset registers, reset a hanging bus and kill active and disconnected commands for target w/o soft reset |
4023c4747 [SCSI] a100u2w: C... |
914 |
Input : host - Pointer to host adapter structure |
1da177e4c Linux-2.6.12-rc2 |
915 916 917 |
Output : None. Return : pSRB - Pointer to SCSI request block. *****************************************************************************/ |
4023c4747 [SCSI] a100u2w: C... |
918 |
static int inia100_bus_reset(struct scsi_cmnd * cmd) |
1da177e4c Linux-2.6.12-rc2 |
919 |
{ /* I need Host Control Block Information */ |
4023c4747 [SCSI] a100u2w: C... |
920 921 922 |
struct orc_host *host; host = (struct orc_host *) cmd->device->host->hostdata; return orc_reset_scsi_bus(host); |
1da177e4c Linux-2.6.12-rc2 |
923 924 925 926 927 |
} /***************************************************************************** Function name : inia100_device_reset Description : Reset the device |
4023c4747 [SCSI] a100u2w: C... |
928 |
Input : host - Pointer to host adapter structure |
1da177e4c Linux-2.6.12-rc2 |
929 930 931 |
Output : None. Return : pSRB - Pointer to SCSI request block. *****************************************************************************/ |
4023c4747 [SCSI] a100u2w: C... |
932 |
static int inia100_device_reset(struct scsi_cmnd * cmd) |
1da177e4c Linux-2.6.12-rc2 |
933 |
{ /* I need Host Control Block Information */ |
4023c4747 [SCSI] a100u2w: C... |
934 935 936 |
struct orc_host *host; host = (struct orc_host *) cmd->device->host->hostdata; return orc_device_reset(host, cmd, scmd_id(cmd)); |
1da177e4c Linux-2.6.12-rc2 |
937 938 |
} |
4023c4747 [SCSI] a100u2w: C... |
939 940 941 942 943 944 945 946 947 948 949 |
/** * inia100_scb_handler - interrupt callback * @host: Host causing the interrupt * @scb: SCB the controller returned as needing processing * * Perform completion processing on a control block. Do the conversions * from host to SCSI midlayer error coding, save any sense data and * the complete with the midlayer and recycle the scb. */ static void inia100_scb_handler(struct orc_host *host, struct orc_scb *scb) |
1da177e4c Linux-2.6.12-rc2 |
950 |
{ |
4023c4747 [SCSI] a100u2w: C... |
951 952 953 954 955 956 957 958 |
struct scsi_cmnd *cmd; /* Pointer to SCSI request block */ struct orc_extended_scb *escb; escb = scb->escb; if ((cmd = (struct scsi_cmnd *) escb->srb) == NULL) { printk(KERN_ERR "inia100_scb_handler: SRB pointer is empty "); orc_release_scb(host, scb); /* Release SCB for current channel */ |
1da177e4c Linux-2.6.12-rc2 |
959 960 |
return; } |
4023c4747 [SCSI] a100u2w: C... |
961 |
escb->srb = NULL; |
1da177e4c Linux-2.6.12-rc2 |
962 |
|
4023c4747 [SCSI] a100u2w: C... |
963 |
switch (scb->hastat) { |
1da177e4c Linux-2.6.12-rc2 |
964 965 966 |
case 0x0: case 0xa: /* Linked command complete without error and linked normally */ case 0xb: /* Linked command complete without error interrupt generated */ |
4023c4747 [SCSI] a100u2w: C... |
967 |
scb->hastat = 0; |
1da177e4c Linux-2.6.12-rc2 |
968 969 970 971 |
break; case 0x11: /* Selection time out-The initiator selection or target reselection was not complete within the SCSI Time out period */ |
4023c4747 [SCSI] a100u2w: C... |
972 |
scb->hastat = DID_TIME_OUT; |
1da177e4c Linux-2.6.12-rc2 |
973 974 975 976 977 978 |
break; case 0x14: /* Target bus phase sequence failure-An invalid bus phase or bus phase sequence was requested by the target. The host adapter will generate a SCSI Reset Condition, notifying the host with a SCRD interrupt */ |
4023c4747 [SCSI] a100u2w: C... |
979 |
scb->hastat = DID_RESET; |
1da177e4c Linux-2.6.12-rc2 |
980 981 982 |
break; case 0x1a: /* SCB Aborted. 07/21/98 */ |
4023c4747 [SCSI] a100u2w: C... |
983 |
scb->hastat = DID_ABORT; |
1da177e4c Linux-2.6.12-rc2 |
984 985 986 987 988 989 990 991 992 |
break; case 0x12: /* Data overrun/underrun-The target attempted to transfer more data than was allocated by the Data Length field or the sum of the Scatter / Gather Data Length fields. */ case 0x13: /* Unexpected bus free-The target dropped the SCSI BSY at an unexpected time. */ case 0x16: /* Invalid CCB Operation Code-The first byte of the CCB was invalid. */ default: |
4023c4747 [SCSI] a100u2w: C... |
993 994 995 |
printk(KERN_DEBUG "inia100: %x %x ", scb->hastat, scb->tastat); scb->hastat = DID_ERROR; /* Couldn't find any better */ |
1da177e4c Linux-2.6.12-rc2 |
996 997 |
break; } |
4023c4747 [SCSI] a100u2w: C... |
998 999 1000 |
if (scb->tastat == 2) { /* Check condition */ memcpy((unsigned char *) &cmd->sense_buffer[0], (unsigned char *) &escb->sglist[0], SENSE_SIZE); |
1da177e4c Linux-2.6.12-rc2 |
1001 |
} |
4023c4747 [SCSI] a100u2w: C... |
1002 1003 1004 1005 |
cmd->result = scb->tastat | (scb->hastat << 16); scsi_dma_unmap(cmd); cmd->scsi_done(cmd); /* Notify system DONE */ orc_release_scb(host, scb); /* Release SCB for current channel */ |
1da177e4c Linux-2.6.12-rc2 |
1006 |
} |
4023c4747 [SCSI] a100u2w: C... |
1007 1008 1009 1010 1011 1012 1013 |
/** * inia100_intr - interrupt handler * @irqno: Interrupt value * @devid: Host adapter * * Entry point for IRQ handling. All the real work is performed * by orc_interrupt. |
1da177e4c Linux-2.6.12-rc2 |
1014 |
*/ |
7d12e780e IRQ: Maintain reg... |
1015 |
static irqreturn_t inia100_intr(int irqno, void *devid) |
1da177e4c Linux-2.6.12-rc2 |
1016 |
{ |
4023c4747 [SCSI] a100u2w: C... |
1017 1018 |
struct Scsi_Host *shost = (struct Scsi_Host *)devid; struct orc_host *host = (struct orc_host *)shost->hostdata; |
1da177e4c Linux-2.6.12-rc2 |
1019 |
unsigned long flags; |
4023c4747 [SCSI] a100u2w: C... |
1020 |
irqreturn_t res; |
1da177e4c Linux-2.6.12-rc2 |
1021 |
|
4023c4747 [SCSI] a100u2w: C... |
1022 1023 1024 |
spin_lock_irqsave(shost->host_lock, flags); res = orc_interrupt(host); spin_unlock_irqrestore(shost->host_lock, flags); |
1da177e4c Linux-2.6.12-rc2 |
1025 |
|
4023c4747 [SCSI] a100u2w: C... |
1026 |
return res; |
1da177e4c Linux-2.6.12-rc2 |
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 |
} static struct scsi_host_template inia100_template = { .proc_name = "inia100", .name = inia100_REVID, .queuecommand = inia100_queue, .eh_abort_handler = inia100_abort, .eh_bus_reset_handler = inia100_bus_reset, .eh_device_reset_handler = inia100_device_reset, .can_queue = 1, .this_id = 1, .sg_tablesize = SG_ALL, .cmd_per_lun = 1, .use_clustering = ENABLE_CLUSTERING, }; static int __devinit inia100_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) { struct Scsi_Host *shost; |
4023c4747 [SCSI] a100u2w: C... |
1047 |
struct orc_host *host; |
1da177e4c Linux-2.6.12-rc2 |
1048 1049 1050 |
unsigned long port, bios; int error = -ENODEV; u32 sz; |
4023c4747 [SCSI] a100u2w: C... |
1051 1052 |
unsigned long biosaddr; char *bios_phys; |
1da177e4c Linux-2.6.12-rc2 |
1053 1054 1055 |
if (pci_enable_device(pdev)) goto out; |
284901a90 dma-mapping: repl... |
1056 |
if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) { |
1da177e4c Linux-2.6.12-rc2 |
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 |
printk(KERN_WARNING "Unable to set 32bit DMA " "on inia100 adapter, ignoring. "); goto out_disable_device; } pci_set_master(pdev); port = pci_resource_start(pdev, 0); if (!request_region(port, 256, "inia100")) { printk(KERN_WARNING "inia100: io port 0x%lx, is busy. ", port); goto out_disable_device; } |
4c3ee8266 drivers/scsi/a100... |
1071 |
/* <02> read from base address + 0x50 offset to get the bios value. */ |
4023c4747 [SCSI] a100u2w: C... |
1072 |
bios = inw(port + 0x50); |
1da177e4c Linux-2.6.12-rc2 |
1073 |
|
4023c4747 [SCSI] a100u2w: C... |
1074 |
shost = scsi_host_alloc(&inia100_template, sizeof(struct orc_host)); |
1da177e4c Linux-2.6.12-rc2 |
1075 1076 |
if (!shost) goto out_release_region; |
4023c4747 [SCSI] a100u2w: C... |
1077 1078 1079 1080 1081 |
host = (struct orc_host *)shost->hostdata; host->pdev = pdev; host->base = port; host->BIOScfg = bios; spin_lock_init(&host->allocation_lock); |
1da177e4c Linux-2.6.12-rc2 |
1082 1083 |
/* Get total memory needed for SCB */ |
4023c4747 [SCSI] a100u2w: C... |
1084 1085 1086 1087 |
sz = ORC_MAXQUEUE * sizeof(struct orc_scb); host->scb_virt = pci_alloc_consistent(pdev, sz, &host->scb_phys); if (!host->scb_virt) { |
1da177e4c Linux-2.6.12-rc2 |
1088 1089 1090 1091 |
printk("inia100: SCB memory allocation error "); goto out_host_put; } |
4023c4747 [SCSI] a100u2w: C... |
1092 |
memset(host->scb_virt, 0, sz); |
1da177e4c Linux-2.6.12-rc2 |
1093 1094 |
/* Get total memory needed for ESCB */ |
4023c4747 [SCSI] a100u2w: C... |
1095 1096 1097 1098 |
sz = ORC_MAXQUEUE * sizeof(struct orc_extended_scb); host->escb_virt = pci_alloc_consistent(pdev, sz, &host->escb_phys); if (!host->escb_virt) { |
1da177e4c Linux-2.6.12-rc2 |
1099 1100 1101 1102 |
printk("inia100: ESCB memory allocation error "); goto out_free_scb_array; } |
4023c4747 [SCSI] a100u2w: C... |
1103 |
memset(host->escb_virt, 0, sz); |
1da177e4c Linux-2.6.12-rc2 |
1104 |
|
4023c4747 [SCSI] a100u2w: C... |
1105 1106 1107 1108 |
biosaddr = host->BIOScfg; biosaddr = (biosaddr << 4); bios_phys = phys_to_virt(biosaddr); if (init_orchid(host)) { /* Initialize orchid chip */ |
1da177e4c Linux-2.6.12-rc2 |
1109 1110 1111 1112 |
printk("inia100: initial orchid fail!! "); goto out_free_escb_array; } |
4023c4747 [SCSI] a100u2w: C... |
1113 |
shost->io_port = host->base; |
1da177e4c Linux-2.6.12-rc2 |
1114 1115 1116 |
shost->n_io_port = 0xff; shost->can_queue = ORC_MAXQUEUE; shost->unique_id = shost->io_port; |
4023c4747 [SCSI] a100u2w: C... |
1117 |
shost->max_id = host->max_targets; |
1da177e4c Linux-2.6.12-rc2 |
1118 |
shost->max_lun = 16; |
4023c4747 [SCSI] a100u2w: C... |
1119 1120 |
shost->irq = pdev->irq; shost->this_id = host->scsi_id; /* Assign HCS index */ |
1da177e4c Linux-2.6.12-rc2 |
1121 1122 1123 |
shost->sg_tablesize = TOTAL_SG_ENTRY; /* Initial orc chip */ |
1d6f359a2 [PATCH] irq-flags... |
1124 |
error = request_irq(pdev->irq, inia100_intr, IRQF_SHARED, |
1da177e4c Linux-2.6.12-rc2 |
1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 |
"inia100", shost); if (error < 0) { printk(KERN_WARNING "inia100: unable to get irq %d ", pdev->irq); goto out_free_escb_array; } pci_set_drvdata(pdev, shost); error = scsi_add_host(shost, &pdev->dev); if (error) goto out_free_irq; scsi_scan_host(shost); return 0; |
4023c4747 [SCSI] a100u2w: C... |
1141 |
out_free_irq: |
1da177e4c Linux-2.6.12-rc2 |
1142 |
free_irq(shost->irq, shost); |
4023c4747 [SCSI] a100u2w: C... |
1143 1144 1145 1146 1147 1148 1149 |
out_free_escb_array: pci_free_consistent(pdev, ORC_MAXQUEUE * sizeof(struct orc_extended_scb), host->escb_virt, host->escb_phys); out_free_scb_array: pci_free_consistent(pdev, ORC_MAXQUEUE * sizeof(struct orc_scb), host->scb_virt, host->scb_phys); out_host_put: |
1da177e4c Linux-2.6.12-rc2 |
1150 |
scsi_host_put(shost); |
4023c4747 [SCSI] a100u2w: C... |
1151 |
out_release_region: |
1da177e4c Linux-2.6.12-rc2 |
1152 |
release_region(port, 256); |
4023c4747 [SCSI] a100u2w: C... |
1153 |
out_disable_device: |
1da177e4c Linux-2.6.12-rc2 |
1154 |
pci_disable_device(pdev); |
4023c4747 [SCSI] a100u2w: C... |
1155 |
out: |
1da177e4c Linux-2.6.12-rc2 |
1156 1157 1158 1159 1160 1161 |
return error; } static void __devexit inia100_remove_one(struct pci_dev *pdev) { struct Scsi_Host *shost = pci_get_drvdata(pdev); |
4023c4747 [SCSI] a100u2w: C... |
1162 |
struct orc_host *host = (struct orc_host *)shost->hostdata; |
1da177e4c Linux-2.6.12-rc2 |
1163 1164 1165 1166 |
scsi_remove_host(shost); free_irq(shost->irq, shost); |
4023c4747 [SCSI] a100u2w: C... |
1167 1168 1169 1170 |
pci_free_consistent(pdev, ORC_MAXQUEUE * sizeof(struct orc_extended_scb), host->escb_virt, host->escb_phys); pci_free_consistent(pdev, ORC_MAXQUEUE * sizeof(struct orc_scb), host->scb_virt, host->scb_phys); |
1da177e4c Linux-2.6.12-rc2 |
1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 |
release_region(shost->io_port, 256); scsi_host_put(shost); } static struct pci_device_id inia100_pci_tbl[] = { {PCI_VENDOR_ID_INIT, 0x1060, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0,} }; MODULE_DEVICE_TABLE(pci, inia100_pci_tbl); static struct pci_driver inia100_pci_driver = { .name = "inia100", .id_table = inia100_pci_tbl, .probe = inia100_probe_one, .remove = __devexit_p(inia100_remove_one), }; static int __init inia100_init(void) { |
dcbccbde0 [SCSI] pci_module... |
1191 |
return pci_register_driver(&inia100_pci_driver); |
1da177e4c Linux-2.6.12-rc2 |
1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 |
} static void __exit inia100_exit(void) { pci_unregister_driver(&inia100_pci_driver); } MODULE_DESCRIPTION("Initio A100U2W SCSI driver"); MODULE_AUTHOR("Initio Corporation"); MODULE_LICENSE("Dual BSD/GPL"); module_init(inia100_init); module_exit(inia100_exit); |