nsp_cs.c 46 KB

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