@@ -131,10 +131,12 @@ struct moxart_host {
131
131
struct dma_async_tx_descriptor * tx_desc ;
132
132
struct mmc_host * mmc ;
133
133
struct mmc_request * mrq ;
134
+ struct scatterlist * cur_sg ;
134
135
struct completion dma_complete ;
135
136
struct completion pio_complete ;
136
137
137
- struct sg_mapping_iter sg_miter ;
138
+ u32 num_sg ;
139
+ u32 data_remain ;
138
140
u32 data_len ;
139
141
u32 fifo_width ;
140
142
u32 timeout ;
@@ -146,6 +148,35 @@ struct moxart_host {
146
148
bool is_removed ;
147
149
};
148
150
151
+ static inline void moxart_init_sg (struct moxart_host * host ,
152
+ struct mmc_data * data )
153
+ {
154
+ host -> cur_sg = data -> sg ;
155
+ host -> num_sg = data -> sg_len ;
156
+ host -> data_remain = host -> cur_sg -> length ;
157
+
158
+ if (host -> data_remain > host -> data_len )
159
+ host -> data_remain = host -> data_len ;
160
+ }
161
+
162
+ static inline int moxart_next_sg (struct moxart_host * host )
163
+ {
164
+ int remain ;
165
+ struct mmc_data * data = host -> mrq -> cmd -> data ;
166
+
167
+ host -> cur_sg ++ ;
168
+ host -> num_sg -- ;
169
+
170
+ if (host -> num_sg > 0 ) {
171
+ host -> data_remain = host -> cur_sg -> length ;
172
+ remain = host -> data_len - data -> bytes_xfered ;
173
+ if (remain > 0 && remain < host -> data_remain )
174
+ host -> data_remain = remain ;
175
+ }
176
+
177
+ return host -> num_sg ;
178
+ }
179
+
149
180
static int moxart_wait_for_status (struct moxart_host * host ,
150
181
u32 mask , u32 * status )
151
182
{
@@ -278,29 +309,14 @@ static void moxart_transfer_dma(struct mmc_data *data, struct moxart_host *host)
278
309
279
310
static void moxart_transfer_pio (struct moxart_host * host )
280
311
{
281
- struct sg_mapping_iter * sgm = & host -> sg_miter ;
282
312
struct mmc_data * data = host -> mrq -> cmd -> data ;
283
313
u32 * sgp , len = 0 , remain , status ;
284
314
285
315
if (host -> data_len == data -> bytes_xfered )
286
316
return ;
287
317
288
- /*
289
- * By updating sgm->consumes this will get a proper pointer into the
290
- * buffer at any time.
291
- */
292
- if (!sg_miter_next (sgm )) {
293
- /* This shold not happen */
294
- dev_err (mmc_dev (host -> mmc ), "ran out of scatterlist prematurely\n" );
295
- data -> error = - EINVAL ;
296
- complete (& host -> pio_complete );
297
- return ;
298
- }
299
- sgp = sgm -> addr ;
300
- remain = sgm -> length ;
301
- if (remain > host -> data_len )
302
- remain = host -> data_len ;
303
- sgm -> consumed = 0 ;
318
+ sgp = sg_virt (host -> cur_sg );
319
+ remain = host -> data_remain ;
304
320
305
321
if (data -> flags & MMC_DATA_WRITE ) {
306
322
while (remain > 0 ) {
@@ -315,7 +331,6 @@ static void moxart_transfer_pio(struct moxart_host *host)
315
331
sgp ++ ;
316
332
len += 4 ;
317
333
}
318
- sgm -> consumed += len ;
319
334
remain -= len ;
320
335
}
321
336
@@ -332,22 +347,22 @@ static void moxart_transfer_pio(struct moxart_host *host)
332
347
sgp ++ ;
333
348
len += 4 ;
334
349
}
335
- sgm -> consumed += len ;
336
350
remain -= len ;
337
351
}
338
352
}
339
353
340
- data -> bytes_xfered += sgm -> consumed ;
341
- if (host -> data_len == data -> bytes_xfered ) {
354
+ data -> bytes_xfered += host -> data_remain - remain ;
355
+ host -> data_remain = remain ;
356
+
357
+ if (host -> data_len != data -> bytes_xfered )
358
+ moxart_next_sg (host );
359
+ else
342
360
complete (& host -> pio_complete );
343
- return ;
344
- }
345
361
}
346
362
347
363
static void moxart_prepare_data (struct moxart_host * host )
348
364
{
349
365
struct mmc_data * data = host -> mrq -> cmd -> data ;
350
- unsigned int flags = SG_MITER_ATOMIC ; /* Used from IRQ */
351
366
u32 datactrl ;
352
367
int blksz_bits ;
353
368
@@ -358,19 +373,15 @@ static void moxart_prepare_data(struct moxart_host *host)
358
373
blksz_bits = ffs (data -> blksz ) - 1 ;
359
374
BUG_ON (1 << blksz_bits != data -> blksz );
360
375
376
+ moxart_init_sg (host , data );
377
+
361
378
datactrl = DCR_DATA_EN | (blksz_bits & DCR_BLK_SIZE );
362
379
363
- if (data -> flags & MMC_DATA_WRITE ) {
364
- flags |= SG_MITER_FROM_SG ;
380
+ if (data -> flags & MMC_DATA_WRITE )
365
381
datactrl |= DCR_DATA_WRITE ;
366
- } else {
367
- flags |= SG_MITER_TO_SG ;
368
- }
369
382
370
383
if (moxart_use_dma (host ))
371
384
datactrl |= DCR_DMA_EN ;
372
- else
373
- sg_miter_start (& host -> sg_miter , data -> sg , data -> sg_len , flags );
374
385
375
386
writel (DCR_DATA_FIFO_RESET , host -> base + REG_DATA_CONTROL );
376
387
writel (MASK_DATA | FIFO_URUN | FIFO_ORUN , host -> base + REG_CLEAR );
@@ -443,9 +454,6 @@ static void moxart_request(struct mmc_host *mmc, struct mmc_request *mrq)
443
454
}
444
455
445
456
request_done :
446
- if (!moxart_use_dma (host ))
447
- sg_miter_stop (& host -> sg_miter );
448
-
449
457
spin_unlock_irqrestore (& host -> lock , flags );
450
458
mmc_request_done (host -> mmc , mrq );
451
459
}
0 commit comments