aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/mtd/ubi/block.c202
1 files changed, 94 insertions, 108 deletions
diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c
index 6b6bce28bd63..00caf460337e 100644
--- a/drivers/mtd/ubi/block.c
+++ b/drivers/mtd/ubi/block.c
@@ -42,11 +42,12 @@
42#include <linux/list.h> 42#include <linux/list.h>
43#include <linux/mutex.h> 43#include <linux/mutex.h>
44#include <linux/slab.h> 44#include <linux/slab.h>
45#include <linux/vmalloc.h>
46#include <linux/mtd/ubi.h> 45#include <linux/mtd/ubi.h>
47#include <linux/workqueue.h> 46#include <linux/workqueue.h>
48#include <linux/blkdev.h> 47#include <linux/blkdev.h>
48#include <linux/blk-mq.h>
49#include <linux/hdreg.h> 49#include <linux/hdreg.h>
50#include <linux/scatterlist.h>
50#include <asm/div64.h> 51#include <asm/div64.h>
51 52
52#include "ubi-media.h" 53#include "ubi-media.h"
@@ -67,6 +68,11 @@ struct ubiblock_param {
67 char name[UBIBLOCK_PARAM_LEN+1]; 68 char name[UBIBLOCK_PARAM_LEN+1];
68}; 69};
69 70
71struct ubiblock_pdu {
72 struct work_struct work;
73 struct ubi_sgl usgl;
74};
75
70/* Numbers of elements set in the @ubiblock_param array */ 76/* Numbers of elements set in the @ubiblock_param array */
71static int ubiblock_devs __initdata; 77static int ubiblock_devs __initdata;
72 78
@@ -84,11 +90,10 @@ struct ubiblock {
84 struct request_queue *rq; 90 struct request_queue *rq;
85 91
86 struct workqueue_struct *wq; 92 struct workqueue_struct *wq;
87 struct work_struct work;
88 93
89 struct mutex dev_mutex; 94 struct mutex dev_mutex;
90 spinlock_t queue_lock;
91 struct list_head list; 95 struct list_head list;
96 struct blk_mq_tag_set tag_set;
92}; 97};
93 98
94/* Linked list of all ubiblock instances */ 99/* Linked list of all ubiblock instances */
@@ -181,31 +186,20 @@ static struct ubiblock *find_dev_nolock(int ubi_num, int vol_id)
181 return NULL; 186 return NULL;
182} 187}
183 188
184static int ubiblock_read_to_buf(struct ubiblock *dev, char *buffer, 189static int ubiblock_read(struct ubiblock_pdu *pdu)
185 int leb, int offset, int len)
186{ 190{
187 int ret; 191 int ret, leb, offset, bytes_left, to_read;
192 u64 pos;
193 struct request *req = blk_mq_rq_from_pdu(pdu);
194 struct ubiblock *dev = req->q->queuedata;
188 195
189 ret = ubi_read(dev->desc, leb, buffer, offset, len); 196 to_read = blk_rq_bytes(req);
190 if (ret) { 197 pos = blk_rq_pos(req) << 9;
191 dev_err(disk_to_dev(dev->gd), "%d while reading from LEB %d (offset %d, length %d)",
192 ret, leb, offset, len);
193 return ret;
194 }
195 return 0;
196}
197
198static int ubiblock_read(struct ubiblock *dev, char *buffer,
199 sector_t sec, int len)
200{
201 int ret, leb, offset;
202 int bytes_left = len;
203 int to_read = len;
204 u64 pos = sec << 9;
205 198
206 /* Get LEB:offset address to read from */ 199 /* Get LEB:offset address to read from */
207 offset = do_div(pos, dev->leb_size); 200 offset = do_div(pos, dev->leb_size);
208 leb = pos; 201 leb = pos;
202 bytes_left = to_read;
209 203
210 while (bytes_left) { 204 while (bytes_left) {
211 /* 205 /*
@@ -215,11 +209,10 @@ static int ubiblock_read(struct ubiblock *dev, char *buffer,
215 if (offset + to_read > dev->leb_size) 209 if (offset + to_read > dev->leb_size)
216 to_read = dev->leb_size - offset; 210 to_read = dev->leb_size - offset;
217 211
218 ret = ubiblock_read_to_buf(dev, buffer, leb, offset, to_read); 212 ret = ubi_read_sg(dev->desc, leb, &pdu->usgl, offset, to_read);
219 if (ret) 213 if (ret < 0)
220 return ret; 214 return ret;
221 215
222 buffer += to_read;
223 bytes_left -= to_read; 216 bytes_left -= to_read;
224 to_read = bytes_left; 217 to_read = bytes_left;
225 leb += 1; 218 leb += 1;
@@ -228,79 +221,6 @@ static int ubiblock_read(struct ubiblock *dev, char *buffer,
228 return 0; 221 return 0;
229} 222}
230 223
231static int do_ubiblock_request(struct ubiblock *dev, struct request *req)
232{
233 int len, ret;
234 sector_t sec;
235
236 if (req->cmd_type != REQ_TYPE_FS)
237 return -EIO;
238
239 if (blk_rq_pos(req) + blk_rq_cur_sectors(req) >
240 get_capacity(req->rq_disk))
241 return -EIO;
242
243 if (rq_data_dir(req) != READ)
244 return -ENOSYS; /* Write not implemented */
245
246 sec = blk_rq_pos(req);
247 len = blk_rq_cur_bytes(req);
248
249 /*
250 * Let's prevent the device from being removed while we're doing I/O
251 * work. Notice that this means we serialize all the I/O operations,
252 * but it's probably of no impact given the NAND core serializes
253 * flash access anyway.
254 */
255 mutex_lock(&dev->dev_mutex);
256 ret = ubiblock_read(dev, bio_data(req->bio), sec, len);
257 mutex_unlock(&dev->dev_mutex);
258
259 return ret;
260}
261
262static void ubiblock_do_work(struct work_struct *work)
263{
264 struct ubiblock *dev =
265 container_of(work, struct ubiblock, work);
266 struct request_queue *rq = dev->rq;
267 struct request *req;
268 int res;
269
270 spin_lock_irq(rq->queue_lock);
271
272 req = blk_fetch_request(rq);
273 while (req) {
274
275 spin_unlock_irq(rq->queue_lock);
276 res = do_ubiblock_request(dev, req);
277 spin_lock_irq(rq->queue_lock);
278
279 /*
280 * If we're done with this request,
281 * we need to fetch a new one
282 */
283 if (!__blk_end_request_cur(req, res))
284 req = blk_fetch_request(rq);
285 }
286
287 spin_unlock_irq(rq->queue_lock);
288}
289
290static void ubiblock_request(struct request_queue *rq)
291{
292 struct ubiblock *dev;
293 struct request *req;
294
295 dev = rq->queuedata;
296
297 if (!dev)
298 while ((req = blk_fetch_request(rq)) != NULL)
299 __blk_end_request_all(req, -ENODEV);
300 else
301 queue_work(dev->wq, &dev->work);
302}
303
304static int ubiblock_open(struct block_device *bdev, fmode_t mode) 224static int ubiblock_open(struct block_device *bdev, fmode_t mode)
305{ 225{
306 struct ubiblock *dev = bdev->bd_disk->private_data; 226 struct ubiblock *dev = bdev->bd_disk->private_data;
@@ -374,6 +294,57 @@ static const struct block_device_operations ubiblock_ops = {
374 .getgeo = ubiblock_getgeo, 294 .getgeo = ubiblock_getgeo,
375}; 295};
376 296
297static void ubiblock_do_work(struct work_struct *work)
298{
299 int ret;
300 struct ubiblock_pdu *pdu = container_of(work, struct ubiblock_pdu, work);
301 struct request *req = blk_mq_rq_from_pdu(pdu);
302
303 blk_mq_start_request(req);
304 blk_rq_map_sg(req->q, req, pdu->usgl.sg);
305
306 ret = ubiblock_read(pdu);
307 blk_mq_end_request(req, ret);
308}
309
310static int ubiblock_queue_rq(struct blk_mq_hw_ctx *hctx,
311 const struct blk_mq_queue_data *bd)
312{
313 struct request *req = bd->rq;
314 struct ubiblock *dev = hctx->queue->queuedata;
315 struct ubiblock_pdu *pdu = blk_mq_rq_to_pdu(req);
316
317 if (req->cmd_type != REQ_TYPE_FS)
318 return BLK_MQ_RQ_QUEUE_ERROR;
319
320 if (rq_data_dir(req) != READ)