rsxx_priv.h 10 KB

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