nsp_cs.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760
  1. /*======================================================================
  2. NinjaSCSI-3 / NinjaSCSI-32Bi PCMCIA SCSI host adapter card driver
  3. By: YOKOTA Hiroshi <yokota@netlab.is.tsukuba.ac.jp>
  4. Ver.2.8 Support 32bit MMIO mode
  5. Support Synchronous Data Transfer Request (SDTR) mode
  6. Ver.2.0 Support 32bit PIO mode
  7. Ver.1.1.2 Fix for scatter list buffer exceeds
  8. Ver.1.1 Support scatter list
  9. Ver.0.1 Initial version
  10. This software may be used and distributed according to the terms of
  11. the GNU General Public License.
  12. ======================================================================*/
  13. /***********************************************************************
  14. This driver is for these PCcards.
  15. I-O DATA PCSC-F (Workbit NinjaSCSI-3)
  16. "WBT", "NinjaSCSI-3", "R1.0"
  17. I-O DATA CBSC-II (Workbit NinjaSCSI-32Bi in 16bit mode)
  18. "IO DATA", "CBSC16 ", "1"
  19. ***********************************************************************/
  20. #include <linux/module.h>
  21. #include <linux/kernel.h>
  22. #include <linux/init.h>
  23. #include <linux/slab.h>
  24. #include <linux/string.h>
  25. #include <linux/timer.h>
  26. #include <linux/ioport.h>
  27. #include <linux/delay.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/major.h>
  30. #include <linux/blkdev.h>
  31. #include <linux/stat.h>
  32. #include <asm/io.h>
  33. #include <asm/irq.h>
  34. #include <../drivers/scsi/scsi.h>
  35. #include <scsi/scsi_host.h>
  36. #include <scsi/scsi.h>
  37. #include <scsi/scsi_ioctl.h>
  38. #include <pcmcia/cistpl.h>
  39. #include <pcmcia/cisreg.h>
  40. #include <pcmcia/ds.h>
  41. #include "nsp_cs.h"
  42. MODULE_AUTHOR("YOKOTA Hiroshi <yokota@netlab.is.tsukuba.ac.jp>");
  43. MODULE_DESCRIPTION("WorkBit NinjaSCSI-3 / NinjaSCSI-32Bi(16bit) PCMCIA SCSI host adapter module");
  44. MODULE_SUPPORTED_DEVICE("sd,sr,sg,st");
  45. #ifdef MODULE_LICENSE
  46. MODULE_LICENSE("GPL");
  47. #endif
  48. #include "nsp_io.h"
  49. /*====================================================================*/
  50. /* Parameters that can be set with 'insmod' */
  51. static int nsp_burst_mode = BURST_MEM32;
  52. module_param(nsp_burst_mode, int, 0);
  53. MODULE_PARM_DESC(nsp_burst_mode, "Burst transfer mode (0=io8, 1=io32, 2=mem32(default))");
  54. /* Release IO ports after configuration? */
  55. static bool free_ports = 0;
  56. module_param(free_ports, bool, 0);
  57. MODULE_PARM_DESC(free_ports, "Release IO ports after configuration? (default: 0 (=no))");
  58. static struct scsi_host_template nsp_driver_template = {
  59. .proc_name = "nsp_cs",
  60. .show_info = nsp_show_info,
  61. .name = "WorkBit NinjaSCSI-3/32Bi(16bit)",
  62. .info = nsp_info,
  63. .queuecommand = nsp_queuecommand,
  64. /* .eh_abort_handler = nsp_eh_abort,*/
  65. .eh_bus_reset_handler = nsp_eh_bus_reset,
  66. .eh_host_reset_handler = nsp_eh_host_reset,
  67. .can_queue = 1,
  68. .this_id = NSP_INITIATOR_ID,
  69. .sg_tablesize = SG_ALL,
  70. .use_clustering = DISABLE_CLUSTERING,
  71. };
  72. static nsp_hw_data nsp_data_base; /* attach <-> detect glue */
  73. /*
  74. * debug, error print
  75. */
  76. #ifndef NSP_DEBUG
  77. # define NSP_DEBUG_MASK 0x000000
  78. # define nsp_msg(type, args...) nsp_cs_message("", 0, (type), args)
  79. # define nsp_dbg(mask, args...) /* */
  80. #else
  81. # define NSP_DEBUG_MASK 0xffffff
  82. # define nsp_msg(type, args...) \
  83. nsp_cs_message (__func__, __LINE__, (type), args)
  84. # define nsp_dbg(mask, args...) \
  85. nsp_cs_dmessage(__func__, __LINE__, (mask), args)
  86. #endif
  87. #define NSP_DEBUG_QUEUECOMMAND BIT(0)
  88. #define NSP_DEBUG_REGISTER BIT(1)
  89. #define NSP_DEBUG_AUTOSCSI BIT(2)
  90. #define NSP_DEBUG_INTR BIT(3)
  91. #define NSP_DEBUG_SGLIST BIT(4)
  92. #define NSP_DEBUG_BUSFREE BIT(5)
  93. #define NSP_DEBUG_CDB_CONTENTS BIT(6)
  94. #define NSP_DEBUG_RESELECTION BIT(7)
  95. #define NSP_DEBUG_MSGINOCCUR BIT(8)
  96. #define NSP_DEBUG_EEPROM BIT(9)
  97. #define NSP_DEBUG_MSGOUTOCCUR BIT(10)
  98. #define NSP_DEBUG_BUSRESET BIT(11)
  99. #define NSP_DEBUG_RESTART BIT(12)
  100. #define NSP_DEBUG_SYNC BIT(13)
  101. #define NSP_DEBUG_WAIT BIT(14)
  102. #define NSP_DEBUG_TARGETFLAG BIT(15)
  103. #define NSP_DEBUG_PROC BIT(16)
  104. #define NSP_DEBUG_INIT BIT(17)
  105. #define NSP_DEBUG_DATA_IO BIT(18)
  106. #define NSP_SPECIAL_PRINT_REGISTER BIT(20)
  107. #define NSP_DEBUG_BUF_LEN 150
  108. static inline void nsp_inc_resid(struct scsi_cmnd *SCpnt, int residInc)
  109. {
  110. scsi_set_resid(SCpnt, scsi_get_resid(SCpnt) + residInc);
  111. }
  112. static void nsp_cs_message(const char *func, int line, char *type, char *fmt, ...)
  113. {
  114. va_list args;
  115. char buf[NSP_DEBUG_BUF_LEN];
  116. va_start(args, fmt);
  117. vsnprintf(buf, sizeof(buf), fmt, args);
  118. va_end(args);
  119. #ifndef NSP_DEBUG
  120. printk("%snsp_cs: %s\n", type, buf);
  121. #else
  122. printk("%snsp_cs: %s (%d): %s\n", type, func, line, buf);
  123. #endif
  124. }
  125. #ifdef NSP_DEBUG
  126. static void nsp_cs_dmessage(const char *func, int line, int mask, char *fmt, ...)
  127. {
  128. va_list args;
  129. char buf[NSP_DEBUG_BUF_LEN];
  130. va_start(args, fmt);
  131. vsnprintf(buf, sizeof(buf), fmt, args);
  132. va_end(args);
  133. if (mask & NSP_DEBUG_MASK) {
  134. printk("nsp_cs-debug: 0x%x %s (%d): %s\n", mask, func, line, buf);
  135. }
  136. }
  137. #endif
  138. /***********************************************************/
  139. /*====================================================
  140. * Clenaup parameters and call done() functions.
  141. * You must be set SCpnt->result before call this function.
  142. */
  143. static void nsp_scsi_done(struct scsi_cmnd *SCpnt)
  144. {
  145. nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
  146. data->CurrentSC = NULL;
  147. SCpnt->scsi_done(SCpnt);
  148. }
  149. static int nsp_queuecommand_lck(struct scsi_cmnd *SCpnt,
  150. void (*done)(struct scsi_cmnd *))
  151. {
  152. #ifdef NSP_DEBUG
  153. /*unsigned int host_id = SCpnt->device->host->this_id;*/
  154. /*unsigned int base = SCpnt->device->host->io_port;*/
  155. unsigned char target = scmd_id(SCpnt);
  156. #endif
  157. nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
  158. nsp_dbg(NSP_DEBUG_QUEUECOMMAND,
  159. "SCpnt=0x%p target=%d lun=%llu sglist=0x%p bufflen=%d sg_count=%d",
  160. SCpnt, target, SCpnt->device->lun, scsi_sglist(SCpnt),
  161. scsi_bufflen(SCpnt), scsi_sg_count(SCpnt));
  162. //nsp_dbg(NSP_DEBUG_QUEUECOMMAND, "before CurrentSC=0x%p", data->CurrentSC);
  163. SCpnt->scsi_done = done;
  164. if (data->CurrentSC != NULL) {
  165. nsp_msg(KERN_DEBUG, "CurrentSC!=NULL this can't be happen");
  166. SCpnt->result = DID_BAD_TARGET << 16;
  167. nsp_scsi_done(SCpnt);
  168. return 0;
  169. }
  170. #if 0
  171. /* XXX: pcmcia-cs generates SCSI command with "scsi_info" utility.
  172. This makes kernel crash when suspending... */
  173. if (data->ScsiInfo->stop != 0) {
  174. nsp_msg(KERN_INFO, "suspending device. reject command.");
  175. SCpnt->result = DID_BAD_TARGET << 16;
  176. nsp_scsi_done(SCpnt);
  177. return SCSI_MLQUEUE_HOST_BUSY;
  178. }
  179. #endif
  180. show_command(SCpnt);
  181. data->CurrentSC = SCpnt;
  182. SCpnt->SCp.Status = CHECK_CONDITION;
  183. SCpnt->SCp.Message = 0;
  184. SCpnt->SCp.have_data_in = IO_UNKNOWN;
  185. SCpnt->SCp.sent_command = 0;
  186. SCpnt->SCp.phase = PH_UNDETERMINED;
  187. scsi_set_resid(SCpnt, scsi_bufflen(SCpnt));
  188. /* setup scratch area
  189. SCp.ptr : buffer pointer
  190. SCp.this_residual : buffer length
  191. SCp.buffer : next buffer
  192. SCp.buffers_residual : left buffers in list
  193. SCp.phase : current state of the command */
  194. if (scsi_bufflen(SCpnt)) {
  195. SCpnt->SCp.buffer = scsi_sglist(SCpnt);
  196. SCpnt->SCp.ptr = BUFFER_ADDR;
  197. SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length;
  198. SCpnt->SCp.buffers_residual = scsi_sg_count(SCpnt) - 1;
  199. } else {
  200. SCpnt->SCp.ptr = NULL;
  201. SCpnt->SCp.this_residual = 0;
  202. SCpnt->SCp.buffer = NULL;
  203. SCpnt->SCp.buffers_residual = 0;
  204. }
  205. if (nsphw_start_selection(SCpnt) == FALSE) {
  206. nsp_dbg(NSP_DEBUG_QUEUECOMMAND, "selection fail");
  207. SCpnt->result = DID_BUS_BUSY << 16;
  208. nsp_scsi_done(SCpnt);
  209. return 0;
  210. }
  211. //nsp_dbg(NSP_DEBUG_QUEUECOMMAND, "out");
  212. #ifdef NSP_DEBUG
  213. data->CmdId++;
  214. #endif
  215. return 0;
  216. }
  217. static DEF_SCSI_QCMD(nsp_queuecommand)
  218. /*
  219. * setup PIO FIFO transfer mode and enable/disable to data out
  220. */
  221. static void nsp_setup_fifo(nsp_hw_data *data, int enabled)
  222. {
  223. unsigned int base = data->BaseAddress;
  224. unsigned char transfer_mode_reg;
  225. //nsp_dbg(NSP_DEBUG_DATA_IO, "enabled=%d", enabled);
  226. if (enabled != FALSE) {
  227. transfer_mode_reg = TRANSFER_GO | BRAIND;
  228. } else {
  229. transfer_mode_reg = 0;
  230. }
  231. transfer_mode_reg |= data->TransferMode;
  232. nsp_index_write(base, TRANSFERMODE, transfer_mode_reg);
  233. }
  234. static void nsphw_init_sync(nsp_hw_data *data)
  235. {
  236. sync_data tmp_sync = { .SyncNegotiation = SYNC_NOT_YET,
  237. .SyncPeriod = 0,
  238. .SyncOffset = 0
  239. };
  240. int i;
  241. /* setup sync data */
  242. for ( i = 0; i < ARRAY_SIZE(data->Sync); i++ ) {
  243. data->Sync[i] = tmp_sync;
  244. }
  245. }
  246. /*
  247. * Initialize Ninja hardware
  248. */
  249. static int nsphw_init(nsp_hw_data *data)
  250. {
  251. unsigned int base = data->BaseAddress;
  252. nsp_dbg(NSP_DEBUG_INIT, "in base=0x%x", base);
  253. data->ScsiClockDiv = CLOCK_40M | FAST_20;
  254. data->CurrentSC = NULL;
  255. data->FifoCount = 0;
  256. data->TransferMode = MODE_IO8;
  257. nsphw_init_sync(data);
  258. /* block all interrupts */
  259. nsp_write(base, IRQCONTROL, IRQCONTROL_ALLMASK);
  260. /* setup SCSI interface */
  261. nsp_write(base, IFSELECT, IF_IFSEL);
  262. nsp_index_write(base, SCSIIRQMODE, 0);
  263. nsp_index_write(base, TRANSFERMODE, MODE_IO8);
  264. nsp_index_write(base, CLOCKDIV, data->ScsiClockDiv);
  265. nsp_index_write(base, PARITYCTRL, 0);
  266. nsp_index_write(base, POINTERCLR, POINTER_CLEAR |
  267. ACK_COUNTER_CLEAR |
  268. REQ_COUNTER_CLEAR |
  269. HOST_COUNTER_CLEAR);
  270. /* setup fifo asic */
  271. nsp_write(base, IFSELECT, IF_REGSEL);
  272. nsp_index_write(base, TERMPWRCTRL, 0);
  273. if ((nsp_index_read(base, OTHERCONTROL) & TPWR_SENSE) == 0) {
  274. nsp_msg(KERN_INFO, "terminator power on");
  275. nsp_index_write(base, TERMPWRCTRL, POWER_ON);
  276. }
  277. nsp_index_write(base, TIMERCOUNT, 0);
  278. nsp_index_write(base, TIMERCOUNT, 0); /* requires 2 times!! */
  279. nsp_index_write(base, SYNCREG, 0);
  280. nsp_index_write(base, ACKWIDTH, 0);
  281. /* enable interrupts and ack them */
  282. nsp_index_write(base, SCSIIRQMODE, SCSI_PHASE_CHANGE_EI |
  283. RESELECT_EI |
  284. SCSI_RESET_IRQ_EI );
  285. nsp_write(base, IRQCONTROL, IRQCONTROL_ALLCLEAR);
  286. nsp_setup_fifo(data, FALSE);
  287. return TRUE;
  288. }
  289. /*
  290. * Start selection phase
  291. */
  292. static int nsphw_start_selection(struct scsi_cmnd *SCpnt)
  293. {
  294. unsigned int host_id = SCpnt->device->host->this_id;
  295. unsigned int base = SCpnt->device->host->io_port;
  296. unsigned char target = scmd_id(SCpnt);
  297. nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
  298. int time_out;
  299. unsigned char phase, arbit;
  300. //nsp_dbg(NSP_DEBUG_RESELECTION, "in");
  301. phase = nsp_index_read(base, SCSIBUSMON);
  302. if(phase != BUSMON_BUS_FREE) {
  303. //nsp_dbg(NSP_DEBUG_RESELECTION, "bus busy");
  304. return FALSE;
  305. }
  306. /* start arbitration */
  307. //nsp_dbg(NSP_DEBUG_RESELECTION, "start arbit");
  308. SCpnt->SCp.phase = PH_ARBSTART;
  309. nsp_index_write(base, SETARBIT, ARBIT_GO);
  310. time_out = 1000;
  311. do {
  312. /* XXX: what a stupid chip! */
  313. arbit = nsp_index_read(base, ARBITSTATUS);
  314. //nsp_dbg(NSP_DEBUG_RESELECTION, "arbit=%d, wait_count=%d", arbit, wait_count);
  315. udelay(1); /* hold 1.2us */
  316. } while((arbit & (ARBIT_WIN | ARBIT_FAIL)) == 0 &&
  317. (time_out-- != 0));
  318. if (!(arbit & ARBIT_WIN)) {
  319. //nsp_dbg(NSP_DEBUG_RESELECTION, "arbit fail");
  320. nsp_index_write(base, SETARBIT, ARBIT_FLAG_CLEAR);
  321. return FALSE;
  322. }
  323. /* assert select line */
  324. //nsp_dbg(NSP_DEBUG_RESELECTION, "assert SEL line");
  325. SCpnt->SCp.phase = PH_SELSTART;
  326. udelay(3); /* wait 2.4us */
  327. nsp_index_write(base, SCSIDATALATCH, BIT(host_id) | BIT(target));
  328. nsp_index_write(base, SCSIBUSCTRL, SCSI_SEL | SCSI_BSY | SCSI_ATN);
  329. udelay(2); /* wait >1.2us */
  330. nsp_index_write(base, SCSIBUSCTRL, SCSI_SEL | SCSI_BSY | SCSI_DATAOUT_ENB | SCSI_ATN);
  331. nsp_index_write(base, SETARBIT, ARBIT_FLAG_CLEAR);
  332. /*udelay(1);*/ /* wait >90ns */
  333. nsp_index_write(base, SCSIBUSCTRL, SCSI_SEL | SCSI_DATAOUT_ENB | SCSI_ATN);
  334. /* check selection timeout */
  335. nsp_start_timer(SCpnt, 1000/51);
  336. data->SelectionTimeOut = 1;
  337. return TRUE;
  338. }
  339. struct nsp_sync_table {
  340. unsigned int min_period;
  341. unsigned int max_period;
  342. unsigned int chip_period;
  343. unsigned int ack_width;
  344. };
  345. static struct nsp_sync_table nsp_sync_table_40M[] = {
  346. {0x0c, 0x0c, 0x1, 0}, /* 20MB 50ns*/
  347. {0x19, 0x19, 0x3, 1}, /* 10MB 100ns*/
  348. {0x1a, 0x25, 0x5, 2}, /* 7.5MB 150ns*/
  349. {0x26, 0x32, 0x7, 3}, /* 5MB 200ns*/
  350. { 0, 0, 0, 0},
  351. };
  352. static struct nsp_sync_table nsp_sync_table_20M[] = {
  353. {0x19, 0x19, 0x1, 0}, /* 10MB 100ns*/
  354. {0x1a, 0x25, 0x2, 0}, /* 7.5MB 150ns*/
  355. {0x26, 0x32, 0x3, 1}, /* 5MB 200ns*/
  356. { 0, 0, 0, 0},
  357. };
  358. /*
  359. * setup synchronous data transfer mode
  360. */
  361. static int nsp_analyze_sdtr(struct scsi_cmnd *SCpnt)
  362. {
  363. unsigned char target = scmd_id(SCpnt);
  364. // unsigned char lun = SCpnt->device->lun;
  365. nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
  366. sync_data *sync = &(data->Sync[target]);
  367. struct nsp_sync_table *sync_table;
  368. unsigned int period, offset;
  369. int i;
  370. nsp_dbg(NSP_DEBUG_SYNC, "in");
  371. period = sync->SyncPeriod;
  372. offset = sync->SyncOffset;
  373. nsp_dbg(NSP_DEBUG_SYNC, "period=0x%x, offset=0x%x", period, offset);
  374. if ((data->ScsiClockDiv & (BIT(0)|BIT(1))) == CLOCK_20M) {
  375. sync_table = nsp_sync_table_20M;
  376. } else {
  377. sync_table = nsp_sync_table_40M;
  378. }
  379. for ( i = 0; sync_table->max_period != 0; i++, sync_table++) {
  380. if ( period >= sync_table->min_period &&
  381. period <= sync_table->max_period ) {
  382. break;
  383. }
  384. }
  385. if (period != 0 && sync_table->max_period == 0) {
  386. /*
  387. * No proper period/offset found
  388. */
  389. nsp_dbg(NSP_DEBUG_SYNC, "no proper period/offset");
  390. sync->SyncPeriod = 0;
  391. sync->SyncOffset = 0;
  392. sync->SyncRegister = 0;
  393. sync->AckWidth = 0;
  394. return FALSE;
  395. }
  396. sync->SyncRegister = (sync_table->chip_period << SYNCREG_PERIOD_SHIFT) |
  397. (offset & SYNCREG_OFFSET_MASK);
  398. sync->AckWidth = sync_table->ack_width;
  399. nsp_dbg(NSP_DEBUG_SYNC, "sync_reg=0x%x, ack_width=0x%x", sync->SyncRegister, sync->AckWidth);
  400. return TRUE;
  401. }
  402. /*
  403. * start ninja hardware timer
  404. */
  405. static void nsp_start_timer(struct scsi_cmnd *SCpnt, int time)
  406. {
  407. unsigned int base = SCpnt->device->host->io_port;
  408. nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
  409. //nsp_dbg(NSP_DEBUG_INTR, "in SCpnt=0x%p, time=%d", SCpnt, time);
  410. data->TimerCount = time;
  411. nsp_index_write(base, TIMERCOUNT, time);
  412. }
  413. /*
  414. * wait for bus phase change
  415. */
  416. static int nsp_negate_signal(struct scsi_cmnd *SCpnt, unsigned char mask,
  417. char *str)
  418. {
  419. unsigned int base = SCpnt->device->host->io_port;
  420. unsigned char reg;
  421. int time_out;
  422. //nsp_dbg(NSP_DEBUG_INTR, "in");
  423. time_out = 100;
  424. do {
  425. reg = nsp_index_read(base, SCSIBUSMON);
  426. if (reg == 0xff) {
  427. break;
  428. }
  429. } while ((--time_out != 0) && (reg & mask) != 0);
  430. if (time_out == 0) {
  431. nsp_msg(KERN_DEBUG, " %s signal off timeout", str);
  432. }
  433. return 0;
  434. }
  435. /*
  436. * expect Ninja Irq
  437. */
  438. static int nsp_expect_signal(struct scsi_cmnd *SCpnt,
  439. unsigned char current_phase,
  440. unsigned char mask)
  441. {
  442. unsigned int base = SCpnt->device->host->io_port;
  443. int time_out;
  444. unsigned char phase, i_src;
  445. //nsp_dbg(NSP_DEBUG_INTR, "current_phase=0x%x, mask=0x%x", current_phase, mask);
  446. time_out = 100;
  447. do {
  448. phase = nsp_index_read(base, SCSIBUSMON);
  449. if (phase == 0xff) {
  450. //nsp_dbg(NSP_DEBUG_INTR, "ret -1");
  451. return -1;
  452. }
  453. i_src = nsp_read(base, IRQSTATUS);
  454. if (i_src & IRQSTATUS_SCSI) {
  455. //nsp_dbg(NSP_DEBUG_INTR, "ret 0 found scsi signal");
  456. return 0;
  457. }
  458. if ((phase & mask) != 0 && (phase & BUSMON_PHASE_MASK) == current_phase) {
  459. //nsp_dbg(NSP_DEBUG_INTR, "ret 1 phase=0x%x", phase);
  460. return 1;
  461. }
  462. } while(time_out-- != 0);
  463. //nsp_dbg(NSP_DEBUG_INTR, "timeout");
  464. return -1;
  465. }
  466. /*
  467. * transfer SCSI message
  468. */
  469. static int nsp_xfer(struct scsi_cmnd *SCpnt, int phase)
  470. {
  471. unsigned int base = SCpnt->device->host->io_port;
  472. nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
  473. char *buf = data->MsgBuffer;
  474. int len = min(MSGBUF_SIZE, data->MsgLen);
  475. int ptr;
  476. int ret;
  477. //nsp_dbg(NSP_DEBUG_DATA_IO, "in");
  478. for (ptr = 0; len > 0; len--, ptr++) {
  479. ret = nsp_expect_signal(SCpnt, phase, BUSMON_REQ);
  480. if (ret <= 0) {
  481. nsp_dbg(NSP_DEBUG_DATA_IO, "xfer quit");
  482. return 0;
  483. }
  484. /* if last byte, negate ATN */
  485. if (len == 1 && SCpnt->SCp.phase == PH_MSG_OUT) {
  486. nsp_index_write(base, SCSIBUSCTRL, AUTODIRECTION | ACKENB);
  487. }
  488. /* read & write message */
  489. if (phase & BUSMON_IO) {
  490. nsp_dbg(NSP_DEBUG_DATA_IO, "read msg");
  491. buf[ptr] = nsp_index_read(base, SCSIDATAWITHACK);
  492. } else {
  493. nsp_dbg(NSP_DEBUG_DATA_IO, "write msg");
  494. nsp_index_write(base, SCSIDATAWITHACK, buf[ptr]);
  495. }
  496. nsp_negate_signal(SCpnt, BUSMON_ACK, "xfer<ack>");
  497. }
  498. return len;
  499. }
  500. /*
  501. * get extra SCSI data from fifo
  502. */
  503. static int nsp_dataphase_bypass(struct scsi_cmnd *SCpnt)
  504. {
  505. nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
  506. unsigned int count;
  507. //nsp_dbg(NSP_DEBUG_DATA_IO, "in");
  508. if (SCpnt->SCp.have_data_in != IO_IN) {
  509. return 0;
  510. }
  511. count = nsp_fifo_count(SCpnt);
  512. if (data->FifoCount == count) {
  513. //nsp_dbg(NSP_DEBUG_DATA_IO, "not use bypass quirk");
  514. return 0;
  515. }
  516. /*
  517. * XXX: NSP_QUIRK
  518. * data phase skip only occures in case of SCSI_LOW_READ
  519. */
  520. nsp_dbg(NSP_DEBUG_DATA_IO, "use bypass quirk");
  521. SCpnt->SCp.phase = PH_DATA;
  522. nsp_pio_read(SCpnt);
  523. nsp_setup_fifo(data, FALSE);
  524. return 0;
  525. }
  526. /*
  527. * accept reselection
  528. */
  529. static int nsp_reselected(struct scsi_cmnd *SCpnt)
  530. {
  531. unsigned int base = SCpnt->device->host->io_port;
  532. unsigned int host_id = SCpnt->device->host->this_id;
  533. //nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
  534. unsigned char bus_reg;
  535. unsigned char id_reg, tmp;
  536. int target;
  537. nsp_dbg(NSP_DEBUG_RESELECTION, "in");
  538. id_reg = nsp_index_read(base, RESELECTID);
  539. tmp = id_reg & (~BIT(host_id));
  540. target = 0;
  541. while(tmp != 0) {
  542. if (tmp & BIT(0)) {
  543. break;
  544. }
  545. tmp >>= 1;
  546. target++;
  547. }
  548. if (scmd_id(SCpnt) != target) {
  549. nsp_msg(KERN_ERR, "XXX: reselect ID must be %d in this implementation.", target);
  550. }
  551. nsp_negate_signal(SCpnt, BUSMON_SEL, "reselect<SEL>");
  552. nsp_nexus(SCpnt);
  553. bus_reg = nsp_index_read(base, SCSIBUSCTRL) & ~(SCSI_BSY | SCSI_ATN);
  554. nsp_index_write(base, SCSIBUSCTRL, bus_reg);
  555. nsp_index_write(base, SCSIBUSCTRL, bus_reg | AUTODIRECTION | ACKENB);
  556. return TRUE;
  557. }
  558. /*
  559. * count how many data transferd
  560. */
  561. static int nsp_fifo_count(struct scsi_cmnd *SCpnt)
  562. {
  563. unsigned int base = SCpnt->device->host->io_port;
  564. unsigned int count;
  565. unsigned int l, m, h, dummy;
  566. nsp_index_write(base, POINTERCLR, POINTER_CLEAR | ACK_COUNTER);
  567. l = nsp_index_read(base, TRANSFERCOUNT);
  568. m = nsp_index_read(base, TRANSFERCOUNT);
  569. h = nsp_index_read(base, TRANSFERCOUNT);
  570. dummy = nsp_index_read(base, TRANSFERCOUNT); /* required this! */
  571. count = (h << 16) | (m << 8) | (l << 0);
  572. //nsp_dbg(NSP_DEBUG_DATA_IO, "count=0x%x", count);
  573. return count;
  574. }
  575. /* fifo size */
  576. #define RFIFO_CRIT 64
  577. #define WFIFO_CRIT 64
  578. /*
  579. * read data in DATA IN phase
  580. */
  581. static void nsp_pio_read(struct scsi_cmnd *SCpnt)
  582. {
  583. unsigned int base = SCpnt->device->host->io_port;
  584. unsigned long mmio_base = SCpnt->device->host->base;
  585. nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
  586. long time_out;
  587. int ocount, res;
  588. unsigned char stat, fifo_stat;
  589. ocount = data->FifoCount;
  590. nsp_dbg(NSP_DEBUG_DATA_IO, "in SCpnt=0x%p resid=%d ocount=%d ptr=0x%p this_residual=%d buffers=0x%p nbuf=%d",
  591. SCpnt, scsi_get_resid(SCpnt), ocount, SCpnt->SCp.ptr,
  592. SCpnt->SCp.this_residual, SCpnt->SCp.buffer,
  593. SCpnt->SCp.buffers_residual);
  594. time_out = 1000;
  595. while ((time_out-- != 0) &&
  596. (SCpnt->SCp.this_residual > 0 || SCpnt->SCp.buffers_residual > 0 ) ) {
  597. stat = nsp_index_read(base, SCSIBUSMON);
  598. stat &= BUSMON_PHASE_MASK;
  599. res = nsp_fifo_count(SCpnt) - ocount;
  600. //nsp_dbg(NSP_DEBUG_DATA_IO, "ptr=0x%p this=0x%x ocount=0x%x res=0x%x", SCpnt->SCp.ptr, SCpnt->SCp.this_residual, ocount, res);
  601. if (res == 0) { /* if some data available ? */
  602. if (stat == BUSPHASE_DATA_IN) { /* phase changed? */
  603. //nsp_dbg(NSP_DEBUG_DATA_IO, " wait for data this=%d", SCpnt->SCp.this_residual);
  604. continue;
  605. } else {
  606. nsp_dbg(NSP_DEBUG_DATA_IO, "phase changed stat=0x%x", stat);
  607. break;
  608. }
  609. }
  610. fifo_stat = nsp_read(base, FIFOSTATUS);
  611. if ((fifo_stat & FIFOSTATUS_FULL_EMPTY) == 0 &&
  612. stat == BUSPHASE_DATA_IN) {
  613. continue;
  614. }
  615. res = min(res, SCpnt->SCp.this_residual);
  616. switch (data->TransferMode) {
  617. case MODE_IO32:
  618. res &= ~(BIT(1)|BIT(0)); /* align 4 */
  619. nsp_fifo32_read(base, SCpnt->SCp.ptr, res >> 2);
  620. break;
  621. case MODE_IO8:
  622. nsp_fifo8_read (base, SCpnt->SCp.ptr, res );
  623. break;
  624. case MODE_MEM32:
  625. res &= ~(BIT(1)|BIT(0)); /* align 4 */
  626. nsp_mmio_fifo32_read(mmio_base, SCpnt->SCp.ptr, res >> 2);
  627. break;
  628. default:
  629. nsp_dbg(NSP_DEBUG_DATA_IO, "unknown read mode");
  630. return;
  631. }
  632. nsp_inc_resid(SCpnt, -res);
  633. SCpnt->SCp.ptr += res;
  634. SCpnt->SCp.this_residual -= res;
  635. ocount += res;
  636. //nsp_dbg(NSP_DEBUG_DATA_IO, "ptr=0x%p this_residual=0x%x ocount=0x%x", SCpnt->SCp.ptr, SCpnt->SCp.this_residual, ocount);
  637. /* go to next scatter list if available */
  638. if (SCpnt->SCp.this_residual == 0 &&
  639. SCpnt->SCp.buffers_residual != 0 ) {
  640. //nsp_dbg(NSP_DEBUG_DATA_IO, "scatterlist next timeout=%d", time_out);
  641. SCpnt->SCp.buffers_residual--;
  642. SCpnt->SCp.buffer++;
  643. SCpnt->SCp.ptr = BUFFER_ADDR;
  644. SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length;
  645. time_out = 1000;
  646. //nsp_dbg(NSP_DEBUG_DATA_IO, "page: 0x%p, off: 0x%x", SCpnt->SCp.buffer->page, SCpnt->SCp.buffer->offset);
  647. }
  648. }
  649. data->FifoCount = ocount;
  650. if (time_out < 0) {
  651. nsp_msg(KERN_DEBUG, "pio read timeout resid=%d this_residual=%d buffers_residual=%d",
  652. scsi_get_resid(SCpnt), SCpnt->SCp.this_residual,
  653. SCpnt->SCp.buffers_residual);
  654. }
  655. nsp_dbg(NSP_DEBUG_DATA_IO, "read ocount=0x%x", ocount);
  656. nsp_dbg(NSP_DEBUG_DATA_IO, "r cmd=%d resid=0x%x\n", data->CmdId,
  657. scsi_get_resid(SCpnt));
  658. }
  659. /*
  660. * write data in DATA OUT phase
  661. */
  662. static void nsp_pio_write(struct scsi_cmnd *SCpnt)
  663. {
  664. unsigned int base = SCpnt->device->host->io_port;
  665. unsigned long mmio_base = SCpnt->device->host->base;
  666. nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
  667. int time_out;
  668. int ocount, res;
  669. unsigned char stat;
  670. ocount = data->FifoCount;
  671. nsp_dbg(NSP_DEBUG_DATA_IO, "in fifocount=%d ptr=0x%p this_residual=%d buffers=0x%p nbuf=%d resid=0x%x",
  672. data->FifoCount, SCpnt->SCp.ptr, SCpnt->SCp.this_residual,
  673. SCpnt->SCp.buffer, SCpnt->SCp.buffers_residual,
  674. scsi_get_resid(SCpnt));
  675. time_out = 1000;
  676. while ((time_out-- != 0) &&
  677. (SCpnt->SCp.this_residual > 0 || SCpnt->SCp.buffers_residual > 0)) {
  678. stat = nsp_index_read(base, SCSIBUSMON);
  679. stat &= BUSMON_PHASE_MASK;
  680. if (stat != BUSPHASE_DATA_OUT) {
  681. res = ocount - nsp_fifo_count(SCpnt);
  682. nsp_dbg(NSP_DEBUG_DATA_IO, "phase changed stat=0x%x, res=%d\n", stat, res);
  683. /* Put back pointer */
  684. nsp_inc_resid(SCpnt, res);
  685. SCpnt->SCp.ptr -= res;
  686. SCpnt->SCp.this_residual += res;
  687. ocount -= res;
  688. break;
  689. }
  690. res = ocount - nsp_fifo_count(SCpnt);
  691. if (res > 0) { /* write all data? */
  692. nsp_dbg(NSP_DEBUG_DATA_IO, "wait for all data out. ocount=0x%x res=%d", ocount, res);
  693. continue;
  694. }
  695. res = min(SCpnt->SCp.this_residual, WFIFO_CRIT);
  696. //nsp_dbg(NSP_DEBUG_DATA_IO, "ptr=0x%p this=0x%x res=0x%x", SCpnt->SCp.ptr, SCpnt->SCp.this_residual, res);
  697. switch (data->TransferMode) {
  698. case MODE_IO32:
  699. res &= ~(BIT(1)|BIT(0)); /* align 4 */
  700. nsp_fifo32_write(base, SCpnt->SCp.ptr, res >> 2);
  701. break;
  702. case MODE_IO8:
  703. nsp_fifo8_write (base, SCpnt->SCp.ptr, res );
  704. break;
  705. case MODE_MEM32:
  706. res &= ~(BIT(1)|BIT(0)); /* align 4 */
  707. nsp_mmio_fifo32_write(mmio_base, SCpnt->SCp.ptr, res >> 2);
  708. break;
  709. default:
  710. nsp_dbg(NSP_DEBUG_DATA_IO, "unknown write mode");
  711. break;
  712. }
  713. nsp_inc_resid(SCpnt, -res);
  714. SCpnt->SCp.ptr += res;
  715. SCpnt->SCp.this_residual -= res;
  716. ocount += res;
  717. /* go to next scatter list if available */
  718. if (SCpnt->SCp.this_residual == 0 &&
  719. SCpnt->SCp.buffers_residual != 0 ) {
  720. //nsp_dbg(NSP_DEBUG_DATA_IO, "scatterlist next");
  721. SCpnt->SCp.buffers_residual--;
  722. SCpnt->SCp.buffer++;
  723. SCpnt->SCp.ptr = BUFFER_ADDR;
  724. SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length;
  725. time_out = 1000;
  726. }
  727. }
  728. data->FifoCount = ocount;
  729. if (time_out < 0) {
  730. nsp_msg(KERN_DEBUG, "pio write timeout resid=0x%x",
  731. scsi_get_resid(SCpnt));
  732. }
  733. nsp_dbg(NSP_DEBUG_DATA_IO, "write ocount=0x%x", ocount);
  734. nsp_dbg(NSP_DEBUG_DATA_IO, "w cmd=%d resid=0x%x\n", data->CmdId,
  735. scsi_get_resid(SCpnt));
  736. }
  737. #undef RFIFO_CRIT
  738. #undef WFIFO_CRIT
  739. /*
  740. * setup synchronous/asynchronous data transfer mode
  741. */
  742. static int nsp_nexus(struct scsi_cmnd *SCpnt)
  743. {
  744. unsigned int base = SCpnt->device->host->io_port;
  745. unsigned char target = scmd_id(SCpnt);
  746. // unsigned char lun = SCpnt->device->lun;
  747. nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
  748. sync_data *sync = &(data->Sync[target]);
  749. //nsp_dbg(NSP_DEBUG_DATA_IO, "in SCpnt=0x%p", SCpnt);
  750. /* setup synch transfer registers */
  751. nsp_index_write(base, SYNCREG, sync->SyncRegister);
  752. nsp_index_write(base, ACKWIDTH, sync->AckWidth);
  753. if (scsi_get_resid(SCpnt) % 4 != 0 ||
  754. scsi_get_resid(SCpnt) <= PAGE_SIZE ) {
  755. data->TransferMode = MODE_IO8;
  756. } else if (nsp_burst_mode == BURST_MEM32) {
  757. data->TransferMode = MODE_MEM32;
  758. } else if (nsp_burst_mode == BURST_IO32) {
  759. data->TransferMode = MODE_IO32;
  760. } else {
  761. data->TransferMode = MODE_IO8;
  762. }
  763. /* setup pdma fifo */
  764. nsp_setup_fifo(data, TRUE);
  765. /* clear ack counter */
  766. data->FifoCount = 0;
  767. nsp_index_write(base, POINTERCLR, POINTER_CLEAR |
  768. ACK_COUNTER_CLEAR |
  769. REQ_COUNTER_CLEAR |
  770. HOST_COUNTER_CLEAR);
  771. return 0;
  772. }
  773. #include "nsp_message.c"
  774. /*
  775. * interrupt handler
  776. */
  777. static irqreturn_t nspintr(int irq, void *dev_id)
  778. {
  779. unsigned int base;
  780. unsigned char irq_status, irq_phase, phase;
  781. struct scsi_cmnd *tmpSC;
  782. unsigned char target, lun;
  783. unsigned int *sync_neg;
  784. int i, tmp;
  785. nsp_hw_data *data;
  786. //nsp_dbg(NSP_DEBUG_INTR, "dev_id=0x%p", dev_id);
  787. //nsp_dbg(NSP_DEBUG_INTR, "host=0x%p", ((scsi_info_t *)dev_id)->host);
  788. if ( dev_id != NULL &&
  789. ((scsi_info_t *)dev_id)->host != NULL ) {
  790. scsi_info_t *info = (scsi_info_t *)dev_id;
  791. data = (nsp_hw_data *)info->host->hostdata;
  792. } else {
  793. nsp_dbg(NSP_DEBUG_INTR, "host data wrong");
  794. return IRQ_NONE;
  795. }
  796. //nsp_dbg(NSP_DEBUG_INTR, "&nsp_data_base=0x%p, dev_id=0x%p", &nsp_data_base, dev_id);
  797. base = data->BaseAddress;
  798. //nsp_dbg(NSP_DEBUG_INTR, "base=0x%x", base);
  799. /*
  800. * interrupt check
  801. */
  802. nsp_write(base, IRQCONTROL, IRQCONTROL_IRQDISABLE);
  803. irq_status = nsp_read(base, IRQSTATUS);
  804. //nsp_dbg(NSP_DEBUG_INTR, "irq_status=0x%x", irq_status);
  805. if ((irq_status == 0xff) || ((irq_status & IRQSTATUS_MASK) == 0)) {
  806. nsp_write(base, IRQCONTROL, 0);
  807. //nsp_dbg(NSP_DEBUG_INTR, "no irq/shared irq");
  808. return IRQ_NONE;
  809. }
  810. /* XXX: IMPORTANT
  811. * Do not read an irq_phase register if no scsi phase interrupt.
  812. * Unless, you should lose a scsi phase interrupt.
  813. */
  814. phase = nsp_index_read(base, SCSIBUSMON);
  815. if((irq_status & IRQSTATUS_SCSI) != 0) {
  816. irq_phase = nsp_index_read(base, IRQPHASESENCE);
  817. } else {
  818. irq_phase = 0;
  819. }
  820. //nsp_dbg(NSP_DEBUG_INTR, "irq_phase=0x%x", irq_phase);
  821. /*
  822. * timer interrupt handler (scsi vs timer interrupts)
  823. */
  824. //nsp_dbg(NSP_DEBUG_INTR, "timercount=%d", data->TimerCount);
  825. if (data->TimerCount != 0) {
  826. //nsp_dbg(NSP_DEBUG_INTR, "stop timer");
  827. nsp_index_write(base, TIMERCOUNT, 0);
  828. nsp_index_write(base, TIMERCOUNT, 0);
  829. data->TimerCount = 0;
  830. }
  831. if ((irq_status & IRQSTATUS_MASK) == IRQSTATUS_TIMER &&
  832. data->SelectionTimeOut == 0) {
  833. //nsp_dbg(NSP_DEBUG_INTR, "timer start");
  834. nsp_write(base, IRQCONTROL, IRQCONTROL_TIMER_CLEAR);
  835. return IRQ_HANDLED;
  836. }
  837. nsp_write(base, IRQCONTROL, IRQCONTROL_TIMER_CLEAR | IRQCONTROL_FIFO_CLEAR);
  838. if ((irq_status & IRQSTATUS_SCSI) &&
  839. (irq_phase & SCSI_RESET_IRQ)) {
  840. nsp_msg(KERN_ERR, "bus reset (power off?)");
  841. nsphw_init(data);
  842. nsp_bus_reset(data);
  843. if(data->CurrentSC != NULL) {
  844. tmpSC = data->CurrentSC;
  845. tmpSC->result = (DID_RESET << 16) |
  846. ((tmpSC->SCp.Message & 0xff) << 8) |
  847. ((tmpSC->SCp.Status & 0xff) << 0);
  848. nsp_scsi_done(tmpSC);
  849. }
  850. return IRQ_HANDLED;
  851. }
  852. if (data->CurrentSC == NULL) {
  853. nsp_msg(KERN_ERR, "CurrentSC==NULL irq_status=0x%x phase=0x%x irq_phase=0x%x this can't be happen. reset everything", irq_status, phase, irq_phase);
  854. nsphw_init(data);
  855. nsp_bus_reset(data);
  856. return IRQ_HANDLED;
  857. }
  858. tmpSC = data->CurrentSC;
  859. target = tmpSC->device->id;
  860. lun = tmpSC->device->lun;
  861. sync_neg = &(data->Sync[target].SyncNegotiation);
  862. /*
  863. * parse hardware SCSI irq reasons register
  864. */
  865. if (irq_status & IRQSTATUS_SCSI) {
  866. if (irq_phase & RESELECT_IRQ) {
  867. nsp_dbg(NSP_DEBUG_INTR, "reselect");
  868. nsp_write(base, IRQCONTROL, IRQCONTROL_RESELECT_CLEAR);
  869. if (nsp_reselected(tmpSC) != FALSE) {
  870. return IRQ_HANDLED;
  871. }
  872. }
  873. if ((irq_phase & (PHASE_CHANGE_IRQ | LATCHED_BUS_FREE)) == 0) {
  874. return IRQ_HANDLED;
  875. }
  876. }
  877. //show_phase(tmpSC);
  878. switch(tmpSC->SCp.phase) {
  879. case PH_SELSTART:
  880. // *sync_neg = SYNC_NOT_YET;
  881. if ((phase & BUSMON_BSY) == 0) {
  882. //nsp_dbg(NSP_DEBUG_INTR, "selection count=%d", data->SelectionTimeOut);
  883. if (data->SelectionTimeOut >= NSP_SELTIMEOUT) {
  884. nsp_dbg(NSP_DEBUG_INTR, "selection time out");
  885. data->SelectionTimeOut = 0;
  886. nsp_index_write(base, SCSIBUSCTRL, 0);
  887. tmpSC->result = DID_TIME_OUT << 16;
  888. nsp_scsi_done(tmpSC);
  889. return IRQ_HANDLED;
  890. }
  891. data->SelectionTimeOut += 1;
  892. nsp_start_timer(tmpSC, 1000/51);
  893. return IRQ_HANDLED;
  894. }
  895. /* attention assert */
  896. //nsp_dbg(NSP_DEBUG_INTR, "attention assert");
  897. data->SelectionTimeOut = 0;
  898. tmpSC->SCp.phase = PH_SELECTED;
  899. nsp_index_write(base, SCSIBUSCTRL, SCSI_ATN);
  900. udelay(1);
  901. nsp_index_write(base, SCSIBUSCTRL, SCSI_ATN | AUTODIRECTION | ACKENB);
  902. return IRQ_HANDLED;
  903. break;
  904. case PH_RESELECT:
  905. //nsp_dbg(NSP_DEBUG_INTR, "phase reselect");
  906. // *sync_neg = SYNC_NOT_YET;
  907. if ((phase & BUSMON_PHASE_MASK) != BUSPHASE_MESSAGE_IN) {
  908. tmpSC->result = DID_ABORT << 16;
  909. nsp_scsi_done(tmpSC);
  910. return IRQ_HANDLED;
  911. }
  912. /* fall thru */
  913. default:
  914. if ((irq_status & (IRQSTATUS_SCSI | IRQSTATUS_FIFO)) == 0) {
  915. return IRQ_HANDLED;
  916. }
  917. break;
  918. }
  919. /*
  920. * SCSI sequencer
  921. */
  922. //nsp_dbg(NSP_DEBUG_INTR, "start scsi seq");
  923. /* normal disconnect */
  924. if (((tmpSC->SCp.phase == PH_MSG_IN) || (tmpSC->SCp.phase == PH_MSG_OUT)) &&
  925. (irq_phase & LATCHED_BUS_FREE) != 0 ) {
  926. nsp_dbg(NSP_DEBUG_INTR, "normal disconnect irq_status=0x%x, phase=0x%x, irq_phase=0x%x", irq_status, phase, irq_phase);
  927. //*sync_neg = SYNC_NOT_YET;
  928. if ((tmpSC->SCp.Message == MSG_COMMAND_COMPLETE)) { /* all command complete and return status */
  929. tmpSC->result = (DID_OK << 16) |
  930. ((tmpSC->SCp.Message & 0xff) << 8) |
  931. ((tmpSC->SCp.Status & 0xff) << 0);
  932. nsp_dbg(NSP_DEBUG_INTR, "command complete result=0x%x", tmpSC->result);
  933. nsp_scsi_done(tmpSC);
  934. return IRQ_HANDLED;
  935. }
  936. return IRQ_HANDLED;
  937. }
  938. /* check unexpected bus free state */
  939. if (phase == 0) {
  940. nsp_msg(KERN_DEBUG, "unexpected bus free. irq_status=0x%x, phase=0x%x, irq_phase=0x%x", irq_status, phase, irq_phase);
  941. *sync_neg = SYNC_NG;
  942. tmpSC->result = DID_ERROR << 16;
  943. nsp_scsi_done(tmpSC);
  944. return IRQ_HANDLED;
  945. }
  946. switch (phase & BUSMON_PHASE_MASK) {
  947. case BUSPHASE_COMMAND:
  948. nsp_dbg(NSP_DEBUG_INTR, "BUSPHASE_COMMAND");
  949. if ((phase & BUSMON_REQ) == 0) {
  950. nsp_dbg(NSP_DEBUG_INTR, "REQ == 0");
  951. return IRQ_HANDLED;
  952. }
  953. tmpSC->SCp.phase = PH_COMMAND;
  954. nsp_nexus(tmpSC);
  955. /* write scsi command */
  956. nsp_dbg(NSP_DEBUG_INTR, "cmd_len=%d", tmpSC->cmd_len);
  957. nsp_index_write(base, COMMANDCTRL, CLEAR_COMMAND_POINTER);
  958. for (i = 0; i < tmpSC->cmd_len; i++) {
  959. nsp_index_write(base, COMMANDDATA, tmpSC->cmnd[i]);
  960. }
  961. nsp_index_write(base, COMMANDCTRL, CLEAR_COMMAND_POINTER | AUTO_COMMAND_GO);
  962. break;
  963. case BUSPHASE_DATA_OUT:
  964. nsp_dbg(NSP_DEBUG_INTR, "BUSPHASE_DATA_OUT");
  965. tmpSC->SCp.phase = PH_DATA;
  966. tmpSC->SCp.have_data_in = IO_OUT;
  967. nsp_pio_write(tmpSC);
  968. break;
  969. case BUSPHASE_DATA_IN:
  970. nsp_dbg(NSP_DEBUG_INTR, "BUSPHASE_DATA_IN");
  971. tmpSC->SCp.phase = PH_DATA;
  972. tmpSC->SCp.have_data_in = IO_IN;
  973. nsp_pio_read(tmpSC);
  974. break;
  975. case BUSPHASE_STATUS:
  976. nsp_dataphase_bypass(tmpSC);
  977. nsp_dbg(NSP_DEBUG_INTR, "BUSPHASE_STATUS");
  978. tmpSC->SCp.phase = PH_STATUS;
  979. tmpSC->SCp.Status = nsp_index_read(base, SCSIDATAWITHACK);
  980. nsp_dbg(NSP_DEBUG_INTR, "message=0x%x status=0x%x", tmpSC->SCp.Message, tmpSC->SCp.Status);
  981. break;
  982. case BUSPHASE_MESSAGE_OUT:
  983. nsp_dbg(NSP_DEBUG_INTR, "BUSPHASE_MESSAGE_OUT");
  984. if ((phase & BUSMON_REQ) == 0) {
  985. goto timer_out;
  986. }
  987. tmpSC->SCp.phase = PH_MSG_OUT;
  988. //*sync_neg = SYNC_NOT_YET;
  989. data->MsgLen = i = 0;
  990. data->MsgBuffer[i] = IDENTIFY(TRUE, lun); i++;
  991. if (*sync_neg == SYNC_NOT_YET) {
  992. data->Sync[target].SyncPeriod = 0;
  993. data->Sync[target].SyncOffset = 0;
  994. /**/
  995. data->MsgBuffer[i] = MSG_EXTENDED; i++;
  996. data->MsgBuffer[i] = 3; i++;
  997. data->MsgBuffer[i] = MSG_EXT_SDTR; i++;
  998. data->MsgBuffer[i] = 0x0c; i++;
  999. data->MsgBuffer[i] = 15; i++;
  1000. /**/
  1001. }
  1002. data->MsgLen = i;
  1003. nsp_analyze_sdtr(tmpSC);
  1004. show_message(data);
  1005. nsp_message_out(tmpSC);
  1006. break;
  1007. case BUSPHASE_MESSAGE_IN:
  1008. nsp_dataphase_bypass(tmpSC);
  1009. nsp_dbg(NSP_DEBUG_INTR, "BUSPHASE_MESSAGE_IN");
  1010. if ((phase & BUSMON_REQ) == 0) {
  1011. goto timer_out;
  1012. }
  1013. tmpSC->SCp.phase = PH_MSG_IN;
  1014. nsp_message_in(tmpSC);
  1015. /**/
  1016. if (*sync_neg == SYNC_NOT_YET) {
  1017. //nsp_dbg(NSP_DEBUG_INTR, "sync target=%d,lun=%d",target,lun);
  1018. if (data->MsgLen >= 5 &&
  1019. data->MsgBuffer[0] == MSG_EXTENDED &&
  1020. data->MsgBuffer[1] == 3 &&
  1021. data->MsgBuffer[2] == MSG_EXT_SDTR ) {
  1022. data->Sync[target].SyncPeriod = data->MsgBuffer[3];
  1023. data->Sync[target].SyncOffset = data->MsgBuffer[4];
  1024. //nsp_dbg(NSP_DEBUG_INTR, "sync ok, %d %d", data->MsgBuffer[3], data->MsgBuffer[4]);
  1025. *sync_neg = SYNC_OK;
  1026. } else {
  1027. data->Sync[target].SyncPeriod = 0;
  1028. data->Sync[target].SyncOffset = 0;
  1029. *sync_neg = SYNC_NG;
  1030. }
  1031. nsp_analyze_sdtr(tmpSC);
  1032. }
  1033. /**/
  1034. /* search last messeage byte */
  1035. tmp = -1;
  1036. for (i = 0; i < data->MsgLen; i++) {
  1037. tmp = data->MsgBuffer[i];
  1038. if (data->MsgBuffer[i] == MSG_EXTENDED) {
  1039. i += (1 + data->MsgBuffer[i+1]);
  1040. }
  1041. }
  1042. tmpSC->SCp.Message = tmp;
  1043. nsp_dbg(NSP_DEBUG_INTR, "message=0x%x len=%d", tmpSC->SCp.Message, data->MsgLen);
  1044. show_message(data);
  1045. break;
  1046. case BUSPHASE_SELECT:
  1047. default:
  1048. nsp_dbg(NSP_DEBUG_INTR, "BUSPHASE other");
  1049. break;
  1050. }
  1051. //nsp_dbg(NSP_DEBUG_INTR, "out");
  1052. return IRQ_HANDLED;
  1053. timer_out:
  1054. nsp_start_timer(tmpSC, 1000/102);
  1055. return IRQ_HANDLED;
  1056. }
  1057. #ifdef NSP_DEBUG
  1058. #include "nsp_debug.c"
  1059. #endif /* NSP_DEBUG */
  1060. /*----------------------------------------------------------------*/
  1061. /* look for ninja3 card and init if found */
  1062. /*----------------------------------------------------------------*/
  1063. static struct Scsi_Host *nsp_detect(struct scsi_host_template *sht)
  1064. {
  1065. struct Scsi_Host *host; /* registered host structure */
  1066. nsp_hw_data *data_b = &nsp_data_base, *data;
  1067. nsp_dbg(NSP_DEBUG_INIT, "this_id=%d", sht->this_id);
  1068. host = scsi_host_alloc(&nsp_driver_template, sizeof(nsp_hw_data));
  1069. if (host == NULL) {
  1070. nsp_dbg(NSP_DEBUG_INIT, "host failed");
  1071. return NULL;
  1072. }
  1073. memcpy(host->hostdata, data_b, sizeof(nsp_hw_data));
  1074. data = (nsp_hw_data *)host->hostdata;
  1075. data->ScsiInfo->host = host;
  1076. #ifdef NSP_DEBUG
  1077. data->CmdId = 0;
  1078. #endif
  1079. nsp_dbg(NSP_DEBUG_INIT, "irq=%d,%d", data_b->IrqNumber, ((nsp_hw_data *)host->hostdata)->IrqNumber);
  1080. host->unique_id = data->BaseAddress;
  1081. host->io_port = data->BaseAddress;
  1082. host->n_io_port = data->NumAddress;
  1083. host->irq = data->IrqNumber;
  1084. host->base = data->MmioAddress;
  1085. spin_lock_init(&(data->Lock));
  1086. snprintf(data->nspinfo,
  1087. sizeof(data->nspinfo),
  1088. "NinjaSCSI-3/32Bi Driver $Revision: 1.23 $ IO:0x%04lx-0x%04lx MMIO(virt addr):0x%04lx IRQ:%02d",
  1089. host->io_port, host->io_port + host->n_io_port - 1,
  1090. host->base,
  1091. host->irq);
  1092. sht->name = data->nspinfo;
  1093. nsp_dbg(NSP_DEBUG_INIT, "end");
  1094. return host; /* detect done. */
  1095. }
  1096. /*----------------------------------------------------------------*/
  1097. /* return info string */
  1098. /*----------------------------------------------------------------*/
  1099. static const char *nsp_info(struct Scsi_Host *shpnt)
  1100. {
  1101. nsp_hw_data *data = (nsp_hw_data *)shpnt->hostdata;
  1102. return data->nspinfo;
  1103. }
  1104. static int nsp_show_info(struct seq_file *m, struct Scsi_Host *host)
  1105. {
  1106. int id;
  1107. int speed;
  1108. unsigned long flags;
  1109. nsp_hw_data *data;
  1110. int hostno;
  1111. hostno = host->host_no;
  1112. data = (nsp_hw_data *)host->hostdata;
  1113. seq_puts(m, "NinjaSCSI status\n\n"
  1114. "Driver version: $Revision: 1.23 $\n");
  1115. seq_printf(m, "SCSI host No.: %d\n", hostno);
  1116. seq_printf(m, "IRQ: %d\n", host->irq);
  1117. seq_printf(m, "IO: 0x%lx-0x%lx\n", host->io_port, host->io_port + host->n_io_port - 1);
  1118. seq_printf(m, "MMIO(virtual address): 0x%lx-0x%lx\n", host->base, host->base + data->MmioLength - 1);
  1119. seq_printf(m, "sg_tablesize: %d\n", host->sg_tablesize);
  1120. seq_puts(m, "burst transfer mode: ");
  1121. switch (nsp_burst_mode) {
  1122. case BURST_IO8:
  1123. seq_puts(m, "io8");
  1124. break;
  1125. case BURST_IO32:
  1126. seq_puts(m, "io32");
  1127. break;
  1128. case BURST_MEM32:
  1129. seq_puts(m, "mem32");
  1130. break;
  1131. default:
  1132. seq_puts(m, "???");
  1133. break;
  1134. }
  1135. seq_putc(m, '\n');
  1136. spin_lock_irqsave(&(data->Lock), flags);
  1137. seq_printf(m, "CurrentSC: 0x%p\n\n", data->CurrentSC);
  1138. spin_unlock_irqrestore(&(data->Lock), flags);
  1139. seq_puts(m, "SDTR status\n");
  1140. for(id = 0; id < ARRAY_SIZE(data->Sync); id++) {
  1141. seq_printf(m, "id %d: ", id);
  1142. if (id == host->this_id) {
  1143. seq_puts(m, "----- NinjaSCSI-3 host adapter\n");
  1144. continue;
  1145. }
  1146. switch(data->Sync[id].SyncNegotiation) {
  1147. case SYNC_OK:
  1148. seq_puts(m, " sync");
  1149. break;
  1150. case SYNC_NG:
  1151. seq_puts(m, "async");
  1152. break;
  1153. case SYNC_NOT_YET:
  1154. seq_puts(m, " none");
  1155. break;
  1156. default:
  1157. seq_puts(m, "?????");
  1158. break;
  1159. }
  1160. if (data->Sync[id].SyncPeriod != 0) {
  1161. speed = 1000000 / (data->Sync[id].SyncPeriod * 4);
  1162. seq_printf(m, " transfer %d.%dMB/s, offset %d",
  1163. speed / 1000,
  1164. speed % 1000,
  1165. data->Sync[id].SyncOffset
  1166. );
  1167. }
  1168. seq_putc(m, '\n');
  1169. }
  1170. return 0;
  1171. }
  1172. /*---------------------------------------------------------------*/
  1173. /* error handler */
  1174. /*---------------------------------------------------------------*/
  1175. /*
  1176. static int nsp_eh_abort(struct scsi_cmnd *SCpnt)
  1177. {
  1178. nsp_dbg(NSP_DEBUG_BUSRESET, "SCpnt=0x%p", SCpnt);
  1179. return nsp_eh_bus_reset(SCpnt);
  1180. }*/
  1181. static int nsp_bus_reset(nsp_hw_data *data)
  1182. {
  1183. unsigned int base = data->BaseAddress;
  1184. int i;
  1185. nsp_write(base, IRQCONTROL, IRQCONTROL_ALLMASK);
  1186. nsp_index_write(base, SCSIBUSCTRL, SCSI_RST);
  1187. mdelay(100); /* 100ms */
  1188. nsp_index_write(base, SCSIBUSCTRL, 0);
  1189. for(i = 0; i < 5; i++) {
  1190. nsp_index_read(base, IRQPHASESENCE); /* dummy read */
  1191. }
  1192. nsphw_init_sync(data);
  1193. nsp_write(base, IRQCONTROL, IRQCONTROL_ALLCLEAR);
  1194. return SUCCESS;
  1195. }
  1196. static int nsp_eh_bus_reset(struct scsi_cmnd *SCpnt)
  1197. {
  1198. nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
  1199. nsp_dbg(NSP_DEBUG_BUSRESET, "SCpnt=0x%p", SCpnt);
  1200. return nsp_bus_reset(data);
  1201. }
  1202. static int nsp_eh_host_reset(struct scsi_cmnd *SCpnt)
  1203. {
  1204. nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
  1205. nsp_dbg(NSP_DEBUG_BUSRESET, "in");
  1206. nsphw_init(data);
  1207. return SUCCESS;
  1208. }
  1209. /**********************************************************************
  1210. PCMCIA functions
  1211. **********************************************************************/
  1212. static int nsp_cs_probe(struct pcmcia_device *link)
  1213. {
  1214. scsi_info_t *info;
  1215. nsp_hw_data *data = &nsp_data_base;
  1216. int ret;
  1217. nsp_dbg(NSP_DEBUG_INIT, "in");
  1218. /* Create new SCSI device */
  1219. info = kzalloc(sizeof(*info), GFP_KERNEL);
  1220. if (info == NULL) { return -ENOMEM; }
  1221. info->p_dev = link;
  1222. link->priv = info;
  1223. data->ScsiInfo = info;
  1224. nsp_dbg(NSP_DEBUG_INIT, "info=0x%p", info);
  1225. ret = nsp_cs_config(link);
  1226. nsp_dbg(NSP_DEBUG_INIT, "link=0x%p", link);
  1227. return ret;
  1228. } /* nsp_cs_attach */
  1229. static void nsp_cs_detach(struct pcmcia_device *link)
  1230. {
  1231. nsp_dbg(NSP_DEBUG_INIT, "in, link=0x%p", link);
  1232. ((scsi_info_t *)link->priv)->stop = 1;
  1233. nsp_cs_release(link);
  1234. kfree(link->priv);
  1235. link->priv = NULL;
  1236. } /* nsp_cs_detach */
  1237. static int nsp_cs_config_check(struct pcmcia_device *p_dev, void *priv_data)
  1238. {
  1239. nsp_hw_data *data = priv_data;
  1240. if (p_dev->config_index == 0)
  1241. return -ENODEV;
  1242. /* This reserves IO space but doesn't actually enable it */
  1243. if (pcmcia_request_io(p_dev) != 0)
  1244. goto next_entry;
  1245. if (resource_size(p_dev->resource[2])) {
  1246. p_dev->resource[2]->flags |= (WIN_DATA_WIDTH_16 |
  1247. WIN_MEMORY_TYPE_CM |
  1248. WIN_ENABLE);
  1249. if (p_dev->resource[2]->end < 0x1000)
  1250. p_dev->resource[2]->end = 0x1000;
  1251. if (pcmcia_request_window(p_dev, p_dev->resource[2], 0) != 0)
  1252. goto next_entry;
  1253. if (pcmcia_map_mem_page(p_dev, p_dev->resource[2],
  1254. p_dev->card_addr) != 0)
  1255. goto next_entry;
  1256. data->MmioAddress = (unsigned long)
  1257. ioremap_nocache(p_dev->resource[2]->start,
  1258. resource_size(p_dev->resource[2]));
  1259. data->MmioLength = resource_size(p_dev->resource[2]);
  1260. }
  1261. /* If we got this far, we're cool! */
  1262. return 0;
  1263. next_entry:
  1264. nsp_dbg(NSP_DEBUG_INIT, "next");
  1265. pcmcia_disable_device(p_dev);
  1266. return -ENODEV;
  1267. }
  1268. static int nsp_cs_config(struct pcmcia_device *link)
  1269. {
  1270. int ret;
  1271. scsi_info_t *info = link->priv;
  1272. struct Scsi_Host *host;
  1273. nsp_hw_data *data = &nsp_data_base;
  1274. nsp_dbg(NSP_DEBUG_INIT, "in");
  1275. link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_CHECK_VCC |
  1276. CONF_AUTO_SET_VPP | CONF_AUTO_AUDIO | CONF_AUTO_SET_IOMEM |
  1277. CONF_AUTO_SET_IO;
  1278. ret = pcmcia_loop_config(link, nsp_cs_config_check, data);
  1279. if (ret)
  1280. goto cs_failed;
  1281. if (pcmcia_request_irq(link, nspintr))
  1282. goto cs_failed;
  1283. ret = pcmcia_enable_device(link);
  1284. if (ret)
  1285. goto cs_failed;
  1286. if (free_ports) {
  1287. if (link->resource[0]) {
  1288. release_region(link->resource[0]->start,
  1289. resource_size(link->resource[0]));
  1290. }
  1291. if (link->resource[1]) {
  1292. release_region(link->resource[1]->start,
  1293. resource_size(link->resource[1]));
  1294. }
  1295. }
  1296. /* Set port and IRQ */
  1297. data->BaseAddress = link->resource[0]->start;
  1298. data->NumAddress = resource_size(link->resource[0]);
  1299. data->IrqNumber = link->irq;
  1300. nsp_dbg(NSP_DEBUG_INIT, "I/O[0x%x+0x%x] IRQ %d",
  1301. data->BaseAddress, data->NumAddress, data->IrqNumber);
  1302. if(nsphw_init(data) == FALSE) {
  1303. goto cs_failed;
  1304. }
  1305. host = nsp_detect(&nsp_driver_template);
  1306. if (host == NULL) {
  1307. nsp_dbg(NSP_DEBUG_INIT, "detect failed");
  1308. goto cs_failed;
  1309. }
  1310. ret = scsi_add_host (host, NULL);
  1311. if (ret)
  1312. goto cs_failed;
  1313. scsi_scan_host(host);
  1314. info->host = host;
  1315. return 0;
  1316. cs_failed:
  1317. nsp_dbg(NSP_DEBUG_INIT, "config fail");
  1318. nsp_cs_release(link);
  1319. return -ENODEV;
  1320. } /* nsp_cs_config */
  1321. static void nsp_cs_release(struct pcmcia_device *link)
  1322. {
  1323. scsi_info_t *info = link->priv;
  1324. nsp_hw_data *data = NULL;
  1325. if (info->host == NULL) {
  1326. nsp_msg(KERN_DEBUG, "unexpected card release call.");
  1327. } else {
  1328. data = (nsp_hw_data *)info->host->hostdata;
  1329. }
  1330. nsp_dbg(NSP_DEBUG_INIT, "link=0x%p", link);
  1331. /* Unlink the device chain */
  1332. if (info->host != NULL) {
  1333. scsi_remove_host(info->host);
  1334. }
  1335. if (resource_size(link->resource[2])) {
  1336. if (data != NULL) {
  1337. iounmap((void *)(data->MmioAddress));
  1338. }
  1339. }
  1340. pcmcia_disable_device(link);
  1341. if (info->host != NULL) {
  1342. scsi_host_put(info->host);
  1343. }
  1344. } /* nsp_cs_release */
  1345. static int nsp_cs_suspend(struct pcmcia_device *link)
  1346. {
  1347. scsi_info_t *info = link->priv;
  1348. nsp_hw_data *data;
  1349. nsp_dbg(NSP_DEBUG_INIT, "event: suspend");
  1350. if (info->host != NULL) {
  1351. nsp_msg(KERN_INFO, "clear SDTR status");
  1352. data = (nsp_hw_data *)info->host->hostdata;
  1353. nsphw_init_sync(data);
  1354. }
  1355. info->stop = 1;
  1356. return 0;
  1357. }
  1358. static int nsp_cs_resume(struct pcmcia_device *link)
  1359. {
  1360. scsi_info_t *info = link->priv;
  1361. nsp_hw_data *data;
  1362. nsp_dbg(NSP_DEBUG_INIT, "event: resume");
  1363. info->stop = 0;
  1364. if (info->host != NULL) {
  1365. nsp_msg(KERN_INFO, "reset host and bus");
  1366. data = (nsp_hw_data *)info->host->hostdata;
  1367. nsphw_init (data);
  1368. nsp_bus_reset(data);
  1369. }
  1370. return 0;
  1371. }
  1372. /*======================================================================*
  1373. * module entry point
  1374. *====================================================================*/
  1375. static const struct pcmcia_device_id nsp_cs_ids[] = {
  1376. PCMCIA_DEVICE_PROD_ID123("IO DATA", "CBSC16 ", "1", 0x547e66dc, 0x0d63a3fd, 0x51de003a),
  1377. PCMCIA_DEVICE_PROD_ID123("KME ", "SCSI-CARD-001", "1", 0x534c02bc, 0x52008408, 0x51de003a),
  1378. PCMCIA_DEVICE_PROD_ID123("KME ", "SCSI-CARD-002", "1", 0x534c02bc, 0xcb09d5b2, 0x51de003a),
  1379. PCMCIA_DEVICE_PROD_ID123("KME ", "SCSI-CARD-003", "1", 0x534c02bc, 0xbc0ee524, 0x51de003a),
  1380. PCMCIA_DEVICE_PROD_ID123("KME ", "SCSI-CARD-004", "1", 0x534c02bc, 0x226a7087, 0x51de003a),
  1381. PCMCIA_DEVICE_PROD_ID123("WBT", "NinjaSCSI-3", "R1.0", 0xc7ba805f, 0xfdc7c97d, 0x6973710e),
  1382. PCMCIA_DEVICE_PROD_ID123("WORKBIT", "UltraNinja-16", "1", 0x28191418, 0xb70f4b09, 0x51de003a),
  1383. PCMCIA_DEVICE_NULL
  1384. };
  1385. MODULE_DEVICE_TABLE(pcmcia, nsp_cs_ids);
  1386. static struct pcmcia_driver nsp_driver = {
  1387. .owner = THIS_MODULE,
  1388. .name = "nsp_cs",
  1389. .probe = nsp_cs_probe,
  1390. .remove = nsp_cs_detach,
  1391. .id_table = nsp_cs_ids,
  1392. .suspend = nsp_cs_suspend,
  1393. .resume = nsp_cs_resume,
  1394. };
  1395. static int __init nsp_cs_init(void)
  1396. {
  1397. return pcmcia_register_driver(&nsp_driver);
  1398. }
  1399. static void __exit nsp_cs_exit(void)
  1400. {
  1401. pcmcia_unregister_driver(&nsp_driver);
  1402. }
  1403. module_init(nsp_cs_init)
  1404. module_exit(nsp_cs_exit)
  1405. /* end */