a100u2w.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241
  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\n", cmd->cmd_len);
  768. scb->cdb_len = IMAX_CDB;
  769. }
  770. scb->ident = (u8)(cmd->device->lun & 0xff) | 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. .use_clustering = ENABLE_CLUSTERING,
  934. };
  935. static int inia100_probe_one(struct pci_dev *pdev,
  936. const struct pci_device_id *id)
  937. {
  938. struct Scsi_Host *shost;
  939. struct orc_host *host;
  940. unsigned long port, bios;
  941. int error = -ENODEV;
  942. u32 sz;
  943. unsigned long biosaddr;
  944. char *bios_phys;
  945. if (pci_enable_device(pdev))
  946. goto out;
  947. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
  948. printk(KERN_WARNING "Unable to set 32bit DMA "
  949. "on inia100 adapter, ignoring.\n");
  950. goto out_disable_device;
  951. }
  952. pci_set_master(pdev);
  953. port = pci_resource_start(pdev, 0);
  954. if (!request_region(port, 256, "inia100")) {
  955. printk(KERN_WARNING "inia100: io port 0x%lx, is busy.\n", port);
  956. goto out_disable_device;
  957. }
  958. /* <02> read from base address + 0x50 offset to get the bios value. */
  959. bios = inw(port + 0x50);
  960. shost = scsi_host_alloc(&inia100_template, sizeof(struct orc_host));
  961. if (!shost)
  962. goto out_release_region;
  963. host = (struct orc_host *)shost->hostdata;
  964. host->pdev = pdev;
  965. host->base = port;
  966. host->BIOScfg = bios;
  967. spin_lock_init(&host->allocation_lock);
  968. /* Get total memory needed for SCB */
  969. sz = ORC_MAXQUEUE * sizeof(struct orc_scb);
  970. host->scb_virt = pci_zalloc_consistent(pdev, sz, &host->scb_phys);
  971. if (!host->scb_virt) {
  972. printk("inia100: SCB memory allocation error\n");
  973. goto out_host_put;
  974. }
  975. /* Get total memory needed for ESCB */
  976. sz = ORC_MAXQUEUE * sizeof(struct orc_extended_scb);
  977. host->escb_virt = pci_zalloc_consistent(pdev, sz, &host->escb_phys);
  978. if (!host->escb_virt) {
  979. printk("inia100: ESCB memory allocation error\n");
  980. goto out_free_scb_array;
  981. }
  982. biosaddr = host->BIOScfg;
  983. biosaddr = (biosaddr << 4);
  984. bios_phys = phys_to_virt(biosaddr);
  985. if (init_orchid(host)) { /* Initialize orchid chip */
  986. printk("inia100: initial orchid fail!!\n");
  987. goto out_free_escb_array;
  988. }
  989. shost->io_port = host->base;
  990. shost->n_io_port = 0xff;
  991. shost->can_queue = ORC_MAXQUEUE;
  992. shost->unique_id = shost->io_port;
  993. shost->max_id = host->max_targets;
  994. shost->max_lun = 16;
  995. shost->irq = pdev->irq;
  996. shost->this_id = host->scsi_id; /* Assign HCS index */
  997. shost->sg_tablesize = TOTAL_SG_ENTRY;
  998. /* Initial orc chip */
  999. error = request_irq(pdev->irq, inia100_intr, IRQF_SHARED,
  1000. "inia100", shost);
  1001. if (error < 0) {
  1002. printk(KERN_WARNING "inia100: unable to get irq %d\n",
  1003. pdev->irq);
  1004. goto out_free_escb_array;
  1005. }
  1006. pci_set_drvdata(pdev, shost);
  1007. error = scsi_add_host(shost, &pdev->dev);
  1008. if (error)
  1009. goto out_free_irq;
  1010. scsi_scan_host(shost);
  1011. return 0;
  1012. out_free_irq:
  1013. free_irq(shost->irq, shost);
  1014. out_free_escb_array:
  1015. pci_free_consistent(pdev, ORC_MAXQUEUE * sizeof(struct orc_extended_scb),
  1016. host->escb_virt, host->escb_phys);
  1017. out_free_scb_array:
  1018. pci_free_consistent(pdev, ORC_MAXQUEUE * sizeof(struct orc_scb),
  1019. host->scb_virt, host->scb_phys);
  1020. out_host_put:
  1021. scsi_host_put(shost);
  1022. out_release_region:
  1023. release_region(port, 256);
  1024. out_disable_device:
  1025. pci_disable_device(pdev);
  1026. out:
  1027. return error;
  1028. }
  1029. static void inia100_remove_one(struct pci_dev *pdev)
  1030. {
  1031. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  1032. struct orc_host *host = (struct orc_host *)shost->hostdata;
  1033. scsi_remove_host(shost);
  1034. free_irq(shost->irq, shost);
  1035. pci_free_consistent(pdev, ORC_MAXQUEUE * sizeof(struct orc_extended_scb),
  1036. host->escb_virt, host->escb_phys);
  1037. pci_free_consistent(pdev, ORC_MAXQUEUE * sizeof(struct orc_scb),
  1038. host->scb_virt, host->scb_phys);
  1039. release_region(shost->io_port, 256);
  1040. scsi_host_put(shost);
  1041. }
  1042. static struct pci_device_id inia100_pci_tbl[] = {
  1043. {PCI_VENDOR_ID_INIT, 0x1060, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1044. {0,}
  1045. };
  1046. MODULE_DEVICE_TABLE(pci, inia100_pci_tbl);
  1047. static struct pci_driver inia100_pci_driver = {
  1048. .name = "inia100",
  1049. .id_table = inia100_pci_tbl,
  1050. .probe = inia100_probe_one,
  1051. .remove = inia100_remove_one,
  1052. };
  1053. static int __init inia100_init(void)
  1054. {
  1055. return pci_register_driver(&inia100_pci_driver);
  1056. }
  1057. static void __exit inia100_exit(void)
  1058. {
  1059. pci_unregister_driver(&inia100_pci_driver);
  1060. }
  1061. MODULE_DESCRIPTION("Initio A100U2W SCSI driver");
  1062. MODULE_AUTHOR("Initio Corporation");
  1063. MODULE_LICENSE("Dual BSD/GPL");
  1064. module_init(inia100_init);
  1065. module_exit(inia100_exit);