1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Filename: rsxx_priv.h
5 * Authors: Joshua Morris <josh.h.morris@us.ibm.com>
6 * Philip Kelleher <pjk1939@linux.vnet.ibm.com>
8 * (C) Copyright 2013 IBM Corporation
11 #ifndef __RSXX_PRIV_H__
12 #define __RSXX_PRIV_H__
14 #include <linux/version.h>
15 #include <linux/semaphore.h>
18 #include <linux/interrupt.h>
19 #include <linux/mutex.h>
20 #include <linux/pci.h>
21 #include <linux/spinlock.h>
22 #include <linux/sysfs.h>
23 #include <linux/workqueue.h>
24 #include <linux/bio.h>
25 #include <linux/vmalloc.h>
26 #include <linux/timer.h>
27 #include <linux/ioctl.h>
28 #include <linux/delay.h>
35 #define PCI_DEVICE_ID_FS70_FLASH 0x04A9
36 #define PCI_DEVICE_ID_FS80_FLASH 0x04AA
38 #define RS70_PCI_REV_SUPPORTED 4
40 #define DRIVER_NAME "rsxx"
41 #define DRIVER_VERSION "4.0.3.2516"
43 /* Block size is 4096 */
44 #define RSXX_HW_BLK_SHIFT 12
45 #define RSXX_HW_BLK_SIZE (1 << RSXX_HW_BLK_SHIFT)
46 #define RSXX_HW_BLK_MASK (RSXX_HW_BLK_SIZE - 1)
48 #define MAX_CREG_DATA8 32
49 #define LOG_BUF_SIZE8 128
51 #define RSXX_MAX_OUTSTANDING_CMDS 255
52 #define RSXX_CS_IDX_MASK 0xff
54 #define STATUS_BUFFER_SIZE8 4096
55 #define COMMAND_BUFFER_SIZE8 4096
57 #define RSXX_MAX_TARGETS 8
59 struct dma_tracker_list
;
61 /* DMA Command/Status Buffer structure */
62 struct rsxx_cs_buffer
{
68 struct rsxx_dma_stats
{
80 u32 issue_rescheduled
;
84 u32 sw_q_depth
; /* Number of DMAs on the SW queue. */
85 atomic_t hw_q_depth
; /* Number of DMAs queued to HW. */
88 struct rsxx_dma_ctrl
{
89 struct rsxx_cardinfo
*card
;
92 struct rsxx_cs_buffer status
;
93 struct rsxx_cs_buffer cmd
;
95 spinlock_t queue_lock
;
96 struct list_head queue
;
97 struct workqueue_struct
*issue_wq
;
98 struct work_struct issue_dma_work
;
99 struct workqueue_struct
*done_wq
;
100 struct work_struct dma_done_work
;
101 struct timer_list activity_timer
;
102 struct dma_tracker_list
*trackers
;
103 struct rsxx_dma_stats stats
;
104 struct mutex work_lock
;
107 struct rsxx_cardinfo
{
110 unsigned int eeh_state
;
112 void __iomem
*regmap
;
114 unsigned int isr_mask
;
115 unsigned int ier_mask
;
117 struct rsxx_card_cfg config
;
120 /* Embedded CPU Communication */
124 struct creg_cmd
*active_cmd
;
125 struct workqueue_struct
*creg_wq
;
126 struct work_struct done_work
;
127 struct list_head queue
;
128 unsigned int q_depth
;
129 /* Cache the creg status to prevent ioreads */
132 u32 failed_cancel_timer
;
135 struct timer_list cmd_timer
;
136 struct mutex reset_lock
;
141 char tmp
[MAX_CREG_DATA8
];
142 char buf
[LOG_BUF_SIZE8
]; /* terminated */
146 struct workqueue_struct
*event_wq
;
147 struct work_struct event_work
;
151 /* Lock the device attach/detach function */
152 struct mutex dev_lock
;
154 /* Block Device Variables */
158 struct request_queue
*queue
;
159 struct gendisk
*gendisk
;
161 /* Used to convert a byte address to a device address. */
168 unsigned int dma_fault
;
173 struct rsxx_dma_ctrl
*ctrl
;
175 struct dentry
*debugfs_dir
;
178 enum rsxx_pci_regmap
{
179 HWID
= 0x00, /* Hardware Identification Register */
180 SCRATCH
= 0x04, /* Scratch/Debug Register */
181 RESET
= 0x08, /* Reset Register */
182 ISR
= 0x10, /* Interrupt Status Register */
183 IER
= 0x14, /* Interrupt Enable Register */
184 IPR
= 0x18, /* Interrupt Poll Register */
185 CB_ADD_LO
= 0x20, /* Command Host Buffer Address [31:0] */
186 CB_ADD_HI
= 0x24, /* Command Host Buffer Address [63:32]*/
187 HW_CMD_IDX
= 0x28, /* Hardware Processed Command Index */
188 SW_CMD_IDX
= 0x2C, /* Software Processed Command Index */
189 SB_ADD_LO
= 0x30, /* Status Host Buffer Address [31:0] */
190 SB_ADD_HI
= 0x34, /* Status Host Buffer Address [63:32] */
191 HW_STATUS_CNT
= 0x38, /* Hardware Status Counter */
192 SW_STATUS_CNT
= 0x3C, /* Deprecated */
193 CREG_CMD
= 0x40, /* CPU Command Register */
194 CREG_ADD
= 0x44, /* CPU Address Register */
195 CREG_CNT
= 0x48, /* CPU Count Register */
196 CREG_STAT
= 0x4C, /* CPU Status Register */
197 CREG_DATA0
= 0x50, /* CPU Data Registers */
205 INTR_COAL
= 0x70, /* Interrupt Coalescing Register */
206 HW_ERROR
= 0x74, /* Card Error Register */
207 PCI_DEBUG0
= 0x78, /* PCI Debug Registers */
215 PCI_POWER_THROTTLE
= 0x98,
217 PERF_TIMER_LO
= 0xa0,
218 PERF_TIMER_HI
= 0xa4,
219 PERF_RD512_LO
= 0xa8,
220 PERF_RD512_HI
= 0xac,
221 PERF_WR512_LO
= 0xb0,
222 PERF_WR512_HI
= 0xb4,
227 CR_INTR_DMA0
= 0x00000001,
228 CR_INTR_CREG
= 0x00000002,
229 CR_INTR_DMA1
= 0x00000004,
230 CR_INTR_EVENT
= 0x00000008,
231 CR_INTR_DMA2
= 0x00000010,
232 CR_INTR_DMA3
= 0x00000020,
233 CR_INTR_DMA4
= 0x00000040,
234 CR_INTR_DMA5
= 0x00000080,
235 CR_INTR_DMA6
= 0x00000100,
236 CR_INTR_DMA7
= 0x00000200,
237 CR_INTR_ALL_C
= 0x0000003f,
238 CR_INTR_ALL_G
= 0x000003ff,
239 CR_INTR_DMA_ALL
= 0x000003f5,
240 CR_INTR_ALL
= 0xffffffff,
243 static inline int CR_INTR_DMA(int N
)
245 static const unsigned int _CR_INTR_DMA
[] = {
246 CR_INTR_DMA0
, CR_INTR_DMA1
, CR_INTR_DMA2
, CR_INTR_DMA3
,
247 CR_INTR_DMA4
, CR_INTR_DMA5
, CR_INTR_DMA6
, CR_INTR_DMA7
249 return _CR_INTR_DMA
[N
];
251 enum rsxx_pci_reset
{
252 DMA_QUEUE_RESET
= 0x00000001,
255 enum rsxx_hw_fifo_flush
{
256 RSXX_FLUSH_BUSY
= 0x00000002,
257 RSXX_FLUSH_TIMEOUT
= 0x00000004,
260 enum rsxx_pci_revision
{
261 RSXX_DISCARD_SUPPORT
= 2,
262 RSXX_EEH_SUPPORT
= 3,
266 CREG_CMD_TAG_MASK
= 0x0000FF00,
267 CREG_OP_WRITE
= 0x000000C0,
268 CREG_OP_READ
= 0x000000E0,
271 enum rsxx_creg_addr
{
272 CREG_ADD_CARD_CMD
= 0x80001000,
273 CREG_ADD_CARD_STATE
= 0x80001004,
274 CREG_ADD_CARD_SIZE
= 0x8000100c,
275 CREG_ADD_CAPABILITIES
= 0x80001050,
276 CREG_ADD_LOG
= 0x80002000,
277 CREG_ADD_NUM_TARGETS
= 0x80003000,
278 CREG_ADD_CRAM
= 0xA0000000,
279 CREG_ADD_CONFIG
= 0xB0000000,
282 enum rsxx_creg_card_cmd
{
283 CARD_CMD_STARTUP
= 1,
284 CARD_CMD_SHUTDOWN
= 2,
285 CARD_CMD_LOW_LEVEL_FORMAT
= 3,
286 CARD_CMD_FPGA_RECONFIG_BR
= 4,
287 CARD_CMD_FPGA_RECONFIG_MAIN
= 5,
290 CARD_CMD_deprecated
= 8,
291 CARD_CMD_UNINITIALIZE
= 9,
292 CARD_CMD_DSTROY_EMERGENCY
= 10,
293 CARD_CMD_DSTROY_NORMAL
= 11,
294 CARD_CMD_DSTROY_EXTENDED
= 12,
295 CARD_CMD_DSTROY_ABORT
= 13,
298 enum rsxx_card_state
{
299 CARD_STATE_SHUTDOWN
= 0x00000001,
300 CARD_STATE_STARTING
= 0x00000002,
301 CARD_STATE_FORMATTING
= 0x00000004,
302 CARD_STATE_UNINITIALIZED
= 0x00000008,
303 CARD_STATE_GOOD
= 0x00000010,
304 CARD_STATE_SHUTTING_DOWN
= 0x00000020,
305 CARD_STATE_FAULT
= 0x00000040,
306 CARD_STATE_RD_ONLY_FAULT
= 0x00000080,
307 CARD_STATE_DSTROYING
= 0x00000100,
316 enum rsxx_creg_flash_lock
{
318 CREG_FLASH_UNLOCK
= 2,
321 enum rsxx_card_capabilities
{
322 CARD_CAP_SUBPAGE_WRITES
= 0x00000080,
325 enum rsxx_creg_stat
{
326 CREG_STAT_STATUS_MASK
= 0x00000003,
327 CREG_STAT_SUCCESS
= 0x1,
328 CREG_STAT_ERROR
= 0x2,
329 CREG_STAT_CHAR_PENDING
= 0x00000004, /* Character I/O pending bit */
330 CREG_STAT_LOG_PENDING
= 0x00000008, /* HW log message pending bit */
331 CREG_STAT_TAG_MASK
= 0x0000ff00,
334 enum rsxx_dma_finish
{
339 static inline unsigned int CREG_DATA(int N
)
341 return CREG_DATA0
+ (N
<< 2);
344 /*----------------- Convenient Log Wrappers -------------------*/
345 #define CARD_TO_DEV(__CARD) (&(__CARD)->dev->dev)
347 /***** config.c *****/
348 int rsxx_load_config(struct rsxx_cardinfo
*card
);
351 void rsxx_enable_ier(struct rsxx_cardinfo
*card
, unsigned int intr
);
352 void rsxx_disable_ier(struct rsxx_cardinfo
*card
, unsigned int intr
);
353 void rsxx_enable_ier_and_isr(struct rsxx_cardinfo
*card
,
355 void rsxx_disable_ier_and_isr(struct rsxx_cardinfo
*card
,
359 int rsxx_attach_dev(struct rsxx_cardinfo
*card
);
360 void rsxx_detach_dev(struct rsxx_cardinfo
*card
);
361 int rsxx_setup_dev(struct rsxx_cardinfo
*card
);
362 void rsxx_destroy_dev(struct rsxx_cardinfo
*card
);
363 int rsxx_dev_init(void);
364 void rsxx_dev_cleanup(void);
367 typedef void (*rsxx_dma_cb
)(struct rsxx_cardinfo
*card
,
369 unsigned int status
);
370 int rsxx_dma_setup(struct rsxx_cardinfo
*card
);
371 void rsxx_dma_destroy(struct rsxx_cardinfo
*card
);
372 int rsxx_dma_init(void);
373 int rsxx_cleanup_dma_queue(struct rsxx_dma_ctrl
*ctrl
,
376 int rsxx_dma_cancel(struct rsxx_dma_ctrl
*ctrl
);
377 void rsxx_dma_cleanup(void);
378 void rsxx_dma_queue_reset(struct rsxx_cardinfo
*card
);
379 int rsxx_dma_configure(struct rsxx_cardinfo
*card
);
380 blk_status_t
rsxx_dma_queue_bio(struct rsxx_cardinfo
*card
,
385 int rsxx_hw_buffers_init(struct pci_dev
*dev
, struct rsxx_dma_ctrl
*ctrl
);
386 int rsxx_eeh_save_issued_dmas(struct rsxx_cardinfo
*card
);
387 int rsxx_eeh_remap_dmas(struct rsxx_cardinfo
*card
);
389 /***** cregs.c *****/
390 int rsxx_creg_write(struct rsxx_cardinfo
*card
, u32 addr
,
394 int rsxx_creg_read(struct rsxx_cardinfo
*card
,
399 int rsxx_read_hw_log(struct rsxx_cardinfo
*card
);
400 int rsxx_get_card_state(struct rsxx_cardinfo
*card
,
401 unsigned int *state
);
402 int rsxx_get_card_size8(struct rsxx_cardinfo
*card
, u64
*size8
);
403 int rsxx_get_num_targets(struct rsxx_cardinfo
*card
,
404 unsigned int *n_targets
);
405 int rsxx_get_card_capabilities(struct rsxx_cardinfo
*card
,
407 int rsxx_issue_card_cmd(struct rsxx_cardinfo
*card
, u32 cmd
);
408 int rsxx_creg_setup(struct rsxx_cardinfo
*card
);
409 void rsxx_creg_destroy(struct rsxx_cardinfo
*card
);
410 int rsxx_creg_init(void);
411 void rsxx_creg_cleanup(void);
412 int rsxx_reg_access(struct rsxx_cardinfo
*card
,
413 struct rsxx_reg_access __user
*ucmd
,
415 void rsxx_eeh_save_issued_creg(struct rsxx_cardinfo
*card
);
416 void rsxx_kick_creg_queue(struct rsxx_cardinfo
*card
);
420 #endif /* __DRIVERS_BLOCK_RSXX_H__ */