rsxx_priv.h 11 KB

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