aha1542.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809
  1. /* $Id: aha1542.c,v 1.1 1992/07/24 06:27:38 root Exp root $
  2. * linux/kernel/aha1542.c
  3. *
  4. * Copyright (C) 1992 Tommy Thorn
  5. * Copyright (C) 1993, 1994, 1995 Eric Youngdale
  6. *
  7. * Modified by Eric Youngdale
  8. * Use request_irq and request_dma to help prevent unexpected conflicts
  9. * Set up on-board DMA controller, such that we do not have to
  10. * have the bios enabled to use the aha1542.
  11. * Modified by David Gentzel
  12. * Don't call request_dma if dma mask is 0 (for BusLogic BT-445S VL-Bus
  13. * controller).
  14. * Modified by Matti Aarnio
  15. * Accept parameters from LILO cmd-line. -- 1-Oct-94
  16. * Modified by Mike McLagan <mike.mclagan@linux.org>
  17. * Recognise extended mode on AHA1542CP, different bit than 1542CF
  18. * 1-Jan-97
  19. * Modified by Bjorn L. Thordarson and Einar Thor Einarsson
  20. * Recognize that DMA0 is valid DMA channel -- 13-Jul-98
  21. * Modified by Chris Faulhaber <jedgar@fxp.org>
  22. * Added module command-line options
  23. * 19-Jul-99
  24. * Modified by Adam Fritzler <mid@auk.cx>
  25. * Added proper detection of the AHA-1640 (MCA version of AHA-1540)
  26. */
  27. #include <linux/config.h>
  28. #include <linux/module.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/kernel.h>
  31. #include <linux/types.h>
  32. #include <linux/string.h>
  33. #include <linux/ioport.h>
  34. #include <linux/delay.h>
  35. #include <linux/proc_fs.h>
  36. #include <linux/init.h>
  37. #include <linux/spinlock.h>
  38. #include <linux/pci.h>
  39. #include <linux/isapnp.h>
  40. #include <linux/blkdev.h>
  41. #include <linux/mca.h>
  42. #include <linux/mca-legacy.h>
  43. #include <asm/dma.h>
  44. #include <asm/system.h>
  45. #include <asm/io.h>
  46. #include "scsi.h"
  47. #include <scsi/scsi_host.h>
  48. #include "aha1542.h"
  49. #define SCSI_BUF_PA(address) isa_virt_to_bus(address)
  50. #define SCSI_SG_PA(sgent) (isa_page_to_bus((sgent)->page) + (sgent)->offset)
  51. static void BAD_DMA(void *address, unsigned int length)
  52. {
  53. printk(KERN_CRIT "buf vaddress %p paddress 0x%lx length %d\n",
  54. address,
  55. SCSI_BUF_PA(address),
  56. length);
  57. panic("Buffer at physical address > 16Mb used for aha1542");
  58. }
  59. static void BAD_SG_DMA(Scsi_Cmnd * SCpnt,
  60. struct scatterlist *sgpnt,
  61. int nseg,
  62. int badseg)
  63. {
  64. printk(KERN_CRIT "sgpnt[%d:%d] page %p/0x%llx length %u\n",
  65. badseg, nseg,
  66. page_address(sgpnt[badseg].page) + sgpnt[badseg].offset,
  67. (unsigned long long)SCSI_SG_PA(&sgpnt[badseg]),
  68. sgpnt[badseg].length);
  69. /*
  70. * Not safe to continue.
  71. */
  72. panic("Buffer at physical address > 16Mb used for aha1542");
  73. }
  74. #include<linux/stat.h>
  75. #ifdef DEBUG
  76. #define DEB(x) x
  77. #else
  78. #define DEB(x)
  79. #endif
  80. /*
  81. static const char RCSid[] = "$Header: /usr/src/linux/kernel/blk_drv/scsi/RCS/aha1542.c,v 1.1 1992/07/24 06:27:38 root Exp root $";
  82. */
  83. /* The adaptec can be configured for quite a number of addresses, but
  84. I generally do not want the card poking around at random. We allow
  85. two addresses - this allows people to use the Adaptec with a Midi
  86. card, which also used 0x330 -- can be overridden with LILO! */
  87. #define MAXBOARDS 4 /* Increase this and the sizes of the
  88. arrays below, if you need more.. */
  89. /* Boards 3,4 slots are reserved for ISAPnP/MCA scans */
  90. static unsigned int bases[MAXBOARDS] __initdata = {0x330, 0x334, 0, 0};
  91. /* set by aha1542_setup according to the command line; they also may
  92. be marked __initdata, but require zero initializers then */
  93. static int setup_called[MAXBOARDS];
  94. static int setup_buson[MAXBOARDS];
  95. static int setup_busoff[MAXBOARDS];
  96. static int setup_dmaspeed[MAXBOARDS] __initdata = { -1, -1, -1, -1 };
  97. /*
  98. * LILO/Module params: aha1542=<PORTBASE>[,<BUSON>,<BUSOFF>[,<DMASPEED>]]
  99. *
  100. * Where: <PORTBASE> is any of the valid AHA addresses:
  101. * 0x130, 0x134, 0x230, 0x234, 0x330, 0x334
  102. * <BUSON> is the time (in microsecs) that AHA spends on the AT-bus
  103. * when transferring data. 1542A power-on default is 11us,
  104. * valid values are in range: 2..15 (decimal)
  105. * <BUSOFF> is the time that AHA spends OFF THE BUS after while
  106. * it is transferring data (not to monopolize the bus).
  107. * Power-on default is 4us, valid range: 1..64 microseconds.
  108. * <DMASPEED> Default is jumper selected (1542A: on the J1),
  109. * but experimenter can alter it with this.
  110. * Valid values: 5, 6, 7, 8, 10 (MB/s)
  111. * Factory default is 5 MB/s.
  112. */
  113. #if defined(MODULE)
  114. static int isapnp = 0;
  115. static int aha1542[] = {0x330, 11, 4, -1};
  116. module_param_array(aha1542, int, NULL, 0);
  117. module_param(isapnp, bool, 0);
  118. static struct isapnp_device_id id_table[] __initdata = {
  119. {
  120. ISAPNP_ANY_ID, ISAPNP_ANY_ID,
  121. ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1542),
  122. 0
  123. },
  124. {0}
  125. };
  126. MODULE_DEVICE_TABLE(isapnp, id_table);
  127. #else
  128. static int isapnp = 1;
  129. #endif
  130. #define BIOS_TRANSLATION_1632 0 /* Used by some old 1542A boards */
  131. #define BIOS_TRANSLATION_6432 1 /* Default case these days */
  132. #define BIOS_TRANSLATION_25563 2 /* Big disk case */
  133. struct aha1542_hostdata {
  134. /* This will effectively start both of them at the first mailbox */
  135. int bios_translation; /* Mapping bios uses - for compatibility */
  136. int aha1542_last_mbi_used;
  137. int aha1542_last_mbo_used;
  138. Scsi_Cmnd *SCint[AHA1542_MAILBOXES];
  139. struct mailbox mb[2 * AHA1542_MAILBOXES];
  140. struct ccb ccb[AHA1542_MAILBOXES];
  141. };
  142. #define HOSTDATA(host) ((struct aha1542_hostdata *) &host->hostdata)
  143. static struct Scsi_Host *aha_host[7]; /* One for each IRQ level (9-15) */
  144. static DEFINE_SPINLOCK(aha1542_lock);
  145. #define WAITnexttimeout 3000000
  146. static void setup_mailboxes(int base_io, struct Scsi_Host *shpnt);
  147. static int aha1542_restart(struct Scsi_Host *shost);
  148. static void aha1542_intr_handle(struct Scsi_Host *shost, void *dev_id, struct pt_regs *regs);
  149. static irqreturn_t do_aha1542_intr_handle(int irq, void *dev_id,
  150. struct pt_regs *regs);
  151. #define aha1542_intr_reset(base) outb(IRST, CONTROL(base))
  152. #define WAIT(port, mask, allof, noneof) \
  153. { register int WAITbits; \
  154. register int WAITtimeout = WAITnexttimeout; \
  155. while (1) { \
  156. WAITbits = inb(port) & (mask); \
  157. if ((WAITbits & (allof)) == (allof) && ((WAITbits & (noneof)) == 0)) \
  158. break; \
  159. if (--WAITtimeout == 0) goto fail; \
  160. } \
  161. }
  162. /* Similar to WAIT, except we use the udelay call to regulate the
  163. amount of time we wait. */
  164. #define WAITd(port, mask, allof, noneof, timeout) \
  165. { register int WAITbits; \
  166. register int WAITtimeout = timeout; \
  167. while (1) { \
  168. WAITbits = inb(port) & (mask); \
  169. if ((WAITbits & (allof)) == (allof) && ((WAITbits & (noneof)) == 0)) \
  170. break; \
  171. mdelay(1); \
  172. if (--WAITtimeout == 0) goto fail; \
  173. } \
  174. }
  175. static void aha1542_stat(void)
  176. {
  177. /* int s = inb(STATUS), i = inb(INTRFLAGS);
  178. printk("status=%x intrflags=%x\n", s, i, WAITnexttimeout-WAITtimeout); */
  179. }
  180. /* This is a bit complicated, but we need to make sure that an interrupt
  181. routine does not send something out while we are in the middle of this.
  182. Fortunately, it is only at boot time that multi-byte messages
  183. are ever sent. */
  184. static int aha1542_out(unsigned int base, unchar * cmdp, int len)
  185. {
  186. unsigned long flags = 0;
  187. int got_lock;
  188. if (len == 1) {
  189. got_lock = 0;
  190. while (1 == 1) {
  191. WAIT(STATUS(base), CDF, 0, CDF);
  192. spin_lock_irqsave(&aha1542_lock, flags);
  193. if (inb(STATUS(base)) & CDF) {
  194. spin_unlock_irqrestore(&aha1542_lock, flags);
  195. continue;
  196. }
  197. outb(*cmdp, DATA(base));
  198. spin_unlock_irqrestore(&aha1542_lock, flags);
  199. return 0;
  200. }
  201. } else {
  202. spin_lock_irqsave(&aha1542_lock, flags);
  203. got_lock = 1;
  204. while (len--) {
  205. WAIT(STATUS(base), CDF, 0, CDF);
  206. outb(*cmdp++, DATA(base));
  207. }
  208. spin_unlock_irqrestore(&aha1542_lock, flags);
  209. }
  210. return 0;
  211. fail:
  212. if (got_lock)
  213. spin_unlock_irqrestore(&aha1542_lock, flags);
  214. printk(KERN_ERR "aha1542_out failed(%d): ", len + 1);
  215. aha1542_stat();
  216. return 1;
  217. }
  218. /* Only used at boot time, so we do not need to worry about latency as much
  219. here */
  220. static int __init aha1542_in(unsigned int base, unchar * cmdp, int len)
  221. {
  222. unsigned long flags;
  223. spin_lock_irqsave(&aha1542_lock, flags);
  224. while (len--) {
  225. WAIT(STATUS(base), DF, DF, 0);
  226. *cmdp++ = inb(DATA(base));
  227. }
  228. spin_unlock_irqrestore(&aha1542_lock, flags);
  229. return 0;
  230. fail:
  231. spin_unlock_irqrestore(&aha1542_lock, flags);
  232. printk(KERN_ERR "aha1542_in failed(%d): ", len + 1);
  233. aha1542_stat();
  234. return 1;
  235. }
  236. /* Similar to aha1542_in, except that we wait a very short period of time.
  237. We use this if we know the board is alive and awake, but we are not sure
  238. if the board will respond to the command we are about to send or not */
  239. static int __init aha1542_in1(unsigned int base, unchar * cmdp, int len)
  240. {
  241. unsigned long flags;
  242. spin_lock_irqsave(&aha1542_lock, flags);
  243. while (len--) {
  244. WAITd(STATUS(base), DF, DF, 0, 100);
  245. *cmdp++ = inb(DATA(base));
  246. }
  247. spin_unlock_irqrestore(&aha1542_lock, flags);
  248. return 0;
  249. fail:
  250. spin_unlock_irqrestore(&aha1542_lock, flags);
  251. return 1;
  252. }
  253. static int makecode(unsigned hosterr, unsigned scsierr)
  254. {
  255. switch (hosterr) {
  256. case 0x0:
  257. case 0xa: /* Linked command complete without error and linked normally */
  258. case 0xb: /* Linked command complete without error, interrupt generated */
  259. hosterr = 0;
  260. break;
  261. case 0x11: /* Selection time out-The initiator selection or target
  262. reselection was not complete within the SCSI Time out period */
  263. hosterr = DID_TIME_OUT;
  264. break;
  265. case 0x12: /* Data overrun/underrun-The target attempted to transfer more data
  266. than was allocated by the Data Length field or the sum of the
  267. Scatter / Gather Data Length fields. */
  268. case 0x13: /* Unexpected bus free-The target dropped the SCSI BSY at an unexpected time. */
  269. case 0x15: /* MBO command was not 00, 01 or 02-The first byte of the CB was
  270. invalid. This usually indicates a software failure. */
  271. case 0x16: /* Invalid CCB Operation Code-The first byte of the CCB was invalid.
  272. This usually indicates a software failure. */
  273. case 0x17: /* Linked CCB does not have the same LUN-A subsequent CCB of a set
  274. of linked CCB's does not specify the same logical unit number as
  275. the first. */
  276. case 0x18: /* Invalid Target Direction received from Host-The direction of a
  277. Target Mode CCB was invalid. */
  278. case 0x19: /* Duplicate CCB Received in Target Mode-More than once CCB was
  279. received to service data transfer between the same target LUN
  280. and initiator SCSI ID in the same direction. */
  281. case 0x1a: /* Invalid CCB or Segment List Parameter-A segment list with a zero
  282. length segment or invalid segment list boundaries was received.
  283. A CCB parameter was invalid. */
  284. DEB(printk("Aha1542: %x %x\n", hosterr, scsierr));
  285. hosterr = DID_ERROR; /* Couldn't find any better */
  286. break;
  287. case 0x14: /* Target bus phase sequence failure-An invalid bus phase or bus
  288. phase sequence was requested by the target. The host adapter
  289. will generate a SCSI Reset Condition, notifying the host with
  290. a SCRD interrupt */
  291. hosterr = DID_RESET;
  292. break;
  293. default:
  294. printk(KERN_ERR "aha1542: makecode: unknown hoststatus %x\n", hosterr);
  295. break;
  296. }
  297. return scsierr | (hosterr << 16);
  298. }
  299. static int __init aha1542_test_port(int bse, struct Scsi_Host *shpnt)
  300. {
  301. unchar inquiry_cmd[] = {CMD_INQUIRY};
  302. unchar inquiry_result[4];
  303. unchar *cmdp;
  304. int len;
  305. volatile int debug = 0;
  306. /* Quick and dirty test for presence of the card. */
  307. if (inb(STATUS(bse)) == 0xff)
  308. return 0;
  309. /* Reset the adapter. I ought to make a hard reset, but it's not really necessary */
  310. /* DEB(printk("aha1542_test_port called \n")); */
  311. /* In case some other card was probing here, reset interrupts */
  312. aha1542_intr_reset(bse); /* reset interrupts, so they don't block */
  313. outb(SRST | IRST /*|SCRST */ , CONTROL(bse));
  314. mdelay(20); /* Wait a little bit for things to settle down. */
  315. debug = 1;
  316. /* Expect INIT and IDLE, any of the others are bad */
  317. WAIT(STATUS(bse), STATMASK, INIT | IDLE, STST | DIAGF | INVDCMD | DF | CDF);
  318. debug = 2;
  319. /* Shouldn't have generated any interrupts during reset */
  320. if (inb(INTRFLAGS(bse)) & INTRMASK)
  321. goto fail;
  322. /* Perform a host adapter inquiry instead so we do not need to set
  323. up the mailboxes ahead of time */
  324. aha1542_out(bse, inquiry_cmd, 1);
  325. debug = 3;
  326. len = 4;
  327. cmdp = &inquiry_result[0];
  328. while (len--) {
  329. WAIT(STATUS(bse), DF, DF, 0);
  330. *cmdp++ = inb(DATA(bse));
  331. }
  332. debug = 8;
  333. /* Reading port should reset DF */
  334. if (inb(STATUS(bse)) & DF)
  335. goto fail;
  336. debug = 9;
  337. /* When HACC, command is completed, and we're though testing */
  338. WAIT(INTRFLAGS(bse), HACC, HACC, 0);
  339. /* now initialize adapter */
  340. debug = 10;
  341. /* Clear interrupts */
  342. outb(IRST, CONTROL(bse));
  343. debug = 11;
  344. return debug; /* 1 = ok */
  345. fail:
  346. return 0; /* 0 = not ok */
  347. }
  348. /* A quick wrapper for do_aha1542_intr_handle to grab the spin lock */
  349. static irqreturn_t do_aha1542_intr_handle(int irq, void *dev_id,
  350. struct pt_regs *regs)
  351. {
  352. unsigned long flags;
  353. struct Scsi_Host *shost;
  354. shost = aha_host[irq - 9];
  355. if (!shost)
  356. panic("Splunge!");
  357. spin_lock_irqsave(shost->host_lock, flags);
  358. aha1542_intr_handle(shost, dev_id, regs);
  359. spin_unlock_irqrestore(shost->host_lock, flags);
  360. return IRQ_HANDLED;
  361. }
  362. /* A "high" level interrupt handler */
  363. static void aha1542_intr_handle(struct Scsi_Host *shost, void *dev_id, struct pt_regs *regs)
  364. {
  365. void (*my_done) (Scsi_Cmnd *) = NULL;
  366. int errstatus, mbi, mbo, mbistatus;
  367. int number_serviced;
  368. unsigned long flags;
  369. Scsi_Cmnd *SCtmp;
  370. int flag;
  371. int needs_restart;
  372. struct mailbox *mb;
  373. struct ccb *ccb;
  374. mb = HOSTDATA(shost)->mb;
  375. ccb = HOSTDATA(shost)->ccb;
  376. #ifdef DEBUG
  377. {
  378. flag = inb(INTRFLAGS(shost->io_port));
  379. printk(KERN_DEBUG "aha1542_intr_handle: ");
  380. if (!(flag & ANYINTR))
  381. printk("no interrupt?");
  382. if (flag & MBIF)
  383. printk("MBIF ");
  384. if (flag & MBOA)
  385. printk("MBOF ");
  386. if (flag & HACC)
  387. printk("HACC ");
  388. if (flag & SCRD)
  389. printk("SCRD ");
  390. printk("status %02x\n", inb(STATUS(shost->io_port)));
  391. };
  392. #endif
  393. number_serviced = 0;
  394. needs_restart = 0;
  395. while (1 == 1) {
  396. flag = inb(INTRFLAGS(shost->io_port));
  397. /* Check for unusual interrupts. If any of these happen, we should
  398. probably do something special, but for now just printing a message
  399. is sufficient. A SCSI reset detected is something that we really
  400. need to deal with in some way. */
  401. if (flag & ~MBIF) {
  402. if (flag & MBOA)
  403. printk("MBOF ");
  404. if (flag & HACC)
  405. printk("HACC ");
  406. if (flag & SCRD) {
  407. needs_restart = 1;
  408. printk("SCRD ");
  409. }
  410. }
  411. aha1542_intr_reset(shost->io_port);
  412. spin_lock_irqsave(&aha1542_lock, flags);
  413. mbi = HOSTDATA(shost)->aha1542_last_mbi_used + 1;
  414. if (mbi >= 2 * AHA1542_MAILBOXES)
  415. mbi = AHA1542_MAILBOXES;
  416. do {
  417. if (mb[mbi].status != 0)
  418. break;
  419. mbi++;
  420. if (mbi >= 2 * AHA1542_MAILBOXES)
  421. mbi = AHA1542_MAILBOXES;
  422. } while (mbi != HOSTDATA(shost)->aha1542_last_mbi_used);
  423. if (mb[mbi].status == 0) {
  424. spin_unlock_irqrestore(&aha1542_lock, flags);
  425. /* Hmm, no mail. Must have read it the last time around */
  426. if (!number_serviced && !needs_restart)
  427. printk(KERN_WARNING "aha1542.c: interrupt received, but no mail.\n");
  428. /* We detected a reset. Restart all pending commands for
  429. devices that use the hard reset option */
  430. if (needs_restart)
  431. aha1542_restart(shost);
  432. return;
  433. };
  434. mbo = (scsi2int(mb[mbi].ccbptr) - (SCSI_BUF_PA(&ccb[0]))) / sizeof(struct ccb);
  435. mbistatus = mb[mbi].status;
  436. mb[mbi].status = 0;
  437. HOSTDATA(shost)->aha1542_last_mbi_used = mbi;
  438. spin_unlock_irqrestore(&aha1542_lock, flags);
  439. #ifdef DEBUG
  440. {
  441. if (ccb[mbo].tarstat | ccb[mbo].hastat)
  442. printk(KERN_DEBUG "aha1542_command: returning %x (status %d)\n",
  443. ccb[mbo].tarstat + ((int) ccb[mbo].hastat << 16), mb[mbi].status);
  444. };
  445. #endif
  446. if (mbistatus == 3)
  447. continue; /* Aborted command not found */
  448. #ifdef DEBUG
  449. printk(KERN_DEBUG "...done %d %d\n", mbo, mbi);
  450. #endif
  451. SCtmp = HOSTDATA(shost)->SCint[mbo];
  452. if (!SCtmp || !SCtmp->scsi_done) {
  453. printk(KERN_WARNING "aha1542_intr_handle: Unexpected interrupt\n");
  454. printk(KERN_WARNING "tarstat=%x, hastat=%x idlun=%x ccb#=%d \n", ccb[mbo].tarstat,
  455. ccb[mbo].hastat, ccb[mbo].idlun, mbo);
  456. return;
  457. }
  458. my_done = SCtmp->scsi_done;
  459. kfree(SCtmp->host_scribble);
  460. SCtmp->host_scribble = NULL;
  461. /* Fetch the sense data, and tuck it away, in the required slot. The
  462. Adaptec automatically fetches it, and there is no guarantee that
  463. we will still have it in the cdb when we come back */
  464. if (ccb[mbo].tarstat == 2)
  465. memcpy(SCtmp->sense_buffer, &ccb[mbo].cdb[ccb[mbo].cdblen],
  466. sizeof(SCtmp->sense_buffer));
  467. /* is there mail :-) */
  468. /* more error checking left out here */
  469. if (mbistatus != 1)
  470. /* This is surely wrong, but I don't know what's right */
  471. errstatus = makecode(ccb[mbo].hastat, ccb[mbo].tarstat);
  472. else
  473. errstatus = 0;
  474. #ifdef DEBUG
  475. if (errstatus)
  476. printk(KERN_DEBUG "(aha1542 error:%x %x %x) ", errstatus,
  477. ccb[mbo].hastat, ccb[mbo].tarstat);
  478. #endif
  479. if (ccb[mbo].tarstat == 2) {
  480. #ifdef DEBUG
  481. int i;
  482. #endif
  483. DEB(printk("aha1542_intr_handle: sense:"));
  484. #ifdef DEBUG
  485. for (i = 0; i < 12; i++)
  486. printk("%02x ", ccb[mbo].cdb[ccb[mbo].cdblen + i]);
  487. printk("\n");
  488. #endif
  489. /*
  490. DEB(printk("aha1542_intr_handle: buf:"));
  491. for (i = 0; i < bufflen; i++)
  492. printk("%02x ", ((unchar *)buff)[i]);
  493. printk("\n");
  494. */
  495. }
  496. DEB(if (errstatus) printk("aha1542_intr_handle: returning %6x\n", errstatus));
  497. SCtmp->result = errstatus;
  498. HOSTDATA(shost)->SCint[mbo] = NULL; /* This effectively frees up the mailbox slot, as
  499. far as queuecommand is concerned */
  500. my_done(SCtmp);
  501. number_serviced++;
  502. };
  503. }
  504. static int aha1542_queuecommand(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *))
  505. {
  506. unchar ahacmd = CMD_START_SCSI;
  507. unchar direction;
  508. unchar *cmd = (unchar *) SCpnt->cmnd;
  509. unchar target = SCpnt->device->id;
  510. unchar lun = SCpnt->device->lun;
  511. unsigned long flags;
  512. void *buff = SCpnt->request_buffer;
  513. int bufflen = SCpnt->request_bufflen;
  514. int mbo;
  515. struct mailbox *mb;
  516. struct ccb *ccb;
  517. DEB(int i);
  518. mb = HOSTDATA(SCpnt->device->host)->mb;
  519. ccb = HOSTDATA(SCpnt->device->host)->ccb;
  520. DEB(if (target > 1) {
  521. SCpnt->result = DID_TIME_OUT << 16;
  522. done(SCpnt); return 0;
  523. }
  524. );
  525. if (*cmd == REQUEST_SENSE) {
  526. /* Don't do the command - we have the sense data already */
  527. #if 0
  528. /* scsi_request_sense() provides a buffer of size 256,
  529. so there is no reason to expect equality */
  530. if (bufflen != sizeof(SCpnt->sense_buffer))
  531. printk(KERN_CRIT "aha1542: Wrong buffer length supplied "
  532. "for request sense (%d)\n", bufflen);
  533. #endif
  534. SCpnt->result = 0;
  535. done(SCpnt);
  536. return 0;
  537. }
  538. #ifdef DEBUG
  539. if (*cmd == READ_10 || *cmd == WRITE_10)
  540. i = xscsi2int(cmd + 2);
  541. else if (*cmd == READ_6 || *cmd == WRITE_6)
  542. i = scsi2int(cmd + 2);
  543. else
  544. i = -1;
  545. if (done)
  546. printk(KERN_DEBUG "aha1542_queuecommand: dev %d cmd %02x pos %d len %d ", target, *cmd, i, bufflen);
  547. else
  548. printk(KERN_DEBUG "aha1542_command: dev %d cmd %02x pos %d len %d ", target, *cmd, i, bufflen);
  549. aha1542_stat();
  550. printk(KERN_DEBUG "aha1542_queuecommand: dumping scsi cmd:");
  551. for (i = 0; i < SCpnt->cmd_len; i++)
  552. printk("%02x ", cmd[i]);
  553. printk("\n");
  554. if (*cmd == WRITE_10 || *cmd == WRITE_6)
  555. return 0; /* we are still testing, so *don't* write */
  556. #endif
  557. /* Use the outgoing mailboxes in a round-robin fashion, because this
  558. is how the host adapter will scan for them */
  559. spin_lock_irqsave(&aha1542_lock, flags);
  560. mbo = HOSTDATA(SCpnt->device->host)->aha1542_last_mbo_used + 1;
  561. if (mbo >= AHA1542_MAILBOXES)
  562. mbo = 0;
  563. do {
  564. if (mb[mbo].status == 0 && HOSTDATA(SCpnt->device->host)->SCint[mbo] == NULL)
  565. break;
  566. mbo++;
  567. if (mbo >= AHA1542_MAILBOXES)
  568. mbo = 0;
  569. } while (mbo != HOSTDATA(SCpnt->device->host)->aha1542_last_mbo_used);
  570. if (mb[mbo].status || HOSTDATA(SCpnt->device->host)->SCint[mbo])
  571. panic("Unable to find empty mailbox for aha1542.\n");
  572. HOSTDATA(SCpnt->device->host)->SCint[mbo] = SCpnt; /* This will effectively prevent someone else from
  573. screwing with this cdb. */
  574. HOSTDATA(SCpnt->device->host)->aha1542_last_mbo_used = mbo;
  575. spin_unlock_irqrestore(&aha1542_lock, flags);
  576. #ifdef DEBUG
  577. printk(KERN_DEBUG "Sending command (%d %x)...", mbo, done);
  578. #endif
  579. any2scsi(mb[mbo].ccbptr, SCSI_BUF_PA(&ccb[mbo])); /* This gets trashed for some reason */
  580. memset(&ccb[mbo], 0, sizeof(struct ccb));
  581. ccb[mbo].cdblen = SCpnt->cmd_len;
  582. direction = 0;
  583. if (*cmd == READ_10 || *cmd == READ_6)
  584. direction = 8;
  585. else if (*cmd == WRITE_10 || *cmd == WRITE_6)
  586. direction = 16;
  587. memcpy(ccb[mbo].cdb, cmd, ccb[mbo].cdblen);
  588. if (SCpnt->use_sg) {
  589. struct scatterlist *sgpnt;
  590. struct chain *cptr;
  591. #ifdef DEBUG
  592. unsigned char *ptr;
  593. #endif
  594. int i;
  595. ccb[mbo].op = 2; /* SCSI Initiator Command w/scatter-gather */
  596. SCpnt->host_scribble = (unsigned char *) kmalloc(512, GFP_KERNEL | GFP_DMA);
  597. sgpnt = (struct scatterlist *) SCpnt->request_buffer;
  598. cptr = (struct chain *) SCpnt->host_scribble;
  599. if (cptr == NULL) {
  600. /* free the claimed mailbox slot */
  601. HOSTDATA(SCpnt->device->host)->SCint[mbo] = NULL;
  602. return SCSI_MLQUEUE_HOST_BUSY;
  603. }
  604. for (i = 0; i < SCpnt->use_sg; i++) {
  605. if (sgpnt[i].length == 0 || SCpnt->use_sg > 16 ||
  606. (((int) sgpnt[i].offset) & 1) || (sgpnt[i].length & 1)) {
  607. unsigned char *ptr;
  608. printk(KERN_CRIT "Bad segment list supplied to aha1542.c (%d, %d)\n", SCpnt->use_sg, i);
  609. for (i = 0; i < SCpnt->use_sg; i++) {
  610. printk(KERN_CRIT "%d: %p %d\n", i,
  611. (page_address(sgpnt[i].page) +
  612. sgpnt[i].offset),
  613. sgpnt[i].length);
  614. };
  615. printk(KERN_CRIT "cptr %x: ", (unsigned int) cptr);
  616. ptr = (unsigned char *) &cptr[i];
  617. for (i = 0; i < 18; i++)
  618. printk("%02x ", ptr[i]);
  619. panic("Foooooooood fight!");
  620. };
  621. any2scsi(cptr[i].dataptr, SCSI_SG_PA(&sgpnt[i]));
  622. if (SCSI_SG_PA(&sgpnt[i]) + sgpnt[i].length - 1 > ISA_DMA_THRESHOLD)
  623. BAD_SG_DMA(SCpnt, sgpnt, SCpnt->use_sg, i);
  624. any2scsi(cptr[i].datalen, sgpnt[i].length);
  625. };
  626. any2scsi(ccb[mbo].datalen, SCpnt->use_sg * sizeof(struct chain));
  627. any2scsi(ccb[mbo].dataptr, SCSI_BUF_PA(cptr));
  628. #ifdef DEBUG
  629. printk("cptr %x: ", cptr);
  630. ptr = (unsigned char *) cptr;
  631. for (i = 0; i < 18; i++)
  632. printk("%02x ", ptr[i]);
  633. #endif
  634. } else {
  635. ccb[mbo].op = 0; /* SCSI Initiator Command */
  636. SCpnt->host_scribble = NULL;
  637. any2scsi(ccb[mbo].datalen, bufflen);
  638. if (buff && SCSI_BUF_PA(buff + bufflen - 1) > ISA_DMA_THRESHOLD)
  639. BAD_DMA(buff, bufflen);
  640. any2scsi(ccb[mbo].dataptr, SCSI_BUF_PA(buff));
  641. };
  642. ccb[mbo].idlun = (target & 7) << 5 | direction | (lun & 7); /*SCSI Target Id */
  643. ccb[mbo].rsalen = 16;
  644. ccb[mbo].linkptr[0] = ccb[mbo].linkptr[1] = ccb[mbo].linkptr[2] = 0;
  645. ccb[mbo].commlinkid = 0;
  646. #ifdef DEBUG
  647. {
  648. int i;
  649. printk(KERN_DEBUG "aha1542_command: sending.. ");
  650. for (i = 0; i < sizeof(ccb[mbo]) - 10; i++)
  651. printk("%02x ", ((unchar *) & ccb[mbo])[i]);
  652. };
  653. #endif
  654. if (done) {
  655. DEB(printk("aha1542_queuecommand: now waiting for interrupt ");
  656. aha1542_stat());
  657. SCpnt->scsi_done = done;
  658. mb[mbo].status = 1;
  659. aha1542_out(SCpnt->device->host->io_port, &ahacmd, 1); /* start scsi command */
  660. DEB(aha1542_stat());
  661. } else
  662. printk("aha1542_queuecommand: done can't be NULL\n");
  663. return 0;
  664. }
  665. /* Initialize mailboxes */
  666. static void setup_mailboxes(int bse, struct Scsi_Host *shpnt)
  667. {
  668. int i;
  669. struct mailbox *mb;
  670. struct ccb *ccb;
  671. unchar cmd[5] = { CMD_MBINIT, AHA1542_MAILBOXES, 0, 0, 0};
  672. mb = HOSTDATA(shpnt)->mb;
  673. ccb = HOSTDATA(shpnt)->ccb;
  674. for (i = 0; i < AHA1542_MAILBOXES; i++) {
  675. mb[i].status = mb[AHA1542_MAILBOXES + i].status = 0;
  676. any2scsi(mb[i].ccbptr, SCSI_BUF_PA(&ccb[i]));
  677. };
  678. aha1542_intr_reset(bse); /* reset interrupts, so they don't block */
  679. any2scsi((cmd + 2), SCSI_BUF_PA(mb));
  680. aha1542_out(bse, cmd, 5);
  681. WAIT(INTRFLAGS(bse), INTRMASK, HACC, 0);
  682. while (0) {
  683. fail:
  684. printk(KERN_ERR "aha1542_detect: failed setting up mailboxes\n");
  685. }
  686. aha1542_intr_reset(bse);
  687. }
  688. static int __init aha1542_getconfig(int base_io, unsigned char *irq_level, unsigned char *dma_chan, unsigned char *scsi_id)
  689. {
  690. unchar inquiry_cmd[] = {CMD_RETCONF};
  691. unchar inquiry_result[3];
  692. int i;
  693. i = inb(STATUS(base_io));
  694. if (i & DF) {
  695. i = inb(DATA(base_io));
  696. };
  697. aha1542_out(base_io, inquiry_cmd, 1);
  698. aha1542_in(base_io, inquiry_result, 3);
  699. WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
  700. while (0) {
  701. fail:
  702. printk(KERN_ERR "aha1542_detect: query board settings\n");
  703. }
  704. aha1542_intr_reset(base_io);
  705. switch (inquiry_result[0]) {
  706. case 0x80:
  707. *dma_chan = 7;
  708. break;
  709. case 0x40:
  710. *dma_chan = 6;
  711. break;
  712. case 0x20:
  713. *dma_chan = 5;
  714. break;
  715. case 0x01:
  716. *dma_chan = 0;
  717. break;
  718. case 0:
  719. /* This means that the adapter, although Adaptec 1542 compatible, doesn't use a DMA channel.
  720. Currently only aware of the BusLogic BT-445S VL-Bus adapter which needs this. */
  721. *dma_chan = 0xFF;
  722. break;
  723. default:
  724. printk(KERN_ERR "Unable to determine Adaptec DMA priority. Disabling board\n");
  725. return -1;
  726. };
  727. switch (inquiry_result[1]) {
  728. case 0x40:
  729. *irq_level = 15;
  730. break;
  731. case 0x20:
  732. *irq_level = 14;
  733. break;
  734. case 0x8:
  735. *irq_level = 12;
  736. break;
  737. case 0x4:
  738. *irq_level = 11;
  739. break;
  740. case 0x2:
  741. *irq_level = 10;
  742. break;
  743. case 0x1:
  744. *irq_level = 9;
  745. break;
  746. default:
  747. printk(KERN_ERR "Unable to determine Adaptec IRQ level. Disabling board\n");
  748. return -1;
  749. };
  750. *scsi_id = inquiry_result[2] & 7;
  751. return 0;
  752. }
  753. /* This function should only be called for 1542C boards - we can detect
  754. the special firmware settings and unlock the board */
  755. static int __init aha1542_mbenable(int base)
  756. {
  757. static unchar mbenable_cmd[3];
  758. static unchar mbenable_result[2];
  759. int retval;
  760. retval = BIOS_TRANSLATION_6432;
  761. mbenable_cmd[0] = CMD_EXTBIOS;
  762. aha1542_out(base, mbenable_cmd, 1);
  763. if (aha1542_in1(base, mbenable_result, 2))
  764. return retval;
  765. WAITd(INTRFLAGS(base), INTRMASK, HACC, 0, 100);
  766. aha1542_intr_reset(base);
  767. if ((mbenable_result[0] & 0x08) || mbenable_result[1]) {
  768. mbenable_cmd[0] = CMD_MBENABLE;
  769. mbenable_cmd[1] = 0;
  770. mbenable_cmd[2] = mbenable_result[1];
  771. if ((mbenable_result[0] & 0x08) && (mbenable_result[1] & 0x03))
  772. retval = BIOS_TRANSLATION_25563;
  773. aha1542_out(base, mbenable_cmd, 3);
  774. WAIT(INTRFLAGS(base), INTRMASK, HACC, 0);
  775. };
  776. while (0) {
  777. fail:
  778. printk(KERN_ERR "aha1542_mbenable: Mailbox init failed\n");
  779. }
  780. aha1542_intr_reset(base);
  781. return retval;
  782. }
  783. /* Query the board to find out if it is a 1542 or a 1740, or whatever. */
  784. static int __init aha1542_query(int base_io, int *transl)
  785. {
  786. unchar inquiry_cmd[] = {CMD_INQUIRY};
  787. unchar inquiry_result[4];
  788. int i;
  789. i = inb(STATUS(base_io));
  790. if (i & DF) {
  791. i = inb(DATA(base_io));
  792. };
  793. aha1542_out(base_io, inquiry_cmd, 1);
  794. aha1542_in(base_io, inquiry_result, 4);
  795. WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
  796. while (0) {
  797. fail:
  798. printk(KERN_ERR "aha1542_detect: query card type\n");
  799. }
  800. aha1542_intr_reset(base_io);
  801. *transl = BIOS_TRANSLATION_6432; /* Default case */
  802. /* For an AHA1740 series board, we ignore the board since there is a
  803. hardware bug which can lead to wrong blocks being returned if the board
  804. is operating in the 1542 emulation mode. Since there is an extended mode
  805. driver, we simply ignore the board and let the 1740 driver pick it up.
  806. */
  807. if (inquiry_result[0] == 0x43) {
  808. printk(KERN_INFO "aha1542.c: Emulation mode not supported for AHA 174N hardware.\n");
  809. return 1;
  810. };
  811. /* Always call this - boards that do not support extended bios translation
  812. will ignore the command, and we will set the proper default */
  813. *transl = aha1542_mbenable(base_io);
  814. return 0;
  815. }
  816. #ifndef MODULE
  817. static char *setup_str[MAXBOARDS] __initdata;
  818. static int setup_idx = 0;
  819. static void __init aha1542_setup(char *str, int *ints)
  820. {
  821. const char *ahausage = "aha1542: usage: aha1542=<PORTBASE>[,<BUSON>,<BUSOFF>[,<DMASPEED>]]\n";
  822. int setup_portbase;
  823. if (setup_idx >= MAXBOARDS) {
  824. printk(KERN_ERR "aha1542: aha1542_setup called too many times! Bad LILO params ?\n");
  825. printk(KERN_ERR " Entryline 1: %s\n", setup_str[0]);
  826. printk(KERN_ERR " Entryline 2: %s\n", setup_str[1]);
  827. printk(KERN_ERR " This line: %s\n", str);
  828. return;
  829. }
  830. if (ints[0] < 1 || ints[0] > 4) {
  831. printk(KERN_ERR "aha1542: %s\n", str);
  832. printk(ahausage);
  833. printk(KERN_ERR "aha1542: Wrong parameters may cause system malfunction.. We try anyway..\n");
  834. }
  835. setup_called[setup_idx] = ints[0];
  836. setup_str[setup_idx] = str;
  837. setup_portbase = ints[0] >= 1 ? ints[1] : 0; /* Preserve the default value.. */
  838. setup_buson[setup_idx] = ints[0] >= 2 ? ints[2] : 7;
  839. setup_busoff[setup_idx] = ints[0] >= 3 ? ints[3] : 5;
  840. if (ints[0] >= 4)
  841. {
  842. int atbt = -1;
  843. switch (ints[4]) {
  844. case 5:
  845. atbt = 0x00;
  846. break;
  847. case 6:
  848. atbt = 0x04;
  849. break;
  850. case 7:
  851. atbt = 0x01;
  852. break;
  853. case 8:
  854. atbt = 0x02;
  855. break;
  856. case 10:
  857. atbt = 0x03;
  858. break;
  859. default:
  860. printk(KERN_ERR "aha1542: %s\n", str);
  861. printk(ahausage);
  862. printk(KERN_ERR "aha1542: Valid values for DMASPEED are 5-8, 10 MB/s. Using jumper defaults.\n");
  863. break;
  864. }
  865. setup_dmaspeed[setup_idx] = atbt;
  866. }
  867. if (setup_portbase != 0)
  868. bases[setup_idx] = setup_portbase;
  869. ++setup_idx;
  870. }
  871. static int __init do_setup(char *str)
  872. {
  873. int ints[5];
  874. int count=setup_idx;
  875. get_options(str, sizeof(ints)/sizeof(int), ints);
  876. aha1542_setup(str,ints);
  877. return count<setup_idx;
  878. }
  879. __setup("aha1542=",do_setup);
  880. #endif
  881. /* return non-zero on detection */
  882. static int __init aha1542_detect(struct scsi_host_template * tpnt)
  883. {
  884. unsigned char dma_chan;
  885. unsigned char irq_level;
  886. unsigned char scsi_id;
  887. unsigned long flags;
  888. unsigned int base_io;
  889. int trans;
  890. struct Scsi_Host *shpnt = NULL;
  891. int count = 0;
  892. int indx;
  893. DEB(printk("aha1542_detect: \n"));
  894. tpnt->proc_name = "aha1542";
  895. #ifdef MODULE
  896. bases[0] = aha1542[0];
  897. setup_buson[0] = aha1542[1];
  898. setup_busoff[0] = aha1542[2];
  899. {
  900. int atbt = -1;
  901. switch (aha1542[3]) {
  902. case 5:
  903. atbt = 0x00;
  904. break;
  905. case 6:
  906. atbt = 0x04;
  907. break;
  908. case 7:
  909. atbt = 0x01;
  910. break;
  911. case 8:
  912. atbt = 0x02;
  913. break;
  914. case 10:
  915. atbt = 0x03;
  916. break;
  917. };
  918. setup_dmaspeed[0] = atbt;
  919. }
  920. #endif
  921. /*
  922. * Find MicroChannel cards (AHA1640)
  923. */
  924. #ifdef CONFIG_MCA_LEGACY
  925. if(MCA_bus) {
  926. int slot = 0;
  927. int pos = 0;
  928. for (indx = 0; (slot != MCA_NOTFOUND) &&
  929. (indx < sizeof(bases)/sizeof(bases[0])); indx++) {
  930. if (bases[indx])
  931. continue;
  932. /* Detect only AHA-1640 cards -- MCA ID 0F1F */
  933. slot = mca_find_unused_adapter(0x0f1f, slot);
  934. if (slot == MCA_NOTFOUND)
  935. break;
  936. /* Found one */
  937. pos = mca_read_stored_pos(slot, 3);
  938. /* Decode address */
  939. if (pos & 0x80) {
  940. if (pos & 0x02) {
  941. if (pos & 0x01)
  942. bases[indx] = 0x334;
  943. else
  944. bases[indx] = 0x234;
  945. } else {
  946. if (pos & 0x01)
  947. bases[indx] = 0x134;
  948. }
  949. } else {
  950. if (pos & 0x02) {
  951. if (pos & 0x01)
  952. bases[indx] = 0x330;
  953. else
  954. bases[indx] = 0x230;
  955. } else {
  956. if (pos & 0x01)
  957. bases[indx] = 0x130;
  958. }
  959. }
  960. /* No need to decode IRQ and Arb level -- those are
  961. * read off the card later.
  962. */
  963. printk(KERN_INFO "Found an AHA-1640 in MCA slot %d, I/O 0x%04x\n", slot, bases[indx]);
  964. mca_set_adapter_name(slot, "Adapter AHA-1640");
  965. mca_set_adapter_procfn(slot, NULL, NULL);
  966. mca_mark_as_used(slot);
  967. /* Go on */
  968. slot++;
  969. }
  970. }
  971. #endif
  972. /*
  973. * Hunt for ISA Plug'n'Pray Adaptecs (AHA1535)
  974. */
  975. if(isapnp)
  976. {
  977. struct pnp_dev *pdev = NULL;
  978. for(indx = 0; indx <sizeof(bases)/sizeof(bases[0]);indx++)
  979. {
  980. if(bases[indx])
  981. continue;
  982. pdev = pnp_find_dev(NULL, ISAPNP_VENDOR('A', 'D', 'P'),
  983. ISAPNP_FUNCTION(0x1542), pdev);
  984. if(pdev==NULL)
  985. break;
  986. /*
  987. * Activate the PnP card
  988. */
  989. if(pnp_device_attach(pdev)<0)
  990. continue;
  991. if(pnp_activate_dev(pdev)<0) {
  992. pnp_device_detach(pdev);
  993. continue;
  994. }
  995. if(!pnp_port_valid(pdev, 0)) {
  996. pnp_device_detach(pdev);
  997. continue;
  998. }
  999. bases[indx] = pnp_port_start(pdev, 0);
  1000. /* The card can be queried for its DMA, we have
  1001. the DMA set up that is enough */
  1002. printk(KERN_INFO "ISAPnP found an AHA1535 at I/O 0x%03X\n", bases[indx]);
  1003. }
  1004. }
  1005. for (indx = 0; indx < sizeof(bases) / sizeof(bases[0]); indx++)
  1006. if (bases[indx] != 0 && request_region(bases[indx], 4, "aha1542")) {
  1007. shpnt = scsi_register(tpnt,
  1008. sizeof(struct aha1542_hostdata));
  1009. if(shpnt==NULL) {
  1010. release_region(bases[indx], 4);
  1011. continue;
  1012. }
  1013. /* For now we do this - until kmalloc is more intelligent
  1014. we are resigned to stupid hacks like this */
  1015. if (SCSI_BUF_PA(shpnt) >= ISA_DMA_THRESHOLD) {
  1016. printk(KERN_ERR "Invalid address for shpnt with 1542.\n");
  1017. goto unregister;
  1018. }
  1019. if (!aha1542_test_port(bases[indx], shpnt))
  1020. goto unregister;
  1021. base_io = bases[indx];
  1022. /* Set the Bus on/off-times as not to ruin floppy performance */
  1023. {
  1024. unchar oncmd[] = {CMD_BUSON_TIME, 7};
  1025. unchar offcmd[] = {CMD_BUSOFF_TIME, 5};
  1026. if (setup_called[indx]) {
  1027. oncmd[1] = setup_buson[indx];
  1028. offcmd[1] = setup_busoff[indx];
  1029. }
  1030. aha1542_intr_reset(base_io);
  1031. aha1542_out(base_io, oncmd, 2);
  1032. WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
  1033. aha1542_intr_reset(base_io);
  1034. aha1542_out(base_io, offcmd, 2);
  1035. WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
  1036. if (setup_dmaspeed[indx] >= 0) {
  1037. unchar dmacmd[] = {CMD_DMASPEED, 0};
  1038. dmacmd[1] = setup_dmaspeed[indx];
  1039. aha1542_intr_reset(base_io);
  1040. aha1542_out(base_io, dmacmd, 2);
  1041. WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
  1042. }
  1043. while (0) {
  1044. fail:
  1045. printk(KERN_ERR "aha1542_detect: setting bus on/off-time failed\n");
  1046. }
  1047. aha1542_intr_reset(base_io);
  1048. }
  1049. if (aha1542_query(base_io, &trans))
  1050. goto unregister;
  1051. if (aha1542_getconfig(base_io, &irq_level, &dma_chan, &scsi_id) == -1)
  1052. goto unregister;
  1053. printk(KERN_INFO "Configuring Adaptec (SCSI-ID %d) at IO:%x, IRQ %d", scsi_id, base_io, irq_level);
  1054. if (dma_chan != 0xFF)
  1055. printk(", DMA priority %d", dma_chan);
  1056. printk("\n");
  1057. DEB(aha1542_stat());
  1058. setup_mailboxes(base_io, shpnt);
  1059. DEB(aha1542_stat());
  1060. DEB(printk("aha1542_detect: enable interrupt channel %d\n", irq_level));
  1061. spin_lock_irqsave(&aha1542_lock, flags);
  1062. if (request_irq(irq_level, do_aha1542_intr_handle, 0, "aha1542", NULL)) {
  1063. printk(KERN_ERR "Unable to allocate IRQ for adaptec controller.\n");
  1064. spin_unlock_irqrestore(&aha1542_lock, flags);
  1065. goto unregister;
  1066. }
  1067. if (dma_chan != 0xFF) {
  1068. if (request_dma(dma_chan, "aha1542")) {
  1069. printk(KERN_ERR "Unable to allocate DMA channel for Adaptec.\n");
  1070. free_irq(irq_level, NULL);
  1071. spin_unlock_irqrestore(&aha1542_lock, flags);
  1072. goto unregister;
  1073. }
  1074. if (dma_chan == 0 || dma_chan >= 5) {
  1075. set_dma_mode(dma_chan, DMA_MODE_CASCADE);
  1076. enable_dma(dma_chan);
  1077. }
  1078. }
  1079. aha_host[irq_level - 9] = shpnt;
  1080. shpnt->this_id = scsi_id;
  1081. shpnt->unique_id = base_io;
  1082. shpnt->io_port = base_io;
  1083. shpnt->n_io_port = 4; /* Number of bytes of I/O space used */
  1084. shpnt->dma_channel = dma_chan;
  1085. shpnt->irq = irq_level;
  1086. HOSTDATA(shpnt)->bios_translation = trans;
  1087. if (trans == BIOS_TRANSLATION_25563)
  1088. printk(KERN_INFO "aha1542.c: Using extended bios translation\n");
  1089. HOSTDATA(shpnt)->aha1542_last_mbi_used = (2 * AHA1542_MAILBOXES - 1);
  1090. HOSTDATA(shpnt)->aha1542_last_mbo_used = (AHA1542_MAILBOXES - 1);
  1091. memset(HOSTDATA(shpnt)->SCint, 0, sizeof(HOSTDATA(shpnt)->SCint));
  1092. spin_unlock_irqrestore(&aha1542_lock, flags);
  1093. #if 0
  1094. DEB(printk(" *** READ CAPACITY ***\n"));
  1095. {
  1096. unchar buf[8];
  1097. static unchar cmd[] = { READ_CAPACITY, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  1098. int i;
  1099. for (i = 0; i < sizeof(buf); ++i)
  1100. buf[i] = 0x87;
  1101. for (i = 0; i < 2; ++i)
  1102. if (!aha1542_command(i, cmd, buf, sizeof(buf))) {
  1103. printk(KERN_DEBUG "aha_detect: LU %d sector_size %d device_size %d\n",
  1104. i, xscsi2int(buf + 4), xscsi2int(buf));
  1105. }
  1106. }
  1107. DEB(printk(" *** NOW RUNNING MY OWN TEST *** \n"));
  1108. for (i = 0; i < 4; ++i) {
  1109. unsigned char cmd[10];
  1110. static buffer[512];
  1111. cmd[0] = READ_10;
  1112. cmd[1] = 0;
  1113. xany2scsi(cmd + 2, i);
  1114. cmd[6] = 0;
  1115. cmd[7] = 0;
  1116. cmd[8] = 1;
  1117. cmd[9] = 0;
  1118. aha1542_command(0, cmd, buffer, 512);
  1119. }
  1120. #endif
  1121. count++;
  1122. continue;
  1123. unregister:
  1124. release_region(bases[indx], 4);
  1125. scsi_unregister(shpnt);
  1126. continue;
  1127. };
  1128. return count;
  1129. }
  1130. static int aha1542_release(struct Scsi_Host *shost)
  1131. {
  1132. if (shost->irq)
  1133. free_irq(shost->irq, NULL);
  1134. if (shost->dma_channel != 0xff)
  1135. free_dma(shost->dma_channel);
  1136. if (shost->io_port && shost->n_io_port)
  1137. release_region(shost->io_port, shost->n_io_port);
  1138. scsi_unregister(shost);
  1139. return 0;
  1140. }
  1141. static int aha1542_restart(struct Scsi_Host *shost)
  1142. {
  1143. int i;
  1144. int count = 0;
  1145. #if 0
  1146. unchar ahacmd = CMD_START_SCSI;
  1147. #endif
  1148. for (i = 0; i < AHA1542_MAILBOXES; i++)
  1149. if (HOSTDATA(shost)->SCint[i] &&
  1150. !(HOSTDATA(shost)->SCint[i]->device->soft_reset)) {
  1151. #if 0
  1152. HOSTDATA(shost)->mb[i].status = 1; /* Indicate ready to restart... */
  1153. #endif
  1154. count++;
  1155. }
  1156. printk(KERN_DEBUG "Potential to restart %d stalled commands...\n", count);
  1157. #if 0
  1158. /* start scsi command */
  1159. if (count)
  1160. aha1542_out(shost->io_port, &ahacmd, 1);
  1161. #endif
  1162. return 0;
  1163. }
  1164. /*
  1165. * This is a device reset. This is handled by sending a special command
  1166. * to the device.
  1167. */
  1168. static int aha1542_dev_reset(Scsi_Cmnd * SCpnt)
  1169. {
  1170. unsigned long flags;
  1171. struct mailbox *mb;
  1172. unchar target = SCpnt->device->id;
  1173. unchar lun = SCpnt->device->lun;
  1174. int mbo;
  1175. struct ccb *ccb;
  1176. unchar ahacmd = CMD_START_SCSI;
  1177. ccb = HOSTDATA(SCpnt->device->host)->ccb;
  1178. mb = HOSTDATA(SCpnt->device->host)->mb;
  1179. spin_lock_irqsave(&aha1542_lock, flags);
  1180. mbo = HOSTDATA(SCpnt->device->host)->aha1542_last_mbo_used + 1;
  1181. if (mbo >= AHA1542_MAILBOXES)
  1182. mbo = 0;
  1183. do {
  1184. if (mb[mbo].status == 0 && HOSTDATA(SCpnt->device->host)->SCint[mbo] == NULL)
  1185. break;
  1186. mbo++;
  1187. if (mbo >= AHA1542_MAILBOXES)
  1188. mbo = 0;
  1189. } while (mbo != HOSTDATA(SCpnt->device->host)->aha1542_last_mbo_used);
  1190. if (mb[mbo].status || HOSTDATA(SCpnt->device->host)->SCint[mbo])
  1191. panic("Unable to find empty mailbox for aha1542.\n");
  1192. HOSTDATA(SCpnt->device->host)->SCint[mbo] = SCpnt; /* This will effectively
  1193. prevent someone else from
  1194. screwing with this cdb. */
  1195. HOSTDATA(SCpnt->device->host)->aha1542_last_mbo_used = mbo;
  1196. spin_unlock_irqrestore(&aha1542_lock, flags);
  1197. any2scsi(mb[mbo].ccbptr, SCSI_BUF_PA(&ccb[mbo])); /* This gets trashed for some reason */
  1198. memset(&ccb[mbo], 0, sizeof(struct ccb));
  1199. ccb[mbo].op = 0x81; /* BUS DEVICE RESET */
  1200. ccb[mbo].idlun = (target & 7) << 5 | (lun & 7); /*SCSI Target Id */
  1201. ccb[mbo].linkptr[0] = ccb[mbo].linkptr[1] = ccb[mbo].linkptr[2] = 0;
  1202. ccb[mbo].commlinkid = 0;
  1203. /*
  1204. * Now tell the 1542 to flush all pending commands for this
  1205. * target
  1206. */
  1207. aha1542_out(SCpnt->device->host->io_port, &ahacmd, 1);
  1208. scmd_printk(KERN_WARNING, SCpnt,
  1209. "Trying device reset for target\n");
  1210. return SUCCESS;
  1211. #ifdef ERIC_neverdef
  1212. /*
  1213. * With the 1542 we apparently never get an interrupt to
  1214. * acknowledge a device reset being sent. Then again, Leonard
  1215. * says we are doing this wrong in the first place...
  1216. *
  1217. * Take a wait and see attitude. If we get spurious interrupts,
  1218. * then the device reset is doing something sane and useful, and
  1219. * we will wait for the interrupt to post completion.
  1220. */
  1221. printk(KERN_WARNING "Sent BUS DEVICE RESET to target %d\n", SCpnt->target);
  1222. /*
  1223. * Free the command block for all commands running on this
  1224. * target...
  1225. */
  1226. for (i = 0; i < AHA1542_MAILBOXES; i++) {
  1227. if (HOSTDATA(SCpnt->host)->SCint[i] &&
  1228. HOSTDATA(SCpnt->host)->SCint[i]->target == SCpnt->target) {
  1229. Scsi_Cmnd *SCtmp;
  1230. SCtmp = HOSTDATA(SCpnt->host)->SCint[i];
  1231. kfree(SCtmp->host_scribble);
  1232. SCtmp->host_scribble = NULL;
  1233. HOSTDATA(SCpnt->host)->SCint[i] = NULL;
  1234. HOSTDATA(SCpnt->host)->mb[i].status = 0;
  1235. }
  1236. }
  1237. return SUCCESS;
  1238. return FAILED;
  1239. #endif /* ERIC_neverdef */
  1240. }
  1241. static int aha1542_bus_reset(Scsi_Cmnd * SCpnt)
  1242. {
  1243. int i;
  1244. /*
  1245. * This does a scsi reset for all devices on the bus.
  1246. * In principle, we could also reset the 1542 - should
  1247. * we do this? Try this first, and we can add that later
  1248. * if it turns out to be useful.
  1249. */
  1250. outb(SCRST, CONTROL(SCpnt->device->host->io_port));
  1251. /*
  1252. * Wait for the thing to settle down a bit. Unfortunately
  1253. * this is going to basically lock up the machine while we
  1254. * wait for this to complete. To be 100% correct, we need to
  1255. * check for timeout, and if we are doing something like this
  1256. * we are pretty desperate anyways.
  1257. */
  1258. ssleep(4);
  1259. spin_lock_irq(SCpnt->device->host->host_lock);
  1260. WAIT(STATUS(SCpnt->device->host->io_port),
  1261. STATMASK, INIT | IDLE, STST | DIAGF | INVDCMD | DF | CDF);
  1262. /*
  1263. * Now try to pick up the pieces. For all pending commands,
  1264. * free any internal data structures, and basically clear things
  1265. * out. We do not try and restart any commands or anything -
  1266. * the strategy handler takes care of that crap.
  1267. */
  1268. printk(KERN_WARNING "Sent BUS RESET to scsi host %d\n", SCpnt->device->host->host_no);
  1269. for (i = 0; i < AHA1542_MAILBOXES; i++) {
  1270. if (HOSTDATA(SCpnt->device->host)->SCint[i] != NULL) {
  1271. Scsi_Cmnd *SCtmp;
  1272. SCtmp = HOSTDATA(SCpnt->device->host)->SCint[i];
  1273. if (SCtmp->device->soft_reset) {
  1274. /*
  1275. * If this device implements the soft reset option,
  1276. * then it is still holding onto the command, and
  1277. * may yet complete it. In this case, we don't
  1278. * flush the data.
  1279. */
  1280. continue;
  1281. }
  1282. kfree(SCtmp->host_scribble);
  1283. SCtmp->host_scribble = NULL;
  1284. HOSTDATA(SCpnt->device->host)->SCint[i] = NULL;
  1285. HOSTDATA(SCpnt->device->host)->mb[i].status = 0;
  1286. }
  1287. }
  1288. spin_unlock_irq(SCpnt->device->host->host_lock);
  1289. return SUCCESS;
  1290. fail:
  1291. spin_unlock_irq(SCpnt->device->host->host_lock);
  1292. return FAILED;
  1293. }
  1294. static int aha1542_host_reset(Scsi_Cmnd * SCpnt)
  1295. {
  1296. int i;
  1297. /*
  1298. * This does a scsi reset for all devices on the bus.
  1299. * In principle, we could also reset the 1542 - should
  1300. * we do this? Try this first, and we can add that later
  1301. * if it turns out to be useful.
  1302. */
  1303. outb(HRST | SCRST, CONTROL(SCpnt->device->host->io_port));
  1304. /*
  1305. * Wait for the thing to settle down a bit. Unfortunately
  1306. * this is going to basically lock up the machine while we
  1307. * wait for this to complete. To be 100% correct, we need to
  1308. * check for timeout, and if we are doing something like this
  1309. * we are pretty desperate anyways.
  1310. */
  1311. ssleep(4);
  1312. spin_lock_irq(SCpnt->device->host->host_lock);
  1313. WAIT(STATUS(SCpnt->device->host->io_port),
  1314. STATMASK, INIT | IDLE, STST | DIAGF | INVDCMD | DF | CDF);
  1315. /*
  1316. * We need to do this too before the 1542 can interact with
  1317. * us again.
  1318. */
  1319. setup_mailboxes(SCpnt->device->host->io_port, SCpnt->device->host);
  1320. /*
  1321. * Now try to pick up the pieces. For all pending commands,
  1322. * free any internal data structures, and basically clear things
  1323. * out. We do not try and restart any commands or anything -
  1324. * the strategy handler takes care of that crap.
  1325. */
  1326. printk(KERN_WARNING "Sent BUS RESET to scsi host %d\n", SCpnt->device->host->host_no);
  1327. for (i = 0; i < AHA1542_MAILBOXES; i++) {
  1328. if (HOSTDATA(SCpnt->device->host)->SCint[i] != NULL) {
  1329. Scsi_Cmnd *SCtmp;
  1330. SCtmp = HOSTDATA(SCpnt->device->host)->SCint[i];
  1331. if (SCtmp->device->soft_reset) {
  1332. /*
  1333. * If this device implements the soft reset option,
  1334. * then it is still holding onto the command, and
  1335. * may yet complete it. In this case, we don't
  1336. * flush the data.
  1337. */
  1338. continue;
  1339. }
  1340. kfree(SCtmp->host_scribble);
  1341. SCtmp->host_scribble = NULL;
  1342. HOSTDATA(SCpnt->device->host)->SCint[i] = NULL;
  1343. HOSTDATA(SCpnt->device->host)->mb[i].status = 0;
  1344. }
  1345. }
  1346. spin_unlock_irq(SCpnt->device->host->host_lock);
  1347. return SUCCESS;
  1348. fail:
  1349. spin_unlock_irq(SCpnt->device->host->host_lock);
  1350. return FAILED;
  1351. }
  1352. #if 0
  1353. /*
  1354. * These are the old error handling routines. They are only temporarily
  1355. * here while we play with the new error handling code.
  1356. */
  1357. static int aha1542_old_abort(Scsi_Cmnd * SCpnt)
  1358. {
  1359. #if 0
  1360. unchar ahacmd = CMD_START_SCSI;
  1361. unsigned long flags;
  1362. struct mailbox *mb;
  1363. int mbi, mbo, i;
  1364. printk(KERN_DEBUG "In aha1542_abort: %x %x\n",
  1365. inb(STATUS(SCpnt->host->io_port)),
  1366. inb(INTRFLAGS(SCpnt->host->io_port)));
  1367. spin_lock_irqsave(&aha1542_lock, flags);
  1368. mb = HOSTDATA(SCpnt->host)->mb;
  1369. mbi = HOSTDATA(SCpnt->host)->aha1542_last_mbi_used + 1;
  1370. if (mbi >= 2 * AHA1542_MAILBOXES)
  1371. mbi = AHA1542_MAILBOXES;
  1372. do {
  1373. if (mb[mbi].status != 0)
  1374. break;
  1375. mbi++;
  1376. if (mbi >= 2 * AHA1542_MAILBOXES)
  1377. mbi = AHA1542_MAILBOXES;
  1378. } while (mbi != HOSTDATA(SCpnt->host)->aha1542_last_mbi_used);
  1379. spin_unlock_irqrestore(&aha1542_lock, flags);
  1380. if (mb[mbi].status) {
  1381. printk(KERN_ERR "Lost interrupt discovered on irq %d - attempting to recover\n",
  1382. SCpnt->host->irq);
  1383. aha1542_intr_handle(SCpnt->host, NULL);
  1384. return 0;
  1385. }
  1386. /* OK, no lost interrupt. Try looking to see how many pending commands
  1387. we think we have. */
  1388. for (i = 0; i < AHA1542_MAILBOXES; i++)
  1389. if (HOSTDATA(SCpnt->host)->SCint[i]) {
  1390. if (HOSTDATA(SCpnt->host)->SCint[i] == SCpnt) {
  1391. printk(KERN_ERR "Timed out command pending for %s\n",
  1392. SCpnt->request->rq_disk ?
  1393. SCpnt->request->rq_disk->disk_name : "?"
  1394. );
  1395. if (HOSTDATA(SCpnt->host)->mb[i].status) {
  1396. printk(KERN_ERR "OGMB still full - restarting\n");
  1397. aha1542_out(SCpnt->host->io_port, &ahacmd, 1);
  1398. };
  1399. } else
  1400. printk(KERN_ERR "Other pending command %s\n",
  1401. SCpnt->request->rq_disk ?
  1402. SCpnt->request->rq_disk->disk_name : "?"
  1403. );
  1404. }
  1405. #endif
  1406. DEB(printk("aha1542_abort\n"));
  1407. #if 0
  1408. spin_lock_irqsave(&aha1542_lock, flags);
  1409. for (mbo = 0; mbo < AHA1542_MAILBOXES; mbo++) {
  1410. if (SCpnt == HOSTDATA(SCpnt->host)->SCint[mbo]) {
  1411. mb[mbo].status = 2; /* Abort command */
  1412. aha1542_out(SCpnt->host->io_port, &ahacmd, 1); /* start scsi command */
  1413. spin_unlock_irqrestore(&aha1542_lock, flags);
  1414. break;
  1415. }
  1416. }
  1417. if (AHA1542_MAILBOXES == mbo)
  1418. spin_unlock_irqrestore(&aha1542_lock, flags);
  1419. #endif
  1420. return SCSI_ABORT_SNOOZE;
  1421. }
  1422. /* We do not implement a reset function here, but the upper level code
  1423. assumes that it will get some kind of response for the command in
  1424. SCpnt. We must oblige, or the command will hang the scsi system.
  1425. For a first go, we assume that the 1542 notifies us with all of the
  1426. pending commands (it does implement soft reset, after all). */
  1427. static int aha1542_old_reset(Scsi_Cmnd * SCpnt, unsigned int reset_flags)
  1428. {
  1429. unchar ahacmd = CMD_START_SCSI;
  1430. int i;
  1431. /*
  1432. * See if a bus reset was suggested.
  1433. */
  1434. if (reset_flags & SCSI_RESET_SUGGEST_BUS_RESET) {
  1435. /*
  1436. * This does a scsi reset for all devices on the bus.
  1437. * In principle, we could also reset the 1542 - should
  1438. * we do this? Try this first, and we can add that later
  1439. * if it turns out to be useful.
  1440. */
  1441. outb(HRST | SCRST, CONTROL(SCpnt->host->io_port));
  1442. /*
  1443. * Wait for the thing to settle down a bit. Unfortunately
  1444. * this is going to basically lock up the machine while we
  1445. * wait for this to complete. To be 100% correct, we need to
  1446. * check for timeout, and if we are doing something like this
  1447. * we are pretty desperate anyways.
  1448. */
  1449. WAIT(STATUS(SCpnt->host->io_port),
  1450. STATMASK, INIT | IDLE, STST | DIAGF | INVDCMD | DF | CDF);
  1451. /*
  1452. * We need to do this too before the 1542 can interact with
  1453. * us again.
  1454. */
  1455. setup_mailboxes(SCpnt->host->io_port, SCpnt->host);
  1456. /*
  1457. * Now try to pick up the pieces. Restart all commands
  1458. * that are currently active on the bus, and reset all of
  1459. * the datastructures. We have some time to kill while
  1460. * things settle down, so print a nice message.
  1461. */
  1462. printk(KERN_WARNING "Sent BUS RESET to scsi host %d\n", SCpnt->host->host_no);
  1463. for (i = 0; i < AHA1542_MAILBOXES; i++)
  1464. if (HOSTDATA(SCpnt->host)->SCint[i] != NULL) {
  1465. Scsi_Cmnd *SCtmp;
  1466. SCtmp = HOSTDATA(SCpnt->host)->SCint[i];
  1467. SCtmp->result = DID_RESET << 16;
  1468. kfree(SCtmp->host_scribble);
  1469. SCtmp->host_scribble = NULL;
  1470. printk(KERN_WARNING "Sending DID_RESET for target %d\n", SCpnt->target);
  1471. SCtmp->scsi_done(SCpnt);
  1472. HOSTDATA(SCpnt->host)->SCint[i] = NULL;
  1473. HOSTDATA(SCpnt->host)->mb[i].status = 0;
  1474. }
  1475. /*
  1476. * Now tell the mid-level code what we did here. Since
  1477. * we have restarted all of the outstanding commands,
  1478. * then report SUCCESS.
  1479. */
  1480. return (SCSI_RESET_SUCCESS | SCSI_RESET_BUS_RESET);
  1481. fail:
  1482. printk(KERN_CRIT "aha1542.c: Unable to perform hard reset.\n");
  1483. printk(KERN_CRIT "Power cycle machine to reset\n");
  1484. return (SCSI_RESET_ERROR | SCSI_RESET_BUS_RESET);
  1485. } else {
  1486. /* This does a selective reset of just the one device */
  1487. /* First locate the ccb for this command */
  1488. for (i = 0; i < AHA1542_MAILBOXES; i++)
  1489. if (HOSTDATA(SCpnt->host)->SCint[i] == SCpnt) {
  1490. HOSTDATA(SCpnt->host)->ccb[i].op = 0x81; /* BUS DEVICE RESET */
  1491. /* Now tell the 1542 to flush all pending commands for this target */
  1492. aha1542_out(SCpnt->host->io_port, &ahacmd, 1);
  1493. /* Here is the tricky part. What to do next. Do we get an interrupt
  1494. for the commands that we aborted with the specified target, or
  1495. do we generate this on our own? Try it without first and see
  1496. what happens */
  1497. printk(KERN_WARNING "Sent BUS DEVICE RESET to target %d\n", SCpnt->target);
  1498. /* If the first does not work, then try the second. I think the
  1499. first option is more likely to be correct. Free the command
  1500. block for all commands running on this target... */
  1501. for (i = 0; i < AHA1542_MAILBOXES; i++)
  1502. if (HOSTDATA(SCpnt->host)->SCint[i] &&
  1503. HOSTDATA(SCpnt->host)->SCint[i]->target == SCpnt->target) {
  1504. Scsi_Cmnd *SCtmp;
  1505. SCtmp = HOSTDATA(SCpnt->host)->SCint[i];
  1506. SCtmp->result = DID_RESET << 16;
  1507. kfree(SCtmp->host_scribble);
  1508. SCtmp->host_scribble = NULL;
  1509. printk(KERN_WARNING "Sending DID_RESET for target %d\n", SCpnt->target);
  1510. SCtmp->scsi_done(SCpnt);
  1511. HOSTDATA(SCpnt->host)->SCint[i] = NULL;
  1512. HOSTDATA(SCpnt->host)->mb[i].status = 0;
  1513. }
  1514. return SCSI_RESET_SUCCESS;
  1515. }
  1516. }
  1517. /* No active command at this time, so this means that each time we got
  1518. some kind of response the last time through. Tell the mid-level code
  1519. to request sense information in order to decide what to do next. */
  1520. return SCSI_RESET_PUNT;
  1521. }
  1522. #endif /* end of big comment block around old_abort + old_reset */
  1523. static int aha1542_biosparam(struct scsi_device *sdev,
  1524. struct block_device *bdev, sector_t capacity, int *ip)
  1525. {
  1526. int translation_algorithm;
  1527. int size = capacity;
  1528. translation_algorithm = HOSTDATA(sdev->host)->bios_translation;
  1529. if ((size >> 11) > 1024 && translation_algorithm == BIOS_TRANSLATION_25563) {
  1530. /* Please verify that this is the same as what DOS returns */
  1531. ip[0] = 255;
  1532. ip[1] = 63;
  1533. ip[2] = size / 255 / 63;
  1534. } else {
  1535. ip[0] = 64;
  1536. ip[1] = 32;
  1537. ip[2] = size >> 11;
  1538. }
  1539. return 0;
  1540. }
  1541. MODULE_LICENSE("GPL");
  1542. static struct scsi_host_template driver_template = {
  1543. .proc_name = "aha1542",
  1544. .name = "Adaptec 1542",
  1545. .detect = aha1542_detect,
  1546. .release = aha1542_release,
  1547. .queuecommand = aha1542_queuecommand,
  1548. .eh_device_reset_handler= aha1542_dev_reset,
  1549. .eh_bus_reset_handler = aha1542_bus_reset,
  1550. .eh_host_reset_handler = aha1542_host_reset,
  1551. .bios_param = aha1542_biosparam,
  1552. .can_queue = AHA1542_MAILBOXES,
  1553. .this_id = 7,
  1554. .sg_tablesize = AHA1542_SCATTER,
  1555. .cmd_per_lun = AHA1542_CMDLUN,
  1556. .unchecked_isa_dma = 1,
  1557. .use_clustering = ENABLE_CLUSTERING,
  1558. };
  1559. #include "scsi_module.c"