hp_sdc_mlc.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. /*
  2. * Access to HP-HIL MLC through HP System Device Controller.
  3. *
  4. * Copyright (c) 2001 Brian S. Julin
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions, and the following disclaimer,
  12. * without modification.
  13. * 2. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * Alternatively, this software may be distributed under the terms of the
  17. * GNU General Public License ("GPL").
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28. *
  29. * References:
  30. * HP-HIL Technical Reference Manual. Hewlett Packard Product No. 45918A
  31. * System Device Controller Microprocessor Firmware Theory of Operation
  32. * for Part Number 1820-4784 Revision B. Dwg No. A-1820-4784-2
  33. *
  34. */
  35. #include <linux/hil_mlc.h>
  36. #include <linux/hp_sdc.h>
  37. #include <linux/errno.h>
  38. #include <linux/kernel.h>
  39. #include <linux/module.h>
  40. #include <linux/init.h>
  41. #include <linux/string.h>
  42. #include <linux/semaphore.h>
  43. #define PREFIX "HP SDC MLC: "
  44. static hil_mlc hp_sdc_mlc;
  45. MODULE_AUTHOR("Brian S. Julin <bri@calyx.com>");
  46. MODULE_DESCRIPTION("Glue for onboard HIL MLC in HP-PARISC machines");
  47. MODULE_LICENSE("Dual BSD/GPL");
  48. static struct hp_sdc_mlc_priv_s {
  49. int emtestmode;
  50. hp_sdc_transaction trans;
  51. u8 tseq[16];
  52. int got5x;
  53. } hp_sdc_mlc_priv;
  54. /************************* Interrupt context ******************************/
  55. static void hp_sdc_mlc_isr (int irq, void *dev_id,
  56. uint8_t status, uint8_t data)
  57. {
  58. int idx;
  59. hil_mlc *mlc = &hp_sdc_mlc;
  60. write_lock(&mlc->lock);
  61. if (mlc->icount < 0) {
  62. printk(KERN_WARNING PREFIX "HIL Overflow!\n");
  63. up(&mlc->isem);
  64. goto out;
  65. }
  66. idx = 15 - mlc->icount;
  67. if ((status & HP_SDC_STATUS_IRQMASK) == HP_SDC_STATUS_HILDATA) {
  68. mlc->ipacket[idx] |= data | HIL_ERR_INT;
  69. mlc->icount--;
  70. if (hp_sdc_mlc_priv.got5x || !idx)
  71. goto check;
  72. if ((mlc->ipacket[idx - 1] & HIL_PKT_ADDR_MASK) !=
  73. (mlc->ipacket[idx] & HIL_PKT_ADDR_MASK)) {
  74. mlc->ipacket[idx] &= ~HIL_PKT_ADDR_MASK;
  75. mlc->ipacket[idx] |= (mlc->ipacket[idx - 1]
  76. & HIL_PKT_ADDR_MASK);
  77. }
  78. goto check;
  79. }
  80. /* We know status is 5X */
  81. if (data & HP_SDC_HIL_ISERR)
  82. goto err;
  83. mlc->ipacket[idx] =
  84. (data & HP_SDC_HIL_R1MASK) << HIL_PKT_ADDR_SHIFT;
  85. hp_sdc_mlc_priv.got5x = 1;
  86. goto out;
  87. check:
  88. hp_sdc_mlc_priv.got5x = 0;
  89. if (mlc->imatch == 0)
  90. goto done;
  91. if ((mlc->imatch == (HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_POL))
  92. && (mlc->ipacket[idx] == (mlc->imatch | idx)))
  93. goto done;
  94. if (mlc->ipacket[idx] == mlc->imatch)
  95. goto done;
  96. goto out;
  97. err:
  98. printk(KERN_DEBUG PREFIX "err code %x\n", data);
  99. switch (data) {
  100. case HP_SDC_HIL_RC_DONE:
  101. printk(KERN_WARNING PREFIX "Bastard SDC reconfigured loop!\n");
  102. break;
  103. case HP_SDC_HIL_ERR:
  104. mlc->ipacket[idx] |= HIL_ERR_INT | HIL_ERR_PERR |
  105. HIL_ERR_FERR | HIL_ERR_FOF;
  106. break;
  107. case HP_SDC_HIL_TO:
  108. mlc->ipacket[idx] |= HIL_ERR_INT | HIL_ERR_LERR;
  109. break;
  110. case HP_SDC_HIL_RC:
  111. printk(KERN_WARNING PREFIX "Bastard SDC decided to reconfigure loop!\n");
  112. break;
  113. default:
  114. printk(KERN_WARNING PREFIX "Unknown HIL Error status (%x)!\n", data);
  115. break;
  116. }
  117. /* No more data will be coming due to an error. */
  118. done:
  119. tasklet_schedule(mlc->tasklet);
  120. up(&mlc->isem);
  121. out:
  122. write_unlock(&mlc->lock);
  123. }
  124. /******************** Tasklet or userspace context functions ****************/
  125. static int hp_sdc_mlc_in(hil_mlc *mlc, suseconds_t timeout)
  126. {
  127. struct hp_sdc_mlc_priv_s *priv;
  128. int rc = 2;
  129. priv = mlc->priv;
  130. /* Try to down the semaphore */
  131. if (down_trylock(&mlc->isem)) {
  132. if (priv->emtestmode) {
  133. mlc->ipacket[0] =
  134. HIL_ERR_INT | (mlc->opacket &
  135. (HIL_PKT_CMD |
  136. HIL_PKT_ADDR_MASK |
  137. HIL_PKT_DATA_MASK));
  138. mlc->icount = 14;
  139. /* printk(KERN_DEBUG PREFIX ">[%x]\n", mlc->ipacket[0]); */
  140. goto wasup;
  141. }
  142. if (time_after(jiffies, mlc->instart + mlc->intimeout)) {
  143. /* printk("!%i %i",
  144. tv.tv_usec - mlc->instart.tv_usec,
  145. mlc->intimeout);
  146. */
  147. rc = 1;
  148. up(&mlc->isem);
  149. }
  150. goto done;
  151. }
  152. wasup:
  153. up(&mlc->isem);
  154. rc = 0;
  155. done:
  156. return rc;
  157. }
  158. static int hp_sdc_mlc_cts(hil_mlc *mlc)
  159. {
  160. struct hp_sdc_mlc_priv_s *priv;
  161. priv = mlc->priv;
  162. /* Try to down the semaphores -- they should be up. */
  163. BUG_ON(down_trylock(&mlc->isem));
  164. BUG_ON(down_trylock(&mlc->osem));
  165. up(&mlc->isem);
  166. up(&mlc->osem);
  167. if (down_trylock(&mlc->csem)) {
  168. if (priv->trans.act.semaphore != &mlc->csem)
  169. goto poll;
  170. else
  171. goto busy;
  172. }
  173. if (!(priv->tseq[4] & HP_SDC_USE_LOOP))
  174. goto done;
  175. poll:
  176. priv->trans.act.semaphore = &mlc->csem;
  177. priv->trans.actidx = 0;
  178. priv->trans.idx = 1;
  179. priv->trans.endidx = 5;
  180. priv->tseq[0] =
  181. HP_SDC_ACT_POSTCMD | HP_SDC_ACT_DATAIN | HP_SDC_ACT_SEMAPHORE;
  182. priv->tseq[1] = HP_SDC_CMD_READ_USE;
  183. priv->tseq[2] = 1;
  184. priv->tseq[3] = 0;
  185. priv->tseq[4] = 0;
  186. return __hp_sdc_enqueue_transaction(&priv->trans);
  187. busy:
  188. return 1;
  189. done:
  190. priv->trans.act.semaphore = &mlc->osem;
  191. up(&mlc->csem);
  192. return 0;
  193. }
  194. static int hp_sdc_mlc_out(hil_mlc *mlc)
  195. {
  196. struct hp_sdc_mlc_priv_s *priv;
  197. priv = mlc->priv;
  198. /* Try to down the semaphore -- it should be up. */
  199. BUG_ON(down_trylock(&mlc->osem));
  200. if (mlc->opacket & HIL_DO_ALTER_CTRL)
  201. goto do_control;
  202. do_data:
  203. if (priv->emtestmode) {
  204. up(&mlc->osem);
  205. return 0;
  206. }
  207. /* Shouldn't be sending commands when loop may be busy */
  208. BUG_ON(down_trylock(&mlc->csem));
  209. up(&mlc->csem);
  210. priv->trans.actidx = 0;
  211. priv->trans.idx = 1;
  212. priv->trans.act.semaphore = &mlc->osem;
  213. priv->trans.endidx = 6;
  214. priv->tseq[0] =
  215. HP_SDC_ACT_DATAREG | HP_SDC_ACT_POSTCMD | HP_SDC_ACT_SEMAPHORE;
  216. priv->tseq[1] = 0x7;
  217. priv->tseq[2] =
  218. (mlc->opacket &
  219. (HIL_PKT_ADDR_MASK | HIL_PKT_CMD))
  220. >> HIL_PKT_ADDR_SHIFT;
  221. priv->tseq[3] =
  222. (mlc->opacket & HIL_PKT_DATA_MASK)
  223. >> HIL_PKT_DATA_SHIFT;
  224. priv->tseq[4] = 0; /* No timeout */
  225. if (priv->tseq[3] == HIL_CMD_DHR)
  226. priv->tseq[4] = 1;
  227. priv->tseq[5] = HP_SDC_CMD_DO_HIL;
  228. goto enqueue;
  229. do_control:
  230. priv->emtestmode = mlc->opacket & HIL_CTRL_TEST;
  231. /* we cannot emulate this, it should not be used. */
  232. BUG_ON((mlc->opacket & (HIL_CTRL_APE | HIL_CTRL_IPF)) == HIL_CTRL_APE);
  233. if ((mlc->opacket & HIL_CTRL_ONLY) == HIL_CTRL_ONLY)
  234. goto control_only;
  235. /* Should not send command/data after engaging APE */
  236. BUG_ON(mlc->opacket & HIL_CTRL_APE);
  237. /* Disengaging APE this way would not be valid either since
  238. * the loop must be allowed to idle.
  239. *
  240. * So, it works out that we really never actually send control
  241. * and data when using SDC, we just send the data.
  242. */
  243. goto do_data;
  244. control_only:
  245. priv->trans.actidx = 0;
  246. priv->trans.idx = 1;
  247. priv->trans.act.semaphore = &mlc->osem;
  248. priv->trans.endidx = 4;
  249. priv->tseq[0] =
  250. HP_SDC_ACT_PRECMD | HP_SDC_ACT_DATAOUT | HP_SDC_ACT_SEMAPHORE;
  251. priv->tseq[1] = HP_SDC_CMD_SET_LPC;
  252. priv->tseq[2] = 1;
  253. /* priv->tseq[3] = (mlc->ddc + 1) | HP_SDC_LPS_ACSUCC; */
  254. priv->tseq[3] = 0;
  255. if (mlc->opacket & HIL_CTRL_APE) {
  256. priv->tseq[3] |= HP_SDC_LPC_APE_IPF;
  257. BUG_ON(down_trylock(&mlc->csem));
  258. }
  259. enqueue:
  260. return hp_sdc_enqueue_transaction(&priv->trans);
  261. }
  262. static int __init hp_sdc_mlc_init(void)
  263. {
  264. hil_mlc *mlc = &hp_sdc_mlc;
  265. int err;
  266. #ifdef __mc68000__
  267. if (!MACH_IS_HP300)
  268. return -ENODEV;
  269. #endif
  270. printk(KERN_INFO PREFIX "Registering the System Domain Controller's HIL MLC.\n");
  271. hp_sdc_mlc_priv.emtestmode = 0;
  272. hp_sdc_mlc_priv.trans.seq = hp_sdc_mlc_priv.tseq;
  273. hp_sdc_mlc_priv.trans.act.semaphore = &mlc->osem;
  274. hp_sdc_mlc_priv.got5x = 0;
  275. mlc->cts = &hp_sdc_mlc_cts;
  276. mlc->in = &hp_sdc_mlc_in;
  277. mlc->out = &hp_sdc_mlc_out;
  278. mlc->priv = &hp_sdc_mlc_priv;
  279. err = hil_mlc_register(mlc);
  280. if (err) {
  281. printk(KERN_WARNING PREFIX "Failed to register MLC structure with hil_mlc\n");
  282. return err;
  283. }
  284. if (hp_sdc_request_hil_irq(&hp_sdc_mlc_isr)) {
  285. printk(KERN_WARNING PREFIX "Request for raw HIL ISR hook denied\n");
  286. if (hil_mlc_unregister(mlc))
  287. printk(KERN_ERR PREFIX "Failed to unregister MLC structure with hil_mlc.\n"
  288. "This is bad. Could cause an oops.\n");
  289. return -EBUSY;
  290. }
  291. return 0;
  292. }
  293. static void __exit hp_sdc_mlc_exit(void)
  294. {
  295. hil_mlc *mlc = &hp_sdc_mlc;
  296. if (hp_sdc_release_hil_irq(&hp_sdc_mlc_isr))
  297. printk(KERN_ERR PREFIX "Failed to release the raw HIL ISR hook.\n"
  298. "This is bad. Could cause an oops.\n");
  299. if (hil_mlc_unregister(mlc))
  300. printk(KERN_ERR PREFIX "Failed to unregister MLC structure with hil_mlc.\n"
  301. "This is bad. Could cause an oops.\n");
  302. }
  303. module_init(hp_sdc_mlc_init);
  304. module_exit(hp_sdc_mlc_exit);