zorro_esp.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * ESP front-end for Amiga ZORRO SCSI systems.
  4. *
  5. * Copyright (C) 1996 Jesper Skov ([email protected])
  6. *
  7. * Copyright (C) 2011,2018 Michael Schmitz ([email protected]) for
  8. * migration to ESP SCSI core
  9. *
  10. * Copyright (C) 2013 Tuomas Vainikka ([email protected]) for
  11. * Blizzard 1230 DMA and probe function fixes
  12. */
  13. /*
  14. * ZORRO bus code from:
  15. */
  16. /*
  17. * Detection routine for the NCR53c710 based Amiga SCSI Controllers for Linux.
  18. * Amiga MacroSystemUS WarpEngine SCSI controller.
  19. * Amiga Technologies/DKB A4091 SCSI controller.
  20. *
  21. * Written 1997 by Alan Hourihane <[email protected]>
  22. * plus modifications of the 53c7xx.c driver to support the Amiga.
  23. *
  24. * Rewritten to use 53c700.c by Kars de Jong <[email protected]>
  25. */
  26. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  27. #include <linux/module.h>
  28. #include <linux/init.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/dma-mapping.h>
  31. #include <linux/scatterlist.h>
  32. #include <linux/delay.h>
  33. #include <linux/zorro.h>
  34. #include <linux/slab.h>
  35. #include <linux/pgtable.h>
  36. #include <asm/page.h>
  37. #include <asm/cacheflush.h>
  38. #include <asm/amigahw.h>
  39. #include <asm/amigaints.h>
  40. #include <scsi/scsi_host.h>
  41. #include <scsi/scsi_transport_spi.h>
  42. #include <scsi/scsi_device.h>
  43. #include <scsi/scsi_tcq.h>
  44. #include "esp_scsi.h"
  45. MODULE_AUTHOR("Michael Schmitz <[email protected]>");
  46. MODULE_DESCRIPTION("Amiga Zorro NCR5C9x (ESP) driver");
  47. MODULE_LICENSE("GPL");
  48. /* per-board register layout definitions */
  49. /* Blizzard 1230 DMA interface */
  50. struct blz1230_dma_registers {
  51. unsigned char dma_addr; /* DMA address [0x0000] */
  52. unsigned char dmapad2[0x7fff];
  53. unsigned char dma_latch; /* DMA latch [0x8000] */
  54. };
  55. /* Blizzard 1230II DMA interface */
  56. struct blz1230II_dma_registers {
  57. unsigned char dma_addr; /* DMA address [0x0000] */
  58. unsigned char dmapad2[0xf];
  59. unsigned char dma_latch; /* DMA latch [0x0010] */
  60. };
  61. /* Blizzard 2060 DMA interface */
  62. struct blz2060_dma_registers {
  63. unsigned char dma_led_ctrl; /* DMA led control [0x000] */
  64. unsigned char dmapad1[0x0f];
  65. unsigned char dma_addr0; /* DMA address (MSB) [0x010] */
  66. unsigned char dmapad2[0x03];
  67. unsigned char dma_addr1; /* DMA address [0x014] */
  68. unsigned char dmapad3[0x03];
  69. unsigned char dma_addr2; /* DMA address [0x018] */
  70. unsigned char dmapad4[0x03];
  71. unsigned char dma_addr3; /* DMA address (LSB) [0x01c] */
  72. };
  73. /* DMA control bits */
  74. #define DMA_WRITE 0x80000000
  75. /* Cyberstorm DMA interface */
  76. struct cyber_dma_registers {
  77. unsigned char dma_addr0; /* DMA address (MSB) [0x000] */
  78. unsigned char dmapad1[1];
  79. unsigned char dma_addr1; /* DMA address [0x002] */
  80. unsigned char dmapad2[1];
  81. unsigned char dma_addr2; /* DMA address [0x004] */
  82. unsigned char dmapad3[1];
  83. unsigned char dma_addr3; /* DMA address (LSB) [0x006] */
  84. unsigned char dmapad4[0x3fb];
  85. unsigned char cond_reg; /* DMA cond (ro) [0x402] */
  86. #define ctrl_reg cond_reg /* DMA control (wo) [0x402] */
  87. };
  88. /* DMA control bits */
  89. #define CYBER_DMA_WRITE 0x40 /* DMA direction. 1 = write */
  90. #define CYBER_DMA_Z3 0x20 /* 16 (Z2) or 32 (CHIP/Z3) bit DMA transfer */
  91. /* DMA status bits */
  92. #define CYBER_DMA_HNDL_INTR 0x80 /* DMA IRQ pending? */
  93. /* The CyberStorm II DMA interface */
  94. struct cyberII_dma_registers {
  95. unsigned char cond_reg; /* DMA cond (ro) [0x000] */
  96. #define ctrl_reg cond_reg /* DMA control (wo) [0x000] */
  97. unsigned char dmapad4[0x3f];
  98. unsigned char dma_addr0; /* DMA address (MSB) [0x040] */
  99. unsigned char dmapad1[3];
  100. unsigned char dma_addr1; /* DMA address [0x044] */
  101. unsigned char dmapad2[3];
  102. unsigned char dma_addr2; /* DMA address [0x048] */
  103. unsigned char dmapad3[3];
  104. unsigned char dma_addr3; /* DMA address (LSB) [0x04c] */
  105. };
  106. /* Fastlane DMA interface */
  107. struct fastlane_dma_registers {
  108. unsigned char cond_reg; /* DMA status (ro) [0x0000] */
  109. #define ctrl_reg cond_reg /* DMA control (wo) [0x0000] */
  110. char dmapad1[0x3f];
  111. unsigned char clear_strobe; /* DMA clear (wo) [0x0040] */
  112. };
  113. /*
  114. * The controller registers can be found in the Z2 config area at these
  115. * offsets:
  116. */
  117. #define FASTLANE_ESP_ADDR 0x1000001
  118. /* DMA status bits */
  119. #define FASTLANE_DMA_MINT 0x80
  120. #define FASTLANE_DMA_IACT 0x40
  121. #define FASTLANE_DMA_CREQ 0x20
  122. /* DMA control bits */
  123. #define FASTLANE_DMA_FCODE 0xa0
  124. #define FASTLANE_DMA_MASK 0xf3
  125. #define FASTLANE_DMA_WRITE 0x08 /* 1 = write */
  126. #define FASTLANE_DMA_ENABLE 0x04 /* Enable DMA */
  127. #define FASTLANE_DMA_EDI 0x02 /* Enable DMA IRQ ? */
  128. #define FASTLANE_DMA_ESI 0x01 /* Enable SCSI IRQ */
  129. /*
  130. * private data used for driver
  131. */
  132. struct zorro_esp_priv {
  133. struct esp *esp; /* our ESP instance - for Scsi_host* */
  134. void __iomem *board_base; /* virtual address (Zorro III board) */
  135. int zorro3; /* board is Zorro III */
  136. unsigned char ctrl_data; /* shadow copy of ctrl_reg */
  137. };
  138. /*
  139. * On all implementations except for the Oktagon, padding between ESP
  140. * registers is three bytes.
  141. * On Oktagon, it is one byte - use a different accessor there.
  142. *
  143. * Oktagon needs PDMA - currently unsupported!
  144. */
  145. static void zorro_esp_write8(struct esp *esp, u8 val, unsigned long reg)
  146. {
  147. writeb(val, esp->regs + (reg * 4UL));
  148. }
  149. static u8 zorro_esp_read8(struct esp *esp, unsigned long reg)
  150. {
  151. return readb(esp->regs + (reg * 4UL));
  152. }
  153. static int zorro_esp_irq_pending(struct esp *esp)
  154. {
  155. /* check ESP status register; DMA has no status reg. */
  156. if (zorro_esp_read8(esp, ESP_STATUS) & ESP_STAT_INTR)
  157. return 1;
  158. return 0;
  159. }
  160. static int cyber_esp_irq_pending(struct esp *esp)
  161. {
  162. struct cyber_dma_registers __iomem *dregs = esp->dma_regs;
  163. unsigned char dma_status = readb(&dregs->cond_reg);
  164. /* It's important to check the DMA IRQ bit in the correct way! */
  165. return ((zorro_esp_read8(esp, ESP_STATUS) & ESP_STAT_INTR) &&
  166. (dma_status & CYBER_DMA_HNDL_INTR));
  167. }
  168. static int fastlane_esp_irq_pending(struct esp *esp)
  169. {
  170. struct fastlane_dma_registers __iomem *dregs = esp->dma_regs;
  171. unsigned char dma_status;
  172. dma_status = readb(&dregs->cond_reg);
  173. if (dma_status & FASTLANE_DMA_IACT)
  174. return 0; /* not our IRQ */
  175. /* Return non-zero if ESP requested IRQ */
  176. return (
  177. (dma_status & FASTLANE_DMA_CREQ) &&
  178. (!(dma_status & FASTLANE_DMA_MINT)) &&
  179. (zorro_esp_read8(esp, ESP_STATUS) & ESP_STAT_INTR));
  180. }
  181. static u32 zorro_esp_dma_length_limit(struct esp *esp, u32 dma_addr,
  182. u32 dma_len)
  183. {
  184. return dma_len > (1U << 16) ? (1U << 16) : dma_len;
  185. }
  186. static u32 fastlane_esp_dma_length_limit(struct esp *esp, u32 dma_addr,
  187. u32 dma_len)
  188. {
  189. /* The old driver used 0xfffc as limit, so do that here too */
  190. return dma_len > 0xfffc ? 0xfffc : dma_len;
  191. }
  192. static void zorro_esp_reset_dma(struct esp *esp)
  193. {
  194. /* nothing to do here */
  195. }
  196. static void zorro_esp_dma_drain(struct esp *esp)
  197. {
  198. /* nothing to do here */
  199. }
  200. static void zorro_esp_dma_invalidate(struct esp *esp)
  201. {
  202. /* nothing to do here */
  203. }
  204. static void fastlane_esp_dma_invalidate(struct esp *esp)
  205. {
  206. struct zorro_esp_priv *zep = dev_get_drvdata(esp->dev);
  207. struct fastlane_dma_registers __iomem *dregs = esp->dma_regs;
  208. unsigned char *ctrl_data = &zep->ctrl_data;
  209. *ctrl_data = (*ctrl_data & FASTLANE_DMA_MASK);
  210. writeb(0, &dregs->clear_strobe);
  211. z_writel(0, zep->board_base);
  212. }
  213. /* Blizzard 1230/60 SCSI-IV DMA */
  214. static void zorro_esp_send_blz1230_dma_cmd(struct esp *esp, u32 addr,
  215. u32 esp_count, u32 dma_count, int write, u8 cmd)
  216. {
  217. struct blz1230_dma_registers __iomem *dregs = esp->dma_regs;
  218. u8 phase = esp->sreg & ESP_STAT_PMASK;
  219. /*
  220. * Use PIO if transferring message bytes to esp->command_block_dma.
  221. * PIO requires a virtual address, so substitute esp->command_block
  222. * for addr.
  223. */
  224. if (phase == ESP_MIP && addr == esp->command_block_dma) {
  225. esp_send_pio_cmd(esp, (u32)esp->command_block, esp_count,
  226. dma_count, write, cmd);
  227. return;
  228. }
  229. /* Clear the results of a possible prior esp->ops->send_dma_cmd() */
  230. esp->send_cmd_error = 0;
  231. esp->send_cmd_residual = 0;
  232. if (write)
  233. /* DMA receive */
  234. dma_sync_single_for_device(esp->dev, addr, esp_count,
  235. DMA_FROM_DEVICE);
  236. else
  237. /* DMA send */
  238. dma_sync_single_for_device(esp->dev, addr, esp_count,
  239. DMA_TO_DEVICE);
  240. addr >>= 1;
  241. if (write)
  242. addr &= ~(DMA_WRITE);
  243. else
  244. addr |= DMA_WRITE;
  245. writeb((addr >> 24) & 0xff, &dregs->dma_latch);
  246. writeb((addr >> 24) & 0xff, &dregs->dma_addr);
  247. writeb((addr >> 16) & 0xff, &dregs->dma_addr);
  248. writeb((addr >> 8) & 0xff, &dregs->dma_addr);
  249. writeb(addr & 0xff, &dregs->dma_addr);
  250. scsi_esp_cmd(esp, ESP_CMD_DMA);
  251. zorro_esp_write8(esp, (esp_count >> 0) & 0xff, ESP_TCLOW);
  252. zorro_esp_write8(esp, (esp_count >> 8) & 0xff, ESP_TCMED);
  253. scsi_esp_cmd(esp, cmd);
  254. }
  255. /* Blizzard 1230-II DMA */
  256. static void zorro_esp_send_blz1230II_dma_cmd(struct esp *esp, u32 addr,
  257. u32 esp_count, u32 dma_count, int write, u8 cmd)
  258. {
  259. struct blz1230II_dma_registers __iomem *dregs = esp->dma_regs;
  260. u8 phase = esp->sreg & ESP_STAT_PMASK;
  261. /* Use PIO if transferring message bytes to esp->command_block_dma */
  262. if (phase == ESP_MIP && addr == esp->command_block_dma) {
  263. esp_send_pio_cmd(esp, (u32)esp->command_block, esp_count,
  264. dma_count, write, cmd);
  265. return;
  266. }
  267. esp->send_cmd_error = 0;
  268. esp->send_cmd_residual = 0;
  269. if (write)
  270. /* DMA receive */
  271. dma_sync_single_for_device(esp->dev, addr, esp_count,
  272. DMA_FROM_DEVICE);
  273. else
  274. /* DMA send */
  275. dma_sync_single_for_device(esp->dev, addr, esp_count,
  276. DMA_TO_DEVICE);
  277. addr >>= 1;
  278. if (write)
  279. addr &= ~(DMA_WRITE);
  280. else
  281. addr |= DMA_WRITE;
  282. writeb((addr >> 24) & 0xff, &dregs->dma_latch);
  283. writeb((addr >> 16) & 0xff, &dregs->dma_addr);
  284. writeb((addr >> 8) & 0xff, &dregs->dma_addr);
  285. writeb(addr & 0xff, &dregs->dma_addr);
  286. scsi_esp_cmd(esp, ESP_CMD_DMA);
  287. zorro_esp_write8(esp, (esp_count >> 0) & 0xff, ESP_TCLOW);
  288. zorro_esp_write8(esp, (esp_count >> 8) & 0xff, ESP_TCMED);
  289. scsi_esp_cmd(esp, cmd);
  290. }
  291. /* Blizzard 2060 DMA */
  292. static void zorro_esp_send_blz2060_dma_cmd(struct esp *esp, u32 addr,
  293. u32 esp_count, u32 dma_count, int write, u8 cmd)
  294. {
  295. struct blz2060_dma_registers __iomem *dregs = esp->dma_regs;
  296. u8 phase = esp->sreg & ESP_STAT_PMASK;
  297. /* Use PIO if transferring message bytes to esp->command_block_dma */
  298. if (phase == ESP_MIP && addr == esp->command_block_dma) {
  299. esp_send_pio_cmd(esp, (u32)esp->command_block, esp_count,
  300. dma_count, write, cmd);
  301. return;
  302. }
  303. esp->send_cmd_error = 0;
  304. esp->send_cmd_residual = 0;
  305. if (write)
  306. /* DMA receive */
  307. dma_sync_single_for_device(esp->dev, addr, esp_count,
  308. DMA_FROM_DEVICE);
  309. else
  310. /* DMA send */
  311. dma_sync_single_for_device(esp->dev, addr, esp_count,
  312. DMA_TO_DEVICE);
  313. addr >>= 1;
  314. if (write)
  315. addr &= ~(DMA_WRITE);
  316. else
  317. addr |= DMA_WRITE;
  318. writeb(addr & 0xff, &dregs->dma_addr3);
  319. writeb((addr >> 8) & 0xff, &dregs->dma_addr2);
  320. writeb((addr >> 16) & 0xff, &dregs->dma_addr1);
  321. writeb((addr >> 24) & 0xff, &dregs->dma_addr0);
  322. scsi_esp_cmd(esp, ESP_CMD_DMA);
  323. zorro_esp_write8(esp, (esp_count >> 0) & 0xff, ESP_TCLOW);
  324. zorro_esp_write8(esp, (esp_count >> 8) & 0xff, ESP_TCMED);
  325. scsi_esp_cmd(esp, cmd);
  326. }
  327. /* Cyberstorm I DMA */
  328. static void zorro_esp_send_cyber_dma_cmd(struct esp *esp, u32 addr,
  329. u32 esp_count, u32 dma_count, int write, u8 cmd)
  330. {
  331. struct zorro_esp_priv *zep = dev_get_drvdata(esp->dev);
  332. struct cyber_dma_registers __iomem *dregs = esp->dma_regs;
  333. u8 phase = esp->sreg & ESP_STAT_PMASK;
  334. unsigned char *ctrl_data = &zep->ctrl_data;
  335. /* Use PIO if transferring message bytes to esp->command_block_dma */
  336. if (phase == ESP_MIP && addr == esp->command_block_dma) {
  337. esp_send_pio_cmd(esp, (u32)esp->command_block, esp_count,
  338. dma_count, write, cmd);
  339. return;
  340. }
  341. esp->send_cmd_error = 0;
  342. esp->send_cmd_residual = 0;
  343. zorro_esp_write8(esp, (esp_count >> 0) & 0xff, ESP_TCLOW);
  344. zorro_esp_write8(esp, (esp_count >> 8) & 0xff, ESP_TCMED);
  345. if (write) {
  346. /* DMA receive */
  347. dma_sync_single_for_device(esp->dev, addr, esp_count,
  348. DMA_FROM_DEVICE);
  349. addr &= ~(1);
  350. } else {
  351. /* DMA send */
  352. dma_sync_single_for_device(esp->dev, addr, esp_count,
  353. DMA_TO_DEVICE);
  354. addr |= 1;
  355. }
  356. writeb((addr >> 24) & 0xff, &dregs->dma_addr0);
  357. writeb((addr >> 16) & 0xff, &dregs->dma_addr1);
  358. writeb((addr >> 8) & 0xff, &dregs->dma_addr2);
  359. writeb(addr & 0xff, &dregs->dma_addr3);
  360. if (write)
  361. *ctrl_data &= ~(CYBER_DMA_WRITE);
  362. else
  363. *ctrl_data |= CYBER_DMA_WRITE;
  364. *ctrl_data &= ~(CYBER_DMA_Z3); /* Z2, do 16 bit DMA */
  365. writeb(*ctrl_data, &dregs->ctrl_reg);
  366. scsi_esp_cmd(esp, cmd);
  367. }
  368. /* Cyberstorm II DMA */
  369. static void zorro_esp_send_cyberII_dma_cmd(struct esp *esp, u32 addr,
  370. u32 esp_count, u32 dma_count, int write, u8 cmd)
  371. {
  372. struct cyberII_dma_registers __iomem *dregs = esp->dma_regs;
  373. u8 phase = esp->sreg & ESP_STAT_PMASK;
  374. /* Use PIO if transferring message bytes to esp->command_block_dma */
  375. if (phase == ESP_MIP && addr == esp->command_block_dma) {
  376. esp_send_pio_cmd(esp, (u32)esp->command_block, esp_count,
  377. dma_count, write, cmd);
  378. return;
  379. }
  380. esp->send_cmd_error = 0;
  381. esp->send_cmd_residual = 0;
  382. zorro_esp_write8(esp, (esp_count >> 0) & 0xff, ESP_TCLOW);
  383. zorro_esp_write8(esp, (esp_count >> 8) & 0xff, ESP_TCMED);
  384. if (write) {
  385. /* DMA receive */
  386. dma_sync_single_for_device(esp->dev, addr, esp_count,
  387. DMA_FROM_DEVICE);
  388. addr &= ~(1);
  389. } else {
  390. /* DMA send */
  391. dma_sync_single_for_device(esp->dev, addr, esp_count,
  392. DMA_TO_DEVICE);
  393. addr |= 1;
  394. }
  395. writeb((addr >> 24) & 0xff, &dregs->dma_addr0);
  396. writeb((addr >> 16) & 0xff, &dregs->dma_addr1);
  397. writeb((addr >> 8) & 0xff, &dregs->dma_addr2);
  398. writeb(addr & 0xff, &dregs->dma_addr3);
  399. scsi_esp_cmd(esp, cmd);
  400. }
  401. /* Fastlane DMA */
  402. static void zorro_esp_send_fastlane_dma_cmd(struct esp *esp, u32 addr,
  403. u32 esp_count, u32 dma_count, int write, u8 cmd)
  404. {
  405. struct zorro_esp_priv *zep = dev_get_drvdata(esp->dev);
  406. struct fastlane_dma_registers __iomem *dregs = esp->dma_regs;
  407. u8 phase = esp->sreg & ESP_STAT_PMASK;
  408. unsigned char *ctrl_data = &zep->ctrl_data;
  409. /* Use PIO if transferring message bytes to esp->command_block_dma */
  410. if (phase == ESP_MIP && addr == esp->command_block_dma) {
  411. esp_send_pio_cmd(esp, (u32)esp->command_block, esp_count,
  412. dma_count, write, cmd);
  413. return;
  414. }
  415. esp->send_cmd_error = 0;
  416. esp->send_cmd_residual = 0;
  417. zorro_esp_write8(esp, (esp_count >> 0) & 0xff, ESP_TCLOW);
  418. zorro_esp_write8(esp, (esp_count >> 8) & 0xff, ESP_TCMED);
  419. if (write) {
  420. /* DMA receive */
  421. dma_sync_single_for_device(esp->dev, addr, esp_count,
  422. DMA_FROM_DEVICE);
  423. addr &= ~(1);
  424. } else {
  425. /* DMA send */
  426. dma_sync_single_for_device(esp->dev, addr, esp_count,
  427. DMA_TO_DEVICE);
  428. addr |= 1;
  429. }
  430. writeb(0, &dregs->clear_strobe);
  431. z_writel(addr, ((addr & 0x00ffffff) + zep->board_base));
  432. if (write) {
  433. *ctrl_data = (*ctrl_data & FASTLANE_DMA_MASK) |
  434. FASTLANE_DMA_ENABLE;
  435. } else {
  436. *ctrl_data = ((*ctrl_data & FASTLANE_DMA_MASK) |
  437. FASTLANE_DMA_ENABLE |
  438. FASTLANE_DMA_WRITE);
  439. }
  440. writeb(*ctrl_data, &dregs->ctrl_reg);
  441. scsi_esp_cmd(esp, cmd);
  442. }
  443. static int zorro_esp_dma_error(struct esp *esp)
  444. {
  445. return esp->send_cmd_error;
  446. }
  447. /* per-board ESP driver ops */
  448. static const struct esp_driver_ops blz1230_esp_ops = {
  449. .esp_write8 = zorro_esp_write8,
  450. .esp_read8 = zorro_esp_read8,
  451. .irq_pending = zorro_esp_irq_pending,
  452. .dma_length_limit = zorro_esp_dma_length_limit,
  453. .reset_dma = zorro_esp_reset_dma,
  454. .dma_drain = zorro_esp_dma_drain,
  455. .dma_invalidate = zorro_esp_dma_invalidate,
  456. .send_dma_cmd = zorro_esp_send_blz1230_dma_cmd,
  457. .dma_error = zorro_esp_dma_error,
  458. };
  459. static const struct esp_driver_ops blz1230II_esp_ops = {
  460. .esp_write8 = zorro_esp_write8,
  461. .esp_read8 = zorro_esp_read8,
  462. .irq_pending = zorro_esp_irq_pending,
  463. .dma_length_limit = zorro_esp_dma_length_limit,
  464. .reset_dma = zorro_esp_reset_dma,
  465. .dma_drain = zorro_esp_dma_drain,
  466. .dma_invalidate = zorro_esp_dma_invalidate,
  467. .send_dma_cmd = zorro_esp_send_blz1230II_dma_cmd,
  468. .dma_error = zorro_esp_dma_error,
  469. };
  470. static const struct esp_driver_ops blz2060_esp_ops = {
  471. .esp_write8 = zorro_esp_write8,
  472. .esp_read8 = zorro_esp_read8,
  473. .irq_pending = zorro_esp_irq_pending,
  474. .dma_length_limit = zorro_esp_dma_length_limit,
  475. .reset_dma = zorro_esp_reset_dma,
  476. .dma_drain = zorro_esp_dma_drain,
  477. .dma_invalidate = zorro_esp_dma_invalidate,
  478. .send_dma_cmd = zorro_esp_send_blz2060_dma_cmd,
  479. .dma_error = zorro_esp_dma_error,
  480. };
  481. static const struct esp_driver_ops cyber_esp_ops = {
  482. .esp_write8 = zorro_esp_write8,
  483. .esp_read8 = zorro_esp_read8,
  484. .irq_pending = cyber_esp_irq_pending,
  485. .dma_length_limit = zorro_esp_dma_length_limit,
  486. .reset_dma = zorro_esp_reset_dma,
  487. .dma_drain = zorro_esp_dma_drain,
  488. .dma_invalidate = zorro_esp_dma_invalidate,
  489. .send_dma_cmd = zorro_esp_send_cyber_dma_cmd,
  490. .dma_error = zorro_esp_dma_error,
  491. };
  492. static const struct esp_driver_ops cyberII_esp_ops = {
  493. .esp_write8 = zorro_esp_write8,
  494. .esp_read8 = zorro_esp_read8,
  495. .irq_pending = zorro_esp_irq_pending,
  496. .dma_length_limit = zorro_esp_dma_length_limit,
  497. .reset_dma = zorro_esp_reset_dma,
  498. .dma_drain = zorro_esp_dma_drain,
  499. .dma_invalidate = zorro_esp_dma_invalidate,
  500. .send_dma_cmd = zorro_esp_send_cyberII_dma_cmd,
  501. .dma_error = zorro_esp_dma_error,
  502. };
  503. static const struct esp_driver_ops fastlane_esp_ops = {
  504. .esp_write8 = zorro_esp_write8,
  505. .esp_read8 = zorro_esp_read8,
  506. .irq_pending = fastlane_esp_irq_pending,
  507. .dma_length_limit = fastlane_esp_dma_length_limit,
  508. .reset_dma = zorro_esp_reset_dma,
  509. .dma_drain = zorro_esp_dma_drain,
  510. .dma_invalidate = fastlane_esp_dma_invalidate,
  511. .send_dma_cmd = zorro_esp_send_fastlane_dma_cmd,
  512. .dma_error = zorro_esp_dma_error,
  513. };
  514. /* Zorro driver config data */
  515. struct zorro_driver_data {
  516. const char *name;
  517. unsigned long offset;
  518. unsigned long dma_offset;
  519. int absolute; /* offset is absolute address */
  520. int scsi_option;
  521. const struct esp_driver_ops *esp_ops;
  522. };
  523. /* board types */
  524. enum {
  525. ZORRO_BLZ1230,
  526. ZORRO_BLZ1230II,
  527. ZORRO_BLZ2060,
  528. ZORRO_CYBER,
  529. ZORRO_CYBERII,
  530. ZORRO_FASTLANE,
  531. };
  532. /* per-board config data */
  533. static const struct zorro_driver_data zorro_esp_boards[] = {
  534. [ZORRO_BLZ1230] = {
  535. .name = "Blizzard 1230",
  536. .offset = 0x8000,
  537. .dma_offset = 0x10000,
  538. .scsi_option = 1,
  539. .esp_ops = &blz1230_esp_ops,
  540. },
  541. [ZORRO_BLZ1230II] = {
  542. .name = "Blizzard 1230II",
  543. .offset = 0x10000,
  544. .dma_offset = 0x10021,
  545. .scsi_option = 1,
  546. .esp_ops = &blz1230II_esp_ops,
  547. },
  548. [ZORRO_BLZ2060] = {
  549. .name = "Blizzard 2060",
  550. .offset = 0x1ff00,
  551. .dma_offset = 0x1ffe0,
  552. .esp_ops = &blz2060_esp_ops,
  553. },
  554. [ZORRO_CYBER] = {
  555. .name = "CyberStormI",
  556. .offset = 0xf400,
  557. .dma_offset = 0xf800,
  558. .esp_ops = &cyber_esp_ops,
  559. },
  560. [ZORRO_CYBERII] = {
  561. .name = "CyberStormII",
  562. .offset = 0x1ff03,
  563. .dma_offset = 0x1ff43,
  564. .scsi_option = 1,
  565. .esp_ops = &cyberII_esp_ops,
  566. },
  567. [ZORRO_FASTLANE] = {
  568. .name = "Fastlane",
  569. .offset = 0x1000001,
  570. .dma_offset = 0x1000041,
  571. .esp_ops = &fastlane_esp_ops,
  572. },
  573. };
  574. static const struct zorro_device_id zorro_esp_zorro_tbl[] = {
  575. { /* Blizzard 1230 IV */
  576. .id = ZORRO_ID(PHASE5, 0x11, 0),
  577. .driver_data = ZORRO_BLZ1230,
  578. },
  579. { /* Blizzard 1230 II (Zorro II) or Fastlane (Zorro III) */
  580. .id = ZORRO_ID(PHASE5, 0x0B, 0),
  581. .driver_data = ZORRO_BLZ1230II,
  582. },
  583. { /* Blizzard 2060 */
  584. .id = ZORRO_ID(PHASE5, 0x18, 0),
  585. .driver_data = ZORRO_BLZ2060,
  586. },
  587. { /* Cyberstorm */
  588. .id = ZORRO_ID(PHASE5, 0x0C, 0),
  589. .driver_data = ZORRO_CYBER,
  590. },
  591. { /* Cyberstorm II */
  592. .id = ZORRO_ID(PHASE5, 0x19, 0),
  593. .driver_data = ZORRO_CYBERII,
  594. },
  595. { 0 }
  596. };
  597. MODULE_DEVICE_TABLE(zorro, zorro_esp_zorro_tbl);
  598. static int zorro_esp_probe(struct zorro_dev *z,
  599. const struct zorro_device_id *ent)
  600. {
  601. struct scsi_host_template *tpnt = &scsi_esp_template;
  602. struct Scsi_Host *host;
  603. struct esp *esp;
  604. const struct zorro_driver_data *zdd;
  605. struct zorro_esp_priv *zep;
  606. unsigned long board, ioaddr, dmaaddr;
  607. int err;
  608. board = zorro_resource_start(z);
  609. zdd = &zorro_esp_boards[ent->driver_data];
  610. pr_info("%s found at address 0x%lx.\n", zdd->name, board);
  611. zep = kzalloc(sizeof(*zep), GFP_KERNEL);
  612. if (!zep) {
  613. pr_err("Can't allocate device private data!\n");
  614. return -ENOMEM;
  615. }
  616. /* let's figure out whether we have a Zorro II or Zorro III board */
  617. if ((z->rom.er_Type & ERT_TYPEMASK) == ERT_ZORROIII) {
  618. if (board > 0xffffff)
  619. zep->zorro3 = 1;
  620. } else {
  621. /*
  622. * Even though most of these boards identify as Zorro II,
  623. * they are in fact CPU expansion slot boards and have full
  624. * access to all of memory. Fix up DMA bitmask here.
  625. */
  626. z->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  627. }
  628. /*
  629. * If Zorro III and ID matches Fastlane, our device table entry
  630. * contains data for the Blizzard 1230 II board which does share the
  631. * same ID. Fix up device table entry here.
  632. * TODO: Some Cyberstom060 boards also share this ID but would need
  633. * to use the Cyberstorm I driver data ... we catch this by checking
  634. * for presence of ESP chip later, but don't try to fix up yet.
  635. */
  636. if (zep->zorro3 && ent->driver_data == ZORRO_BLZ1230II) {
  637. pr_info("%s at address 0x%lx is Fastlane Z3, fixing data!\n",
  638. zdd->name, board);
  639. zdd = &zorro_esp_boards[ZORRO_FASTLANE];
  640. }
  641. if (zdd->absolute) {
  642. ioaddr = zdd->offset;
  643. dmaaddr = zdd->dma_offset;
  644. } else {
  645. ioaddr = board + zdd->offset;
  646. dmaaddr = board + zdd->dma_offset;
  647. }
  648. if (!zorro_request_device(z, zdd->name)) {
  649. pr_err("cannot reserve region 0x%lx, abort\n",
  650. board);
  651. err = -EBUSY;
  652. goto fail_free_zep;
  653. }
  654. host = scsi_host_alloc(tpnt, sizeof(struct esp));
  655. if (!host) {
  656. pr_err("No host detected; board configuration problem?\n");
  657. err = -ENOMEM;
  658. goto fail_release_device;
  659. }
  660. host->base = ioaddr;
  661. host->this_id = 7;
  662. esp = shost_priv(host);
  663. esp->host = host;
  664. esp->dev = &z->dev;
  665. esp->scsi_id = host->this_id;
  666. esp->scsi_id_mask = (1 << esp->scsi_id);
  667. esp->cfreq = 40000000;
  668. zep->esp = esp;
  669. dev_set_drvdata(esp->dev, zep);
  670. /* additional setup required for Fastlane */
  671. if (zep->zorro3 && ent->driver_data == ZORRO_BLZ1230II) {
  672. /* map full address space up to ESP base for DMA */
  673. zep->board_base = ioremap(board, FASTLANE_ESP_ADDR - 1);
  674. if (!zep->board_base) {
  675. pr_err("Cannot allocate board address space\n");
  676. err = -ENOMEM;
  677. goto fail_free_host;
  678. }
  679. /* initialize DMA control shadow register */
  680. zep->ctrl_data = (FASTLANE_DMA_FCODE |
  681. FASTLANE_DMA_EDI | FASTLANE_DMA_ESI);
  682. }
  683. esp->ops = zdd->esp_ops;
  684. if (ioaddr > 0xffffff)
  685. esp->regs = ioremap(ioaddr, 0x20);
  686. else
  687. /* ZorroII address space remapped nocache by early startup */
  688. esp->regs = ZTWO_VADDR(ioaddr);
  689. if (!esp->regs) {
  690. err = -ENOMEM;
  691. goto fail_unmap_fastlane;
  692. }
  693. esp->fifo_reg = esp->regs + ESP_FDATA * 4;
  694. /* Check whether a Blizzard 12x0 or CyberstormII really has SCSI */
  695. if (zdd->scsi_option) {
  696. zorro_esp_write8(esp, (ESP_CONFIG1_PENABLE | 7), ESP_CFG1);
  697. if (zorro_esp_read8(esp, ESP_CFG1) != (ESP_CONFIG1_PENABLE|7)) {
  698. err = -ENODEV;
  699. goto fail_unmap_regs;
  700. }
  701. }
  702. if (zep->zorro3) {
  703. /*
  704. * Only Fastlane Z3 for now - add switch for correct struct
  705. * dma_registers size if adding any more
  706. */
  707. esp->dma_regs = ioremap(dmaaddr,
  708. sizeof(struct fastlane_dma_registers));
  709. } else
  710. /* ZorroII address space remapped nocache by early startup */
  711. esp->dma_regs = ZTWO_VADDR(dmaaddr);
  712. if (!esp->dma_regs) {
  713. err = -ENOMEM;
  714. goto fail_unmap_regs;
  715. }
  716. esp->command_block = dma_alloc_coherent(esp->dev, 16,
  717. &esp->command_block_dma,
  718. GFP_KERNEL);
  719. if (!esp->command_block) {
  720. err = -ENOMEM;
  721. goto fail_unmap_dma_regs;
  722. }
  723. host->irq = IRQ_AMIGA_PORTS;
  724. err = request_irq(host->irq, scsi_esp_intr, IRQF_SHARED,
  725. "Amiga Zorro ESP", esp);
  726. if (err < 0) {
  727. err = -ENODEV;
  728. goto fail_free_command_block;
  729. }
  730. /* register the chip */
  731. err = scsi_esp_register(esp);
  732. if (err) {
  733. err = -ENOMEM;
  734. goto fail_free_irq;
  735. }
  736. return 0;
  737. fail_free_irq:
  738. free_irq(host->irq, esp);
  739. fail_free_command_block:
  740. dma_free_coherent(esp->dev, 16,
  741. esp->command_block,
  742. esp->command_block_dma);
  743. fail_unmap_dma_regs:
  744. if (zep->zorro3)
  745. iounmap(esp->dma_regs);
  746. fail_unmap_regs:
  747. if (ioaddr > 0xffffff)
  748. iounmap(esp->regs);
  749. fail_unmap_fastlane:
  750. if (zep->zorro3)
  751. iounmap(zep->board_base);
  752. fail_free_host:
  753. scsi_host_put(host);
  754. fail_release_device:
  755. zorro_release_device(z);
  756. fail_free_zep:
  757. kfree(zep);
  758. return err;
  759. }
  760. static void zorro_esp_remove(struct zorro_dev *z)
  761. {
  762. struct zorro_esp_priv *zep = dev_get_drvdata(&z->dev);
  763. struct esp *esp = zep->esp;
  764. struct Scsi_Host *host = esp->host;
  765. scsi_esp_unregister(esp);
  766. free_irq(host->irq, esp);
  767. dma_free_coherent(esp->dev, 16,
  768. esp->command_block,
  769. esp->command_block_dma);
  770. if (zep->zorro3) {
  771. iounmap(zep->board_base);
  772. iounmap(esp->dma_regs);
  773. }
  774. if (host->base > 0xffffff)
  775. iounmap(esp->regs);
  776. scsi_host_put(host);
  777. zorro_release_device(z);
  778. kfree(zep);
  779. }
  780. static struct zorro_driver zorro_esp_driver = {
  781. .name = KBUILD_MODNAME,
  782. .id_table = zorro_esp_zorro_tbl,
  783. .probe = zorro_esp_probe,
  784. .remove = zorro_esp_remove,
  785. };
  786. static int __init zorro_esp_scsi_init(void)
  787. {
  788. return zorro_register_driver(&zorro_esp_driver);
  789. }
  790. static void __exit zorro_esp_scsi_exit(void)
  791. {
  792. zorro_unregister_driver(&zorro_esp_driver);
  793. }
  794. module_init(zorro_esp_scsi_init);
  795. module_exit(zorro_esp_scsi_exit);