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

  • Committer: Suren A. Chilingaryan
  • Date: 2015-04-20 20:01:04 UTC
  • Revision ID: csa@suren.me-20150420200104-b5xny65io8lvoz3w
Big redign of model structures

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
    val = packet_size;
26
26
    nwl_write_register(val, ctx, ctx->base_addr, PKT_SIZE_ADDRESS);
27
27
 
28
 
    if (ctx->type == PCILIB_DMA_MODIFICATION_DEFAULT) {
 
28
    if (ctx->type == NWL_MODIFICATION_DEFAULT) {
29
29
        switch (direction) {
30
30
          case PCILIB_DMA_BIDIRECTIONAL:
31
31
            val = LOOPBACK;
54
54
        engine initialized in previous run, and benchmark is only actual usage.
55
55
        Otherwise, we should detect current loopback status during initialization */
56
56
 
57
 
    if (ctx->type == PCILIB_DMA_MODIFICATION_DEFAULT) {
 
57
    if (ctx->type == NWL_MODIFICATION_DEFAULT) {
58
58
        nwl_write_register(val, ctx, ctx->base_addr, TX_CONFIG_ADDRESS);
59
59
        nwl_write_register(val, ctx, ctx->base_addr, RX_CONFIG_ADDRESS);
60
60
    }
77
77
 
78
78
    nwl_dma_t *ctx = (nwl_dma_t*)vctx;
79
79
 
80
 
    pcilib_dma_engine_t readid = pcilib_find_dma_by_addr(ctx->pcilib, PCILIB_DMA_FROM_DEVICE, dma);
81
 
    pcilib_dma_engine_t writeid = pcilib_find_dma_by_addr(ctx->pcilib, PCILIB_DMA_TO_DEVICE, dma);
 
80
    pcilib_dma_engine_t readid = pcilib_find_dma_by_addr(ctx->dmactx.pcilib, PCILIB_DMA_FROM_DEVICE, dma);
 
81
    pcilib_dma_engine_t writeid = pcilib_find_dma_by_addr(ctx->dmactx.pcilib, PCILIB_DMA_TO_DEVICE, dma);
82
82
 
83
83
    if (size%sizeof(uint32_t)) size = 1 + size / sizeof(uint32_t);
84
84
    else size /= sizeof(uint32_t);
85
85
 
86
86
        // Not supported
87
 
    if (ctx->type == PCILIB_DMA_MODIFICATION_DEFAULT) {
 
87
    if (ctx->type == NWL_MODIFICATION_DEFAULT) {
88
88
        if (direction == PCILIB_DMA_TO_DEVICE) return -1.;
89
89
    }
90
 
//    else if ((direction == PCILIB_DMA_FROM_DEVICE)&&(ctx->type != PCILIB_DMA_MODIFICATION_DEFAULT)) return -1.;
 
90
//    else if ((direction == PCILIB_DMA_FROM_DEVICE)&&(ctx->type != NWL_MODIFICATION_DEFAULT)) return -1.;
91
91
 
92
92
        // Stop Generators and drain old data
93
 
    if (ctx->type == PCILIB_DMA_MODIFICATION_DEFAULT) dma_nwl_stop_loopback(ctx);
 
93
    if (ctx->type == NWL_MODIFICATION_DEFAULT) dma_nwl_stop_loopback(ctx);
94
94
//    dma_nwl_stop_engine(ctx, readid); // DS: replace with something better
95
95
 
96
96
    __sync_synchronize();
97
97
 
98
 
    err = pcilib_skip_dma(ctx->pcilib, readid);
 
98
    err = pcilib_skip_dma(ctx->dmactx.pcilib, readid);
99
99
    if (err) {
100
100
        pcilib_error("Can't start benchmark, devices continuously writes unexpected data using DMA engine");
101
101
        return -1;
125
125
        return -1;
126
126
    }
127
127
 
128
 
    if (ctx->type == PCILIB_NWL_MODIFICATION_IPECAMERA) {
129
 
        pcilib_write_register(ctx->pcilib, NULL, "control", 0x1e5);
 
128
    if (ctx->type == NWL_MODIFICATION_IPECAMERA) {
 
129
        pcilib_write_register(ctx->dmactx.pcilib, NULL, "control", 0x1e5);
130
130
        usleep(100000);
131
 
        pcilib_write_register(ctx->pcilib, NULL, "control", 0x1e1);
 
131
        pcilib_write_register(ctx->dmactx.pcilib, NULL, "control", 0x1e1);
132
132
 
133
133
            // This way causes more problems with garbage
134
 
        //pcilib_write_register(ctx->pcilib, NULL, "control", 0x3e1);
 
134
        //pcilib_write_register(ctx->dmactx.pcilib, NULL, "control", 0x3e1);
135
135
    }
136
136
 
137
137
        // Benchmark
138
138
    for (iter = 0; iter < iterations; iter++) {
139
139
        memset(cmp, 0x13 + iter, size * sizeof(uint32_t));
140
140
 
141
 
        if (ctx->type == PCILIB_NWL_MODIFICATION_IPECAMERA) {
142
 
            pcilib_write_register(ctx->pcilib, NULL, "control", 0x1e1);
 
141
        if (ctx->type == NWL_MODIFICATION_IPECAMERA) {
 
142
            pcilib_write_register(ctx->dmactx.pcilib, NULL, "control", 0x1e1);
143
143
        }
144
144
 
145
 
        if ((direction&PCILIB_DMA_TO_DEVICE)||(ctx->type != PCILIB_DMA_MODIFICATION_DEFAULT)) {
 
145
        if ((direction&PCILIB_DMA_TO_DEVICE)||(ctx->type != NWL_MODIFICATION_DEFAULT)) {
146
146
            memcpy(buf, cmp, size * sizeof(uint32_t));
147
147
 
148
148
            if (direction&PCILIB_DMA_TO_DEVICE) {
149
149
                gettimeofday(&start, NULL);
150
150
            }
151
151
            
152
 
            err = pcilib_write_dma(ctx->pcilib, writeid, addr, size * sizeof(uint32_t), buf, &bytes);
 
152
            err = pcilib_write_dma(ctx->dmactx.pcilib, writeid, addr, size * sizeof(uint32_t), buf, &bytes);
153
153
            if ((err)||(bytes != size * sizeof(uint32_t))) {
154
154
                error = "Write failed";
155
155
                break;
165
165
            }
166
166
        }
167
167
 
168
 
        if (ctx->type == PCILIB_NWL_MODIFICATION_IPECAMERA) {
169
 
            pcilib_write_register(ctx->pcilib, NULL, "control", 0x3e1);
 
168
        if (ctx->type == NWL_MODIFICATION_IPECAMERA) {
 
169
            pcilib_write_register(ctx->dmactx.pcilib, NULL, "control", 0x3e1);
170
170
        }
171
171
 
172
172
        memset(buf, 0, size * sizeof(uint32_t));
180
180
            retry:
181
181
#endif
182
182
    
183
 
            err = pcilib_read_dma(ctx->pcilib, readid, addr, packet_size * sizeof(uint32_t), buf + (bytes>>2), &rbytes);
 
183
            err = pcilib_read_dma(ctx->dmactx.pcilib, readid, addr, packet_size * sizeof(uint32_t), buf + (bytes>>2), &rbytes);
184
184
            if ((err)||(rbytes%sizeof(uint32_t))) {
185
185
                break;
186
186
            } 
227
227
#endif
228
228
    }
229
229
 
230
 
    if (ctx->type == PCILIB_NWL_MODIFICATION_IPECAMERA) {
231
 
        pcilib_write_register(ctx->pcilib, NULL, "control", 0x1e1);
 
230
    if (ctx->type == NWL_MODIFICATION_IPECAMERA) {
 
231
        pcilib_write_register(ctx->dmactx.pcilib, NULL, "control", 0x1e1);
232
232
    }
233
233
 
234
234
    if (error) {
245
245
    __sync_synchronize();
246
246
    
247
247
    if (direction == PCILIB_DMA_FROM_DEVICE) {
248
 
        pcilib_skip_dma(ctx->pcilib, readid);
 
248
        pcilib_skip_dma(ctx->dmactx.pcilib, readid);
249
249
    }
250
250
    
251
251
    free(cmp);