rsxx_priv.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. /*
  2. * Filename: rsxx_priv.h
  3. *
  4. *
  5. * Authors: Joshua Morris <josh.h.morris@us.ibm.com>
  6. * Philip Kelleher <pjk1939@linux.vnet.ibm.com>
  7. *
  8. * (C) Copyright 2013 IBM Corporation
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software Foundation,
  22. * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. #ifndef __RSXX_PRIV_H__
  25. #define __RSXX_PRIV_H__
  26. #include <linux/version.h>
  27. #include <linux/semaphore.h>
  28. #include <linux/fs.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/mutex.h>
  31. #include <linux/pci.h>
  32. #include <linux/spinlock.h>
  33. #include <linux/sysfs.h>
  34. #include <linux/workqueue.h>
  35. #include <linux/bio.h>
  36. #include <linux/vmalloc.h>
  37. #include <linux/timer.h>
  38. #include <linux/ioctl.h>
  39. #include "rsxx.h"
  40. #include "rsxx_cfg.h"
  41. struct proc_cmd;
  42. #define PCI_DEVICE_ID_FS70_FLASH 0x04A9
  43. #define PCI_DEVICE_ID_FS80_FLASH 0x04AA
  44. #define RS70_PCI_REV_SUPPORTED 4
  45. #define DRIVER_NAME "rsxx"
  46. #define DRIVER_VERSION "4.0"
  47. /* Block size is 4096 */
  48. #define RSXX_HW_BLK_SHIFT 12
  49. #define RSXX_HW_BLK_SIZE (1 << RSXX_HW_BLK_SHIFT)
  50. #define RSXX_HW_BLK_MASK (RSXX_HW_BLK_SIZE - 1)
  51. #define MAX_CREG_DATA8 32
  52. #define LOG_BUF_SIZE8 128
  53. #define RSXX_MAX_OUTSTANDING_CMDS 255
  54. #define RSXX_CS_IDX_MASK 0xff
  55. #define RSXX_MAX_TARGETS 8
  56. struct dma_tracker_list;
  57. /* DMA Command/Status Buffer structure */
  58. struct rsxx_cs_buffer {
  59. dma_addr_t dma_addr;
  60. void *buf;
  61. u32 idx;
  62. };
  63. struct rsxx_dma_stats {
  64. u32 crc_errors;
  65. u32 hard_errors;
  66. u32 soft_errors;
  67. u32 writes_issued;
  68. u32 writes_failed;
  69. u32 reads_issued;
  70. u32 reads_failed;
  71. u32 reads_retried;
  72. u32 discards_issued;
  73. u32 discards_failed;
  74. u32 done_rescheduled;
  75. u32 issue_rescheduled;
  76. u32 sw_q_depth; /* Number of DMAs on the SW queue. */
  77. atomic_t hw_q_depth; /* Number of DMAs queued to HW. */
  78. };
  79. struct rsxx_dma_ctrl {
  80. struct rsxx_cardinfo *card;
  81. int id;
  82. void __iomem *regmap;
  83. struct rsxx_cs_buffer status;
  84. struct rsxx_cs_buffer cmd;
  85. u16 e_cnt;
  86. spinlock_t queue_lock;
  87. struct list_head queue;
  88. struct workqueue_struct *issue_wq;
  89. struct work_struct issue_dma_work;
  90. struct workqueue_struct *done_wq;
  91. struct work_struct dma_done_work;
  92. struct timer_list activity_timer;
  93. struct dma_tracker_list *trackers;
  94. struct rsxx_dma_stats stats;
  95. };
  96. struct rsxx_cardinfo {
  97. struct pci_dev *dev;
  98. unsigned int halt;
  99. void __iomem *regmap;
  100. spinlock_t irq_lock;
  101. unsigned int isr_mask;
  102. unsigned int ier_mask;
  103. struct rsxx_card_cfg config;
  104. int config_valid;
  105. /* Embedded CPU Communication */
  106. struct {
  107. spinlock_t lock;
  108. bool active;
  109. struct creg_cmd *active_cmd;
  110. struct work_struct done_work;
  111. struct list_head queue;
  112. unsigned int q_depth;
  113. /* Cache the creg status to prevent ioreads */
  114. struct {
  115. u32 stat;
  116. u32 failed_cancel_timer;
  117. u32 creg_timeout;
  118. } creg_stats;
  119. struct timer_list cmd_timer;
  120. struct mutex reset_lock;
  121. int reset;
  122. } creg_ctrl;
  123. struct {
  124. char tmp[MAX_CREG_DATA8];
  125. char buf[LOG_BUF_SIZE8]; /* terminated */
  126. int buf_len;
  127. } log;
  128. struct work_struct event_work;
  129. unsigned int state;
  130. u64 size8;
  131. /* Lock the device attach/detach function */
  132. struct mutex dev_lock;
  133. /* Block Device Variables */
  134. bool bdev_attached;
  135. int disk_id;
  136. int major;
  137. struct request_queue *queue;
  138. struct gendisk *gendisk;
  139. struct {
  140. /* Used to convert a byte address to a device address. */
  141. u64 lower_mask;
  142. u64 upper_shift;
  143. u64 upper_mask;
  144. u64 target_mask;
  145. u64 target_shift;
  146. } _stripe;
  147. unsigned int dma_fault;
  148. int scrub_hard;
  149. int n_targets;
  150. struct rsxx_dma_ctrl *ctrl;
  151. };
  152. enum rsxx_pci_regmap {
  153. HWID = 0x00, /* Hardware Identification Register */
  154. SCRATCH = 0x04, /* Scratch/Debug Register */
  155. RESET = 0x08, /* Reset Register */
  156. ISR = 0x10, /* Interrupt Status Register */
  157. IER = 0x14, /* Interrupt Enable Register */
  158. IPR = 0x18, /* Interrupt Poll Register */
  159. CB_ADD_LO = 0x20, /* Command Host Buffer Address [31:0] */
  160. CB_ADD_HI = 0x24, /* Command Host Buffer Address [63:32]*/
  161. HW_CMD_IDX = 0x28, /* Hardware Processed Command Index */
  162. SW_CMD_IDX = 0x2C, /* Software Processed Command Index */
  163. SB_ADD_LO = 0x30, /* Status Host Buffer Address [31:0] */
  164. SB_ADD_HI = 0x34, /* Status Host Buffer Address [63:32] */
  165. HW_STATUS_CNT = 0x38, /* Hardware Status Counter */
  166. SW_STATUS_CNT = 0x3C, /* Deprecated */
  167. CREG_CMD = 0x40, /* CPU Command Register */
  168. CREG_ADD = 0x44, /* CPU Address Register */
  169. CREG_CNT = 0x48, /* CPU Count Register */
  170. CREG_STAT = 0x4C, /* CPU Status Register */
  171. CREG_DATA0 = 0x50, /* CPU Data Registers */
  172. CREG_DATA1 = 0x54,
  173. CREG_DATA2 = 0x58,
  174. CREG_DATA3 = 0x5C,
  175. CREG_DATA4 = 0x60,
  176. CREG_DATA5 = 0x64,
  177. CREG_DATA6 = 0x68,
  178. CREG_DATA7 = 0x6c,
  179. INTR_COAL = 0x70, /* Interrupt Coalescing Register */
  180. HW_ERROR = 0x74, /* Card Error Register */
  181. PCI_DEBUG0 = 0x78, /* PCI Debug Registers */
  182. PCI_DEBUG1 = 0x7C,
  183. PCI_DEBUG2 = 0x80,
  184. PCI_DEBUG3 = 0x84,
  185. PCI_DEBUG4 = 0x88,
  186. PCI_DEBUG5 = 0x8C,
  187. PCI_DEBUG6 = 0x90,
  188. PCI_DEBUG7 = 0x94,
  189. PCI_POWER_THROTTLE = 0x98,
  190. PERF_CTRL = 0x9c,
  191. PERF_TIMER_LO = 0xa0,
  192. PERF_TIMER_HI = 0xa4,
  193. PERF_RD512_LO = 0xa8,
  194. PERF_RD512_HI = 0xac,
  195. PERF_WR512_LO = 0xb0,
  196. PERF_WR512_HI = 0xb4,
  197. };
  198. enum rsxx_intr {
  199. CR_INTR_DMA0 = 0x00000001,
  200. CR_INTR_CREG = 0x00000002,
  201. CR_INTR_DMA1 = 0x00000004,
  202. CR_INTR_EVENT = 0x00000008,
  203. CR_INTR_DMA2 = 0x00000010,
  204. CR_INTR_DMA3 = 0x00000020,
  205. CR_INTR_DMA4 = 0x00000040,
  206. CR_INTR_DMA5 = 0x00000080,
  207. CR_INTR_DMA6 = 0x00000100,
  208. CR_INTR_DMA7 = 0x00000200,
  209. CR_INTR_DMA_ALL = 0x000003f5,
  210. CR_INTR_ALL = 0xffffffff,
  211. };
  212. static inline int CR_INTR_DMA(int N)
  213. {
  214. static const unsigned int _CR_INTR_DMA[] = {
  215. CR_INTR_DMA0, CR_INTR_DMA1, CR_INTR_DMA2, CR_INTR_DMA3,
  216. CR_INTR_DMA4, CR_INTR_DMA5, CR_INTR_DMA6, CR_INTR_DMA7
  217. };
  218. return _CR_INTR_DMA[N];
  219. }
  220. enum rsxx_pci_reset {
  221. DMA_QUEUE_RESET = 0x00000001,
  222. };
  223. enum rsxx_pci_revision {
  224. RSXX_DISCARD_SUPPORT = 2,
  225. };
  226. enum rsxx_creg_cmd {
  227. CREG_CMD_TAG_MASK = 0x0000FF00,
  228. CREG_OP_WRITE = 0x000000C0,
  229. CREG_OP_READ = 0x000000E0,
  230. };
  231. enum rsxx_creg_addr {
  232. CREG_ADD_CARD_CMD = 0x80001000,
  233. CREG_ADD_CARD_STATE = 0x80001004,
  234. CREG_ADD_CARD_SIZE = 0x8000100c,
  235. CREG_ADD_CAPABILITIES = 0x80001050,
  236. CREG_ADD_LOG = 0x80002000,
  237. CREG_ADD_NUM_TARGETS = 0x80003000,
  238. CREG_ADD_CONFIG = 0xB0000000,
  239. };
  240. enum rsxx_creg_card_cmd {
  241. CARD_CMD_STARTUP = 1,
  242. CARD_CMD_SHUTDOWN = 2,
  243. CARD_CMD_LOW_LEVEL_FORMAT = 3,
  244. CARD_CMD_FPGA_RECONFIG_BR = 4,
  245. CARD_CMD_FPGA_RECONFIG_MAIN = 5,
  246. CARD_CMD_BACKUP = 6,
  247. CARD_CMD_RESET = 7,
  248. CARD_CMD_deprecated = 8,
  249. CARD_CMD_UNINITIALIZE = 9,
  250. CARD_CMD_DSTROY_EMERGENCY = 10,
  251. CARD_CMD_DSTROY_NORMAL = 11,
  252. CARD_CMD_DSTROY_EXTENDED = 12,
  253. CARD_CMD_DSTROY_ABORT = 13,
  254. };
  255. enum rsxx_card_state {
  256. CARD_STATE_SHUTDOWN = 0x00000001,
  257. CARD_STATE_STARTING = 0x00000002,
  258. CARD_STATE_FORMATTING = 0x00000004,
  259. CARD_STATE_UNINITIALIZED = 0x00000008,
  260. CARD_STATE_GOOD = 0x00000010,
  261. CARD_STATE_SHUTTING_DOWN = 0x00000020,
  262. CARD_STATE_FAULT = 0x00000040,
  263. CARD_STATE_RD_ONLY_FAULT = 0x00000080,
  264. CARD_STATE_DSTROYING = 0x00000100,
  265. };
  266. enum rsxx_led {
  267. LED_DEFAULT = 0x0,
  268. LED_IDENTIFY = 0x1,
  269. LED_SOAK = 0x2,
  270. };
  271. enum rsxx_creg_flash_lock {
  272. CREG_FLASH_LOCK = 1,
  273. CREG_FLASH_UNLOCK = 2,
  274. };
  275. enum rsxx_card_capabilities {
  276. CARD_CAP_SUBPAGE_WRITES = 0x00000080,
  277. };
  278. enum rsxx_creg_stat {
  279. CREG_STAT_STATUS_MASK = 0x00000003,
  280. CREG_STAT_SUCCESS = 0x1,
  281. CREG_STAT_ERROR = 0x2,
  282. CREG_STAT_CHAR_PENDING = 0x00000004, /* Character I/O pending bit */
  283. CREG_STAT_LOG_PENDING = 0x00000008, /* HW log message pending bit */
  284. CREG_STAT_TAG_MASK = 0x0000ff00,
  285. };
  286. static inline unsigned int CREG_DATA(int N)
  287. {
  288. return CREG_DATA0 + (N << 2);
  289. }
  290. /*----------------- Convenient Log Wrappers -------------------*/
  291. #define CARD_TO_DEV(__CARD) (&(__CARD)->dev->dev)
  292. /***** config.c *****/
  293. int rsxx_load_config(struct rsxx_cardinfo *card);
  294. /***** core.c *****/
  295. void rsxx_enable_ier(struct rsxx_cardinfo *card, unsigned int intr);
  296. void rsxx_disable_ier(struct rsxx_cardinfo *card, unsigned int intr);
  297. void rsxx_enable_ier_and_isr(struct rsxx_cardinfo *card,
  298. unsigned int intr);
  299. void rsxx_disable_ier_and_isr(struct rsxx_cardinfo *card,
  300. unsigned int intr);
  301. /***** dev.c *****/
  302. int rsxx_attach_dev(struct rsxx_cardinfo *card);
  303. void rsxx_detach_dev(struct rsxx_cardinfo *card);
  304. int rsxx_setup_dev(struct rsxx_cardinfo *card);
  305. void rsxx_destroy_dev(struct rsxx_cardinfo *card);
  306. int rsxx_dev_init(void);
  307. void rsxx_dev_cleanup(void);
  308. /***** dma.c ****/
  309. typedef void (*rsxx_dma_cb)(struct rsxx_cardinfo *card,
  310. void *cb_data,
  311. unsigned int status);
  312. int rsxx_dma_setup(struct rsxx_cardinfo *card);
  313. void rsxx_dma_destroy(struct rsxx_cardinfo *card);
  314. int rsxx_dma_init(void);
  315. void rsxx_dma_cleanup(void);
  316. int rsxx_dma_queue_bio(struct rsxx_cardinfo *card,
  317. struct bio *bio,
  318. atomic_t *n_dmas,
  319. rsxx_dma_cb cb,
  320. void *cb_data);
  321. /***** cregs.c *****/
  322. int rsxx_creg_write(struct rsxx_cardinfo *card, u32 addr,
  323. unsigned int size8,
  324. void *data,
  325. int byte_stream);
  326. int rsxx_creg_read(struct rsxx_cardinfo *card,
  327. u32 addr,
  328. unsigned int size8,
  329. void *data,
  330. int byte_stream);
  331. int rsxx_read_hw_log(struct rsxx_cardinfo *card);
  332. int rsxx_get_card_state(struct rsxx_cardinfo *card,
  333. unsigned int *state);
  334. int rsxx_get_card_size8(struct rsxx_cardinfo *card, u64 *size8);
  335. int rsxx_get_num_targets(struct rsxx_cardinfo *card,
  336. unsigned int *n_targets);
  337. int rsxx_get_card_capabilities(struct rsxx_cardinfo *card,
  338. u32 *capabilities);
  339. int rsxx_issue_card_cmd(struct rsxx_cardinfo *card, u32 cmd);
  340. int rsxx_creg_setup(struct rsxx_cardinfo *card);
  341. void rsxx_creg_destroy(struct rsxx_cardinfo *card);
  342. int rsxx_creg_init(void);
  343. void rsxx_creg_cleanup(void);
  344. int rsxx_reg_access(struct rsxx_cardinfo *card,
  345. struct rsxx_reg_access __user *ucmd,
  346. int read);
  347. #endif /* __DRIVERS_BLOCK_RSXX_H__ */