/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/ipe.c

  • Committer: Suren A. Chilingaryan
  • Date: 2015-01-25 03:53:58 UTC
  • Revision ID: csa@suren.me-20150125035358-cgztq7br1h0hj49u
Add delays to workaround problems in IPEDMA. Also provide other modifications to reflect minor changes in hardware

Show diffs side-by-side

added added

removed removed

Lines of Context:
84
84
    volatile void *desc_va;
85
85
    volatile uint32_t *last_written_addr_ptr;
86
86
 
87
 
    pcilib_register_value_t value;
 
87
    pcilib_register_value_t value, value2;
88
88
 
89
89
    if (dma == PCILIB_DMA_ENGINE_INVALID) return 0;
90
90
    else if (dma > 1) return PCILIB_ERROR_INVALID_BANK;
116
116
#ifndef IPEDMA_BUG_DMARD
117
117
                RD(IPEDMA_REG_PAGE_COUNT, value);
118
118
 
119
 
                if ((value + 1) != IPEDMA_DMA_PAGES) pcilib_warning("Inconsistent DMA buffers are found (Number of allocated buffers does not match current request), reinitializing...");
 
119
                if (value != IPEDMA_DMA_PAGES) pcilib_warning("Inconsistent DMA buffers are found (Number of allocated buffers (%lu) does not match current request (%lu)), reinitializing...", value + 1, IPEDMA_DMA_PAGES);
120
120
                else
121
121
#endif /* IPEDMA_BUG_DMARD */
122
122
                    preserve = 1;
152
152
 
153
153
            // Disable DMA
154
154
        WR(IPEDMA_REG_CONTROL, 0x0);
 
155
        usleep(100000);
155
156
        
156
157
            // Reset DMA engine
157
158
        WR(IPEDMA_REG_RESET, 0x1);
158
159
        usleep(100000);
159
160
        WR(IPEDMA_REG_RESET, 0x0);
 
161
        usleep(100000);
160
162
 
161
163
#ifndef IPEDMA_BUG_DMARD
162
164
            // Verify PCIe link status
163
165
        RD(IPEDMA_REG_RESET, value);
164
 
        if (value != 0x14031700) pcilib_warning("PCIe is not ready");
 
166
        if (value != 0x14031700) pcilib_warning("PCIe is not ready, code is %lx", value);
165
167
#endif /* IPEDMA_BUG_DMARD */
166
 
 
 
168
 
167
169
            // Configuring TLP and PACKET sizes (40 bit mode can be used with big pre-allocated buffers later)
168
170
        WR(IPEDMA_REG_TLP_SIZE, IPEDMA_TLP_SIZE);
169
171
        WR(IPEDMA_REG_TLP_COUNT, IPEDMA_PAGE_SIZE / (4 * IPEDMA_TLP_SIZE * IPEDMA_CORES));
183
185
 
184
186
        
185
187
        for (i = 0; i < IPEDMA_DMA_PAGES; i++) {
186
 
            uintptr_t bus_addr = pcilib_kmem_get_block_ba(ctx->pcilib, pages, i);
 
188
            uintptr_t bus_addr_check, bus_addr = pcilib_kmem_get_block_ba(ctx->pcilib, pages, i);
187
189
            WR(IPEDMA_REG_PAGE_ADDR, bus_addr);
188
190
            if (bus_addr%4096) printf("Bad address %lu: %lx\n", i, bus_addr);
 
191
            
 
192
            RD(IPEDMA_REG_PAGE_ADDR, bus_addr_check);
 
193
            if (bus_addr_check != bus_addr) {
 
194
                pcilib_error("Written (%x) and read (%x) bus addresses does not match\n", bus_addr, bus_addr_check);
 
195
            }
 
196
            
189
197
            usleep(1000);
190
198
        }
191
199
        
192
200
            // Enable DMA
193
 
        WR(IPEDMA_REG_CONTROL, 0x1);
 
201
//      WR(IPEDMA_REG_CONTROL, 0x1);
194
202
        
195
203
        ctx->last_read = IPEDMA_DMA_PAGES - 1;
196
204
 
203
211
#endif /* IPEDMA_BUG_DMARD */
204
212
    }
205
213
 
206
 
    ctx->last_read_addr = htonl(pcilib_kmem_get_block_ba(ctx->pcilib, pages, ctx->last_read));
 
214
//    ctx->last_read_addr = htonl(pcilib_kmem_get_block_ba(ctx->pcilib, pages, ctx->last_read));
 
215
    ctx->last_read_addr = pcilib_kmem_get_block_ba(ctx->pcilib, pages, ctx->last_read);
207
216
 
208
217
 
209
218
    ctx->desc = desc;
237
246
 
238
247
            // Disable DMA
239
248
        WR(IPEDMA_REG_CONTROL, 0);
 
249
        usleep(100000);
240
250
        
241
251
            // Reset DMA engine
242
252
        WR(IPEDMA_REG_RESET, 0x1);
243
253
        usleep(100000);
244
254
        WR(IPEDMA_REG_RESET, 0x0);
 
255
        usleep(100000);
245
256
 
246
257
            // Reseting configured DMA pages
247
258
        WR(IPEDMA_REG_PAGE_COUNT, 0);
 
259
        usleep(100000);
248
260
    }
249
261
 
250
262
        // Clean buffers
392
404
        WR(IPEDMA_REG_LAST_READ, ctx->last_read + 1);
393
405
 
394
406
        ctx->last_read = cur_read;
395
 
        ctx->last_read_addr = htonl(pcilib_kmem_get_block_ba(ctx->pcilib, ctx->pages, cur_read));
 
407
//      ctx->last_read_addr = htonl(pcilib_kmem_get_block_ba(ctx->pcilib, ctx->pages, cur_read));
 
408
        ctx->last_read_addr = pcilib_kmem_get_block_ba(ctx->pcilib, ctx->pages, cur_read);
396
409
 
397
410
#ifdef IPEDMA_BUG_DMARD
398
411
        FILE *f = fopen("/tmp/pcitool_lastread", "w");