a100u2w.c 36 KB

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