rsxx_priv.h 11 KB

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