a100u2w.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203
  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. * --------------------------------------------------------------------------
  23. *
  24. * Redistribution and use in source and binary forms, with or without
  25. * modification, are permitted provided that the following conditions
  26. * are met:
  27. * 1. Redistributions of source code must retain the above copyright
  28. * notice, this list of conditions, and the following disclaimer,
  29. * without modification, immediately at the beginning of the file.
  30. * 2. Redistributions in binary form must reproduce the above copyright
  31. * notice, this list of conditions and the following disclaimer in the
  32. * documentation and/or other materials provided with the distribution.
  33. * 3. The name of the author may not be used to endorse or promote products
  34. * derived from this software without specific prior written permission.
  35. *
  36. * Where this Software is combined with software released under the terms of
  37. * the GNU General Public License ("GPL") and the terms of the GPL would require the
  38. * combined work to also be released under the terms of the GPL, the terms
  39. * and conditions of this License will apply in addition to those of the
  40. * GPL with the exception of any terms or conditions of this License that
  41. * conflict with, or are expressly prohibited by, the GPL.
  42. *
  43. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  44. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  45. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  46. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
  47. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  48. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  49. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  50. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  51. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  52. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  53. * SUCH DAMAGE.
  54. */
  55. /*
  56. * Revision History:
  57. * 07/02/98 hl - v.91n Initial drivers.
  58. * 09/14/98 hl - v1.01 Support new Kernel.
  59. * 09/22/98 hl - v1.01a Support reset.
  60. * 09/24/98 hl - v1.01b Fixed reset.
  61. * 10/05/98 hl - v1.02 split the source code and release.
  62. * 12/19/98 bv - v1.02a Use spinlocks for 2.1.95 and up
  63. * 01/31/99 bv - v1.02b Use mdelay instead of waitForPause
  64. * 08/08/99 bv - v1.02c Use waitForPause again.
  65. * 06/25/02 Doug Ledford <dledford@redhat.com> - v1.02d
  66. * - Remove limit on number of controllers
  67. * - Port to DMA mapping API
  68. * - Clean up interrupt handler registration
  69. * - Fix memory leaks
  70. * - Fix allocation of scsi host structs and private data
  71. * 11/18/03 Christoph Hellwig <hch@lst.de>
  72. * - Port to new probing API
  73. * - Fix some more leaks in init failure cases
  74. * 9/28/04 Christoph Hellwig <hch@lst.de>
  75. * - merge the two source files
  76. * - remove internal queueing code
  77. */
  78. #include <linux/module.h>
  79. #include <linux/errno.h>
  80. #include <linux/delay.h>
  81. #include <linux/interrupt.h>
  82. #include <linux/pci.h>
  83. #include <linux/init.h>
  84. #include <linux/blkdev.h>
  85. #include <linux/spinlock.h>
  86. #include <linux/kernel.h>
  87. #include <linux/string.h>
  88. #include <linux/ioport.h>
  89. #include <linux/slab.h>
  90. #include <linux/dma-mapping.h>
  91. #include <asm/io.h>
  92. #include <asm/irq.h>
  93. #include <scsi/scsi.h>
  94. #include <scsi/scsi_cmnd.h>
  95. #include <scsi/scsi_device.h>
  96. #include <scsi/scsi_host.h>
  97. #include "a100u2w.h"
  98. #define JIFFIES_TO_MS(t) ((t) * 1000 / HZ)
  99. #define MS_TO_JIFFIES(j) ((j * HZ) / 1000)
  100. static ORC_SCB *orc_alloc_scb(ORC_HCS * hcsp);
  101. static void inia100SCBPost(BYTE * pHcb, BYTE * pScb);
  102. static NVRAM nvram, *nvramp = &nvram;
  103. static UCHAR dftNvRam[64] =
  104. {
  105. /*----------header -------------*/
  106. 0x01, /* 0x00: Sub System Vendor ID 0 */
  107. 0x11, /* 0x01: Sub System Vendor ID 1 */
  108. 0x60, /* 0x02: Sub System ID 0 */
  109. 0x10, /* 0x03: Sub System ID 1 */
  110. 0x00, /* 0x04: SubClass */
  111. 0x01, /* 0x05: Vendor ID 0 */
  112. 0x11, /* 0x06: Vendor ID 1 */
  113. 0x60, /* 0x07: Device ID 0 */
  114. 0x10, /* 0x08: Device ID 1 */
  115. 0x00, /* 0x09: Reserved */
  116. 0x00, /* 0x0A: Reserved */
  117. 0x01, /* 0x0B: Revision of Data Structure */
  118. /* -- Host Adapter Structure --- */
  119. 0x01, /* 0x0C: Number Of SCSI Channel */
  120. 0x01, /* 0x0D: BIOS Configuration 1 */
  121. 0x00, /* 0x0E: BIOS Configuration 2 */
  122. 0x00, /* 0x0F: BIOS Configuration 3 */
  123. /* --- SCSI Channel 0 Configuration --- */
  124. 0x07, /* 0x10: H/A ID */
  125. 0x83, /* 0x11: Channel Configuration */
  126. 0x20, /* 0x12: MAX TAG per target */
  127. 0x0A, /* 0x13: SCSI Reset Recovering time */
  128. 0x00, /* 0x14: Channel Configuration4 */
  129. 0x00, /* 0x15: Channel Configuration5 */
  130. /* SCSI Channel 0 Target Configuration */
  131. /* 0x16-0x25 */
  132. 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8,
  133. 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8,
  134. /* --- SCSI Channel 1 Configuration --- */
  135. 0x07, /* 0x26: H/A ID */
  136. 0x83, /* 0x27: Channel Configuration */
  137. 0x20, /* 0x28: MAX TAG per target */
  138. 0x0A, /* 0x29: SCSI Reset Recovering time */
  139. 0x00, /* 0x2A: Channel Configuration4 */
  140. 0x00, /* 0x2B: Channel Configuration5 */
  141. /* SCSI Channel 1 Target Configuration */
  142. /* 0x2C-0x3B */
  143. 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8,
  144. 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8,
  145. 0x00, /* 0x3C: Reserved */
  146. 0x00, /* 0x3D: Reserved */
  147. 0x00, /* 0x3E: Reserved */
  148. 0x00 /* 0x3F: Checksum */
  149. };
  150. /***************************************************************************/
  151. static void waitForPause(unsigned amount)
  152. {
  153. ULONG the_time = jiffies + MS_TO_JIFFIES(amount);
  154. while (time_before_eq(jiffies, the_time))
  155. cpu_relax();
  156. }
  157. /***************************************************************************/
  158. static UCHAR waitChipReady(ORC_HCS * hcsp)
  159. {
  160. int i;
  161. for (i = 0; i < 10; i++) { /* Wait 1 second for report timeout */
  162. if (ORC_RD(hcsp->HCS_Base, ORC_HCTRL) & HOSTSTOP) /* Wait HOSTSTOP set */
  163. return 1;
  164. waitForPause(100); /* wait 100ms before try again */
  165. }
  166. return 0;
  167. }
  168. /***************************************************************************/
  169. static UCHAR waitFWReady(ORC_HCS * hcsp)
  170. {
  171. int i;
  172. for (i = 0; i < 10; i++) { /* Wait 1 second for report timeout */
  173. if (ORC_RD(hcsp->HCS_Base, ORC_HSTUS) & RREADY) /* Wait READY set */
  174. return 1;
  175. waitForPause(100); /* wait 100ms before try again */
  176. }
  177. return 0;
  178. }
  179. /***************************************************************************/
  180. static UCHAR waitSCSIRSTdone(ORC_HCS * hcsp)
  181. {
  182. int i;
  183. for (i = 0; i < 10; i++) { /* Wait 1 second for report timeout */
  184. if (!(ORC_RD(hcsp->HCS_Base, ORC_HCTRL) & SCSIRST)) /* Wait SCSIRST done */
  185. return 1;
  186. waitForPause(100); /* wait 100ms before try again */
  187. }
  188. return 0;
  189. }
  190. /***************************************************************************/
  191. static UCHAR waitHDOoff(ORC_HCS * hcsp)
  192. {
  193. int i;
  194. for (i = 0; i < 10; i++) { /* Wait 1 second for report timeout */
  195. if (!(ORC_RD(hcsp->HCS_Base, ORC_HCTRL) & HDO)) /* Wait HDO off */
  196. return 1;
  197. waitForPause(100); /* wait 100ms before try again */
  198. }
  199. return 0;
  200. }
  201. /***************************************************************************/
  202. static UCHAR waitHDIset(ORC_HCS * hcsp, UCHAR * pData)
  203. {
  204. int i;
  205. for (i = 0; i < 10; i++) { /* Wait 1 second for report timeout */
  206. if ((*pData = ORC_RD(hcsp->HCS_Base, ORC_HSTUS)) & HDI)
  207. return 1; /* Wait HDI set */
  208. waitForPause(100); /* wait 100ms before try again */
  209. }
  210. return 0;
  211. }
  212. /***************************************************************************/
  213. static unsigned short get_FW_version(ORC_HCS * hcsp)
  214. {
  215. UCHAR bData;
  216. union {
  217. unsigned short sVersion;
  218. unsigned char cVersion[2];
  219. } Version;
  220. ORC_WR(hcsp->HCS_Base + ORC_HDATA, ORC_CMD_VERSION);
  221. ORC_WR(hcsp->HCS_Base + ORC_HCTRL, HDO);
  222. if (waitHDOoff(hcsp) == 0) /* Wait HDO off */
  223. return 0;
  224. if (waitHDIset(hcsp, &bData) == 0) /* Wait HDI set */
  225. return 0;
  226. Version.cVersion[0] = ORC_RD(hcsp->HCS_Base, ORC_HDATA);
  227. ORC_WR(hcsp->HCS_Base + ORC_HSTUS, bData); /* Clear HDI */
  228. if (waitHDIset(hcsp, &bData) == 0) /* Wait HDI set */
  229. return 0;
  230. Version.cVersion[1] = ORC_RD(hcsp->HCS_Base, ORC_HDATA);
  231. ORC_WR(hcsp->HCS_Base + ORC_HSTUS, bData); /* Clear HDI */
  232. return (Version.sVersion);
  233. }
  234. /***************************************************************************/
  235. static UCHAR set_NVRAM(ORC_HCS * hcsp, unsigned char address, unsigned char value)
  236. {
  237. ORC_WR(hcsp->HCS_Base + ORC_HDATA, ORC_CMD_SET_NVM); /* Write command */
  238. ORC_WR(hcsp->HCS_Base + ORC_HCTRL, HDO);
  239. if (waitHDOoff(hcsp) == 0) /* Wait HDO off */
  240. return 0;
  241. ORC_WR(hcsp->HCS_Base + ORC_HDATA, address); /* Write address */
  242. ORC_WR(hcsp->HCS_Base + ORC_HCTRL, HDO);
  243. if (waitHDOoff(hcsp) == 0) /* Wait HDO off */
  244. return 0;
  245. ORC_WR(hcsp->HCS_Base + ORC_HDATA, value); /* Write value */
  246. ORC_WR(hcsp->HCS_Base + ORC_HCTRL, HDO);
  247. if (waitHDOoff(hcsp) == 0) /* Wait HDO off */
  248. return 0;
  249. return 1;
  250. }
  251. /***************************************************************************/
  252. static UCHAR get_NVRAM(ORC_HCS * hcsp, unsigned char address, unsigned char *pDataIn)
  253. {
  254. unsigned char bData;
  255. ORC_WR(hcsp->HCS_Base + ORC_HDATA, ORC_CMD_GET_NVM); /* Write command */
  256. ORC_WR(hcsp->HCS_Base + ORC_HCTRL, HDO);
  257. if (waitHDOoff(hcsp) == 0) /* Wait HDO off */
  258. return 0;
  259. ORC_WR(hcsp->HCS_Base + ORC_HDATA, address); /* Write address */
  260. ORC_WR(hcsp->HCS_Base + ORC_HCTRL, HDO);
  261. if (waitHDOoff(hcsp) == 0) /* Wait HDO off */
  262. return 0;
  263. if (waitHDIset(hcsp, &bData) == 0) /* Wait HDI set */
  264. return 0;
  265. *pDataIn = ORC_RD(hcsp->HCS_Base, ORC_HDATA);
  266. ORC_WR(hcsp->HCS_Base + ORC_HSTUS, bData); /* Clear HDI */
  267. return 1;
  268. }
  269. /***************************************************************************/
  270. static void orc_exec_scb(ORC_HCS * hcsp, ORC_SCB * scbp)
  271. {
  272. scbp->SCB_Status = ORCSCB_POST;
  273. ORC_WR(hcsp->HCS_Base + ORC_PQUEUE, scbp->SCB_ScbIdx);
  274. return;
  275. }
  276. /***********************************************************************
  277. Read SCSI H/A configuration parameters from serial EEPROM
  278. ************************************************************************/
  279. static int se2_rd_all(ORC_HCS * hcsp)
  280. {
  281. int i;
  282. UCHAR *np, chksum = 0;
  283. np = (UCHAR *) nvramp;
  284. for (i = 0; i < 64; i++, np++) { /* <01> */
  285. if (get_NVRAM(hcsp, (unsigned char) i, np) == 0)
  286. return -1;
  287. // *np++ = get_NVRAM(hcsp, (unsigned char ) i);
  288. }
  289. /*------ Is ckecksum ok ? ------*/
  290. np = (UCHAR *) nvramp;
  291. for (i = 0; i < 63; i++)
  292. chksum += *np++;
  293. if (nvramp->CheckSum != (UCHAR) chksum)
  294. return -1;
  295. return 1;
  296. }
  297. /************************************************************************
  298. Update SCSI H/A configuration parameters from serial EEPROM
  299. *************************************************************************/
  300. static void se2_update_all(ORC_HCS * hcsp)
  301. { /* setup default pattern */
  302. int i;
  303. UCHAR *np, *np1, chksum = 0;
  304. /* Calculate checksum first */
  305. np = (UCHAR *) dftNvRam;
  306. for (i = 0; i < 63; i++)
  307. chksum += *np++;
  308. *np = chksum;
  309. np = (UCHAR *) dftNvRam;
  310. np1 = (UCHAR *) nvramp;
  311. for (i = 0; i < 64; i++, np++, np1++) {
  312. if (*np != *np1) {
  313. set_NVRAM(hcsp, (unsigned char) i, *np);
  314. }
  315. }
  316. return;
  317. }
  318. /*************************************************************************
  319. Function name : read_eeprom
  320. **************************************************************************/
  321. static void read_eeprom(ORC_HCS * hcsp)
  322. {
  323. if (se2_rd_all(hcsp) != 1) {
  324. se2_update_all(hcsp); /* setup default pattern */
  325. se2_rd_all(hcsp); /* load again */
  326. }
  327. }
  328. /***************************************************************************/
  329. static UCHAR load_FW(ORC_HCS * hcsp)
  330. {
  331. U32 dData;
  332. USHORT wBIOSAddress;
  333. USHORT i;
  334. UCHAR *pData, bData;
  335. bData = ORC_RD(hcsp->HCS_Base, ORC_GCFG);
  336. ORC_WR(hcsp->HCS_Base + ORC_GCFG, bData | EEPRG); /* Enable EEPROM programming */
  337. ORC_WR(hcsp->HCS_Base + ORC_EBIOSADR2, 0x00);
  338. ORC_WRSHORT(hcsp->HCS_Base + ORC_EBIOSADR0, 0x00);
  339. if (ORC_RD(hcsp->HCS_Base, ORC_EBIOSDATA) != 0x55) {
  340. ORC_WR(hcsp->HCS_Base + ORC_GCFG, bData); /* Disable EEPROM programming */
  341. return 0;
  342. }
  343. ORC_WRSHORT(hcsp->HCS_Base + ORC_EBIOSADR0, 0x01);
  344. if (ORC_RD(hcsp->HCS_Base, ORC_EBIOSDATA) != 0xAA) {
  345. ORC_WR(hcsp->HCS_Base + ORC_GCFG, bData); /* Disable EEPROM programming */
  346. return 0;
  347. }
  348. ORC_WR(hcsp->HCS_Base + ORC_RISCCTL, PRGMRST | DOWNLOAD); /* Enable SRAM programming */
  349. pData = (UCHAR *) & dData;
  350. dData = 0; /* Initial FW address to 0 */
  351. ORC_WRSHORT(hcsp->HCS_Base + ORC_EBIOSADR0, 0x10);
  352. *pData = ORC_RD(hcsp->HCS_Base, ORC_EBIOSDATA); /* Read from BIOS */
  353. ORC_WRSHORT(hcsp->HCS_Base + ORC_EBIOSADR0, 0x11);
  354. *(pData + 1) = ORC_RD(hcsp->HCS_Base, ORC_EBIOSDATA); /* Read from BIOS */
  355. ORC_WRSHORT(hcsp->HCS_Base + ORC_EBIOSADR0, 0x12);
  356. *(pData + 2) = ORC_RD(hcsp->HCS_Base, ORC_EBIOSDATA); /* Read from BIOS */
  357. ORC_WR(hcsp->HCS_Base + ORC_EBIOSADR2, *(pData + 2));
  358. ORC_WRLONG(hcsp->HCS_Base + ORC_FWBASEADR, dData); /* Write FW address */
  359. wBIOSAddress = (USHORT) dData; /* FW code locate at BIOS address + ? */
  360. for (i = 0, pData = (UCHAR *) & dData; /* Download the code */
  361. i < 0x1000; /* Firmware code size = 4K */
  362. i++, wBIOSAddress++) {
  363. ORC_WRSHORT(hcsp->HCS_Base + ORC_EBIOSADR0, wBIOSAddress);
  364. *pData++ = ORC_RD(hcsp->HCS_Base, ORC_EBIOSDATA); /* Read from BIOS */
  365. if ((i % 4) == 3) {
  366. ORC_WRLONG(hcsp->HCS_Base + ORC_RISCRAM, dData); /* Write every 4 bytes */
  367. pData = (UCHAR *) & dData;
  368. }
  369. }
  370. ORC_WR(hcsp->HCS_Base + ORC_RISCCTL, PRGMRST | DOWNLOAD); /* Reset program count 0 */
  371. wBIOSAddress -= 0x1000; /* Reset the BIOS adddress */
  372. for (i = 0, pData = (UCHAR *) & dData; /* Check the code */
  373. i < 0x1000; /* Firmware code size = 4K */
  374. i++, wBIOSAddress++) {
  375. ORC_WRSHORT(hcsp->HCS_Base + ORC_EBIOSADR0, wBIOSAddress);
  376. *pData++ = ORC_RD(hcsp->HCS_Base, ORC_EBIOSDATA); /* Read from BIOS */
  377. if ((i % 4) == 3) {
  378. if (ORC_RDLONG(hcsp->HCS_Base, ORC_RISCRAM) != dData) {
  379. ORC_WR(hcsp->HCS_Base + ORC_RISCCTL, PRGMRST); /* Reset program to 0 */
  380. ORC_WR(hcsp->HCS_Base + ORC_GCFG, bData); /*Disable EEPROM programming */
  381. return 0;
  382. }
  383. pData = (UCHAR *) & dData;
  384. }
  385. }
  386. ORC_WR(hcsp->HCS_Base + ORC_RISCCTL, PRGMRST); /* Reset program to 0 */
  387. ORC_WR(hcsp->HCS_Base + ORC_GCFG, bData); /* Disable EEPROM programming */
  388. return 1;
  389. }
  390. /***************************************************************************/
  391. static void setup_SCBs(ORC_HCS * hcsp)
  392. {
  393. ORC_SCB *pVirScb;
  394. int i;
  395. ESCB *pVirEscb;
  396. dma_addr_t pPhysEscb;
  397. /* Setup SCB HCS_Base and SCB Size registers */
  398. ORC_WR(hcsp->HCS_Base + ORC_SCBSIZE, ORC_MAXQUEUE); /* Total number of SCBs */
  399. /* SCB HCS_Base address 0 */
  400. ORC_WRLONG(hcsp->HCS_Base + ORC_SCBBASE0, hcsp->HCS_physScbArray);
  401. /* SCB HCS_Base address 1 */
  402. ORC_WRLONG(hcsp->HCS_Base + ORC_SCBBASE1, hcsp->HCS_physScbArray);
  403. /* setup scatter list address with one buffer */
  404. pVirScb = hcsp->HCS_virScbArray;
  405. pVirEscb = hcsp->HCS_virEscbArray;
  406. for (i = 0; i < ORC_MAXQUEUE; i++) {
  407. pPhysEscb = (hcsp->HCS_physEscbArray + (sizeof(ESCB) * i));
  408. pVirScb->SCB_SGPAddr = (U32) pPhysEscb;
  409. pVirScb->SCB_SensePAddr = (U32) pPhysEscb;
  410. pVirScb->SCB_EScb = pVirEscb;
  411. pVirScb->SCB_ScbIdx = i;
  412. pVirScb++;
  413. pVirEscb++;
  414. }
  415. return;
  416. }
  417. /***************************************************************************/
  418. static void initAFlag(ORC_HCS * hcsp)
  419. {
  420. UCHAR i, j;
  421. for (i = 0; i < MAX_CHANNELS; i++) {
  422. for (j = 0; j < 8; j++) {
  423. hcsp->BitAllocFlag[i][j] = 0xffffffff;
  424. }
  425. }
  426. }
  427. /***************************************************************************/
  428. static int init_orchid(ORC_HCS * hcsp)
  429. {
  430. UBYTE *readBytep;
  431. USHORT revision;
  432. UCHAR i;
  433. initAFlag(hcsp);
  434. ORC_WR(hcsp->HCS_Base + ORC_GIMSK, 0xFF); /* Disable all interrupt */
  435. if (ORC_RD(hcsp->HCS_Base, ORC_HSTUS) & RREADY) { /* Orchid is ready */
  436. revision = get_FW_version(hcsp);
  437. if (revision == 0xFFFF) {
  438. ORC_WR(hcsp->HCS_Base + ORC_HCTRL, DEVRST); /* Reset Host Adapter */
  439. if (waitChipReady(hcsp) == 0)
  440. return (-1);
  441. load_FW(hcsp); /* Download FW */
  442. setup_SCBs(hcsp); /* Setup SCB HCS_Base and SCB Size registers */
  443. ORC_WR(hcsp->HCS_Base + ORC_HCTRL, 0); /* clear HOSTSTOP */
  444. if (waitFWReady(hcsp) == 0)
  445. return (-1);
  446. /* Wait for firmware ready */
  447. } else {
  448. setup_SCBs(hcsp); /* Setup SCB HCS_Base and SCB Size registers */
  449. }
  450. } else { /* Orchid is not Ready */
  451. ORC_WR(hcsp->HCS_Base + ORC_HCTRL, DEVRST); /* Reset Host Adapter */
  452. if (waitChipReady(hcsp) == 0)
  453. return (-1);
  454. load_FW(hcsp); /* Download FW */
  455. setup_SCBs(hcsp); /* Setup SCB HCS_Base and SCB Size registers */
  456. ORC_WR(hcsp->HCS_Base + ORC_HCTRL, HDO); /* Do Hardware Reset & */
  457. /* clear HOSTSTOP */
  458. if (waitFWReady(hcsp) == 0) /* Wait for firmware ready */
  459. return (-1);
  460. }
  461. /*------------- get serial EEProm settting -------*/
  462. read_eeprom(hcsp);
  463. if (nvramp->Revision != 1)
  464. return (-1);
  465. hcsp->HCS_SCSI_ID = nvramp->SCSI0Id;
  466. hcsp->HCS_BIOS = nvramp->BIOSConfig1;
  467. hcsp->HCS_MaxTar = MAX_TARGETS;
  468. readBytep = (UCHAR *) & (nvramp->Target00Config);
  469. for (i = 0; i < 16; readBytep++, i++) {
  470. hcsp->TargetFlag[i] = *readBytep;
  471. hcsp->MaximumTags[i] = ORC_MAXTAGS;
  472. } /* for */
  473. if (nvramp->SCSI0Config & NCC_BUSRESET) { /* Reset SCSI bus */
  474. hcsp->HCS_Flags |= HCF_SCSI_RESET;
  475. }
  476. ORC_WR(hcsp->HCS_Base + ORC_GIMSK, 0xFB); /* enable RP FIFO interrupt */
  477. return (0);
  478. }
  479. /*****************************************************************************
  480. Function name : orc_reset_scsi_bus
  481. Description : Reset registers, reset a hanging bus and
  482. kill active and disconnected commands for target w/o soft reset
  483. Input : pHCB - Pointer to host adapter structure
  484. Output : None.
  485. Return : pSRB - Pointer to SCSI request block.
  486. *****************************************************************************/
  487. static int orc_reset_scsi_bus(ORC_HCS * pHCB)
  488. { /* I need Host Control Block Information */
  489. ULONG flags;
  490. spin_lock_irqsave(&(pHCB->BitAllocFlagLock), flags);
  491. initAFlag(pHCB);
  492. /* reset scsi bus */
  493. ORC_WR(pHCB->HCS_Base + ORC_HCTRL, SCSIRST);
  494. if (waitSCSIRSTdone(pHCB) == 0) {
  495. spin_unlock_irqrestore(&(pHCB->BitAllocFlagLock), flags);
  496. return FAILED;
  497. } else {
  498. spin_unlock_irqrestore(&(pHCB->BitAllocFlagLock), flags);
  499. return SUCCESS;
  500. }
  501. }
  502. /*****************************************************************************
  503. Function name : orc_device_reset
  504. Description : Reset registers, reset a hanging bus and
  505. kill active and disconnected commands for target w/o soft reset
  506. Input : pHCB - Pointer to host adapter structure
  507. Output : None.
  508. Return : pSRB - Pointer to SCSI request block.
  509. *****************************************************************************/
  510. static int orc_device_reset(ORC_HCS * pHCB, struct scsi_cmnd *SCpnt, unsigned int target)
  511. { /* I need Host Control Block Information */
  512. ORC_SCB *pScb;
  513. ESCB *pVirEscb;
  514. ORC_SCB *pVirScb;
  515. UCHAR i;
  516. ULONG flags;
  517. spin_lock_irqsave(&(pHCB->BitAllocFlagLock), flags);
  518. pScb = (ORC_SCB *) NULL;
  519. pVirEscb = (ESCB *) NULL;
  520. /* setup scatter list address with one buffer */
  521. pVirScb = pHCB->HCS_virScbArray;
  522. initAFlag(pHCB);
  523. /* device reset */
  524. for (i = 0; i < ORC_MAXQUEUE; i++) {
  525. pVirEscb = pVirScb->SCB_EScb;
  526. if ((pVirScb->SCB_Status) && (pVirEscb->SCB_Srb == SCpnt))
  527. break;
  528. pVirScb++;
  529. }
  530. if (i == ORC_MAXQUEUE) {
  531. printk("Unable to Reset - No SCB Found\n");
  532. spin_unlock_irqrestore(&(pHCB->BitAllocFlagLock), flags);
  533. return FAILED;
  534. }
  535. if ((pScb = orc_alloc_scb(pHCB)) == NULL) {
  536. spin_unlock_irqrestore(&(pHCB->BitAllocFlagLock), flags);
  537. return FAILED;
  538. }
  539. pScb->SCB_Opcode = ORC_BUSDEVRST;
  540. pScb->SCB_Target = target;
  541. pScb->SCB_HaStat = 0;
  542. pScb->SCB_TaStat = 0;
  543. pScb->SCB_Status = 0x0;
  544. pScb->SCB_Link = 0xFF;
  545. pScb->SCB_Reserved0 = 0;
  546. pScb->SCB_Reserved1 = 0;
  547. pScb->SCB_XferLen = 0;
  548. pScb->SCB_SGLen = 0;
  549. pVirEscb->SCB_Srb = NULL;
  550. pVirEscb->SCB_Srb = SCpnt;
  551. orc_exec_scb(pHCB, pScb); /* Start execute SCB */
  552. spin_unlock_irqrestore(&(pHCB->BitAllocFlagLock), flags);
  553. return SUCCESS;
  554. }
  555. /***************************************************************************/
  556. static ORC_SCB *__orc_alloc_scb(ORC_HCS * hcsp)
  557. {
  558. ORC_SCB *pTmpScb;
  559. UCHAR Ch;
  560. ULONG idx;
  561. UCHAR index;
  562. UCHAR i;
  563. Ch = hcsp->HCS_Index;
  564. for (i = 0; i < 8; i++) {
  565. for (index = 0; index < 32; index++) {
  566. if ((hcsp->BitAllocFlag[Ch][i] >> index) & 0x01) {
  567. hcsp->BitAllocFlag[Ch][i] &= ~(1 << index);
  568. break;
  569. }
  570. }
  571. idx = index + 32 * i;
  572. pTmpScb = (ORC_SCB *) ((ULONG) hcsp->HCS_virScbArray + (idx * sizeof(ORC_SCB)));
  573. return (pTmpScb);
  574. }
  575. return (NULL);
  576. }
  577. static ORC_SCB *orc_alloc_scb(ORC_HCS * hcsp)
  578. {
  579. ORC_SCB *pTmpScb;
  580. ULONG flags;
  581. spin_lock_irqsave(&(hcsp->BitAllocFlagLock), flags);
  582. pTmpScb = __orc_alloc_scb(hcsp);
  583. spin_unlock_irqrestore(&(hcsp->BitAllocFlagLock), flags);
  584. return (pTmpScb);
  585. }
  586. /***************************************************************************/
  587. static void orc_release_scb(ORC_HCS * hcsp, ORC_SCB * scbp)
  588. {
  589. ULONG flags;
  590. UCHAR Index;
  591. UCHAR i;
  592. UCHAR Ch;
  593. spin_lock_irqsave(&(hcsp->BitAllocFlagLock), flags);
  594. Ch = hcsp->HCS_Index;
  595. Index = scbp->SCB_ScbIdx;
  596. i = Index / 32;
  597. Index %= 32;
  598. hcsp->BitAllocFlag[Ch][i] |= (1 << Index);
  599. spin_unlock_irqrestore(&(hcsp->BitAllocFlagLock), flags);
  600. }
  601. /*****************************************************************************
  602. Function name : abort_SCB
  603. Description : Abort a queued command.
  604. (commands that are on the bus can't be aborted easily)
  605. Input : pHCB - Pointer to host adapter structure
  606. Output : None.
  607. Return : pSRB - Pointer to SCSI request block.
  608. *****************************************************************************/
  609. static int abort_SCB(ORC_HCS * hcsp, ORC_SCB * pScb)
  610. {
  611. unsigned char bData, bStatus;
  612. ORC_WR(hcsp->HCS_Base + ORC_HDATA, ORC_CMD_ABORT_SCB); /* Write command */
  613. ORC_WR(hcsp->HCS_Base + ORC_HCTRL, HDO);
  614. if (waitHDOoff(hcsp) == 0) /* Wait HDO off */
  615. return 0;
  616. ORC_WR(hcsp->HCS_Base + ORC_HDATA, pScb->SCB_ScbIdx); /* Write address */
  617. ORC_WR(hcsp->HCS_Base + ORC_HCTRL, HDO);
  618. if (waitHDOoff(hcsp) == 0) /* Wait HDO off */
  619. return 0;
  620. if (waitHDIset(hcsp, &bData) == 0) /* Wait HDI set */
  621. return 0;
  622. bStatus = ORC_RD(hcsp->HCS_Base, ORC_HDATA);
  623. ORC_WR(hcsp->HCS_Base + ORC_HSTUS, bData); /* Clear HDI */
  624. if (bStatus == 1) /* 0 - Successfully */
  625. return 0; /* 1 - Fail */
  626. return 1;
  627. }
  628. /*****************************************************************************
  629. Function name : inia100_abort
  630. Description : Abort a queued command.
  631. (commands that are on the bus can't be aborted easily)
  632. Input : pHCB - Pointer to host adapter structure
  633. Output : None.
  634. Return : pSRB - Pointer to SCSI request block.
  635. *****************************************************************************/
  636. static int orc_abort_srb(ORC_HCS * hcsp, struct scsi_cmnd *SCpnt)
  637. {
  638. ESCB *pVirEscb;
  639. ORC_SCB *pVirScb;
  640. UCHAR i;
  641. ULONG flags;
  642. spin_lock_irqsave(&(hcsp->BitAllocFlagLock), flags);
  643. pVirScb = hcsp->HCS_virScbArray;
  644. for (i = 0; i < ORC_MAXQUEUE; i++, pVirScb++) {
  645. pVirEscb = pVirScb->SCB_EScb;
  646. if ((pVirScb->SCB_Status) && (pVirEscb->SCB_Srb == SCpnt)) {
  647. if (pVirScb->SCB_TagMsg == 0) {
  648. spin_unlock_irqrestore(&(hcsp->BitAllocFlagLock), flags);
  649. return FAILED;
  650. } else {
  651. if (abort_SCB(hcsp, pVirScb)) {
  652. pVirEscb->SCB_Srb = NULL;
  653. spin_unlock_irqrestore(&(hcsp->BitAllocFlagLock), flags);
  654. return SUCCESS;
  655. } else {
  656. spin_unlock_irqrestore(&(hcsp->BitAllocFlagLock), flags);
  657. return FAILED;
  658. }
  659. }
  660. }
  661. }
  662. spin_unlock_irqrestore(&(hcsp->BitAllocFlagLock), flags);
  663. return FAILED;
  664. }
  665. /***********************************************************************
  666. Routine Description:
  667. This is the interrupt service routine for the Orchid SCSI adapter.
  668. It reads the interrupt register to determine if the adapter is indeed
  669. the source of the interrupt and clears the interrupt at the device.
  670. Arguments:
  671. HwDeviceExtension - HBA miniport driver's adapter data storage
  672. Return Value:
  673. ***********************************************************************/
  674. static void orc_interrupt(
  675. ORC_HCS * hcsp
  676. )
  677. {
  678. BYTE bScbIdx;
  679. ORC_SCB *pScb;
  680. if (ORC_RD(hcsp->HCS_Base, ORC_RQUEUECNT) == 0) {
  681. return; // 0;
  682. }
  683. do {
  684. bScbIdx = ORC_RD(hcsp->HCS_Base, ORC_RQUEUE);
  685. pScb = (ORC_SCB *) ((ULONG) hcsp->HCS_virScbArray + (ULONG) (sizeof(ORC_SCB) * bScbIdx));
  686. pScb->SCB_Status = 0x0;
  687. inia100SCBPost((BYTE *) hcsp, (BYTE *) pScb);
  688. } while (ORC_RD(hcsp->HCS_Base, ORC_RQUEUECNT));
  689. return; //1;
  690. } /* End of I1060Interrupt() */
  691. /*****************************************************************************
  692. Function name : inia100BuildSCB
  693. Description :
  694. Input : pHCB - Pointer to host adapter structure
  695. Output : None.
  696. Return : pSRB - Pointer to SCSI request block.
  697. *****************************************************************************/
  698. static void inia100BuildSCB(ORC_HCS * pHCB, ORC_SCB * pSCB, struct scsi_cmnd * SCpnt)
  699. { /* Create corresponding SCB */
  700. struct scatterlist *pSrbSG;
  701. ORC_SG *pSG; /* Pointer to SG list */
  702. int i, count_sg;
  703. ESCB *pEScb;
  704. pEScb = pSCB->SCB_EScb;
  705. pEScb->SCB_Srb = SCpnt;
  706. pSG = NULL;
  707. pSCB->SCB_Opcode = ORC_EXECSCSI;
  708. pSCB->SCB_Flags = SCF_NO_DCHK; /* Clear done bit */
  709. pSCB->SCB_Target = SCpnt->device->id;
  710. pSCB->SCB_Lun = SCpnt->device->lun;
  711. pSCB->SCB_Reserved0 = 0;
  712. pSCB->SCB_Reserved1 = 0;
  713. pSCB->SCB_SGLen = 0;
  714. if ((pSCB->SCB_XferLen = (U32) SCpnt->request_bufflen)) {
  715. pSG = (ORC_SG *) & pEScb->ESCB_SGList[0];
  716. if (SCpnt->use_sg) {
  717. pSrbSG = (struct scatterlist *) SCpnt->request_buffer;
  718. count_sg = pci_map_sg(pHCB->pdev, pSrbSG, SCpnt->use_sg,
  719. SCpnt->sc_data_direction);
  720. pSCB->SCB_SGLen = (U32) (count_sg * 8);
  721. for (i = 0; i < count_sg; i++, pSG++, pSrbSG++) {
  722. pSG->SG_Ptr = (U32) sg_dma_address(pSrbSG);
  723. pSG->SG_Len = (U32) sg_dma_len(pSrbSG);
  724. }
  725. } else if (SCpnt->request_bufflen != 0) {/* Non SG */
  726. pSCB->SCB_SGLen = 0x8;
  727. SCpnt->SCp.dma_handle = pci_map_single(pHCB->pdev,
  728. SCpnt->request_buffer,
  729. SCpnt->request_bufflen,
  730. SCpnt->sc_data_direction);
  731. pSG->SG_Ptr = (U32) SCpnt->SCp.dma_handle;
  732. pSG->SG_Len = (U32) SCpnt->request_bufflen;
  733. } else {
  734. pSCB->SCB_SGLen = 0;
  735. pSG->SG_Ptr = 0;
  736. pSG->SG_Len = 0;
  737. }
  738. }
  739. pSCB->SCB_SGPAddr = (U32) pSCB->SCB_SensePAddr;
  740. pSCB->SCB_HaStat = 0;
  741. pSCB->SCB_TaStat = 0;
  742. pSCB->SCB_Link = 0xFF;
  743. pSCB->SCB_SenseLen = SENSE_SIZE;
  744. pSCB->SCB_CDBLen = SCpnt->cmd_len;
  745. if (pSCB->SCB_CDBLen >= IMAX_CDB) {
  746. printk("max cdb length= %x\b", SCpnt->cmd_len);
  747. pSCB->SCB_CDBLen = IMAX_CDB;
  748. }
  749. pSCB->SCB_Ident = SCpnt->device->lun | DISC_ALLOW;
  750. if (SCpnt->device->tagged_supported) { /* Tag Support */
  751. pSCB->SCB_TagMsg = SIMPLE_QUEUE_TAG; /* Do simple tag only */
  752. } else {
  753. pSCB->SCB_TagMsg = 0; /* No tag support */
  754. }
  755. memcpy(&pSCB->SCB_CDB[0], &SCpnt->cmnd, pSCB->SCB_CDBLen);
  756. return;
  757. }
  758. /*****************************************************************************
  759. Function name : inia100_queue
  760. Description : Queue a command and setup interrupts for a free bus.
  761. Input : pHCB - Pointer to host adapter structure
  762. Output : None.
  763. Return : pSRB - Pointer to SCSI request block.
  764. *****************************************************************************/
  765. static int inia100_queue(struct scsi_cmnd * SCpnt, void (*done) (struct scsi_cmnd *))
  766. {
  767. register ORC_SCB *pSCB;
  768. ORC_HCS *pHCB; /* Point to Host adapter control block */
  769. pHCB = (ORC_HCS *) SCpnt->device->host->hostdata;
  770. SCpnt->scsi_done = done;
  771. /* Get free SCSI control block */
  772. if ((pSCB = orc_alloc_scb(pHCB)) == NULL)
  773. return SCSI_MLQUEUE_HOST_BUSY;
  774. inia100BuildSCB(pHCB, pSCB, SCpnt);
  775. orc_exec_scb(pHCB, pSCB); /* Start execute SCB */
  776. return (0);
  777. }
  778. /*****************************************************************************
  779. Function name : inia100_abort
  780. Description : Abort a queued command.
  781. (commands that are on the bus can't be aborted easily)
  782. Input : pHCB - Pointer to host adapter structure
  783. Output : None.
  784. Return : pSRB - Pointer to SCSI request block.
  785. *****************************************************************************/
  786. static int inia100_abort(struct scsi_cmnd * SCpnt)
  787. {
  788. ORC_HCS *hcsp;
  789. hcsp = (ORC_HCS *) SCpnt->device->host->hostdata;
  790. return orc_abort_srb(hcsp, SCpnt);
  791. }
  792. /*****************************************************************************
  793. Function name : inia100_reset
  794. Description : Reset registers, reset a hanging bus and
  795. kill active and disconnected commands for target w/o soft reset
  796. Input : pHCB - Pointer to host adapter structure
  797. Output : None.
  798. Return : pSRB - Pointer to SCSI request block.
  799. *****************************************************************************/
  800. static int inia100_bus_reset(struct scsi_cmnd * SCpnt)
  801. { /* I need Host Control Block Information */
  802. ORC_HCS *pHCB;
  803. pHCB = (ORC_HCS *) SCpnt->device->host->hostdata;
  804. return orc_reset_scsi_bus(pHCB);
  805. }
  806. /*****************************************************************************
  807. Function name : inia100_device_reset
  808. Description : Reset the device
  809. Input : pHCB - Pointer to host adapter structure
  810. Output : None.
  811. Return : pSRB - Pointer to SCSI request block.
  812. *****************************************************************************/
  813. static int inia100_device_reset(struct scsi_cmnd * SCpnt)
  814. { /* I need Host Control Block Information */
  815. ORC_HCS *pHCB;
  816. pHCB = (ORC_HCS *) SCpnt->device->host->hostdata;
  817. return orc_device_reset(pHCB, SCpnt, scmd_id(SCpnt));
  818. }
  819. /*****************************************************************************
  820. Function name : inia100SCBPost
  821. Description : This is callback routine be called when orc finish one
  822. SCSI command.
  823. Input : pHCB - Pointer to host adapter control block.
  824. pSCB - Pointer to SCSI control block.
  825. Output : None.
  826. Return : None.
  827. *****************************************************************************/
  828. static void inia100SCBPost(BYTE * pHcb, BYTE * pScb)
  829. {
  830. struct scsi_cmnd *pSRB; /* Pointer to SCSI request block */
  831. ORC_HCS *pHCB;
  832. ORC_SCB *pSCB;
  833. ESCB *pEScb;
  834. pHCB = (ORC_HCS *) pHcb;
  835. pSCB = (ORC_SCB *) pScb;
  836. pEScb = pSCB->SCB_EScb;
  837. if ((pSRB = (struct scsi_cmnd *) pEScb->SCB_Srb) == 0) {
  838. printk("inia100SCBPost: SRB pointer is empty\n");
  839. orc_release_scb(pHCB, pSCB); /* Release SCB for current channel */
  840. return;
  841. }
  842. pEScb->SCB_Srb = NULL;
  843. switch (pSCB->SCB_HaStat) {
  844. case 0x0:
  845. case 0xa: /* Linked command complete without error and linked normally */
  846. case 0xb: /* Linked command complete without error interrupt generated */
  847. pSCB->SCB_HaStat = 0;
  848. break;
  849. case 0x11: /* Selection time out-The initiator selection or target
  850. reselection was not complete within the SCSI Time out period */
  851. pSCB->SCB_HaStat = DID_TIME_OUT;
  852. break;
  853. case 0x14: /* Target bus phase sequence failure-An invalid bus phase or bus
  854. phase sequence was requested by the target. The host adapter
  855. will generate a SCSI Reset Condition, notifying the host with
  856. a SCRD interrupt */
  857. pSCB->SCB_HaStat = DID_RESET;
  858. break;
  859. case 0x1a: /* SCB Aborted. 07/21/98 */
  860. pSCB->SCB_HaStat = DID_ABORT;
  861. break;
  862. case 0x12: /* Data overrun/underrun-The target attempted to transfer more data
  863. than was allocated by the Data Length field or the sum of the
  864. Scatter / Gather Data Length fields. */
  865. case 0x13: /* Unexpected bus free-The target dropped the SCSI BSY at an unexpected time. */
  866. case 0x16: /* Invalid CCB Operation Code-The first byte of the CCB was invalid. */
  867. default:
  868. printk("inia100: %x %x\n", pSCB->SCB_HaStat, pSCB->SCB_TaStat);
  869. pSCB->SCB_HaStat = DID_ERROR; /* Couldn't find any better */
  870. break;
  871. }
  872. if (pSCB->SCB_TaStat == 2) { /* Check condition */
  873. memcpy((unsigned char *) &pSRB->sense_buffer[0],
  874. (unsigned char *) &pEScb->ESCB_SGList[0], SENSE_SIZE);
  875. }
  876. pSRB->result = pSCB->SCB_TaStat | (pSCB->SCB_HaStat << 16);
  877. if (pSRB->use_sg) {
  878. pci_unmap_sg(pHCB->pdev,
  879. (struct scatterlist *)pSRB->request_buffer,
  880. pSRB->use_sg, pSRB->sc_data_direction);
  881. } else if (pSRB->request_bufflen != 0) {
  882. pci_unmap_single(pHCB->pdev, pSRB->SCp.dma_handle,
  883. pSRB->request_bufflen,
  884. pSRB->sc_data_direction);
  885. }
  886. pSRB->scsi_done(pSRB); /* Notify system DONE */
  887. orc_release_scb(pHCB, pSCB); /* Release SCB for current channel */
  888. }
  889. /*
  890. * Interrupt handler (main routine of the driver)
  891. */
  892. static irqreturn_t inia100_intr(int irqno, void *devid, struct pt_regs *regs)
  893. {
  894. struct Scsi_Host *host = (struct Scsi_Host *)devid;
  895. ORC_HCS *pHcb = (ORC_HCS *)host->hostdata;
  896. unsigned long flags;
  897. spin_lock_irqsave(host->host_lock, flags);
  898. orc_interrupt(pHcb);
  899. spin_unlock_irqrestore(host->host_lock, flags);
  900. return IRQ_HANDLED;
  901. }
  902. static struct scsi_host_template inia100_template = {
  903. .proc_name = "inia100",
  904. .name = inia100_REVID,
  905. .queuecommand = inia100_queue,
  906. .eh_abort_handler = inia100_abort,
  907. .eh_bus_reset_handler = inia100_bus_reset,
  908. .eh_device_reset_handler = inia100_device_reset,
  909. .can_queue = 1,
  910. .this_id = 1,
  911. .sg_tablesize = SG_ALL,
  912. .cmd_per_lun = 1,
  913. .use_clustering = ENABLE_CLUSTERING,
  914. };
  915. static int __devinit inia100_probe_one(struct pci_dev *pdev,
  916. const struct pci_device_id *id)
  917. {
  918. struct Scsi_Host *shost;
  919. ORC_HCS *pHCB;
  920. unsigned long port, bios;
  921. int error = -ENODEV;
  922. u32 sz;
  923. unsigned long dBiosAdr;
  924. char *pbBiosAdr;
  925. if (pci_enable_device(pdev))
  926. goto out;
  927. if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
  928. printk(KERN_WARNING "Unable to set 32bit DMA "
  929. "on inia100 adapter, ignoring.\n");
  930. goto out_disable_device;
  931. }
  932. pci_set_master(pdev);
  933. port = pci_resource_start(pdev, 0);
  934. if (!request_region(port, 256, "inia100")) {
  935. printk(KERN_WARNING "inia100: io port 0x%lx, is busy.\n", port);
  936. goto out_disable_device;
  937. }
  938. /* <02> read from base address + 0x50 offset to get the bios balue. */
  939. bios = ORC_RDWORD(port, 0x50);
  940. shost = scsi_host_alloc(&inia100_template, sizeof(ORC_HCS));
  941. if (!shost)
  942. goto out_release_region;
  943. pHCB = (ORC_HCS *)shost->hostdata;
  944. pHCB->pdev = pdev;
  945. pHCB->HCS_Base = port;
  946. pHCB->HCS_BIOS = bios;
  947. spin_lock_init(&pHCB->BitAllocFlagLock);
  948. /* Get total memory needed for SCB */
  949. sz = ORC_MAXQUEUE * sizeof(ORC_SCB);
  950. pHCB->HCS_virScbArray = pci_alloc_consistent(pdev, sz,
  951. &pHCB->HCS_physScbArray);
  952. if (!pHCB->HCS_virScbArray) {
  953. printk("inia100: SCB memory allocation error\n");
  954. goto out_host_put;
  955. }
  956. memset(pHCB->HCS_virScbArray, 0, sz);
  957. /* Get total memory needed for ESCB */
  958. sz = ORC_MAXQUEUE * sizeof(ESCB);
  959. pHCB->HCS_virEscbArray = pci_alloc_consistent(pdev, sz,
  960. &pHCB->HCS_physEscbArray);
  961. if (!pHCB->HCS_virEscbArray) {
  962. printk("inia100: ESCB memory allocation error\n");
  963. goto out_free_scb_array;
  964. }
  965. memset(pHCB->HCS_virEscbArray, 0, sz);
  966. dBiosAdr = pHCB->HCS_BIOS;
  967. dBiosAdr = (dBiosAdr << 4);
  968. pbBiosAdr = phys_to_virt(dBiosAdr);
  969. if (init_orchid(pHCB)) { /* Initialize orchid chip */
  970. printk("inia100: initial orchid fail!!\n");
  971. goto out_free_escb_array;
  972. }
  973. shost->io_port = pHCB->HCS_Base;
  974. shost->n_io_port = 0xff;
  975. shost->can_queue = ORC_MAXQUEUE;
  976. shost->unique_id = shost->io_port;
  977. shost->max_id = pHCB->HCS_MaxTar;
  978. shost->max_lun = 16;
  979. shost->irq = pHCB->HCS_Intr = pdev->irq;
  980. shost->this_id = pHCB->HCS_SCSI_ID; /* Assign HCS index */
  981. shost->sg_tablesize = TOTAL_SG_ENTRY;
  982. /* Initial orc chip */
  983. error = request_irq(pdev->irq, inia100_intr, SA_SHIRQ,
  984. "inia100", shost);
  985. if (error < 0) {
  986. printk(KERN_WARNING "inia100: unable to get irq %d\n",
  987. pdev->irq);
  988. goto out_free_escb_array;
  989. }
  990. pci_set_drvdata(pdev, shost);
  991. error = scsi_add_host(shost, &pdev->dev);
  992. if (error)
  993. goto out_free_irq;
  994. scsi_scan_host(shost);
  995. return 0;
  996. out_free_irq:
  997. free_irq(shost->irq, shost);
  998. out_free_escb_array:
  999. pci_free_consistent(pdev, ORC_MAXQUEUE * sizeof(ESCB),
  1000. pHCB->HCS_virEscbArray, pHCB->HCS_physEscbArray);
  1001. out_free_scb_array:
  1002. pci_free_consistent(pdev, ORC_MAXQUEUE * sizeof(ORC_SCB),
  1003. pHCB->HCS_virScbArray, pHCB->HCS_physScbArray);
  1004. out_host_put:
  1005. scsi_host_put(shost);
  1006. out_release_region:
  1007. release_region(port, 256);
  1008. out_disable_device:
  1009. pci_disable_device(pdev);
  1010. out:
  1011. return error;
  1012. }
  1013. static void __devexit inia100_remove_one(struct pci_dev *pdev)
  1014. {
  1015. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  1016. ORC_HCS *pHCB = (ORC_HCS *)shost->hostdata;
  1017. scsi_remove_host(shost);
  1018. free_irq(shost->irq, shost);
  1019. pci_free_consistent(pdev, ORC_MAXQUEUE * sizeof(ESCB),
  1020. pHCB->HCS_virEscbArray, pHCB->HCS_physEscbArray);
  1021. pci_free_consistent(pdev, ORC_MAXQUEUE * sizeof(ORC_SCB),
  1022. pHCB->HCS_virScbArray, pHCB->HCS_physScbArray);
  1023. release_region(shost->io_port, 256);
  1024. scsi_host_put(shost);
  1025. }
  1026. static struct pci_device_id inia100_pci_tbl[] = {
  1027. {PCI_VENDOR_ID_INIT, 0x1060, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1028. {0,}
  1029. };
  1030. MODULE_DEVICE_TABLE(pci, inia100_pci_tbl);
  1031. static struct pci_driver inia100_pci_driver = {
  1032. .name = "inia100",
  1033. .id_table = inia100_pci_tbl,
  1034. .probe = inia100_probe_one,
  1035. .remove = __devexit_p(inia100_remove_one),
  1036. };
  1037. static int __init inia100_init(void)
  1038. {
  1039. return pci_module_init(&inia100_pci_driver);
  1040. }
  1041. static void __exit inia100_exit(void)
  1042. {
  1043. pci_unregister_driver(&inia100_pci_driver);
  1044. }
  1045. MODULE_DESCRIPTION("Initio A100U2W SCSI driver");
  1046. MODULE_AUTHOR("Initio Corporation");
  1047. MODULE_LICENSE("Dual BSD/GPL");
  1048. module_init(inia100_init);
  1049. module_exit(inia100_exit);