a100u2w.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  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@redhat.com>
  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/slab.h>
  71. #include <linux/dma-mapping.h>
  72. #include <asm/io.h>
  73. #include <asm/irq.h>
  74. #include <scsi/scsi.h>
  75. #include <scsi/scsi_cmnd.h>
  76. #include <scsi/scsi_device.h>
  77. #include <scsi/scsi_host.h>
  78. #include "a100u2w.h"
  79. static struct orc_scb *__orc_alloc_scb(struct orc_host * host);
  80. static void inia100_scb_handler(struct orc_host *host, struct orc_scb *scb);
  81. static struct orc_nvram nvram, *nvramp = &nvram;
  82. static u8 default_nvram[64] =
  83. {
  84. /*----------header -------------*/
  85. 0x01, /* 0x00: Sub System Vendor ID 0 */
  86. 0x11, /* 0x01: Sub System Vendor ID 1 */
  87. 0x60, /* 0x02: Sub System ID 0 */
  88. 0x10, /* 0x03: Sub System ID 1 */
  89. 0x00, /* 0x04: SubClass */
  90. 0x01, /* 0x05: Vendor ID 0 */
  91. 0x11, /* 0x06: Vendor ID 1 */
  92. 0x60, /* 0x07: Device ID 0 */
  93. 0x10, /* 0x08: Device ID 1 */
  94. 0x00, /* 0x09: Reserved */
  95. 0x00, /* 0x0A: Reserved */
  96. 0x01, /* 0x0B: Revision of Data Structure */
  97. /* -- Host Adapter Structure --- */
  98. 0x01, /* 0x0C: Number Of SCSI Channel */
  99. 0x01, /* 0x0D: BIOS Configuration 1 */
  100. 0x00, /* 0x0E: BIOS Configuration 2 */
  101. 0x00, /* 0x0F: BIOS Configuration 3 */
  102. /* --- SCSI Channel 0 Configuration --- */
  103. 0x07, /* 0x10: H/A ID */
  104. 0x83, /* 0x11: Channel Configuration */
  105. 0x20, /* 0x12: MAX TAG per target */
  106. 0x0A, /* 0x13: SCSI Reset Recovering time */
  107. 0x00, /* 0x14: Channel Configuration4 */
  108. 0x00, /* 0x15: Channel Configuration5 */
  109. /* SCSI Channel 0 Target Configuration */
  110. /* 0x16-0x25 */
  111. 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8,
  112. 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8,
  113. /* --- SCSI Channel 1 Configuration --- */
  114. 0x07, /* 0x26: H/A ID */
  115. 0x83, /* 0x27: Channel Configuration */
  116. 0x20, /* 0x28: MAX TAG per target */
  117. 0x0A, /* 0x29: SCSI Reset Recovering time */
  118. 0x00, /* 0x2A: Channel Configuration4 */
  119. 0x00, /* 0x2B: Channel Configuration5 */
  120. /* SCSI Channel 1 Target Configuration */
  121. /* 0x2C-0x3B */
  122. 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8,
  123. 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8,
  124. 0x00, /* 0x3C: Reserved */
  125. 0x00, /* 0x3D: Reserved */
  126. 0x00, /* 0x3E: Reserved */
  127. 0x00 /* 0x3F: Checksum */
  128. };
  129. static u8 wait_chip_ready(struct orc_host * host)
  130. {
  131. int i;
  132. for (i = 0; i < 10; i++) { /* Wait 1 second for report timeout */
  133. if (inb(host->base + ORC_HCTRL) & HOSTSTOP) /* Wait HOSTSTOP set */
  134. return 1;
  135. mdelay(100);
  136. }
  137. return 0;
  138. }
  139. static u8 wait_firmware_ready(struct orc_host * host)
  140. {
  141. int i;
  142. for (i = 0; i < 10; i++) { /* Wait 1 second for report timeout */
  143. if (inb(host->base + ORC_HSTUS) & RREADY) /* Wait READY set */
  144. return 1;
  145. mdelay(100); /* wait 100ms before try again */
  146. }
  147. return 0;
  148. }
  149. /***************************************************************************/
  150. static u8 wait_scsi_reset_done(struct orc_host * host)
  151. {
  152. int i;
  153. for (i = 0; i < 10; i++) { /* Wait 1 second for report timeout */
  154. if (!(inb(host->base + ORC_HCTRL) & SCSIRST)) /* Wait SCSIRST done */
  155. return 1;
  156. mdelay(100); /* wait 100ms before try again */
  157. }
  158. return 0;
  159. }
  160. /***************************************************************************/
  161. static u8 wait_HDO_off(struct orc_host * host)
  162. {
  163. int i;
  164. for (i = 0; i < 10; i++) { /* Wait 1 second for report timeout */
  165. if (!(inb(host->base + ORC_HCTRL) & HDO)) /* Wait HDO off */
  166. return 1;
  167. mdelay(100); /* wait 100ms before try again */
  168. }
  169. return 0;
  170. }
  171. /***************************************************************************/
  172. static u8 wait_hdi_set(struct orc_host * host, u8 * data)
  173. {
  174. int i;
  175. for (i = 0; i < 10; i++) { /* Wait 1 second for report timeout */
  176. if ((*data = inb(host->base + ORC_HSTUS)) & HDI)
  177. return 1; /* Wait HDI set */
  178. mdelay(100); /* wait 100ms before try again */
  179. }
  180. return 0;
  181. }
  182. /***************************************************************************/
  183. static unsigned short orc_read_fwrev(struct orc_host * host)
  184. {
  185. u16 version;
  186. u8 data;
  187. outb(ORC_CMD_VERSION, host->base + ORC_HDATA);
  188. outb(HDO, host->base + ORC_HCTRL);
  189. if (wait_HDO_off(host) == 0) /* Wait HDO off */
  190. return 0;
  191. if (wait_hdi_set(host, &data) == 0) /* Wait HDI set */
  192. return 0;
  193. version = inb(host->base + ORC_HDATA);
  194. outb(data, host->base + ORC_HSTUS); /* Clear HDI */
  195. if (wait_hdi_set(host, &data) == 0) /* Wait HDI set */
  196. return 0;
  197. version |= inb(host->base + ORC_HDATA) << 8;
  198. outb(data, host->base + ORC_HSTUS); /* Clear HDI */
  199. return version;
  200. }
  201. /***************************************************************************/
  202. static u8 orc_nv_write(struct orc_host * host, unsigned char address, unsigned char value)
  203. {
  204. outb(ORC_CMD_SET_NVM, host->base + ORC_HDATA); /* Write command */
  205. outb(HDO, host->base + ORC_HCTRL);
  206. if (wait_HDO_off(host) == 0) /* Wait HDO off */
  207. return 0;
  208. outb(address, host->base + ORC_HDATA); /* Write address */
  209. outb(HDO, host->base + ORC_HCTRL);
  210. if (wait_HDO_off(host) == 0) /* Wait HDO off */
  211. return 0;
  212. outb(value, host->base + ORC_HDATA); /* Write value */
  213. outb(HDO, host->base + ORC_HCTRL);
  214. if (wait_HDO_off(host) == 0) /* Wait HDO off */
  215. return 0;
  216. return 1;
  217. }
  218. /***************************************************************************/
  219. static u8 orc_nv_read(struct orc_host * host, u8 address, u8 *ptr)
  220. {
  221. unsigned char data;
  222. outb(ORC_CMD_GET_NVM, host->base + ORC_HDATA); /* Write command */
  223. outb(HDO, host->base + ORC_HCTRL);
  224. if (wait_HDO_off(host) == 0) /* Wait HDO off */
  225. return 0;
  226. outb(address, host->base + ORC_HDATA); /* Write address */
  227. outb(HDO, host->base + ORC_HCTRL);
  228. if (wait_HDO_off(host) == 0) /* Wait HDO off */
  229. return 0;
  230. if (wait_hdi_set(host, &data) == 0) /* Wait HDI set */
  231. return 0;
  232. *ptr = inb(host->base + ORC_HDATA);
  233. outb(data, host->base + ORC_HSTUS); /* Clear HDI */
  234. return 1;
  235. }
  236. /**
  237. * orc_exec_sb - Queue an SCB with the HA
  238. * @host: host adapter the SCB belongs to
  239. * @scb: SCB to queue for execution
  240. */
  241. static void orc_exec_scb(struct orc_host * host, struct orc_scb * scb)
  242. {
  243. scb->status = ORCSCB_POST;
  244. outb(scb->scbidx, host->base + ORC_PQUEUE);
  245. }
  246. /**
  247. * se2_rd_all - read SCSI parameters from EEPROM
  248. * @host: Host whose EEPROM is being loaded
  249. *
  250. * Read SCSI H/A configuration parameters from serial EEPROM
  251. */
  252. static int se2_rd_all(struct orc_host * host)
  253. {
  254. int i;
  255. u8 *np, chksum = 0;
  256. np = (u8 *) nvramp;
  257. for (i = 0; i < 64; i++, np++) { /* <01> */
  258. if (orc_nv_read(host, (u8) i, np) == 0)
  259. return -1;
  260. }
  261. /*------ Is ckecksum ok ? ------*/
  262. np = (u8 *) nvramp;
  263. for (i = 0; i < 63; i++)
  264. chksum += *np++;
  265. if (nvramp->CheckSum != (u8) chksum)
  266. return -1;
  267. return 1;
  268. }
  269. /**
  270. * se2_update_all - update the EEPROM
  271. * @host: Host whose EEPROM is being updated
  272. *
  273. * Update changed bytes in the EEPROM image.
  274. */
  275. static void se2_update_all(struct orc_host * host)
  276. { /* setup default pattern */
  277. int i;
  278. u8 *np, *np1, chksum = 0;
  279. /* Calculate checksum first */
  280. np = (u8 *) default_nvram;
  281. for (i = 0; i < 63; i++)
  282. chksum += *np++;
  283. *np = chksum;
  284. np = (u8 *) default_nvram;
  285. np1 = (u8 *) nvramp;
  286. for (i = 0; i < 64; i++, np++, np1++) {
  287. if (*np != *np1)
  288. orc_nv_write(host, (u8) i, *np);
  289. }
  290. }
  291. /**
  292. * read_eeprom - load EEPROM
  293. * @host: Host EEPROM to read
  294. *
  295. * Read the EEPROM for a given host. If it is invalid or fails
  296. * the restore the defaults and use them.
  297. */
  298. static void read_eeprom(struct orc_host * host)
  299. {
  300. if (se2_rd_all(host) != 1) {
  301. se2_update_all(host); /* setup default pattern */
  302. se2_rd_all(host); /* load again */
  303. }
  304. }
  305. /**
  306. * orc_load_firmware - initialise firmware
  307. * @host: Host to set up
  308. *
  309. * Load the firmware from the EEPROM into controller SRAM. This
  310. * is basically a 4K block copy and then a 4K block read to check
  311. * correctness. The rest is convulted by the indirect interfaces
  312. * in the hardware
  313. */
  314. static u8 orc_load_firmware(struct orc_host * host)
  315. {
  316. u32 data32;
  317. u16 bios_addr;
  318. u16 i;
  319. u8 *data32_ptr, data;
  320. /* Set up the EEPROM for access */
  321. data = inb(host->base + ORC_GCFG);
  322. outb(data | EEPRG, host->base + ORC_GCFG); /* Enable EEPROM programming */
  323. outb(0x00, host->base + ORC_EBIOSADR2);
  324. outw(0x0000, host->base + ORC_EBIOSADR0);
  325. if (inb(host->base + ORC_EBIOSDATA) != 0x55) {
  326. outb(data, host->base + ORC_GCFG); /* Disable EEPROM programming */
  327. return 0;
  328. }
  329. outw(0x0001, host->base + ORC_EBIOSADR0);
  330. if (inb(host->base + ORC_EBIOSDATA) != 0xAA) {
  331. outb(data, host->base + ORC_GCFG); /* Disable EEPROM programming */
  332. return 0;
  333. }
  334. outb(PRGMRST | DOWNLOAD, host->base + ORC_RISCCTL); /* Enable SRAM programming */
  335. data32_ptr = (u8 *) & data32;
  336. data32 = cpu_to_le32(0); /* Initial FW address to 0 */
  337. outw(0x0010, host->base + ORC_EBIOSADR0);
  338. *data32_ptr = inb(host->base + ORC_EBIOSDATA); /* Read from BIOS */
  339. outw(0x0011, host->base + ORC_EBIOSADR0);
  340. *(data32_ptr + 1) = inb(host->base + ORC_EBIOSDATA); /* Read from BIOS */
  341. outw(0x0012, host->base + ORC_EBIOSADR0);
  342. *(data32_ptr + 2) = inb(host->base + ORC_EBIOSDATA); /* Read from BIOS */
  343. outw(*(data32_ptr + 2), host->base + ORC_EBIOSADR2);
  344. outl(le32_to_cpu(data32), host->base + ORC_FWBASEADR); /* Write FW address */
  345. /* Copy the code from the BIOS to the SRAM */
  346. udelay(500); /* Required on Sun Ultra 5 ... 350 -> failures */
  347. bios_addr = (u16) le32_to_cpu(data32); /* FW code locate at BIOS address + ? */
  348. for (i = 0, data32_ptr = (u8 *) & data32; /* Download the code */
  349. i < 0x1000; /* Firmware code size = 4K */
  350. i++, bios_addr++) {
  351. outw(bios_addr, host->base + ORC_EBIOSADR0);
  352. *data32_ptr++ = inb(host->base + ORC_EBIOSDATA); /* Read from BIOS */
  353. if ((i % 4) == 3) {
  354. outl(le32_to_cpu(data32), host->base + ORC_RISCRAM); /* Write every 4 bytes */
  355. data32_ptr = (u8 *) & data32;
  356. }
  357. }
  358. /* Go back and check they match */
  359. outb(PRGMRST | DOWNLOAD, host->base + ORC_RISCCTL); /* Reset program count 0 */
  360. bios_addr -= 0x1000; /* Reset the BIOS adddress */
  361. for (i = 0, data32_ptr = (u8 *) & data32; /* Check the code */
  362. i < 0x1000; /* Firmware code size = 4K */
  363. i++, bios_addr++) {
  364. outw(bios_addr, host->base + ORC_EBIOSADR0);
  365. *data32_ptr++ = inb(host->base + ORC_EBIOSDATA); /* Read from BIOS */
  366. if ((i % 4) == 3) {
  367. if (inl(host->base + ORC_RISCRAM) != le32_to_cpu(data32)) {
  368. outb(PRGMRST, host->base + ORC_RISCCTL); /* Reset program to 0 */
  369. outb(data, host->base + ORC_GCFG); /*Disable EEPROM programming */
  370. return 0;
  371. }
  372. data32_ptr = (u8 *) & data32;
  373. }
  374. }
  375. /* Success */
  376. outb(PRGMRST, host->base + ORC_RISCCTL); /* Reset program to 0 */
  377. outb(data, host->base + ORC_GCFG); /* Disable EEPROM programming */
  378. return 1;
  379. }
  380. /***************************************************************************/
  381. static void setup_SCBs(struct orc_host * host)
  382. {
  383. struct orc_scb *scb;
  384. int i;
  385. struct orc_extended_scb *escb;
  386. dma_addr_t escb_phys;
  387. /* Setup SCB base and SCB Size registers */
  388. outb(ORC_MAXQUEUE, host->base + ORC_SCBSIZE); /* Total number of SCBs */
  389. /* SCB base address 0 */
  390. outl(host->scb_phys, host->base + ORC_SCBBASE0);
  391. /* SCB base address 1 */
  392. outl(host->scb_phys, host->base + ORC_SCBBASE1);
  393. /* setup scatter list address with one buffer */
  394. scb = host->scb_virt;
  395. escb = host->escb_virt;
  396. for (i = 0; i < ORC_MAXQUEUE; i++) {
  397. escb_phys = (host->escb_phys + (sizeof(struct orc_extended_scb) * i));
  398. scb->sg_addr = cpu_to_le32((u32) escb_phys);
  399. scb->sense_addr = cpu_to_le32((u32) escb_phys);
  400. scb->escb = escb;
  401. scb->scbidx = i;
  402. scb++;
  403. escb++;
  404. }
  405. }
  406. /**
  407. * init_alloc_map - initialise allocation map
  408. * @host: host map to configure
  409. *
  410. * Initialise the allocation maps for this device. If the device
  411. * is not quiescent the caller must hold the allocation lock
  412. */
  413. static void init_alloc_map(struct orc_host * host)
  414. {
  415. u8 i, j;
  416. for (i = 0; i < MAX_CHANNELS; i++) {
  417. for (j = 0; j < 8; j++) {
  418. host->allocation_map[i][j] = 0xffffffff;
  419. }
  420. }
  421. }
  422. /**
  423. * init_orchid - initialise the host adapter
  424. * @host:host adapter to initialise
  425. *
  426. * Initialise the controller and if neccessary load the firmware.
  427. *
  428. * Returns -1 if the initialisation fails.
  429. */
  430. static int init_orchid(struct orc_host * host)
  431. {
  432. u8 *ptr;
  433. u16 revision;
  434. u8 i;
  435. init_alloc_map(host);
  436. outb(0xFF, host->base + ORC_GIMSK); /* Disable all interrupts */
  437. if (inb(host->base + ORC_HSTUS) & RREADY) { /* Orchid is ready */
  438. revision = orc_read_fwrev(host);
  439. if (revision == 0xFFFF) {
  440. outb(DEVRST, host->base + ORC_HCTRL); /* Reset Host Adapter */
  441. if (wait_chip_ready(host) == 0)
  442. return -1;
  443. orc_load_firmware(host); /* Download FW */
  444. setup_SCBs(host); /* Setup SCB base and SCB Size registers */
  445. outb(0x00, host->base + ORC_HCTRL); /* clear HOSTSTOP */
  446. if (wait_firmware_ready(host) == 0)
  447. return -1;
  448. /* Wait for firmware ready */
  449. } else {
  450. setup_SCBs(host); /* Setup SCB base and SCB Size registers */
  451. }
  452. } else { /* Orchid is not Ready */
  453. outb(DEVRST, host->base + ORC_HCTRL); /* Reset Host Adapter */
  454. if (wait_chip_ready(host) == 0)
  455. return -1;
  456. orc_load_firmware(host); /* Download FW */
  457. setup_SCBs(host); /* Setup SCB base and SCB Size registers */
  458. outb(HDO, host->base + ORC_HCTRL); /* Do Hardware Reset & */
  459. /* clear HOSTSTOP */
  460. if (wait_firmware_ready(host) == 0) /* Wait for firmware ready */
  461. return -1;
  462. }
  463. /* Load an EEProm copy into RAM */
  464. /* Assumes single threaded at this point */
  465. read_eeprom(host);
  466. if (nvramp->revision != 1)
  467. return -1;
  468. host->scsi_id = nvramp->scsi_id;
  469. host->BIOScfg = nvramp->BIOSConfig1;
  470. host->max_targets = MAX_TARGETS;
  471. ptr = (u8 *) & (nvramp->Target00Config);
  472. for (i = 0; i < 16; ptr++, i++) {
  473. host->target_flag[i] = *ptr;
  474. host->max_tags[i] = ORC_MAXTAGS;
  475. }
  476. if (nvramp->SCSI0Config & NCC_BUSRESET)
  477. host->flags |= HCF_SCSI_RESET;
  478. outb(0xFB, host->base + ORC_GIMSK); /* enable RP FIFO interrupt */
  479. return 0;
  480. }
  481. /**
  482. * orc_reset_scsi_bus - perform bus reset
  483. * @host: host being reset
  484. *
  485. * Perform a full bus reset on the adapter.
  486. */
  487. static int orc_reset_scsi_bus(struct orc_host * host)
  488. { /* I need Host Control Block Information */
  489. unsigned long flags;
  490. spin_lock_irqsave(&host->allocation_lock, flags);
  491. init_alloc_map(host);
  492. /* reset scsi bus */
  493. outb(SCSIRST, host->base + ORC_HCTRL);
  494. /* FIXME: We can spend up to a second with the lock held and
  495. interrupts off here */
  496. if (wait_scsi_reset_done(host) == 0) {
  497. spin_unlock_irqrestore(&host->allocation_lock, flags);
  498. return FAILED;
  499. } else {
  500. spin_unlock_irqrestore(&host->allocation_lock, flags);
  501. return SUCCESS;
  502. }
  503. }
  504. /**
  505. * orc_device_reset - device reset handler
  506. * @host: host to reset
  507. * @cmd: command causing the reset
  508. * @target; target device
  509. *
  510. * Reset registers, reset a hanging bus and kill active and disconnected
  511. * commands for target w/o soft reset
  512. */
  513. static int orc_device_reset(struct orc_host * host, struct scsi_cmnd *cmd, unsigned int target)
  514. { /* I need Host Control Block Information */
  515. struct orc_scb *scb;
  516. struct orc_extended_scb *escb;
  517. struct orc_scb *host_scb;
  518. u8 i;
  519. unsigned long flags;
  520. spin_lock_irqsave(&(host->allocation_lock), flags);
  521. scb = (struct orc_scb *) NULL;
  522. escb = (struct orc_extended_scb *) NULL;
  523. /* setup scatter list address with one buffer */
  524. host_scb = host->scb_virt;
  525. /* FIXME: is this safe if we then fail to issue the reset or race
  526. a completion ? */
  527. init_alloc_map(host);
  528. /* Find the scb corresponding to the command */
  529. for (i = 0; i < ORC_MAXQUEUE; i++) {
  530. escb = host_scb->escb;
  531. if (host_scb->status && escb->srb == cmd)
  532. break;
  533. host_scb++;
  534. }
  535. if (i == ORC_MAXQUEUE) {
  536. printk(KERN_ERR "Unable to Reset - No SCB Found\n");
  537. spin_unlock_irqrestore(&(host->allocation_lock), flags);
  538. return FAILED;
  539. }
  540. /* Allocate a new SCB for the reset command to the firmware */
  541. if ((scb = __orc_alloc_scb(host)) == NULL) {
  542. /* Can't happen.. */
  543. spin_unlock_irqrestore(&(host->allocation_lock), flags);
  544. return FAILED;
  545. }
  546. /* Reset device is handled by the firmare, we fill in an SCB and
  547. fire it at the controller, it does the rest */
  548. scb->opcode = ORC_BUSDEVRST;
  549. scb->target = target;
  550. scb->hastat = 0;
  551. scb->tastat = 0;
  552. scb->status = 0x0;
  553. scb->link = 0xFF;
  554. scb->reserved0 = 0;
  555. scb->reserved1 = 0;
  556. scb->xferlen = cpu_to_le32(0);
  557. scb->sg_len = cpu_to_le32(0);
  558. escb->srb = NULL;
  559. escb->srb = cmd;
  560. orc_exec_scb(host, scb); /* Start execute SCB */
  561. spin_unlock_irqrestore(&host->allocation_lock, flags);
  562. return SUCCESS;
  563. }
  564. /**
  565. * __orc_alloc_scb - allocate an SCB
  566. * @host: host to allocate from
  567. *
  568. * Allocate an SCB and return a pointer to the SCB object. NULL
  569. * is returned if no SCB is free. The caller must already hold
  570. * the allocator lock at this point.
  571. */
  572. static struct orc_scb *__orc_alloc_scb(struct orc_host * host)
  573. {
  574. u8 channel;
  575. unsigned long idx;
  576. u8 index;
  577. u8 i;
  578. channel = host->index;
  579. for (i = 0; i < 8; i++) {
  580. for (index = 0; index < 32; index++) {
  581. if ((host->allocation_map[channel][i] >> index) & 0x01) {
  582. host->allocation_map[channel][i] &= ~(1 << index);
  583. idx = index + 32 * i;
  584. /*
  585. * Translate the index to a structure instance
  586. */
  587. return host->scb_virt + idx;
  588. }
  589. }
  590. }
  591. return NULL;
  592. }
  593. /**
  594. * orc_alloc_scb - allocate an SCB
  595. * @host: host to allocate from
  596. *
  597. * Allocate an SCB and return a pointer to the SCB object. NULL
  598. * is returned if no SCB is free.
  599. */
  600. static struct orc_scb *orc_alloc_scb(struct orc_host * host)
  601. {
  602. struct orc_scb *scb;
  603. unsigned long flags;
  604. spin_lock_irqsave(&host->allocation_lock, flags);
  605. scb = __orc_alloc_scb(host);
  606. spin_unlock_irqrestore(&host->allocation_lock, flags);
  607. return scb;
  608. }
  609. /**
  610. * orc_release_scb - release an SCB
  611. * @host: host owning the SCB
  612. * @scb: SCB that is now free
  613. *
  614. * Called to return a completed SCB to the allocation pool. Before
  615. * calling the SCB must be out of use on both the host and the HA.
  616. */
  617. static void orc_release_scb(struct orc_host *host, struct orc_scb *scb)
  618. {
  619. unsigned long flags;
  620. u8 index, i, channel;
  621. spin_lock_irqsave(&(host->allocation_lock), flags);
  622. channel = host->index; /* Channel */
  623. index = scb->scbidx;
  624. i = index / 32;
  625. index %= 32;
  626. host->allocation_map[channel][i] |= (1 << index);
  627. spin_unlock_irqrestore(&(host->allocation_lock), flags);
  628. }
  629. /**
  630. * orchid_abort_scb - abort a command
  631. *
  632. * Abort a queued command that has been passed to the firmware layer
  633. * if possible. This is all handled by the firmware. We aks the firmware
  634. * and it either aborts the command or fails
  635. */
  636. static int orchid_abort_scb(struct orc_host * host, struct orc_scb * scb)
  637. {
  638. unsigned char data, status;
  639. outb(ORC_CMD_ABORT_SCB, host->base + ORC_HDATA); /* Write command */
  640. outb(HDO, host->base + ORC_HCTRL);
  641. if (wait_HDO_off(host) == 0) /* Wait HDO off */
  642. return 0;
  643. outb(scb->scbidx, host->base + ORC_HDATA); /* Write address */
  644. outb(HDO, host->base + ORC_HCTRL);
  645. if (wait_HDO_off(host) == 0) /* Wait HDO off */
  646. return 0;
  647. if (wait_hdi_set(host, &data) == 0) /* Wait HDI set */
  648. return 0;
  649. status = inb(host->base + ORC_HDATA);
  650. outb(data, host->base + ORC_HSTUS); /* Clear HDI */
  651. if (status == 1) /* 0 - Successfully */
  652. return 0; /* 1 - Fail */
  653. return 1;
  654. }
  655. static int inia100_abort_cmd(struct orc_host * host, struct scsi_cmnd *cmd)
  656. {
  657. struct orc_extended_scb *escb;
  658. struct orc_scb *scb;
  659. u8 i;
  660. unsigned long flags;
  661. spin_lock_irqsave(&(host->allocation_lock), flags);
  662. scb = host->scb_virt;
  663. /* Walk the queue until we find the SCB that belongs to the command
  664. block. This isn't a performance critical path so a walk in the park
  665. here does no harm */
  666. for (i = 0; i < ORC_MAXQUEUE; i++, scb++) {
  667. escb = scb->escb;
  668. if (scb->status && escb->srb == cmd) {
  669. if (scb->tag_msg == 0) {
  670. goto out;
  671. } else {
  672. /* Issue an ABORT to the firmware */
  673. if (orchid_abort_scb(host, scb)) {
  674. escb->srb = NULL;
  675. spin_unlock_irqrestore(&host->allocation_lock, flags);
  676. return SUCCESS;
  677. } else
  678. goto out;
  679. }
  680. }
  681. }
  682. out:
  683. spin_unlock_irqrestore(&host->allocation_lock, flags);
  684. return FAILED;
  685. }
  686. /**
  687. * orc_interrupt - IRQ processing
  688. * @host: Host causing the interrupt
  689. *
  690. * This function is called from the IRQ handler and protected
  691. * by the host lock. While the controller reports that there are
  692. * scb's for processing we pull them off the controller, turn the
  693. * index into a host address pointer to the scb and call the scb
  694. * handler.
  695. *
  696. * Returns IRQ_HANDLED if any SCBs were processed, IRQ_NONE otherwise
  697. */
  698. static irqreturn_t orc_interrupt(struct orc_host * host)
  699. {
  700. u8 scb_index;
  701. struct orc_scb *scb;
  702. /* Check if we have an SCB queued for servicing */
  703. if (inb(host->base + ORC_RQUEUECNT) == 0)
  704. return IRQ_NONE;
  705. do {
  706. /* Get the SCB index of the SCB to service */
  707. scb_index = inb(host->base + ORC_RQUEUE);
  708. /* Translate it back to a host pointer */
  709. scb = (struct orc_scb *) ((unsigned long) host->scb_virt + (unsigned long) (sizeof(struct orc_scb) * scb_index));
  710. scb->status = 0x0;
  711. /* Process the SCB */
  712. inia100_scb_handler(host, scb);
  713. } while (inb(host->base + ORC_RQUEUECNT));
  714. return IRQ_HANDLED;
  715. } /* End of I1060Interrupt() */
  716. /**
  717. * inia100_build_scb - build SCB
  718. * @host: host owing the control block
  719. * @scb: control block to use
  720. * @cmd: Mid layer command
  721. *
  722. * Build a host adapter control block from the SCSI mid layer command
  723. */
  724. static int inia100_build_scb(struct orc_host * host, struct orc_scb * scb, struct scsi_cmnd * cmd)
  725. { /* Create corresponding SCB */
  726. struct scatterlist *sg;
  727. struct orc_sgent *sgent; /* Pointer to SG list */
  728. int i, count_sg;
  729. struct orc_extended_scb *escb;
  730. /* Links between the escb, scb and Linux scsi midlayer cmd */
  731. escb = scb->escb;
  732. escb->srb = cmd;
  733. sgent = NULL;
  734. /* Set up the SCB to do a SCSI command block */
  735. scb->opcode = ORC_EXECSCSI;
  736. scb->flags = SCF_NO_DCHK; /* Clear done bit */
  737. scb->target = cmd->device->id;
  738. scb->lun = cmd->device->lun;
  739. scb->reserved0 = 0;
  740. scb->reserved1 = 0;
  741. scb->sg_len = cpu_to_le32(0);
  742. scb->xferlen = cpu_to_le32((u32) scsi_bufflen(cmd));
  743. sgent = (struct orc_sgent *) & escb->sglist[0];
  744. count_sg = scsi_dma_map(cmd);
  745. if (count_sg < 0)
  746. return count_sg;
  747. BUG_ON(count_sg > TOTAL_SG_ENTRY);
  748. /* Build the scatter gather lists */
  749. if (count_sg) {
  750. scb->sg_len = cpu_to_le32((u32) (count_sg * 8));
  751. scsi_for_each_sg(cmd, sg, count_sg, i) {
  752. sgent->base = cpu_to_le32((u32) sg_dma_address(sg));
  753. sgent->length = cpu_to_le32((u32) sg_dma_len(sg));
  754. sgent++;
  755. }
  756. } else {
  757. scb->sg_len = cpu_to_le32(0);
  758. sgent->base = cpu_to_le32(0);
  759. sgent->length = cpu_to_le32(0);
  760. }
  761. scb->sg_addr = (u32) scb->sense_addr; /* sense_addr is already little endian */
  762. scb->hastat = 0;
  763. scb->tastat = 0;
  764. scb->link = 0xFF;
  765. scb->sense_len = SENSE_SIZE;
  766. scb->cdb_len = cmd->cmd_len;
  767. if (scb->cdb_len >= IMAX_CDB) {
  768. printk("max cdb length= %x\b", cmd->cmd_len);
  769. scb->cdb_len = IMAX_CDB;
  770. }
  771. scb->ident = cmd->device->lun | DISC_ALLOW;
  772. if (cmd->device->tagged_supported) { /* Tag Support */
  773. scb->tag_msg = SIMPLE_QUEUE_TAG; /* Do simple tag only */
  774. } else {
  775. scb->tag_msg = 0; /* No tag support */
  776. }
  777. memcpy(scb->cdb, cmd->cmnd, scb->cdb_len);
  778. return 0;
  779. }
  780. /**
  781. * inia100_queue - queue command with host
  782. * @cmd: Command block
  783. * @done: Completion function
  784. *
  785. * Called by the mid layer to queue a command. Process the command
  786. * block, build the host specific scb structures and if there is room
  787. * queue the command down to the controller
  788. */
  789. static int inia100_queue(struct scsi_cmnd * cmd, void (*done) (struct scsi_cmnd *))
  790. {
  791. struct orc_scb *scb;
  792. struct orc_host *host; /* Point to Host adapter control block */
  793. host = (struct orc_host *) cmd->device->host->hostdata;
  794. cmd->scsi_done = done;
  795. /* Get free SCSI control block */
  796. if ((scb = orc_alloc_scb(host)) == NULL)
  797. return SCSI_MLQUEUE_HOST_BUSY;
  798. if (inia100_build_scb(host, scb, cmd)) {
  799. orc_release_scb(host, scb);
  800. return SCSI_MLQUEUE_HOST_BUSY;
  801. }
  802. orc_exec_scb(host, scb); /* Start execute SCB */
  803. return 0;
  804. }
  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_32BIT_MASK)) {
  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);