ARM64: firefly: Add rk3399-firefly board support
[firefly-linux-kernel-4.4.55.git] / drivers / mmc / card / queue.h
1 #ifndef MMC_QUEUE_H
2 #define MMC_QUEUE_H
3
4 #define MMC_REQ_SPECIAL_MASK    (REQ_DISCARD | REQ_FLUSH)
5
6 struct request;
7 struct task_struct;
8
9 struct mmc_blk_request {
10         struct mmc_request      mrq;
11         struct mmc_command      sbc;
12         struct mmc_command      cmd;
13         struct mmc_command      stop;
14         struct mmc_data         data;
15         int                     retune_retry_done;
16 };
17
18 enum mmc_packed_type {
19         MMC_PACKED_NONE = 0,
20         MMC_PACKED_WRITE,
21 };
22
23 #define mmc_packed_cmd(type)    ((type) != MMC_PACKED_NONE)
24 #define mmc_packed_wr(type)     ((type) == MMC_PACKED_WRITE)
25
26 struct mmc_packed {
27         struct list_head        list;
28         __le32                  cmd_hdr[1024];
29         unsigned int            blocks;
30         u8                      nr_entries;
31         u8                      retries;
32         s16                     idx_failure;
33 };
34
35 struct mmc_queue_req {
36         struct request          *req;
37         struct mmc_blk_request  brq;
38         struct scatterlist      *sg;
39         char                    *bounce_buf;
40         struct scatterlist      *bounce_sg;
41         unsigned int            bounce_sg_len;
42         struct mmc_async_req    mmc_active;
43         enum mmc_packed_type    cmd_type;
44         struct mmc_packed       *packed;
45 };
46
47 struct mmc_queue {
48         struct mmc_card         *card;
49         struct task_struct      *thread;
50         struct semaphore        thread_sem;
51         unsigned int            flags;
52 #define MMC_QUEUE_SUSPENDED     (1 << 0)
53 #define MMC_QUEUE_NEW_REQUEST   (1 << 1)
54
55         int                     (*issue_fn)(struct mmc_queue *, struct request *);
56         void                    *data;
57         struct request_queue    *queue;
58         struct mmc_queue_req    mqrq[2];
59         struct mmc_queue_req    *mqrq_cur;
60         struct mmc_queue_req    *mqrq_prev;
61 #ifdef CONFIG_MMC_SIMULATE_MAX_SPEED
62         atomic_t max_write_speed;
63         atomic_t max_read_speed;
64         atomic_t cache_size;
65         /* i/o tracking */
66         atomic_long_t cache_used;
67         unsigned long cache_jiffies;
68 #endif
69 };
70
71 /*
72  * There is one mmc_blk_data per slot.
73  */
74 struct mmc_blk_data {
75         spinlock_t      lock;
76         struct gendisk  *disk;
77         struct mmc_queue queue;
78         struct list_head part;
79
80         unsigned int    flags;
81 #define MMC_BLK_CMD23   (1 << 0)        /* Can do SET_BLOCK_COUNT for multiblock */
82 #define MMC_BLK_REL_WR  (1 << 1)        /* MMC Reliable write support */
83 #define MMC_BLK_PACKED_CMD      (1 << 2)        /* MMC packed command support */
84
85         unsigned int    usage;
86         unsigned int    read_only;
87         unsigned int    part_type;
88         unsigned int    name_idx;
89         unsigned int    reset_done;
90 #define MMC_BLK_READ            BIT(0)
91 #define MMC_BLK_WRITE           BIT(1)
92 #define MMC_BLK_DISCARD         BIT(2)
93 #define MMC_BLK_SECDISCARD      BIT(3)
94 #define MMC_BLK_RPMB            BIT(4)
95
96         /*
97          * Only set in main mmc_blk_data associated
98          * with mmc_card with mmc_set_drvdata, and keeps
99          * track of the current selected device partition.
100          */
101         unsigned int    part_curr;
102         struct device_attribute force_ro;
103         struct device_attribute power_ro_lock;
104         int     area_type;
105 };
106
107 extern int mmc_init_queue(struct mmc_queue *, struct mmc_card *, spinlock_t *,
108                           const char *);
109 extern void mmc_cleanup_queue(struct mmc_queue *);
110 extern void mmc_queue_suspend(struct mmc_queue *);
111 extern void mmc_queue_resume(struct mmc_queue *);
112
113 extern unsigned int mmc_queue_map_sg(struct mmc_queue *,
114                                      struct mmc_queue_req *);
115 extern void mmc_queue_bounce_pre(struct mmc_queue_req *);
116 extern void mmc_queue_bounce_post(struct mmc_queue_req *);
117
118 extern int mmc_packed_init(struct mmc_queue *, struct mmc_card *);
119 extern void mmc_packed_clean(struct mmc_queue *);
120
121 extern int mmc_access_rpmb(struct mmc_queue *);
122 void mmc_blk_emmc_remove(struct mmc_card *card);
123 void mmc_blk_emmc_add(struct mmc_card *card, size_t data_size);
124
125 #endif