ultrastor.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211
  1. /*
  2. * ultrastor.c Copyright (C) 1992 David B. Gentzel
  3. * Low-level SCSI driver for UltraStor 14F, 24F, and 34F
  4. * by David B. Gentzel, Whitfield Software Services, Carnegie, PA
  5. * (gentzel@nova.enet.dec.com)
  6. * scatter/gather added by Scott Taylor (n217cg@tamuts.tamu.edu)
  7. * 24F and multiple command support by John F. Carr (jfc@athena.mit.edu)
  8. * John's work modified by Caleb Epstein (cae@jpmorgan.com) and
  9. * Eric Youngdale (ericy@cais.com).
  10. * Thanks to UltraStor for providing the necessary documentation
  11. *
  12. * This is an old driver, for the 14F and 34F you should be using the
  13. * u14-34f driver instead.
  14. */
  15. /*
  16. * TODO:
  17. * 1. Find out why scatter/gather is limited to 16 requests per command.
  18. * This is fixed, at least on the 24F, as of version 1.12 - CAE.
  19. * 2. Look at command linking (mscp.command_link and
  20. * mscp.command_link_id). (Does not work with many disks,
  21. * and no performance increase. ERY).
  22. * 3. Allow multiple adapters.
  23. */
  24. /*
  25. * NOTES:
  26. * The UltraStor 14F, 24F, and 34F are a family of intelligent, high
  27. * performance SCSI-2 host adapters. They all support command queueing
  28. * and scatter/gather I/O. Some of them can also emulate the standard
  29. * WD1003 interface for use with OS's which don't support SCSI. Here
  30. * is the scoop on the various models:
  31. * 14F - ISA first-party DMA HA with floppy support and WD1003 emulation.
  32. * 14N - ISA HA with floppy support. I think that this is a non-DMA
  33. * HA. Nothing further known.
  34. * 24F - EISA Bus Master HA with floppy support and WD1003 emulation.
  35. * 34F - VL-Bus Bus Master HA with floppy support (no WD1003 emulation).
  36. *
  37. * The 14F, 24F, and 34F are supported by this driver.
  38. *
  39. * Places flagged with a triple question-mark are things which are either
  40. * unfinished, questionable, or wrong.
  41. */
  42. /* Changes from version 1.11 alpha to 1.12
  43. *
  44. * Increased the size of the scatter-gather list to 33 entries for
  45. * the 24F adapter (it was 16). I don't have the specs for the 14F
  46. * or the 34F, so they may support larger s-g lists as well.
  47. *
  48. * Caleb Epstein <cae@jpmorgan.com>
  49. */
  50. /* Changes from version 1.9 to 1.11
  51. *
  52. * Patches to bring this driver up to speed with the default kernel
  53. * driver which supports only the 14F and 34F adapters. This version
  54. * should compile cleanly into 0.99.13, 0.99.12 and probably 0.99.11.
  55. *
  56. * Fixes from Eric Youngdale to fix a few possible race conditions and
  57. * several problems with bit testing operations (insufficient
  58. * parentheses).
  59. *
  60. * Removed the ultrastor_abort() and ultrastor_reset() functions
  61. * (enclosed them in #if 0 / #endif). These functions, at least on
  62. * the 24F, cause the SCSI bus to do odd things and generally lead to
  63. * kernel panics and machine hangs. This is like the Adaptec code.
  64. *
  65. * Use check/snarf_region for 14f, 34f to avoid I/O space address conflicts.
  66. */
  67. /* Changes from version 1.8 to version 1.9
  68. *
  69. * 0.99.11 patches (cae@jpmorgan.com) */
  70. /* Changes from version 1.7 to version 1.8
  71. *
  72. * Better error reporting.
  73. */
  74. /* Changes from version 1.6 to version 1.7
  75. *
  76. * Removed CSIR command code.
  77. *
  78. * Better race condition avoidance (xchgb function added).
  79. *
  80. * Set ICM and OGM status to zero at probe (24F)
  81. *
  82. * reset sends soft reset to UltraStor adapter
  83. *
  84. * reset adapter if adapter interrupts with an invalid MSCP address
  85. *
  86. * handle aborted command interrupt (24F)
  87. *
  88. */
  89. /* Changes from version 1.5 to version 1.6:
  90. *
  91. * Read MSCP address from ICM _before_ clearing the interrupt flag.
  92. * This fixes a race condition.
  93. */
  94. /* Changes from version 1.4 to version 1.5:
  95. *
  96. * Abort now calls done when multiple commands are enabled.
  97. *
  98. * Clear busy when aborted command finishes, not when abort is called.
  99. *
  100. * More debugging messages for aborts.
  101. */
  102. /* Changes from version 1.3 to version 1.4:
  103. *
  104. * Enable automatic request of sense data on error (requires newer version
  105. * of scsi.c to be useful).
  106. *
  107. * Fix PORT_OVERRIDE for 14F.
  108. *
  109. * Fix abort and reset to work properly (config.aborted wasn't cleared
  110. * after it was tested, so after a command abort no further commands would
  111. * work).
  112. *
  113. * Boot time test to enable SCSI bus reset (defaults to not allowing reset).
  114. *
  115. * Fix test for OGM busy -- the busy bit is in different places on the 24F.
  116. *
  117. * Release ICM slot by clearing first byte on 24F.
  118. */
  119. #include <linux/module.h>
  120. #include <linux/blkdev.h>
  121. #include <linux/interrupt.h>
  122. #include <linux/stddef.h>
  123. #include <linux/string.h>
  124. #include <linux/kernel.h>
  125. #include <linux/ioport.h>
  126. #include <linux/proc_fs.h>
  127. #include <linux/spinlock.h>
  128. #include <linux/stat.h>
  129. #include <linux/bitops.h>
  130. #include <linux/delay.h>
  131. #include <asm/io.h>
  132. #include <asm/dma.h>
  133. #define ULTRASTOR_PRIVATE /* Get the private stuff from ultrastor.h */
  134. #include "scsi.h"
  135. #include <scsi/scsi_host.h>
  136. #include "ultrastor.h"
  137. #define FALSE 0
  138. #define TRUE 1
  139. #ifndef ULTRASTOR_DEBUG
  140. #define ULTRASTOR_DEBUG (UD_ABORT|UD_CSIR|UD_RESET)
  141. #endif
  142. #define VERSION "1.12"
  143. #define PACKED __attribute__((packed))
  144. #define ALIGNED(x) __attribute__((aligned(x)))
  145. /* The 14F uses an array of 4-byte ints for its scatter/gather list.
  146. The data can be unaligned, but need not be. It's easier to give
  147. the list normal alignment since it doesn't need to fit into a
  148. packed structure. */
  149. typedef struct {
  150. u32 address;
  151. u32 num_bytes;
  152. } ultrastor_sg_list;
  153. /* MailBox SCSI Command Packet. Basic command structure for communicating
  154. with controller. */
  155. struct mscp {
  156. unsigned char opcode: 3; /* type of command */
  157. unsigned char xdir: 2; /* data transfer direction */
  158. unsigned char dcn: 1; /* disable disconnect */
  159. unsigned char ca: 1; /* use cache (if available) */
  160. unsigned char sg: 1; /* scatter/gather operation */
  161. unsigned char target_id: 3; /* target SCSI id */
  162. unsigned char ch_no: 2; /* SCSI channel (always 0 for 14f) */
  163. unsigned char lun: 3; /* logical unit number */
  164. unsigned int transfer_data PACKED; /* transfer data pointer */
  165. unsigned int transfer_data_length PACKED; /* length in bytes */
  166. unsigned int command_link PACKED; /* for linking command chains */
  167. unsigned char scsi_command_link_id; /* identifies command in chain */
  168. unsigned char number_of_sg_list; /* (if sg is set) 8 bytes per list */
  169. unsigned char length_of_sense_byte;
  170. unsigned char length_of_scsi_cdbs; /* 6, 10, or 12 */
  171. unsigned char scsi_cdbs[12]; /* SCSI commands */
  172. unsigned char adapter_status; /* non-zero indicates HA error */
  173. unsigned char target_status; /* non-zero indicates target error */
  174. u32 sense_data PACKED;
  175. /* The following fields are for software only. They are included in
  176. the MSCP structure because they are associated with SCSI requests. */
  177. void (*done) (struct scsi_cmnd *);
  178. struct scsi_cmnd *SCint;
  179. ultrastor_sg_list sglist[ULTRASTOR_24F_MAX_SG]; /* use larger size for 24F */
  180. };
  181. /* Port addresses (relative to the base address) */
  182. #define U14F_PRODUCT_ID(port) ((port) + 0x4)
  183. #define CONFIG(port) ((port) + 0x6)
  184. /* Port addresses relative to the doorbell base address. */
  185. #define LCL_DOORBELL_MASK(port) ((port) + 0x0)
  186. #define LCL_DOORBELL_INTR(port) ((port) + 0x1)
  187. #define SYS_DOORBELL_MASK(port) ((port) + 0x2)
  188. #define SYS_DOORBELL_INTR(port) ((port) + 0x3)
  189. /* Used to store configuration info read from config i/o registers. Most of
  190. this is not used yet, but might as well save it.
  191. This structure also holds port addresses that are not at the same offset
  192. on the 14F and 24F.
  193. This structure holds all data that must be duplicated to support multiple
  194. adapters. */
  195. static struct ultrastor_config
  196. {
  197. unsigned short port_address; /* base address of card */
  198. unsigned short doorbell_address; /* base address of doorbell CSRs */
  199. unsigned short ogm_address; /* base address of OGM */
  200. unsigned short icm_address; /* base address of ICM */
  201. const void *bios_segment;
  202. unsigned char interrupt: 4;
  203. unsigned char dma_channel: 3;
  204. unsigned char bios_drive_number: 1;
  205. unsigned char heads;
  206. unsigned char sectors;
  207. unsigned char ha_scsi_id: 3;
  208. unsigned char subversion: 4;
  209. unsigned char revision;
  210. /* The slot number is used to distinguish the 24F (slot != 0) from
  211. the 14F and 34F (slot == 0). */
  212. unsigned char slot;
  213. #ifdef PRINT_U24F_VERSION
  214. volatile int csir_done;
  215. #endif
  216. /* A pool of MSCP structures for this adapter, and a bitmask of
  217. busy structures. (If ULTRASTOR_14F_MAX_CMDS == 1, a 1 byte
  218. busy flag is used instead.) */
  219. #if ULTRASTOR_MAX_CMDS == 1
  220. unsigned char mscp_busy;
  221. #else
  222. unsigned long mscp_free;
  223. #endif
  224. volatile unsigned char aborted[ULTRASTOR_MAX_CMDS];
  225. struct mscp mscp[ULTRASTOR_MAX_CMDS];
  226. } config = {0};
  227. /* Set this to 1 to reset the SCSI bus on error. */
  228. static int ultrastor_bus_reset;
  229. /* Allowed BIOS base addresses (NULL indicates reserved) */
  230. static const void *const bios_segment_table[8] = {
  231. NULL, (void *)0xC4000, (void *)0xC8000, (void *)0xCC000,
  232. (void *)0xD0000, (void *)0xD4000, (void *)0xD8000, (void *)0xDC000,
  233. };
  234. /* Allowed IRQs for 14f */
  235. static const unsigned char interrupt_table_14f[4] = { 15, 14, 11, 10 };
  236. /* Allowed DMA channels for 14f (0 indicates reserved) */
  237. static const unsigned char dma_channel_table_14f[4] = { 5, 6, 7, 0 };
  238. /* Head/sector mappings allowed by 14f */
  239. static const struct {
  240. unsigned char heads;
  241. unsigned char sectors;
  242. } mapping_table[4] = { { 16, 63 }, { 64, 32 }, { 64, 63 }, { 64, 32 } };
  243. #ifndef PORT_OVERRIDE
  244. /* ??? A probe of address 0x310 screws up NE2000 cards */
  245. static const unsigned short ultrastor_ports_14f[] = {
  246. 0x330, 0x340, /*0x310,*/ 0x230, 0x240, 0x210, 0x130, 0x140,
  247. };
  248. #endif
  249. static void ultrastor_interrupt(void *);
  250. static irqreturn_t do_ultrastor_interrupt(int, void *);
  251. static inline void build_sg_list(struct mscp *, struct scsi_cmnd *SCpnt);
  252. /* Always called with host lock held */
  253. static inline int find_and_clear_bit_16(unsigned long *field)
  254. {
  255. int rv;
  256. if (*field == 0)
  257. panic("No free mscp");
  258. asm volatile (
  259. "xorl %0,%0\n\t"
  260. "0: bsfw %1,%w0\n\t"
  261. "btr %0,%1\n\t"
  262. "jnc 0b"
  263. : "=&r" (rv), "+m" (*field) :);
  264. return rv;
  265. }
  266. /* This has been re-implemented with the help of Richard Earnshaw,
  267. <rwe@pegasus.esprit.ec.org> and works with gcc-2.5.8 and gcc-2.6.0.
  268. The instability noted by jfc below appears to be a bug in
  269. gcc-2.5.x when compiling w/o optimization. --Caleb
  270. This asm is fragile: it doesn't work without the casts and it may
  271. not work without optimization. Maybe I should add a swap builtin
  272. to gcc. --jfc */
  273. static inline unsigned char xchgb(unsigned char reg,
  274. volatile unsigned char *mem)
  275. {
  276. __asm__ ("xchgb %0,%1" : "=q" (reg), "=m" (*mem) : "0" (reg));
  277. return reg;
  278. }
  279. #if ULTRASTOR_DEBUG & (UD_COMMAND | UD_ABORT)
  280. /* Always called with the host lock held */
  281. static void log_ultrastor_abort(struct ultrastor_config *config,
  282. int command)
  283. {
  284. static char fmt[80] = "abort %d (%x); MSCP free pool: %x;";
  285. int i;
  286. for (i = 0; i < ULTRASTOR_MAX_CMDS; i++)
  287. {
  288. fmt[20 + i*2] = ' ';
  289. if (! (config->mscp_free & (1 << i)))
  290. fmt[21 + i*2] = '0' + config->mscp[i].target_id;
  291. else
  292. fmt[21 + i*2] = '-';
  293. }
  294. fmt[20 + ULTRASTOR_MAX_CMDS * 2] = '\n';
  295. fmt[21 + ULTRASTOR_MAX_CMDS * 2] = 0;
  296. printk(fmt, command, &config->mscp[command], config->mscp_free);
  297. }
  298. #endif
  299. static int ultrastor_14f_detect(struct scsi_host_template * tpnt)
  300. {
  301. size_t i;
  302. unsigned char in_byte, version_byte = 0;
  303. struct config_1 {
  304. unsigned char bios_segment: 3;
  305. unsigned char removable_disks_as_fixed: 1;
  306. unsigned char interrupt: 2;
  307. unsigned char dma_channel: 2;
  308. } config_1;
  309. struct config_2 {
  310. unsigned char ha_scsi_id: 3;
  311. unsigned char mapping_mode: 2;
  312. unsigned char bios_drive_number: 1;
  313. unsigned char tfr_port: 2;
  314. } config_2;
  315. #if (ULTRASTOR_DEBUG & UD_DETECT)
  316. printk("US14F: detect: called\n");
  317. #endif
  318. /* If a 24F has already been configured, don't look for a 14F. */
  319. if (config.bios_segment)
  320. return FALSE;
  321. #ifdef PORT_OVERRIDE
  322. if(!request_region(PORT_OVERRIDE, 0xc, "ultrastor")) {
  323. printk("Ultrastor I/O space already in use\n");
  324. return FALSE;
  325. };
  326. config.port_address = PORT_OVERRIDE;
  327. #else
  328. for (i = 0; i < ARRAY_SIZE(ultrastor_ports_14f); i++) {
  329. if(!request_region(ultrastor_ports_14f[i], 0x0c, "ultrastor")) continue;
  330. config.port_address = ultrastor_ports_14f[i];
  331. #endif
  332. #if (ULTRASTOR_DEBUG & UD_DETECT)
  333. printk("US14F: detect: testing port address %03X\n", config.port_address);
  334. #endif
  335. in_byte = inb(U14F_PRODUCT_ID(config.port_address));
  336. if (in_byte != US14F_PRODUCT_ID_0) {
  337. #if (ULTRASTOR_DEBUG & UD_DETECT)
  338. # ifdef PORT_OVERRIDE
  339. printk("US14F: detect: wrong product ID 0 - %02X\n", in_byte);
  340. # else
  341. printk("US14F: detect: no adapter at port %03X\n", config.port_address);
  342. # endif
  343. #endif
  344. #ifdef PORT_OVERRIDE
  345. goto out_release_port;
  346. #else
  347. release_region(config.port_address, 0x0c);
  348. continue;
  349. #endif
  350. }
  351. in_byte = inb(U14F_PRODUCT_ID(config.port_address) + 1);
  352. /* Only upper nibble is significant for Product ID 1 */
  353. if ((in_byte & 0xF0) != US14F_PRODUCT_ID_1) {
  354. #if (ULTRASTOR_DEBUG & UD_DETECT)
  355. # ifdef PORT_OVERRIDE
  356. printk("US14F: detect: wrong product ID 1 - %02X\n", in_byte);
  357. # else
  358. printk("US14F: detect: no adapter at port %03X\n", config.port_address);
  359. # endif
  360. #endif
  361. #ifdef PORT_OVERRIDE
  362. goto out_release_port;
  363. #else
  364. release_region(config.port_address, 0x0c);
  365. continue;
  366. #endif
  367. }
  368. version_byte = in_byte;
  369. #ifndef PORT_OVERRIDE
  370. break;
  371. }
  372. if (i == ARRAY_SIZE(ultrastor_ports_14f)) {
  373. # if (ULTRASTOR_DEBUG & UD_DETECT)
  374. printk("US14F: detect: no port address found!\n");
  375. # endif
  376. /* all ports probed already released - we can just go straight out */
  377. return FALSE;
  378. }
  379. #endif
  380. #if (ULTRASTOR_DEBUG & UD_DETECT)
  381. printk("US14F: detect: adapter found at port address %03X\n",
  382. config.port_address);
  383. #endif
  384. /* Set local doorbell mask to disallow bus reset unless
  385. ultrastor_bus_reset is true. */
  386. outb(ultrastor_bus_reset ? 0xc2 : 0x82, LCL_DOORBELL_MASK(config.port_address));
  387. /* All above tests passed, must be the right thing. Get some useful
  388. info. */
  389. /* Register the I/O space that we use */
  390. *(char *)&config_1 = inb(CONFIG(config.port_address + 0));
  391. *(char *)&config_2 = inb(CONFIG(config.port_address + 1));
  392. config.bios_segment = bios_segment_table[config_1.bios_segment];
  393. config.doorbell_address = config.port_address;
  394. config.ogm_address = config.port_address + 0x8;
  395. config.icm_address = config.port_address + 0xC;
  396. config.interrupt = interrupt_table_14f[config_1.interrupt];
  397. config.ha_scsi_id = config_2.ha_scsi_id;
  398. config.heads = mapping_table[config_2.mapping_mode].heads;
  399. config.sectors = mapping_table[config_2.mapping_mode].sectors;
  400. config.bios_drive_number = config_2.bios_drive_number;
  401. config.subversion = (version_byte & 0x0F);
  402. if (config.subversion == U34F)
  403. config.dma_channel = 0;
  404. else
  405. config.dma_channel = dma_channel_table_14f[config_1.dma_channel];
  406. if (!config.bios_segment) {
  407. #if (ULTRASTOR_DEBUG & UD_DETECT)
  408. printk("US14F: detect: not detected.\n");
  409. #endif
  410. goto out_release_port;
  411. }
  412. /* Final consistency check, verify previous info. */
  413. if (config.subversion != U34F)
  414. if (!config.dma_channel || !(config_2.tfr_port & 0x2)) {
  415. #if (ULTRASTOR_DEBUG & UD_DETECT)
  416. printk("US14F: detect: consistency check failed\n");
  417. #endif
  418. goto out_release_port;
  419. }
  420. /* If we were TRULY paranoid, we could issue a host adapter inquiry
  421. command here and verify the data returned. But frankly, I'm
  422. exhausted! */
  423. /* Finally! Now I'm satisfied... */
  424. #if (ULTRASTOR_DEBUG & UD_DETECT)
  425. printk("US14F: detect: detect succeeded\n"
  426. " Port address: %03X\n"
  427. " BIOS segment: %05X\n"
  428. " Interrupt: %u\n"
  429. " DMA channel: %u\n"
  430. " H/A SCSI ID: %u\n"
  431. " Subversion: %u\n",
  432. config.port_address, config.bios_segment, config.interrupt,
  433. config.dma_channel, config.ha_scsi_id, config.subversion);
  434. #endif
  435. tpnt->this_id = config.ha_scsi_id;
  436. tpnt->unchecked_isa_dma = (config.subversion != U34F);
  437. #if ULTRASTOR_MAX_CMDS > 1
  438. config.mscp_free = ~0;
  439. #endif
  440. /*
  441. * Brrr, &config.mscp[0].SCint->host) it is something magical....
  442. * XXX and FIXME
  443. */
  444. if (request_irq(config.interrupt, do_ultrastor_interrupt, 0, "Ultrastor", &config.mscp[0].SCint->device->host)) {
  445. printk("Unable to allocate IRQ%u for UltraStor controller.\n",
  446. config.interrupt);
  447. goto out_release_port;
  448. }
  449. if (config.dma_channel && request_dma(config.dma_channel,"Ultrastor")) {
  450. printk("Unable to allocate DMA channel %u for UltraStor controller.\n",
  451. config.dma_channel);
  452. free_irq(config.interrupt, NULL);
  453. goto out_release_port;
  454. }
  455. tpnt->sg_tablesize = ULTRASTOR_14F_MAX_SG;
  456. printk("UltraStor driver version" VERSION ". Using %d SG lists.\n",
  457. ULTRASTOR_14F_MAX_SG);
  458. return TRUE;
  459. out_release_port:
  460. release_region(config.port_address, 0x0c);
  461. return FALSE;
  462. }
  463. static int ultrastor_24f_detect(struct scsi_host_template * tpnt)
  464. {
  465. int i;
  466. struct Scsi_Host * shpnt = NULL;
  467. #if (ULTRASTOR_DEBUG & UD_DETECT)
  468. printk("US24F: detect");
  469. #endif
  470. /* probe each EISA slot at slot address C80 */
  471. for (i = 1; i < 15; i++)
  472. {
  473. unsigned char config_1, config_2;
  474. unsigned short addr = (i << 12) | ULTRASTOR_24F_PORT;
  475. if (inb(addr) != US24F_PRODUCT_ID_0 &&
  476. inb(addr+1) != US24F_PRODUCT_ID_1 &&
  477. inb(addr+2) != US24F_PRODUCT_ID_2)
  478. continue;
  479. config.revision = inb(addr+3);
  480. config.slot = i;
  481. if (! (inb(addr+4) & 1))
  482. {
  483. #if (ULTRASTOR_DEBUG & UD_DETECT)
  484. printk("U24F: found disabled card in slot %u\n", i);
  485. #endif
  486. continue;
  487. }
  488. #if (ULTRASTOR_DEBUG & UD_DETECT)
  489. printk("U24F: found card in slot %u\n", i);
  490. #endif
  491. config_1 = inb(addr + 5);
  492. config.bios_segment = bios_segment_table[config_1 & 7];
  493. switch(config_1 >> 4)
  494. {
  495. case 1:
  496. config.interrupt = 15;
  497. break;
  498. case 2:
  499. config.interrupt = 14;
  500. break;
  501. case 4:
  502. config.interrupt = 11;
  503. break;
  504. case 8:
  505. config.interrupt = 10;
  506. break;
  507. default:
  508. printk("U24F: invalid IRQ\n");
  509. return FALSE;
  510. }
  511. /* BIOS addr set */
  512. /* base port set */
  513. config.port_address = addr;
  514. config.doorbell_address = addr + 12;
  515. config.ogm_address = addr + 0x17;
  516. config.icm_address = addr + 0x1C;
  517. config_2 = inb(addr + 7);
  518. config.ha_scsi_id = config_2 & 7;
  519. config.heads = mapping_table[(config_2 >> 3) & 3].heads;
  520. config.sectors = mapping_table[(config_2 >> 3) & 3].sectors;
  521. #if (ULTRASTOR_DEBUG & UD_DETECT)
  522. printk("US24F: detect: detect succeeded\n"
  523. " Port address: %03X\n"
  524. " BIOS segment: %05X\n"
  525. " Interrupt: %u\n"
  526. " H/A SCSI ID: %u\n",
  527. config.port_address, config.bios_segment,
  528. config.interrupt, config.ha_scsi_id);
  529. #endif
  530. tpnt->this_id = config.ha_scsi_id;
  531. tpnt->unchecked_isa_dma = 0;
  532. tpnt->sg_tablesize = ULTRASTOR_24F_MAX_SG;
  533. shpnt = scsi_register(tpnt, 0);
  534. if (!shpnt) {
  535. printk(KERN_WARNING "(ultrastor:) Could not register scsi device. Aborting registration.\n");
  536. free_irq(config.interrupt, do_ultrastor_interrupt);
  537. return FALSE;
  538. }
  539. if (request_irq(config.interrupt, do_ultrastor_interrupt, 0, "Ultrastor", shpnt))
  540. {
  541. printk("Unable to allocate IRQ%u for UltraStor controller.\n",
  542. config.interrupt);
  543. return FALSE;
  544. }
  545. shpnt->irq = config.interrupt;
  546. shpnt->dma_channel = config.dma_channel;
  547. shpnt->io_port = config.port_address;
  548. #if ULTRASTOR_MAX_CMDS > 1
  549. config.mscp_free = ~0;
  550. #endif
  551. /* Mark ICM and OGM free */
  552. outb(0, addr + 0x16);
  553. outb(0, addr + 0x1B);
  554. /* Set local doorbell mask to disallow bus reset unless
  555. ultrastor_bus_reset is true. */
  556. outb(ultrastor_bus_reset ? 0xc2 : 0x82, LCL_DOORBELL_MASK(addr+12));
  557. outb(0x02, SYS_DOORBELL_MASK(addr+12));
  558. printk("UltraStor driver version " VERSION ". Using %d SG lists.\n",
  559. tpnt->sg_tablesize);
  560. return TRUE;
  561. }
  562. return FALSE;
  563. }
  564. static int ultrastor_detect(struct scsi_host_template * tpnt)
  565. {
  566. tpnt->proc_name = "ultrastor";
  567. return ultrastor_14f_detect(tpnt) || ultrastor_24f_detect(tpnt);
  568. }
  569. static int ultrastor_release(struct Scsi_Host *shost)
  570. {
  571. if (shost->irq)
  572. free_irq(shost->irq, NULL);
  573. if (shost->dma_channel != 0xff)
  574. free_dma(shost->dma_channel);
  575. if (shost->io_port && shost->n_io_port)
  576. release_region(shost->io_port, shost->n_io_port);
  577. scsi_unregister(shost);
  578. return 0;
  579. }
  580. static const char *ultrastor_info(struct Scsi_Host * shpnt)
  581. {
  582. static char buf[64];
  583. if (config.slot)
  584. sprintf(buf, "UltraStor 24F SCSI @ Slot %u IRQ%u",
  585. config.slot, config.interrupt);
  586. else if (config.subversion)
  587. sprintf(buf, "UltraStor 34F SCSI @ Port %03X BIOS %05X IRQ%u",
  588. config.port_address, (int)config.bios_segment,
  589. config.interrupt);
  590. else
  591. sprintf(buf, "UltraStor 14F SCSI @ Port %03X BIOS %05X IRQ%u DMA%u",
  592. config.port_address, (int)config.bios_segment,
  593. config.interrupt, config.dma_channel);
  594. return buf;
  595. }
  596. static inline void build_sg_list(struct mscp *mscp, struct scsi_cmnd *SCpnt)
  597. {
  598. struct scatterlist *sg;
  599. long transfer_length = 0;
  600. int i, max;
  601. max = scsi_sg_count(SCpnt);
  602. scsi_for_each_sg(SCpnt, sg, max, i) {
  603. mscp->sglist[i].address = isa_page_to_bus(sg_page(sg)) + sg->offset;
  604. mscp->sglist[i].num_bytes = sg->length;
  605. transfer_length += sg->length;
  606. }
  607. mscp->number_of_sg_list = max;
  608. mscp->transfer_data = isa_virt_to_bus(mscp->sglist);
  609. /* ??? May not be necessary. Docs are unclear as to whether transfer
  610. length field is ignored or whether it should be set to the total
  611. number of bytes of the transfer. */
  612. mscp->transfer_data_length = transfer_length;
  613. }
  614. static int ultrastor_queuecommand_lck(struct scsi_cmnd *SCpnt,
  615. void (*done) (struct scsi_cmnd *))
  616. {
  617. struct mscp *my_mscp;
  618. #if ULTRASTOR_MAX_CMDS > 1
  619. int mscp_index;
  620. #endif
  621. unsigned int status;
  622. /* Next test is for debugging; "can't happen" */
  623. if ((config.mscp_free & ((1U << ULTRASTOR_MAX_CMDS) - 1)) == 0)
  624. panic("ultrastor_queuecommand: no free MSCP\n");
  625. mscp_index = find_and_clear_bit_16(&config.mscp_free);
  626. /* Has the command been aborted? */
  627. if (xchgb(0xff, &config.aborted[mscp_index]) != 0)
  628. {
  629. status = DID_ABORT << 16;
  630. goto aborted;
  631. }
  632. my_mscp = &config.mscp[mscp_index];
  633. *(unsigned char *)my_mscp = OP_SCSI | (DTD_SCSI << 3);
  634. /* Tape drives don't work properly if the cache is used. The SCSI
  635. READ command for a tape doesn't have a block offset, and the adapter
  636. incorrectly assumes that all reads from the tape read the same
  637. blocks. Results will depend on read buffer size and other disk
  638. activity.
  639. ??? Which other device types should never use the cache? */
  640. my_mscp->ca = SCpnt->device->type != TYPE_TAPE;
  641. my_mscp->target_id = SCpnt->device->id;
  642. my_mscp->ch_no = 0;
  643. my_mscp->lun = SCpnt->device->lun;
  644. if (scsi_sg_count(SCpnt)) {
  645. /* Set scatter/gather flag in SCSI command packet */
  646. my_mscp->sg = TRUE;
  647. build_sg_list(my_mscp, SCpnt);
  648. } else {
  649. /* Unset scatter/gather flag in SCSI command packet */
  650. my_mscp->sg = FALSE;
  651. my_mscp->transfer_data = isa_virt_to_bus(scsi_sglist(SCpnt));
  652. my_mscp->transfer_data_length = scsi_bufflen(SCpnt);
  653. }
  654. my_mscp->command_link = 0; /*???*/
  655. my_mscp->scsi_command_link_id = 0; /*???*/
  656. my_mscp->length_of_sense_byte = SCSI_SENSE_BUFFERSIZE;
  657. my_mscp->length_of_scsi_cdbs = SCpnt->cmd_len;
  658. memcpy(my_mscp->scsi_cdbs, SCpnt->cmnd, my_mscp->length_of_scsi_cdbs);
  659. my_mscp->adapter_status = 0;
  660. my_mscp->target_status = 0;
  661. my_mscp->sense_data = isa_virt_to_bus(&SCpnt->sense_buffer);
  662. my_mscp->done = done;
  663. my_mscp->SCint = SCpnt;
  664. SCpnt->host_scribble = (unsigned char *)my_mscp;
  665. /* Find free OGM slot. On 24F, look for OGM status byte == 0.
  666. On 14F and 34F, wait for local interrupt pending flag to clear.
  667. FIXME: now we are using new_eh we should punt here and let the
  668. midlayer sort it out */
  669. retry:
  670. if (config.slot)
  671. while (inb(config.ogm_address - 1) != 0 && config.aborted[mscp_index] == 0xff)
  672. barrier();
  673. /* else??? */
  674. while ((inb(LCL_DOORBELL_INTR(config.doorbell_address)) & (config.slot ? 2 : 1)) && config.aborted[mscp_index] == 0xff)
  675. barrier();
  676. /* To avoid race conditions, keep the code to write to the adapter
  677. atomic. This simplifies the abort code. Right now the
  678. scsi mid layer has the host_lock already held
  679. */
  680. if (inb(LCL_DOORBELL_INTR(config.doorbell_address)) & (config.slot ? 2 : 1))
  681. goto retry;
  682. status = xchgb(0, &config.aborted[mscp_index]);
  683. if (status != 0xff) {
  684. #if ULTRASTOR_DEBUG & (UD_COMMAND | UD_ABORT)
  685. printk("USx4F: queuecommand: aborted\n");
  686. #if ULTRASTOR_MAX_CMDS > 1
  687. log_ultrastor_abort(&config, mscp_index);
  688. #endif
  689. #endif
  690. status <<= 16;
  691. aborted:
  692. set_bit(mscp_index, &config.mscp_free);
  693. /* If the driver queues commands, call the done proc here. Otherwise
  694. return an error. */
  695. #if ULTRASTOR_MAX_CMDS > 1
  696. SCpnt->result = status;
  697. done(SCpnt);
  698. return 0;
  699. #else
  700. return status;
  701. #endif
  702. }
  703. /* Store pointer in OGM address bytes */
  704. outl(isa_virt_to_bus(my_mscp), config.ogm_address);
  705. /* Issue OGM interrupt */
  706. if (config.slot) {
  707. /* Write OGM command register on 24F */
  708. outb(1, config.ogm_address - 1);
  709. outb(0x2, LCL_DOORBELL_INTR(config.doorbell_address));
  710. } else {
  711. outb(0x1, LCL_DOORBELL_INTR(config.doorbell_address));
  712. }
  713. #if (ULTRASTOR_DEBUG & UD_COMMAND)
  714. printk("USx4F: queuecommand: returning\n");
  715. #endif
  716. return 0;
  717. }
  718. static DEF_SCSI_QCMD(ultrastor_queuecommand)
  719. /* This code must deal with 2 cases:
  720. 1. The command has not been written to the OGM. In this case, set
  721. the abort flag and return.
  722. 2. The command has been written to the OGM and is stuck somewhere in
  723. the adapter.
  724. 2a. On a 24F, ask the adapter to abort the command. It will interrupt
  725. when it does.
  726. 2b. Call the command's done procedure.
  727. */
  728. static int ultrastor_abort(struct scsi_cmnd *SCpnt)
  729. {
  730. #if ULTRASTOR_DEBUG & UD_ABORT
  731. char out[108];
  732. unsigned char icm_status = 0, ogm_status = 0;
  733. unsigned int icm_addr = 0, ogm_addr = 0;
  734. #endif
  735. unsigned int mscp_index;
  736. unsigned char old_aborted;
  737. unsigned long flags;
  738. void (*done)(struct scsi_cmnd *);
  739. struct Scsi_Host *host = SCpnt->device->host;
  740. if(config.slot)
  741. return FAILED; /* Do not attempt an abort for the 24f */
  742. /* Simple consistency checking */
  743. if(!SCpnt->host_scribble)
  744. return FAILED;
  745. mscp_index = ((struct mscp *)SCpnt->host_scribble) - config.mscp;
  746. if (mscp_index >= ULTRASTOR_MAX_CMDS)
  747. panic("Ux4F aborting invalid MSCP");
  748. #if ULTRASTOR_DEBUG & UD_ABORT
  749. if (config.slot)
  750. {
  751. int port0 = (config.slot << 12) | 0xc80;
  752. int i;
  753. unsigned long flags;
  754. spin_lock_irqsave(host->host_lock, flags);
  755. strcpy(out, "OGM %d:%x ICM %d:%x ports: ");
  756. for (i = 0; i < 16; i++)
  757. {
  758. unsigned char p = inb(port0 + i);
  759. out[28 + i * 3] = "0123456789abcdef"[p >> 4];
  760. out[29 + i * 3] = "0123456789abcdef"[p & 15];
  761. out[30 + i * 3] = ' ';
  762. }
  763. out[28 + i * 3] = '\n';
  764. out[29 + i * 3] = 0;
  765. ogm_status = inb(port0 + 22);
  766. ogm_addr = (unsigned int)isa_bus_to_virt(inl(port0 + 23));
  767. icm_status = inb(port0 + 27);
  768. icm_addr = (unsigned int)isa_bus_to_virt(inl(port0 + 28));
  769. spin_unlock_irqrestore(host->host_lock, flags);
  770. }
  771. /* First check to see if an interrupt is pending. I suspect the SiS
  772. chipset loses interrupts. (I also suspect is mangles data, but
  773. one bug at a time... */
  774. if (config.slot ? inb(config.icm_address - 1) == 2 :
  775. (inb(SYS_DOORBELL_INTR(config.doorbell_address)) & 1))
  776. {
  777. printk("Ux4F: abort while completed command pending\n");
  778. spin_lock_irqsave(host->host_lock, flags);
  779. /* FIXME: Ewww... need to think about passing host around properly */
  780. ultrastor_interrupt(NULL);
  781. spin_unlock_irqrestore(host->host_lock, flags);
  782. return SUCCESS;
  783. }
  784. #endif
  785. old_aborted = xchgb(DID_ABORT, &config.aborted[mscp_index]);
  786. /* aborted == 0xff is the signal that queuecommand has not yet sent
  787. the command. It will notice the new abort flag and fail. */
  788. if (old_aborted == 0xff)
  789. return SUCCESS;
  790. /* On 24F, send an abort MSCP request. The adapter will interrupt
  791. and the interrupt handler will call done. */
  792. if (config.slot && inb(config.ogm_address - 1) == 0)
  793. {
  794. unsigned long flags;
  795. spin_lock_irqsave(host->host_lock, flags);
  796. outl(isa_virt_to_bus(&config.mscp[mscp_index]), config.ogm_address);
  797. udelay(8);
  798. outb(0x80, config.ogm_address - 1);
  799. outb(0x2, LCL_DOORBELL_INTR(config.doorbell_address));
  800. #if ULTRASTOR_DEBUG & UD_ABORT
  801. log_ultrastor_abort(&config, mscp_index);
  802. printk(out, ogm_status, ogm_addr, icm_status, icm_addr);
  803. #endif
  804. spin_unlock_irqrestore(host->host_lock, flags);
  805. /* FIXME: add a wait for the abort to complete */
  806. return SUCCESS;
  807. }
  808. #if ULTRASTOR_DEBUG & UD_ABORT
  809. log_ultrastor_abort(&config, mscp_index);
  810. #endif
  811. /* Can't request a graceful abort. Either this is not a 24F or
  812. the OGM is busy. Don't free the command -- the adapter might
  813. still be using it. Setting SCint = 0 causes the interrupt
  814. handler to ignore the command. */
  815. /* FIXME - devices that implement soft resets will still be running
  816. the command after a bus reset. We would probably rather leave
  817. the command in the queue. The upper level code will automatically
  818. leave the command in the active state instead of requeueing it. ERY */
  819. #if ULTRASTOR_DEBUG & UD_ABORT
  820. if (config.mscp[mscp_index].SCint != SCpnt)
  821. printk("abort: command mismatch, %p != %p\n",
  822. config.mscp[mscp_index].SCint, SCpnt);
  823. #endif
  824. if (config.mscp[mscp_index].SCint == NULL)
  825. return FAILED;
  826. if (config.mscp[mscp_index].SCint != SCpnt) panic("Bad abort");
  827. config.mscp[mscp_index].SCint = NULL;
  828. done = config.mscp[mscp_index].done;
  829. config.mscp[mscp_index].done = NULL;
  830. SCpnt->result = DID_ABORT << 16;
  831. /* Take the host lock to guard against scsi layer re-entry */
  832. done(SCpnt);
  833. /* Need to set a timeout here in case command never completes. */
  834. return SUCCESS;
  835. }
  836. static int ultrastor_host_reset(struct scsi_cmnd * SCpnt)
  837. {
  838. unsigned long flags;
  839. int i;
  840. struct Scsi_Host *host = SCpnt->device->host;
  841. #if (ULTRASTOR_DEBUG & UD_RESET)
  842. printk("US14F: reset: called\n");
  843. #endif
  844. if(config.slot)
  845. return FAILED;
  846. spin_lock_irqsave(host->host_lock, flags);
  847. /* Reset the adapter and SCSI bus. The SCSI bus reset can be
  848. inhibited by clearing ultrastor_bus_reset before probe. */
  849. outb(0xc0, LCL_DOORBELL_INTR(config.doorbell_address));
  850. if (config.slot)
  851. {
  852. outb(0, config.ogm_address - 1);
  853. outb(0, config.icm_address - 1);
  854. }
  855. #if ULTRASTOR_MAX_CMDS == 1
  856. if (config.mscp_busy && config.mscp->done && config.mscp->SCint)
  857. {
  858. config.mscp->SCint->result = DID_RESET << 16;
  859. config.mscp->done(config.mscp->SCint);
  860. }
  861. config.mscp->SCint = 0;
  862. #else
  863. for (i = 0; i < ULTRASTOR_MAX_CMDS; i++)
  864. {
  865. if (! (config.mscp_free & (1 << i)) &&
  866. config.mscp[i].done && config.mscp[i].SCint)
  867. {
  868. config.mscp[i].SCint->result = DID_RESET << 16;
  869. config.mscp[i].done(config.mscp[i].SCint);
  870. config.mscp[i].done = NULL;
  871. }
  872. config.mscp[i].SCint = NULL;
  873. }
  874. #endif
  875. /* FIXME - if the device implements soft resets, then the command
  876. will still be running. ERY
  877. Even bigger deal with new_eh!
  878. */
  879. memset((unsigned char *)config.aborted, 0, sizeof config.aborted);
  880. #if ULTRASTOR_MAX_CMDS == 1
  881. config.mscp_busy = 0;
  882. #else
  883. config.mscp_free = ~0;
  884. #endif
  885. spin_unlock_irqrestore(host->host_lock, flags);
  886. return SUCCESS;
  887. }
  888. int ultrastor_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  889. sector_t capacity, int * dkinfo)
  890. {
  891. int size = capacity;
  892. unsigned int s = config.heads * config.sectors;
  893. dkinfo[0] = config.heads;
  894. dkinfo[1] = config.sectors;
  895. dkinfo[2] = size / s; /* Ignore partial cylinders */
  896. #if 0
  897. if (dkinfo[2] > 1024)
  898. dkinfo[2] = 1024;
  899. #endif
  900. return 0;
  901. }
  902. static void ultrastor_interrupt(void *dev_id)
  903. {
  904. unsigned int status;
  905. #if ULTRASTOR_MAX_CMDS > 1
  906. unsigned int mscp_index;
  907. #endif
  908. struct mscp *mscp;
  909. void (*done) (struct scsi_cmnd *);
  910. struct scsi_cmnd *SCtmp;
  911. #if ULTRASTOR_MAX_CMDS == 1
  912. mscp = &config.mscp[0];
  913. #else
  914. mscp = (struct mscp *)isa_bus_to_virt(inl(config.icm_address));
  915. mscp_index = mscp - config.mscp;
  916. if (mscp_index >= ULTRASTOR_MAX_CMDS) {
  917. printk("Ux4F interrupt: bad MSCP address %x\n", (unsigned int) mscp);
  918. /* A command has been lost. Reset and report an error
  919. for all commands. */
  920. ultrastor_host_reset(dev_id);
  921. return;
  922. }
  923. #endif
  924. /* Clean ICM slot (set ICMINT bit to 0) */
  925. if (config.slot) {
  926. unsigned char icm_status = inb(config.icm_address - 1);
  927. #if ULTRASTOR_DEBUG & (UD_INTERRUPT|UD_ERROR|UD_ABORT)
  928. if (icm_status != 1 && icm_status != 2)
  929. printk("US24F: ICM status %x for MSCP %d (%x)\n", icm_status,
  930. mscp_index, (unsigned int) mscp);
  931. #endif
  932. /* The manual says clear interrupt then write 0 to ICM status.
  933. This seems backwards, but I'll do it anyway. --jfc */
  934. outb(2, SYS_DOORBELL_INTR(config.doorbell_address));
  935. outb(0, config.icm_address - 1);
  936. if (icm_status == 4) {
  937. printk("UltraStor abort command failed\n");
  938. return;
  939. }
  940. if (icm_status == 3) {
  941. void (*done)(struct scsi_cmnd *) = mscp->done;
  942. if (done) {
  943. mscp->done = NULL;
  944. mscp->SCint->result = DID_ABORT << 16;
  945. done(mscp->SCint);
  946. }
  947. return;
  948. }
  949. } else {
  950. outb(1, SYS_DOORBELL_INTR(config.doorbell_address));
  951. }
  952. SCtmp = mscp->SCint;
  953. mscp->SCint = NULL;
  954. if (!SCtmp)
  955. {
  956. #if ULTRASTOR_DEBUG & (UD_ABORT|UD_INTERRUPT)
  957. printk("MSCP %d (%x): no command\n", mscp_index, (unsigned int) mscp);
  958. #endif
  959. #if ULTRASTOR_MAX_CMDS == 1
  960. config.mscp_busy = FALSE;
  961. #else
  962. set_bit(mscp_index, &config.mscp_free);
  963. #endif
  964. config.aborted[mscp_index] = 0;
  965. return;
  966. }
  967. /* Save done locally and zero before calling. This is needed as
  968. once we call done, we may get another command queued before this
  969. interrupt service routine can return. */
  970. done = mscp->done;
  971. mscp->done = NULL;
  972. /* Let the higher levels know that we're done */
  973. switch (mscp->adapter_status)
  974. {
  975. case 0:
  976. status = DID_OK << 16;
  977. break;
  978. case 0x01: /* invalid command */
  979. case 0x02: /* invalid parameters */
  980. case 0x03: /* invalid data list */
  981. default:
  982. status = DID_ERROR << 16;
  983. break;
  984. case 0x84: /* SCSI bus abort */
  985. status = DID_ABORT << 16;
  986. break;
  987. case 0x91:
  988. status = DID_TIME_OUT << 16;
  989. break;
  990. }
  991. SCtmp->result = status | mscp->target_status;
  992. SCtmp->host_scribble = NULL;
  993. /* Free up mscp block for next command */
  994. #if ULTRASTOR_MAX_CMDS == 1
  995. config.mscp_busy = FALSE;
  996. #else
  997. set_bit(mscp_index, &config.mscp_free);
  998. #endif
  999. #if ULTRASTOR_DEBUG & (UD_ABORT|UD_INTERRUPT)
  1000. if (config.aborted[mscp_index])
  1001. printk("Ux4 interrupt: MSCP %d (%x) aborted = %d\n",
  1002. mscp_index, (unsigned int) mscp, config.aborted[mscp_index]);
  1003. #endif
  1004. config.aborted[mscp_index] = 0;
  1005. if (done)
  1006. done(SCtmp);
  1007. else
  1008. printk("US14F: interrupt: unexpected interrupt\n");
  1009. if (config.slot ? inb(config.icm_address - 1) :
  1010. (inb(SYS_DOORBELL_INTR(config.doorbell_address)) & 1))
  1011. #if (ULTRASTOR_DEBUG & UD_MULTI_CMD)
  1012. printk("Ux4F: multiple commands completed\n");
  1013. #else
  1014. ;
  1015. #endif
  1016. #if (ULTRASTOR_DEBUG & UD_INTERRUPT)
  1017. printk("USx4F: interrupt: returning\n");
  1018. #endif
  1019. }
  1020. static irqreturn_t do_ultrastor_interrupt(int irq, void *dev_id)
  1021. {
  1022. unsigned long flags;
  1023. struct Scsi_Host *dev = dev_id;
  1024. spin_lock_irqsave(dev->host_lock, flags);
  1025. ultrastor_interrupt(dev_id);
  1026. spin_unlock_irqrestore(dev->host_lock, flags);
  1027. return IRQ_HANDLED;
  1028. }
  1029. MODULE_LICENSE("GPL");
  1030. static struct scsi_host_template driver_template = {
  1031. .name = "UltraStor 14F/24F/34F",
  1032. .detect = ultrastor_detect,
  1033. .release = ultrastor_release,
  1034. .info = ultrastor_info,
  1035. .queuecommand = ultrastor_queuecommand,
  1036. .eh_abort_handler = ultrastor_abort,
  1037. .eh_host_reset_handler = ultrastor_host_reset,
  1038. .bios_param = ultrastor_biosparam,
  1039. .can_queue = ULTRASTOR_MAX_CMDS,
  1040. .sg_tablesize = ULTRASTOR_14F_MAX_SG,
  1041. .cmd_per_lun = ULTRASTOR_MAX_CMDS_PER_LUN,
  1042. .unchecked_isa_dma = 1,
  1043. .use_clustering = ENABLE_CLUSTERING,
  1044. };
  1045. #include "scsi_module.c"