mic_x100.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. * Intel MIC Platform Software Stack (MPSS)
  3. *
  4. * Copyright(c) 2013 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License, version 2, as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * The full GNU General Public License is included in this distribution in
  16. * the file called "COPYING".
  17. *
  18. * Disclaimer: The codes contained in these modules may be specific to
  19. * the Intel Software Development Platform codenamed: Knights Ferry, and
  20. * the Intel product codenamed: Knights Corner, and are not backward
  21. * compatible with other Intel products. Additionally, Intel will NOT
  22. * support the codes or instruction set in future products.
  23. *
  24. * Intel MIC Card driver.
  25. *
  26. */
  27. #include <linux/module.h>
  28. #include <linux/pci.h>
  29. #include <linux/platform_device.h>
  30. #include "../common/mic_dev.h"
  31. #include "mic_device.h"
  32. #include "mic_x100.h"
  33. static const char mic_driver_name[] = "mic";
  34. static struct mic_driver g_drv;
  35. /**
  36. * mic_read_spad - read from the scratchpad register
  37. * @mdev: pointer to mic_device instance
  38. * @idx: index to scratchpad register, 0 based
  39. *
  40. * This function allows reading of the 32bit scratchpad register.
  41. *
  42. * RETURNS: An appropriate -ERRNO error value on error, or zero for success.
  43. */
  44. u32 mic_read_spad(struct mic_device *mdev, unsigned int idx)
  45. {
  46. return mic_mmio_read(&mdev->mmio,
  47. MIC_X100_SBOX_BASE_ADDRESS +
  48. MIC_X100_SBOX_SPAD0 + idx * 4);
  49. }
  50. /**
  51. * __mic_send_intr - Send interrupt to Host.
  52. * @mdev: pointer to mic_device instance
  53. * @doorbell: Doorbell number.
  54. */
  55. void mic_send_intr(struct mic_device *mdev, int doorbell)
  56. {
  57. struct mic_mw *mw = &mdev->mmio;
  58. if (doorbell > MIC_X100_MAX_DOORBELL_IDX)
  59. return;
  60. /* Ensure that the interrupt is ordered w.r.t previous stores. */
  61. wmb();
  62. mic_mmio_write(mw, MIC_X100_SBOX_SDBIC0_DBREQ_BIT,
  63. MIC_X100_SBOX_BASE_ADDRESS +
  64. (MIC_X100_SBOX_SDBIC0 + (4 * doorbell)));
  65. }
  66. /**
  67. * mic_ack_interrupt - Device specific interrupt handling.
  68. * @mdev: pointer to mic_device instance
  69. *
  70. * Returns: bitmask of doorbell events triggered.
  71. */
  72. u32 mic_ack_interrupt(struct mic_device *mdev)
  73. {
  74. return 0;
  75. }
  76. static inline int mic_get_sbox_irq(int db)
  77. {
  78. return MIC_X100_IRQ_BASE + db;
  79. }
  80. static inline int mic_get_rdmasr_irq(int index)
  81. {
  82. return MIC_X100_RDMASR_IRQ_BASE + index;
  83. }
  84. /**
  85. * mic_hw_intr_init - Initialize h/w specific interrupt
  86. * information.
  87. * @mdrv: pointer to mic_driver
  88. */
  89. void mic_hw_intr_init(struct mic_driver *mdrv)
  90. {
  91. mdrv->intr_info.num_intr = MIC_X100_NUM_SBOX_IRQ +
  92. MIC_X100_NUM_RDMASR_IRQ;
  93. }
  94. /**
  95. * mic_db_to_irq - Retrieve irq number corresponding to a doorbell.
  96. * @mdrv: pointer to mic_driver
  97. * @db: The doorbell obtained for which the irq is needed. Doorbell
  98. * may correspond to an sbox doorbell or an rdmasr index.
  99. *
  100. * Returns the irq corresponding to the doorbell.
  101. */
  102. int mic_db_to_irq(struct mic_driver *mdrv, int db)
  103. {
  104. int rdmasr_index;
  105. if (db < MIC_X100_NUM_SBOX_IRQ) {
  106. return mic_get_sbox_irq(db);
  107. } else {
  108. rdmasr_index = db - MIC_X100_NUM_SBOX_IRQ +
  109. MIC_X100_RDMASR_IRQ_BASE;
  110. return mic_get_rdmasr_irq(rdmasr_index);
  111. }
  112. }
  113. /*
  114. * mic_card_map - Allocate virtual address for a remote memory region.
  115. * @mdev: pointer to mic_device instance.
  116. * @addr: Remote DMA address.
  117. * @size: Size of the region.
  118. *
  119. * Returns: Virtual address backing the remote memory region.
  120. */
  121. void __iomem *
  122. mic_card_map(struct mic_device *mdev, dma_addr_t addr, size_t size)
  123. {
  124. return ioremap(addr, size);
  125. }
  126. /*
  127. * mic_card_unmap - Unmap the virtual address for a remote memory region.
  128. * @mdev: pointer to mic_device instance.
  129. * @addr: Virtual address for remote memory region.
  130. *
  131. * Returns: None.
  132. */
  133. void mic_card_unmap(struct mic_device *mdev, void __iomem *addr)
  134. {
  135. iounmap(addr);
  136. }
  137. static int __init mic_probe(struct platform_device *pdev)
  138. {
  139. struct mic_driver *mdrv = &g_drv;
  140. struct mic_device *mdev = &mdrv->mdev;
  141. int rc = 0;
  142. mdrv->dev = &pdev->dev;
  143. snprintf(mdrv->name, sizeof(mic_driver_name), mic_driver_name);
  144. mdev->mmio.pa = MIC_X100_MMIO_BASE;
  145. mdev->mmio.len = MIC_X100_MMIO_LEN;
  146. mdev->mmio.va = ioremap(MIC_X100_MMIO_BASE, MIC_X100_MMIO_LEN);
  147. if (!mdev->mmio.va) {
  148. dev_err(&pdev->dev, "Cannot remap MMIO BAR\n");
  149. rc = -EIO;
  150. goto done;
  151. }
  152. mic_hw_intr_init(mdrv);
  153. rc = mic_driver_init(mdrv);
  154. if (rc) {
  155. dev_err(&pdev->dev, "mic_driver_init failed rc %d\n", rc);
  156. goto iounmap;
  157. }
  158. done:
  159. return rc;
  160. iounmap:
  161. iounmap(mdev->mmio.va);
  162. return rc;
  163. }
  164. static int mic_remove(struct platform_device *pdev)
  165. {
  166. struct mic_driver *mdrv = &g_drv;
  167. struct mic_device *mdev = &mdrv->mdev;
  168. mic_driver_uninit(mdrv);
  169. iounmap(mdev->mmio.va);
  170. return 0;
  171. }
  172. static void mic_platform_shutdown(struct platform_device *pdev)
  173. {
  174. mic_remove(pdev);
  175. }
  176. static struct platform_device mic_platform_dev = {
  177. .name = mic_driver_name,
  178. .id = 0,
  179. .num_resources = 0,
  180. };
  181. static struct platform_driver __refdata mic_platform_driver = {
  182. .probe = mic_probe,
  183. .remove = mic_remove,
  184. .shutdown = mic_platform_shutdown,
  185. .driver = {
  186. .name = mic_driver_name,
  187. .owner = THIS_MODULE,
  188. },
  189. };
  190. static int __init mic_init(void)
  191. {
  192. int ret;
  193. struct cpuinfo_x86 *c = &cpu_data(0);
  194. if (!(c->x86 == 11 && c->x86_model == 1)) {
  195. ret = -ENODEV;
  196. pr_err("%s not running on X100 ret %d\n", __func__, ret);
  197. goto done;
  198. }
  199. mic_init_card_debugfs();
  200. ret = platform_device_register(&mic_platform_dev);
  201. if (ret) {
  202. pr_err("platform_device_register ret %d\n", ret);
  203. goto cleanup_debugfs;
  204. }
  205. ret = platform_driver_register(&mic_platform_driver);
  206. if (ret) {
  207. pr_err("platform_driver_register ret %d\n", ret);
  208. goto device_unregister;
  209. }
  210. return ret;
  211. device_unregister:
  212. platform_device_unregister(&mic_platform_dev);
  213. cleanup_debugfs:
  214. mic_exit_card_debugfs();
  215. done:
  216. return ret;
  217. }
  218. static void __exit mic_exit(void)
  219. {
  220. platform_driver_unregister(&mic_platform_driver);
  221. platform_device_unregister(&mic_platform_dev);
  222. mic_exit_card_debugfs();
  223. }
  224. module_init(mic_init);
  225. module_exit(mic_exit);
  226. MODULE_AUTHOR("Intel Corporation");
  227. MODULE_DESCRIPTION("Intel(R) MIC X100 Card driver");
  228. MODULE_LICENSE("GPL v2");