eata_pio.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  1. /************************************************************
  2. * *
  3. * Linux EATA SCSI PIO driver *
  4. * *
  5. * based on the CAM document CAM/89-004 rev. 2.0c, *
  6. * DPT's driver kit, some internal documents and source, *
  7. * and several other Linux scsi drivers and kernel docs. *
  8. * *
  9. * The driver currently: *
  10. * -supports all EATA-PIO boards *
  11. * -only supports DASD devices *
  12. * *
  13. * (c)1993-96 Michael Neuffer, Alfred Arnold *
  14. * neuffer@goofy.zdv.uni-mainz.de *
  15. * a.arnold@kfa-juelich.de *
  16. * *
  17. * Updated 2002 by Alan Cox <alan@lxorguk.ukuu.org.uk> for *
  18. * Linux 2.5.x and the newer locking and error handling *
  19. * *
  20. * This program is free software; you can redistribute it *
  21. * and/or modify it under the terms of the GNU General *
  22. * Public License as published by the Free Software *
  23. * Foundation; either version 2 of the License, or *
  24. * (at your option) any later version. *
  25. * *
  26. * This program is distributed in the hope that it will be *
  27. * useful, but WITHOUT ANY WARRANTY; without even the *
  28. * implied warranty of MERCHANTABILITY or FITNESS FOR A *
  29. * PARTICULAR PURPOSE. See the GNU General Public License *
  30. * for more details. *
  31. * *
  32. * You should have received a copy of the GNU General *
  33. * Public License along with this kernel; if not, write to *
  34. * the Free Software Foundation, Inc., 675 Mass Ave, *
  35. * Cambridge, MA 02139, USA. *
  36. * *
  37. * For the avoidance of doubt the "preferred form" of this *
  38. * code is one which is in an open non patent encumbered *
  39. * format. Where cryptographic key signing forms part of *
  40. * the process of creating an executable the information *
  41. * including keys needed to generate an equivalently *
  42. * functional executable are deemed to be part of the *
  43. * source code are deemed to be part of the source code. *
  44. * *
  45. ************************************************************
  46. * last change: 2002/11/02 OS: Linux 2.5.45 *
  47. ************************************************************/
  48. #include <linux/module.h>
  49. #include <linux/kernel.h>
  50. #include <linux/string.h>
  51. #include <linux/ioport.h>
  52. #include <linux/in.h>
  53. #include <linux/pci.h>
  54. #include <linux/proc_fs.h>
  55. #include <linux/interrupt.h>
  56. #include <linux/blkdev.h>
  57. #include <linux/spinlock.h>
  58. #include <linux/delay.h>
  59. #include <asm/io.h>
  60. #include <scsi/scsi.h>
  61. #include <scsi/scsi_cmnd.h>
  62. #include <scsi/scsi_device.h>
  63. #include <scsi/scsi_host.h>
  64. #include "eata_generic.h"
  65. #include "eata_pio.h"
  66. static unsigned int ISAbases[MAXISA] = {
  67. 0x1F0, 0x170, 0x330, 0x230
  68. };
  69. static unsigned int ISAirqs[MAXISA] = {
  70. 14, 12, 15, 11
  71. };
  72. static unsigned char EISAbases[] = {
  73. 1, 1, 1, 1, 1, 1, 1, 1,
  74. 1, 1, 1, 1, 1, 1, 1, 1
  75. };
  76. static unsigned int registered_HBAs;
  77. static struct Scsi_Host *last_HBA;
  78. static struct Scsi_Host *first_HBA;
  79. static unsigned char reg_IRQ[16];
  80. static unsigned char reg_IRQL[16];
  81. static unsigned long int_counter;
  82. static unsigned long queue_counter;
  83. static struct scsi_host_template driver_template;
  84. static int eata_pio_show_info(struct seq_file *m, struct Scsi_Host *shost)
  85. {
  86. seq_printf(m, "EATA (Extended Attachment) PIO driver version: "
  87. "%d.%d%s\n",VER_MAJOR, VER_MINOR, VER_SUB);
  88. seq_printf(m, "queued commands: %10ld\n"
  89. "processed interrupts:%10ld\n", queue_counter, int_counter);
  90. seq_printf(m, "\nscsi%-2d: HBA %.10s\n",
  91. shost->host_no, SD(shost)->name);
  92. seq_printf(m, "Firmware revision: v%s\n",
  93. SD(shost)->revision);
  94. seq_puts(m, "IO: PIO\n");
  95. seq_printf(m, "Base IO : %#.4x\n", (u32) shost->base);
  96. seq_printf(m, "Host Bus: %s\n",
  97. (SD(shost)->bustype == 'P')?"PCI ":
  98. (SD(shost)->bustype == 'E')?"EISA":"ISA ");
  99. return 0;
  100. }
  101. static int eata_pio_release(struct Scsi_Host *sh)
  102. {
  103. hostdata *hd = SD(sh);
  104. if (sh->irq && reg_IRQ[sh->irq] == 1)
  105. free_irq(sh->irq, NULL);
  106. else
  107. reg_IRQ[sh->irq]--;
  108. if (SD(sh)->channel == 0) {
  109. if (sh->io_port && sh->n_io_port)
  110. release_region(sh->io_port, sh->n_io_port);
  111. }
  112. /* At this point the PCI reference can go */
  113. if (hd->pdev)
  114. pci_dev_put(hd->pdev);
  115. return 1;
  116. }
  117. static void IncStat(struct scsi_pointer *SCp, unsigned int Increment)
  118. {
  119. SCp->ptr += Increment;
  120. if ((SCp->this_residual -= Increment) == 0) {
  121. if ((--SCp->buffers_residual) == 0)
  122. SCp->Status = 0;
  123. else {
  124. SCp->buffer++;
  125. SCp->ptr = sg_virt(SCp->buffer);
  126. SCp->this_residual = SCp->buffer->length;
  127. }
  128. }
  129. }
  130. static irqreturn_t eata_pio_int_handler(int irq, void *dev_id);
  131. static irqreturn_t do_eata_pio_int_handler(int irq, void *dev_id)
  132. {
  133. unsigned long flags;
  134. struct Scsi_Host *dev = dev_id;
  135. irqreturn_t ret;
  136. spin_lock_irqsave(dev->host_lock, flags);
  137. ret = eata_pio_int_handler(irq, dev_id);
  138. spin_unlock_irqrestore(dev->host_lock, flags);
  139. return ret;
  140. }
  141. static irqreturn_t eata_pio_int_handler(int irq, void *dev_id)
  142. {
  143. unsigned int eata_stat = 0xfffff;
  144. struct scsi_cmnd *cmd;
  145. hostdata *hd;
  146. struct eata_ccb *cp;
  147. unsigned long base;
  148. unsigned int x, z;
  149. struct Scsi_Host *sh;
  150. unsigned short zwickel = 0;
  151. unsigned char stat, odd;
  152. irqreturn_t ret = IRQ_NONE;
  153. for (x = 1, sh = first_HBA; x <= registered_HBAs; x++, sh = SD(sh)->prev)
  154. {
  155. if (sh->irq != irq)
  156. continue;
  157. if (inb(sh->base + HA_RSTATUS) & HA_SBUSY)
  158. continue;
  159. int_counter++;
  160. ret = IRQ_HANDLED;
  161. hd = SD(sh);
  162. cp = &hd->ccb[0];
  163. cmd = cp->cmd;
  164. base = cmd->device->host->base;
  165. do {
  166. stat = inb(base + HA_RSTATUS);
  167. if (stat & HA_SDRQ) {
  168. if (cp->DataIn) {
  169. z = 256;
  170. odd = 0;
  171. while ((cmd->SCp.Status) && ((z > 0) || (odd))) {
  172. if (odd) {
  173. *(cmd->SCp.ptr) = zwickel >> 8;
  174. IncStat(&cmd->SCp, 1);
  175. odd = 0;
  176. }
  177. x = min_t(unsigned int, z, cmd->SCp.this_residual / 2);
  178. insw(base + HA_RDATA, cmd->SCp.ptr, x);
  179. z -= x;
  180. IncStat(&cmd->SCp, 2 * x);
  181. if ((z > 0) && (cmd->SCp.this_residual == 1)) {
  182. zwickel = inw(base + HA_RDATA);
  183. *(cmd->SCp.ptr) = zwickel & 0xff;
  184. IncStat(&cmd->SCp, 1);
  185. z--;
  186. odd = 1;
  187. }
  188. }
  189. while (z > 0) {
  190. zwickel = inw(base + HA_RDATA);
  191. z--;
  192. }
  193. } else { /* cp->DataOut */
  194. odd = 0;
  195. z = 256;
  196. while ((cmd->SCp.Status) && ((z > 0) || (odd))) {
  197. if (odd) {
  198. zwickel += *(cmd->SCp.ptr) << 8;
  199. IncStat(&cmd->SCp, 1);
  200. outw(zwickel, base + HA_RDATA);
  201. z--;
  202. odd = 0;
  203. }
  204. x = min_t(unsigned int, z, cmd->SCp.this_residual / 2);
  205. outsw(base + HA_RDATA, cmd->SCp.ptr, x);
  206. z -= x;
  207. IncStat(&cmd->SCp, 2 * x);
  208. if ((z > 0) && (cmd->SCp.this_residual == 1)) {
  209. zwickel = *(cmd->SCp.ptr);
  210. zwickel &= 0xff;
  211. IncStat(&cmd->SCp, 1);
  212. odd = 1;
  213. }
  214. }
  215. while (z > 0 || odd) {
  216. outw(zwickel, base + HA_RDATA);
  217. z--;
  218. odd = 0;
  219. }
  220. }
  221. }
  222. }
  223. while ((stat & HA_SDRQ) || ((stat & HA_SMORE) && hd->moresupport));
  224. /* terminate handler if HBA goes busy again, i.e. transfers
  225. * more data */
  226. if (stat & HA_SBUSY)
  227. break;
  228. /* OK, this is quite stupid, but I haven't found any correct
  229. * way to get HBA&SCSI status so far */
  230. if (!(inb(base + HA_RSTATUS) & HA_SERROR)) {
  231. cmd->result = (DID_OK << 16);
  232. hd->devflags |= (1 << cp->cp_id);
  233. } else if (hd->devflags & (1 << cp->cp_id))
  234. cmd->result = (DID_OK << 16) + 0x02;
  235. else
  236. cmd->result = (DID_NO_CONNECT << 16);
  237. if (cp->status == LOCKED) {
  238. cp->status = FREE;
  239. eata_stat = inb(base + HA_RSTATUS);
  240. printk(KERN_CRIT "eata_pio: int_handler, freeing locked " "queueslot\n");
  241. return ret;
  242. }
  243. #if DBG_INTR2
  244. if (stat != 0x50)
  245. printk(KERN_DEBUG "stat: %#.2x, result: %#.8x\n", stat, cmd->result);
  246. #endif
  247. cp->status = FREE; /* now we can release the slot */
  248. cmd->scsi_done(cmd);
  249. }
  250. return ret;
  251. }
  252. static inline unsigned int eata_pio_send_command(unsigned long base, unsigned char command)
  253. {
  254. unsigned int loop = 50;
  255. while (inb(base + HA_RSTATUS) & HA_SBUSY)
  256. if (--loop == 0)
  257. return 1;
  258. /* Enable interrupts for HBA. It is not the best way to do it at this
  259. * place, but I hope that it doesn't interfere with the IDE driver
  260. * initialization this way */
  261. outb(HA_CTRL_8HEADS, base + HA_CTRLREG);
  262. outb(command, base + HA_WCOMMAND);
  263. return 0;
  264. }
  265. static int eata_pio_queue_lck(struct scsi_cmnd *cmd,
  266. void (*done)(struct scsi_cmnd *))
  267. {
  268. unsigned int x, y;
  269. unsigned long base;
  270. hostdata *hd;
  271. struct Scsi_Host *sh;
  272. struct eata_ccb *cp;
  273. queue_counter++;
  274. hd = HD(cmd);
  275. sh = cmd->device->host;
  276. base = sh->base;
  277. /* use only slot 0, as 2001 can handle only one cmd at a time */
  278. y = x = 0;
  279. if (hd->ccb[y].status != FREE) {
  280. DBG(DBG_QUEUE, printk(KERN_EMERG "can_queue %d, x %d, y %d\n", sh->can_queue, x, y));
  281. #if DEBUG_EATA
  282. panic(KERN_EMERG "eata_pio: run out of queue slots cmdno:%ld " "intrno: %ld\n", queue_counter, int_counter);
  283. #else
  284. panic(KERN_EMERG "eata_pio: run out of queue slots....\n");
  285. #endif
  286. }
  287. cp = &hd->ccb[y];
  288. memset(cp, 0, sizeof(struct eata_ccb));
  289. cp->status = USED; /* claim free slot */
  290. DBG(DBG_QUEUE, scmd_printk(KERN_DEBUG, cmd,
  291. "eata_pio_queue 0x%p, y %d\n", cmd, y));
  292. cmd->scsi_done = (void *) done;
  293. if (cmd->sc_data_direction == DMA_TO_DEVICE)
  294. cp->DataOut = 1; /* Output mode */
  295. else
  296. cp->DataIn = 0; /* Input mode */
  297. cp->Interpret = (cmd->device->id == hd->hostid);
  298. cp->cp_datalen = cpu_to_be32(scsi_bufflen(cmd));
  299. cp->Auto_Req_Sen = 0;
  300. cp->cp_reqDMA = 0;
  301. cp->reqlen = 0;
  302. cp->cp_id = cmd->device->id;
  303. cp->cp_lun = cmd->device->lun;
  304. cp->cp_dispri = 0;
  305. cp->cp_identify = 1;
  306. memcpy(cp->cp_cdb, cmd->cmnd, COMMAND_SIZE(*cmd->cmnd));
  307. cp->cp_statDMA = 0;
  308. cp->cp_viraddr = cp;
  309. cp->cmd = cmd;
  310. cmd->host_scribble = (char *) &hd->ccb[y];
  311. if (!scsi_bufflen(cmd)) {
  312. cmd->SCp.buffers_residual = 1;
  313. cmd->SCp.ptr = NULL;
  314. cmd->SCp.this_residual = 0;
  315. cmd->SCp.buffer = NULL;
  316. } else {
  317. cmd->SCp.buffer = scsi_sglist(cmd);
  318. cmd->SCp.buffers_residual = scsi_sg_count(cmd);
  319. cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
  320. cmd->SCp.this_residual = cmd->SCp.buffer->length;
  321. }
  322. cmd->SCp.Status = (cmd->SCp.this_residual != 0); /* TRUE as long as bytes
  323. * are to transfer */
  324. if (eata_pio_send_command(base, EATA_CMD_PIO_SEND_CP)) {
  325. cmd->result = DID_BUS_BUSY << 16;
  326. scmd_printk(KERN_NOTICE, cmd,
  327. "eata_pio_queue pid 0x%p, HBA busy, "
  328. "returning DID_BUS_BUSY, done.\n", cmd);
  329. done(cmd);
  330. cp->status = FREE;
  331. return 0;
  332. }
  333. /* FIXME: timeout */
  334. while (!(inb(base + HA_RSTATUS) & HA_SDRQ))
  335. cpu_relax();
  336. outsw(base + HA_RDATA, cp, hd->cplen);
  337. outb(EATA_CMD_PIO_TRUNC, base + HA_WCOMMAND);
  338. for (x = 0; x < hd->cppadlen; x++)
  339. outw(0, base + HA_RDATA);
  340. DBG(DBG_QUEUE, scmd_printk(KERN_DEBUG, cmd,
  341. "Queued base %#.4lx cmd: 0x%p "
  342. "slot %d irq %d\n", sh->base, cmd, y, sh->irq));
  343. return 0;
  344. }
  345. static DEF_SCSI_QCMD(eata_pio_queue)
  346. static int eata_pio_abort(struct scsi_cmnd *cmd)
  347. {
  348. unsigned int loop = 100;
  349. DBG(DBG_ABNORM, scmd_printk(KERN_WARNING, cmd,
  350. "eata_pio_abort called pid: 0x%p\n", cmd));
  351. while (inb(cmd->device->host->base + HA_RAUXSTAT) & HA_ABUSY)
  352. if (--loop == 0) {
  353. printk(KERN_WARNING "eata_pio: abort, timeout error.\n");
  354. return FAILED;
  355. }
  356. if (CD(cmd)->status == FREE) {
  357. DBG(DBG_ABNORM, printk(KERN_WARNING "Returning: SCSI_ABORT_NOT_RUNNING\n"));
  358. return FAILED;
  359. }
  360. if (CD(cmd)->status == USED) {
  361. DBG(DBG_ABNORM, printk(KERN_WARNING "Returning: SCSI_ABORT_BUSY\n"));
  362. /* We want to sleep a bit more here */
  363. return FAILED; /* SNOOZE */
  364. }
  365. if (CD(cmd)->status == RESET) {
  366. printk(KERN_WARNING "eata_pio: abort, command reset error.\n");
  367. return FAILED;
  368. }
  369. if (CD(cmd)->status == LOCKED) {
  370. DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio: abort, queue slot " "locked.\n"));
  371. return FAILED;
  372. }
  373. panic("eata_pio: abort: invalid slot status\n");
  374. }
  375. static int eata_pio_host_reset(struct scsi_cmnd *cmd)
  376. {
  377. unsigned int x, limit = 0;
  378. unsigned char success = 0;
  379. struct scsi_cmnd *sp;
  380. struct Scsi_Host *host = cmd->device->host;
  381. DBG(DBG_ABNORM, scmd_printk(KERN_WARNING, cmd,
  382. "eata_pio_reset called\n"));
  383. spin_lock_irq(host->host_lock);
  384. if (HD(cmd)->state == RESET) {
  385. printk(KERN_WARNING "eata_pio_reset: exit, already in reset.\n");
  386. spin_unlock_irq(host->host_lock);
  387. return FAILED;
  388. }
  389. /* force all slots to be free */
  390. for (x = 0; x < cmd->device->host->can_queue; x++) {
  391. if (HD(cmd)->ccb[x].status == FREE)
  392. continue;
  393. sp = HD(cmd)->ccb[x].cmd;
  394. HD(cmd)->ccb[x].status = RESET;
  395. printk(KERN_WARNING "eata_pio_reset: slot %d in reset.\n", x);
  396. if (sp == NULL)
  397. panic("eata_pio_reset: slot %d, sp==NULL.\n", x);
  398. }
  399. /* hard reset the HBA */
  400. outb(EATA_CMD_RESET, cmd->device->host->base + HA_WCOMMAND);
  401. DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: board reset done.\n"));
  402. HD(cmd)->state = RESET;
  403. spin_unlock_irq(host->host_lock);
  404. msleep(3000);
  405. spin_lock_irq(host->host_lock);
  406. DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: interrupts disabled, " "loops %d.\n", limit));
  407. for (x = 0; x < cmd->device->host->can_queue; x++) {
  408. /* Skip slots already set free by interrupt */
  409. if (HD(cmd)->ccb[x].status != RESET)
  410. continue;
  411. sp = HD(cmd)->ccb[x].cmd;
  412. sp->result = DID_RESET << 16;
  413. /* This mailbox is terminated */
  414. printk(KERN_WARNING "eata_pio_reset: reset ccb %d.\n", x);
  415. HD(cmd)->ccb[x].status = FREE;
  416. sp->scsi_done(sp);
  417. }
  418. HD(cmd)->state = 0;
  419. spin_unlock_irq(host->host_lock);
  420. if (success) { /* hmmm... */
  421. DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: exit, success.\n"));
  422. return SUCCESS;
  423. } else {
  424. DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: exit, wakeup.\n"));
  425. return FAILED;
  426. }
  427. }
  428. static char *get_pio_board_data(unsigned long base, unsigned int irq, unsigned int id, unsigned long cplen, unsigned short cppadlen)
  429. {
  430. struct eata_ccb cp;
  431. static char buff[256];
  432. int z;
  433. memset(&cp, 0, sizeof(struct eata_ccb));
  434. memset(buff, 0, sizeof(buff));
  435. cp.DataIn = 1;
  436. cp.Interpret = 1; /* Interpret command */
  437. cp.cp_datalen = cpu_to_be32(254);
  438. cp.cp_dataDMA = cpu_to_be32(0);
  439. cp.cp_id = id;
  440. cp.cp_lun = 0;
  441. cp.cp_cdb[0] = INQUIRY;
  442. cp.cp_cdb[1] = 0;
  443. cp.cp_cdb[2] = 0;
  444. cp.cp_cdb[3] = 0;
  445. cp.cp_cdb[4] = 254;
  446. cp.cp_cdb[5] = 0;
  447. if (eata_pio_send_command(base, EATA_CMD_PIO_SEND_CP))
  448. return NULL;
  449. while (!(inb(base + HA_RSTATUS) & HA_SDRQ))
  450. cpu_relax();
  451. outsw(base + HA_RDATA, &cp, cplen);
  452. outb(EATA_CMD_PIO_TRUNC, base + HA_WCOMMAND);
  453. for (z = 0; z < cppadlen; z++)
  454. outw(0, base + HA_RDATA);
  455. while (inb(base + HA_RSTATUS) & HA_SBUSY)
  456. cpu_relax();
  457. if (inb(base + HA_RSTATUS) & HA_SERROR)
  458. return NULL;
  459. else if (!(inb(base + HA_RSTATUS) & HA_SDRQ))
  460. return NULL;
  461. else {
  462. insw(base + HA_RDATA, &buff, 127);
  463. while (inb(base + HA_RSTATUS) & HA_SDRQ)
  464. inw(base + HA_RDATA);
  465. return buff;
  466. }
  467. }
  468. static int get_pio_conf_PIO(unsigned long base, struct get_conf *buf)
  469. {
  470. unsigned long loop = HZ / 2;
  471. int z;
  472. unsigned short *p;
  473. if (!request_region(base, 9, "eata_pio"))
  474. return 0;
  475. memset(buf, 0, sizeof(struct get_conf));
  476. while (inb(base + HA_RSTATUS) & HA_SBUSY)
  477. if (--loop == 0)
  478. goto fail;
  479. DBG(DBG_PIO && DBG_PROBE, printk(KERN_DEBUG "Issuing PIO READ CONFIG to HBA at %#lx\n", base));
  480. eata_pio_send_command(base, EATA_CMD_PIO_READ_CONFIG);
  481. loop = 50;
  482. for (p = (unsigned short *) buf; (long) p <= ((long) buf + (sizeof(struct get_conf) / 2)); p++) {
  483. while (!(inb(base + HA_RSTATUS) & HA_SDRQ))
  484. if (--loop == 0)
  485. goto fail;
  486. loop = 50;
  487. *p = inw(base + HA_RDATA);
  488. }
  489. if (inb(base + HA_RSTATUS) & HA_SERROR) {
  490. DBG(DBG_PROBE, printk("eata_dma: get_conf_PIO, error during "
  491. "transfer for HBA at %lx\n", base));
  492. goto fail;
  493. }
  494. if (cpu_to_be32(EATA_SIGNATURE) != buf->signature)
  495. goto fail;
  496. DBG(DBG_PIO && DBG_PROBE, printk(KERN_NOTICE "EATA Controller found "
  497. "at %#4lx EATA Level: %x\n",
  498. base, (unsigned int) (buf->version)));
  499. while (inb(base + HA_RSTATUS) & HA_SDRQ)
  500. inw(base + HA_RDATA);
  501. if (!ALLOW_DMA_BOARDS) {
  502. for (z = 0; z < MAXISA; z++)
  503. if (base == ISAbases[z]) {
  504. buf->IRQ = ISAirqs[z];
  505. break;
  506. }
  507. }
  508. return 1;
  509. fail:
  510. release_region(base, 9);
  511. return 0;
  512. }
  513. static void print_pio_config(struct get_conf *gc)
  514. {
  515. printk("Please check values: (read config data)\n");
  516. printk("LEN: %d ver:%d OCS:%d TAR:%d TRNXFR:%d MORES:%d\n", be32_to_cpu(gc->len), gc->version, gc->OCS_enabled, gc->TAR_support, gc->TRNXFR, gc->MORE_support);
  517. printk("HAAV:%d SCSIID0:%d ID1:%d ID2:%d QUEUE:%d SG:%d SEC:%d\n", gc->HAA_valid, gc->scsi_id[3], gc->scsi_id[2], gc->scsi_id[1], be16_to_cpu(gc->queuesiz), be16_to_cpu(gc->SGsiz), gc->SECOND);
  518. printk("IRQ:%d IRQT:%d FORCADR:%d MCH:%d RIDQ:%d\n", gc->IRQ, gc->IRQ_TR, gc->FORCADR, gc->MAX_CHAN, gc->ID_qest);
  519. }
  520. static unsigned int print_selftest(unsigned int base)
  521. {
  522. unsigned char buffer[512];
  523. #ifdef VERBOSE_SETUP
  524. int z;
  525. #endif
  526. printk("eata_pio: executing controller self test & setup...\n");
  527. while (inb(base + HA_RSTATUS) & HA_SBUSY);
  528. outb(EATA_CMD_PIO_SETUPTEST, base + HA_WCOMMAND);
  529. do {
  530. while (inb(base + HA_RSTATUS) & HA_SBUSY)
  531. /* nothing */ ;
  532. if (inb(base + HA_RSTATUS) & HA_SDRQ) {
  533. insw(base + HA_RDATA, &buffer, 256);
  534. #ifdef VERBOSE_SETUP
  535. /* no beeps please... */
  536. for (z = 0; z < 511 && buffer[z]; z++)
  537. if (buffer[z] != 7)
  538. printk("%c", buffer[z]);
  539. #endif
  540. }
  541. } while (inb(base + HA_RSTATUS) & (HA_SBUSY | HA_SDRQ));
  542. return (!(inb(base + HA_RSTATUS) & HA_SERROR));
  543. }
  544. static int register_pio_HBA(long base, struct get_conf *gc, struct pci_dev *pdev)
  545. {
  546. unsigned long size = 0;
  547. char *buff;
  548. unsigned long cplen;
  549. unsigned short cppadlen;
  550. struct Scsi_Host *sh;
  551. hostdata *hd;
  552. DBG(DBG_REGISTER, print_pio_config(gc));
  553. if (gc->DMA_support) {
  554. printk("HBA at %#.4lx supports DMA. Please use EATA-DMA driver.\n", base);
  555. if (!ALLOW_DMA_BOARDS)
  556. return 0;
  557. }
  558. if ((buff = get_pio_board_data(base, gc->IRQ, gc->scsi_id[3], cplen = (cpu_to_be32(gc->cplen) + 1) / 2, cppadlen = (cpu_to_be16(gc->cppadlen) + 1) / 2)) == NULL) {
  559. printk("HBA at %#lx didn't react on INQUIRY. Sorry.\n", base);
  560. return 0;
  561. }
  562. if (!print_selftest(base) && !ALLOW_DMA_BOARDS) {
  563. printk("HBA at %#lx failed while performing self test & setup.\n", base);
  564. return 0;
  565. }
  566. size = sizeof(hostdata) + (sizeof(struct eata_ccb) * be16_to_cpu(gc->queuesiz));
  567. sh = scsi_register(&driver_template, size);
  568. if (sh == NULL)
  569. return 0;
  570. if (!reg_IRQ[gc->IRQ]) { /* Interrupt already registered ? */
  571. if (!request_irq(gc->IRQ, do_eata_pio_int_handler, 0, "EATA-PIO", sh)) {
  572. reg_IRQ[gc->IRQ]++;
  573. if (!gc->IRQ_TR)
  574. reg_IRQL[gc->IRQ] = 1; /* IRQ is edge triggered */
  575. } else {
  576. printk("Couldn't allocate IRQ %d, Sorry.\n", gc->IRQ);
  577. return 0;
  578. }
  579. } else { /* More than one HBA on this IRQ */
  580. if (reg_IRQL[gc->IRQ]) {
  581. printk("Can't support more than one HBA on this IRQ,\n" " if the IRQ is edge triggered. Sorry.\n");
  582. return 0;
  583. } else
  584. reg_IRQ[gc->IRQ]++;
  585. }
  586. hd = SD(sh);
  587. memset(hd->ccb, 0, (sizeof(struct eata_ccb) * be16_to_cpu(gc->queuesiz)));
  588. memset(hd->reads, 0, sizeof(hd->reads));
  589. strlcpy(SD(sh)->vendor, &buff[8], sizeof(SD(sh)->vendor));
  590. strlcpy(SD(sh)->name, &buff[16], sizeof(SD(sh)->name));
  591. SD(sh)->revision[0] = buff[32];
  592. SD(sh)->revision[1] = buff[33];
  593. SD(sh)->revision[2] = buff[34];
  594. SD(sh)->revision[3] = '.';
  595. SD(sh)->revision[4] = buff[35];
  596. SD(sh)->revision[5] = 0;
  597. switch (be32_to_cpu(gc->len)) {
  598. case 0x1c:
  599. SD(sh)->EATA_revision = 'a';
  600. break;
  601. case 0x1e:
  602. SD(sh)->EATA_revision = 'b';
  603. break;
  604. case 0x22:
  605. SD(sh)->EATA_revision = 'c';
  606. break;
  607. case 0x24:
  608. SD(sh)->EATA_revision = 'z';
  609. default:
  610. SD(sh)->EATA_revision = '?';
  611. }
  612. if (be32_to_cpu(gc->len) >= 0x22) {
  613. if (gc->is_PCI)
  614. hd->bustype = IS_PCI;
  615. else if (gc->is_EISA)
  616. hd->bustype = IS_EISA;
  617. else
  618. hd->bustype = IS_ISA;
  619. } else {
  620. if (buff[21] == '4')
  621. hd->bustype = IS_PCI;
  622. else if (buff[21] == '2')
  623. hd->bustype = IS_EISA;
  624. else
  625. hd->bustype = IS_ISA;
  626. }
  627. SD(sh)->cplen = cplen;
  628. SD(sh)->cppadlen = cppadlen;
  629. SD(sh)->hostid = gc->scsi_id[3];
  630. SD(sh)->devflags = 1 << gc->scsi_id[3];
  631. SD(sh)->moresupport = gc->MORE_support;
  632. sh->unique_id = base;
  633. sh->base = base;
  634. sh->io_port = base;
  635. sh->n_io_port = 9;
  636. sh->irq = gc->IRQ;
  637. sh->dma_channel = PIO;
  638. sh->this_id = gc->scsi_id[3];
  639. sh->can_queue = 1;
  640. sh->cmd_per_lun = 1;
  641. sh->sg_tablesize = SG_ALL;
  642. hd->channel = 0;
  643. hd->pdev = pci_dev_get(pdev); /* Keep a PCI reference */
  644. sh->max_id = 8;
  645. sh->max_lun = 8;
  646. if (gc->SECOND)
  647. hd->primary = 0;
  648. else
  649. hd->primary = 1;
  650. hd->next = NULL; /* build a linked list of all HBAs */
  651. hd->prev = last_HBA;
  652. if (hd->prev != NULL)
  653. SD(hd->prev)->next = sh;
  654. last_HBA = sh;
  655. if (first_HBA == NULL)
  656. first_HBA = sh;
  657. registered_HBAs++;
  658. return (1);
  659. }
  660. static void find_pio_ISA(struct get_conf *buf)
  661. {
  662. int i;
  663. for (i = 0; i < MAXISA; i++) {
  664. if (!ISAbases[i])
  665. continue;
  666. if (!get_pio_conf_PIO(ISAbases[i], buf))
  667. continue;
  668. if (!register_pio_HBA(ISAbases[i], buf, NULL))
  669. release_region(ISAbases[i], 9);
  670. else
  671. ISAbases[i] = 0;
  672. }
  673. return;
  674. }
  675. static void find_pio_EISA(struct get_conf *buf)
  676. {
  677. u32 base;
  678. int i;
  679. #ifdef CHECKPAL
  680. u8 pal1, pal2, pal3;
  681. #endif
  682. for (i = 0; i < MAXEISA; i++) {
  683. if (EISAbases[i]) { /* Still a possibility ? */
  684. base = 0x1c88 + (i * 0x1000);
  685. #ifdef CHECKPAL
  686. pal1 = inb((u16) base - 8);
  687. pal2 = inb((u16) base - 7);
  688. pal3 = inb((u16) base - 6);
  689. if (((pal1 == 0x12) && (pal2 == 0x14)) || ((pal1 == 0x38) && (pal2 == 0xa3) && (pal3 == 0x82)) || ((pal1 == 0x06) && (pal2 == 0x94) && (pal3 == 0x24))) {
  690. DBG(DBG_PROBE, printk(KERN_NOTICE "EISA EATA id tags found: " "%x %x %x \n", (int) pal1, (int) pal2, (int) pal3));
  691. #endif
  692. if (get_pio_conf_PIO(base, buf)) {
  693. DBG(DBG_PROBE && DBG_EISA, print_pio_config(buf));
  694. if (buf->IRQ) {
  695. if (!register_pio_HBA(base, buf, NULL))
  696. release_region(base, 9);
  697. } else {
  698. printk(KERN_NOTICE "eata_dma: No valid IRQ. HBA " "removed from list\n");
  699. release_region(base, 9);
  700. }
  701. }
  702. /* Nothing found here so we take it from the list */
  703. EISAbases[i] = 0;
  704. #ifdef CHECKPAL
  705. }
  706. #endif
  707. }
  708. }
  709. return;
  710. }
  711. static void find_pio_PCI(struct get_conf *buf)
  712. {
  713. #ifndef CONFIG_PCI
  714. printk("eata_dma: kernel PCI support not enabled. Skipping scan for PCI HBAs.\n");
  715. #else
  716. struct pci_dev *dev = NULL;
  717. unsigned long base, x;
  718. while ((dev = pci_get_device(PCI_VENDOR_ID_DPT, PCI_DEVICE_ID_DPT, dev)) != NULL) {
  719. DBG(DBG_PROBE && DBG_PCI, printk("eata_pio: find_PCI, HBA at %s\n", pci_name(dev)));
  720. if (pci_enable_device(dev))
  721. continue;
  722. pci_set_master(dev);
  723. base = pci_resource_flags(dev, 0);
  724. if (base & IORESOURCE_MEM) {
  725. printk("eata_pio: invalid base address of device %s\n", pci_name(dev));
  726. continue;
  727. }
  728. base = pci_resource_start(dev, 0);
  729. /* EISA tag there ? */
  730. if ((inb(base) == 0x12) && (inb(base + 1) == 0x14))
  731. continue; /* Jep, it's forced, so move on */
  732. base += 0x10; /* Now, THIS is the real address */
  733. if (base != 0x1f8) {
  734. /* We didn't find it in the primary search */
  735. if (get_pio_conf_PIO(base, buf)) {
  736. if (buf->FORCADR) { /* If the address is forced */
  737. release_region(base, 9);
  738. continue; /* we'll find it later */
  739. }
  740. /* OK. We made it till here, so we can go now
  741. * and register it. We only have to check and
  742. * eventually remove it from the EISA and ISA list
  743. */
  744. if (!register_pio_HBA(base, buf, dev)) {
  745. release_region(base, 9);
  746. continue;
  747. }
  748. if (base < 0x1000) {
  749. for (x = 0; x < MAXISA; ++x) {
  750. if (ISAbases[x] == base) {
  751. ISAbases[x] = 0;
  752. break;
  753. }
  754. }
  755. } else if ((base & 0x0fff) == 0x0c88) {
  756. x = (base >> 12) & 0x0f;
  757. EISAbases[x] = 0;
  758. }
  759. }
  760. #ifdef CHECK_BLINK
  761. else if (check_blink_state(base)) {
  762. printk("eata_pio: HBA is in BLINK state.\n" "Consult your HBAs manual to correct this.\n");
  763. }
  764. #endif
  765. }
  766. }
  767. #endif /* #ifndef CONFIG_PCI */
  768. }
  769. static int eata_pio_detect(struct scsi_host_template *tpnt)
  770. {
  771. struct Scsi_Host *HBA_ptr;
  772. struct get_conf gc;
  773. int i;
  774. find_pio_PCI(&gc);
  775. find_pio_EISA(&gc);
  776. find_pio_ISA(&gc);
  777. for (i = 0; i < MAXIRQ; i++)
  778. if (reg_IRQ[i])
  779. request_irq(i, do_eata_pio_int_handler, 0, "EATA-PIO", NULL);
  780. HBA_ptr = first_HBA;
  781. if (registered_HBAs != 0) {
  782. printk("EATA (Extended Attachment) PIO driver version: %d.%d%s\n"
  783. "(c) 1993-95 Michael Neuffer, neuffer@goofy.zdv.uni-mainz.de\n" " Alfred Arnold, a.arnold@kfa-juelich.de\n" "This release only supports DASD devices (harddisks)\n", VER_MAJOR, VER_MINOR, VER_SUB);
  784. printk("Registered HBAs:\n");
  785. printk("HBA no. Boardtype: Revis: EATA: Bus: BaseIO: IRQ: Ch: ID: Pr:" " QS: SG: CPL:\n");
  786. for (i = 1; i <= registered_HBAs; i++) {
  787. printk("scsi%-2d: %.10s v%s 2.0%c %s %#.4lx %2d %d %d %c"
  788. " %2d %2d %2d\n",
  789. HBA_ptr->host_no, SD(HBA_ptr)->name, SD(HBA_ptr)->revision,
  790. SD(HBA_ptr)->EATA_revision, (SD(HBA_ptr)->bustype == 'P') ?
  791. "PCI " : (SD(HBA_ptr)->bustype == 'E') ? "EISA" : "ISA ",
  792. HBA_ptr->base, HBA_ptr->irq, SD(HBA_ptr)->channel, HBA_ptr->this_id,
  793. SD(HBA_ptr)->primary ? 'Y' : 'N', HBA_ptr->can_queue,
  794. HBA_ptr->sg_tablesize, HBA_ptr->cmd_per_lun);
  795. HBA_ptr = SD(HBA_ptr)->next;
  796. }
  797. }
  798. return (registered_HBAs);
  799. }
  800. static struct scsi_host_template driver_template = {
  801. .proc_name = "eata_pio",
  802. .name = "EATA (Extended Attachment) PIO driver",
  803. .show_info = eata_pio_show_info,
  804. .detect = eata_pio_detect,
  805. .release = eata_pio_release,
  806. .queuecommand = eata_pio_queue,
  807. .eh_abort_handler = eata_pio_abort,
  808. .eh_host_reset_handler = eata_pio_host_reset,
  809. .use_clustering = ENABLE_CLUSTERING,
  810. };
  811. MODULE_AUTHOR("Michael Neuffer, Alfred Arnold");
  812. MODULE_DESCRIPTION("EATA SCSI PIO driver");
  813. MODULE_LICENSE("GPL");
  814. #include "scsi_module.c"