/alps/pcitool

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/pcitool

« back to all changes in this revision

Viewing changes to dma/nwl_engine_buffers.h

  • Committer: Suren A. Chilingaryan
  • Date: 2011-10-26 05:12:31 UTC
  • Revision ID: csa@dside.dyndns.org-20111026051231-5ntkozz31hvjzvb5
Improvements of DMA engine

Show diffs side-by-side

added added

removed removed

Lines of Context:
276
276
    
277
277
    val = ring_pa + info->head * PCILIB_NWL_DMA_DESCRIPTOR_SIZE;
278
278
    nwl_write_register(val, ctx, info->base_addr, REG_SW_NEXT_BD);
279
 
//    nwl_read_register(val, ctx, info->base_addr, 0x18);
280
 
 
281
 
//    usleep(10000);
282
 
 
283
 
//    nwl_read_register(val, ctx, info->base_addr, REG_DMA_ENG_LAST_BD);
284
 
//    printf("Last BD(Write): %lx %lx\n", ring, val);
285
 
    
286
279
    
287
280
    return 0;
288
281
}
293
286
    struct timeval start, cur;
294
287
    uint32_t status_size, status, control;
295
288
 
296
 
//    usleep(10000);
297
 
    
298
289
    unsigned char *ring = pcilib_kmem_get_ua(ctx->pcilib, info->ring);
299
290
    
300
 
//    status_size = NWL_RING_GET(ring, DMA_BD_BUFL_STATUS_OFFSET);
301
 
//    printf("Status0: %lx\n", status_size);
302
 
 
303
291
    ring += info->tail * PCILIB_NWL_DMA_DESCRIPTOR_SIZE;
304
292
 
305
293
    gettimeofday(&start, NULL);
306
294
    
307
 
//    printf("Waiting %li\n", info->tail);
308
 
//    nwl_read_register(val, ctx, info->base_addr, REG_DMA_ENG_LAST_BD);
309
 
//    printf("Last BD(Read): %lx %lx\n", ring, val);
310
 
 
311
295
    do {
312
296
        status_size = NWL_RING_GET(ring, DMA_BD_BUFL_STATUS_OFFSET);
313
297
        status = status_size & DMA_BD_STATUS_MASK;
314
298
        
315
 
//      printf("%i: %lx\n", info->tail, status_size);
316
 
    
317
299
        if (status & DMA_BD_ERROR_MASK) {
318
300
            pcilib_error("NWL DMA Engine reported error in ring descriptor");
319
301
            return (size_t)-1;
322
304
        if (status & DMA_BD_COMP_MASK) {
323
305
            if (status & DMA_BD_EOP_MASK) *eop = 1;
324
306
            else *eop = 0;
325
 
        
 
307
                    
326
308
            *size = status_size & DMA_BD_BUFL_MASK;
 
309
 
 
310
/*          
 
311
            if (mrd) {
 
312
                if ((info->tail + 1) == info->ring_size) ring -= info->tail * PCILIB_NWL_DMA_DESCRIPTOR_SIZE;
 
313
                else ring += PCILIB_NWL_DMA_DESCRIPTOR_SIZE;
 
314
                *mrd = NWL_RING_GET(ring, DMA_BD_BUFL_STATUS_OFFSET)&DMA_BD_COMP_MASK;
 
315
            }
 
316
*/
327
317
        
328
 
//          printf("Status: %lx\n", status_size);
329
318
            return info->tail;
330
319
        }
331
320
        
333
322
        gettimeofday(&cur, NULL);
334
323
    } while ((timeout == PCILIB_TIMEOUT_INFINITE)||(((cur.tv_sec - start.tv_sec)*1000000 + (cur.tv_usec - start.tv_usec)) < timeout));
335
324
 
336
 
//    printf("Final status: %lx\n", status_size);
337
 
    
338
325
    return (size_t)-1;
339
326
}
340
327
 
 
328
static int dma_nwl_is_overflown(nwl_dma_t *ctx, pcilib_nwl_engine_description_t *info) {
 
329
    uint32_t status;
 
330
    unsigned char *ring = pcilib_kmem_get_ua(ctx->pcilib, info->ring);
 
331
    if (info->tail > 0) ring += (info->tail - 1) * PCILIB_NWL_DMA_DESCRIPTOR_SIZE;
 
332
    else ring += (info->ring_size - 1) * PCILIB_NWL_DMA_DESCRIPTOR_SIZE;
 
333
 
 
334
    status = NWL_RING_GET(ring, DMA_BD_BUFL_STATUS_OFFSET);
 
335
    return status&DMA_BD_COMP_MASK?1:0;
 
336
}
 
337
 
341
338
static int dma_nwl_return_buffer(nwl_dma_t *ctx, pcilib_nwl_engine_description_t *info) {
342
339
    uint32_t val;
343
340
 
346
343
    size_t bufsz = pcilib_kmem_get_block_size(ctx->pcilib, info->pages, info->tail);
347
344
 
348
345
    ring += info->tail * PCILIB_NWL_DMA_DESCRIPTOR_SIZE;
349
 
//    printf("Returning: %i\n", info->tail);
350
346
 
351
347
#ifdef NWL_GENERATE_DMA_IRQ    
352
348
    NWL_RING_SET(ring, DMA_BD_BUFL_CTRL_OFFSET, bufsz | DMA_BD_INT_ERROR_MASK | DMA_BD_INT_COMP_MASK);
358
354
 
359
355
    val = ring_pa + info->tail * PCILIB_NWL_DMA_DESCRIPTOR_SIZE;
360
356
    nwl_write_register(val, ctx, info->base_addr, REG_SW_NEXT_BD);
361
 
//    nwl_read_register(val, ctx, info->base_addr, 0x18);
362
357
    
363
358
    info->tail++;
364
359
    if (info->tail == info->ring_size) info->tail = 0;
365
360
}
366
361
 
367
 
int dma_nwl_get_status(pcilib_t *vctx, pcilib_dma_engine_t dma, pcilib_dma_engine_status_t *status, size_t n_buffers, pcilib_dma_buffer_status_t *buffers) {
 
362
int dma_nwl_get_status(pcilib_dma_context_t *vctx, pcilib_dma_engine_t dma, pcilib_dma_engine_status_t *status, size_t n_buffers, pcilib_dma_buffer_status_t *buffers) {
368
363
    size_t i;
369
364
    uint32_t bstatus;
370
365
    nwl_dma_t *ctx = (nwl_dma_t*)vctx;
410
405
    
411
406
    return 0;
412
407
}
413
 
 
414
 
/*
415
 
    unsigned char *ring = pcilib_kmem_get_ua(ctx->pcilib, info->ring);
416
 
    
417
 
//    status_size = NWL_RING_GET(ring, DMA_BD_BUFL_STATUS_OFFSET);
418
 
//    printf("Status0: %lx\n", status_size);
419
 
 
420
 
    ring += info->tail * PCILIB_NWL_DMA_DESCRIPTOR_SIZE;
421
 
 
422
 
    gettimeofday(&start, NULL);
423
 
    
424
 
//    printf("Waiting %li\n", info->tail);
425
 
//    nwl_read_register(val, ctx, info->base_addr, REG_DMA_ENG_LAST_BD);
426
 
//    printf("Last BD(Read): %lx %lx\n", ring, val);
427
 
 
428
 
    do {
429
 
        status_size = NWL_RING_GET(ring, DMA_BD_BUFL_STATUS_OFFSET);
430
 
        status = status_size & DMA_BD_STATUS_MASK;
431
 
        
432
 
//      printf("%i: %lx\n", info->tail, status_size);
433
 
    
434
 
        if (status & DMA_BD_ERROR_MASK) {
435
 
            pcilib_error("NWL DMA Engine reported error in ring descriptor");
436
 
            return (size_t)-1;
437
 
        }       
438
 
        
439
 
        if (status & DMA_BD_COMP_MASK) {
440
 
            if (status & DMA_BD_EOP_MASK) *eop = 1;
441
 
            else *eop = 0;
442
 
        
443
 
            *size = status_size & DMA_BD_BUFL_MASK;
444
 
        
445
 
//          printf("Status: %lx\n", status_size);
446
 
            return info->tail;
447
 
        }
448
 
        
449
 
        usleep(10);
450
 
        gettimeofday(&cur, NULL);
451
 
    } while ((timeout == PCILIB_TIMEOUT_INFINITE)||(((cur.tv_sec - start.tv_sec)*1000000 + (cur.tv_usec - start.tv_usec)) < timeout));
452
 
*/
 
 
b'\\ No newline at end of file'