summaryrefslogtreecommitdiffstats
path: root/src/tools/g2/props.c
blob: 41df97ab7ddae9ff3a8a4986e69852b8f807f58a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/*
 *------------------------------------------------------------------
 * Copyright (c) 1997-2016 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <stdio.h>
#include <ctype.h>
#include <malloc.h>
#include <time.h>
#include <gtk/gtk.h>
#include <string.h>

static char *sxerox (char *s);
void exit(int);

#define NBUCKETS 97

typedef struct prop_ {
    struct prop_ *next;
    char *name;
    char *value;
} prop_t;

static prop_t *buckets [NBUCKETS];
static int hash_shifts[4] = {24, 16, 8, 0};

/*
 * getprop
 */

char *getprop (char *name)
{
    unsigned char *cp;
    unsigned long hash=0;
    prop_t *bp;
    int i=0;

    for (cp = (unsigned char *) name; *cp; cp++)
        hash ^= (*cp)<<(hash_shifts[(i++)&0x3]);

    bp = buckets [hash%NBUCKETS];

    while (bp && strcmp (bp->name, name)) {
        bp = bp->next;
    }

    if (bp == NULL)
        return (0);
    else
        return (bp->value);
}

/*
 * getprop_default
 */

char *getprop_default (char *name, char *def)
{
    char *rv;
    rv = getprop (name);
    if (rv)
        return (rv);
    else
        return (def);
}

/*
 * addprop
 */

void addprop (char *name, char *value)
{
    unsigned char *cp;
    unsigned long hash=0;
    prop_t **bpp;
    prop_t *bp;
    int i=0;

    bp = (prop_t *)g_malloc (sizeof (prop_t));

    bp->next = 0;
    bp->name = sxerox (name);
    bp->value = sxerox (value);

    for (cp = (unsigned char *)name; *cp; cp++)
        hash ^= (*cp)<<(hash_shifts[(i++)&0x3]);

    bpp = &buckets [hash%NBUCKETS];

    if (*bpp == NULL)
        *bpp = bp;
    else {
        bp->next = *bpp;
        *bpp = bp;
    }
}

/*
 * sxerox
 */

static char *sxerox (char *s)
{
    char *rv = (char *) g_malloc (strlen (s) + 1);
    strcpy (rv, s);
    return rv;
}

/*
 * readprops
 */

#define START 0
#define READNAME  1
#define READVALUE 2
#define C_COMMENT 3
#define CPP_COMMENT 4

int readprops (char *filename)
{
    FILE *ifp;
    unsigned char c;
    int state=START;
    int linenum=1;
    char namebuf [128];
    char valbuf [512];
    int i;

    ifp = fopen (filename, "r");

    if (ifp == NULL)
        return (-1);

    while (1) {

    readchar:
        c = getc (ifp);

    again:
        switch (state) {
        case START:
            if (feof (ifp)) {
                fclose (ifp);
                return (0);
            }

            if (c == ' ' || c == '\t')
                goto readchar;

            if (c == '\n') {
                linenum++;
                goto readchar;
            }
            if (isalpha (c) || (c == '_')) {
                state = READNAME;
                goto again;
            }
            if (c == '/') {
                c = getc (ifp);
                if (c == '/') {
                    state = CPP_COMMENT;
                    goto readchar;
                } else if (c == '*') {
                    state = C_COMMENT;
                    goto readchar;
                } else {
                    fprintf (stderr, "unknown token '/' line %d\n",
                             linenum);
                    exit (1);
                }
            }
            fprintf (stderr, "unknown token '%c' line %d\n",
                     c, linenum);
            exit (1);
            break;

        case CPP_COMMENT:
            while (1) {
                c = getc (ifp);
                if (feof (ifp))
                    return (0);
                if (c == '\n') {
                    linenum++;
                    state = START;
                    goto readchar;
                }
            }
            break;

        case C_COMMENT:
            while (1) {
                c = getc (ifp);
                if (feof (ifp)) {
                    fprintf (stderr, "unterminated comment, line %d\n",
                             linenum);
                    exit (1);
                }
                if (c == '*') {
                staragain:
                    c = getc (ifp);
                    if (c == '/') {
                        state = START;
                        goto readchar;
                    }
                    if (c == '*')
                        goto staragain;
                }
            }
            break;

        case READNAME:
            i = 0;
            namebuf[i++] = c;
            while (1) {
                c = getc (ifp);
                if (feof (ifp)) {
                    fprintf (stderr, "EOF while reading a name, line %d\n",
                             linenum);
                    exit (1);
                }
                if ((!isalnum (c)) && (c != '_')) {
                    namebuf [i] = 0;
                    state = READVALUE;
                    goto again;
                }
                namebuf [i++] = c;
            }
            break;

        case READVALUE:
            i = 0;
            while ((c == ' ') || (c == '\t') || (c == '=')) {
                c = getc (ifp);
                if (feof (ifp)) {
                    fprintf (stderr, "EOF while reading a value, line %d\n",
                             linenum);
                    exit (1);
                }
            }
            goto firsttime;
            while (1) {
                c = getc (ifp);

            firsttime:
                if (c == '\\') {
                    c = getc (ifp);
                    if (feof (ifp)) {
                        fprintf (stderr, "EOF after '\\', line %d\n",
                                 linenum);
                        exit (1);
                    }
                    valbuf[i++] = c;
                    continue;
                }
                if (c == '\n') {
                    linenum++;
                    while (valbuf [i-1] == ' ' || valbuf[i-1] == '\t')
                        i--;
                    valbuf[i] = 0;
                    addprop (namebuf, valbuf);
                    state = START;
                    goto readchar;
                }
                valbuf[i++] = c;
            }

        }
    }
}
class="gi">+ dev_err(enic, "error in allocation of data rq\n"); + goto err_free_rq_sop; + } + nb_data_desc = rq_data->ring.desc_count; + } rc = vnic_cq_alloc(enic->vdev, &enic->cq[queue_idx], queue_idx, - socket_id, nb_desc, - sizeof(struct cq_enet_rq_desc)); + socket_id, nb_sop_desc + nb_data_desc, + sizeof(struct cq_enet_rq_desc)); if (rc) { dev_err(enic, "error in allocation of cq for rq\n"); - goto err_free_rq_exit; + goto err_free_rq_data; } - /* Allocate the mbuf ring */ - rq->mbuf_ring = (struct rte_mbuf **)rte_zmalloc_socket("rq->mbuf_ring", - sizeof(struct rte_mbuf *) * nb_desc, - RTE_CACHE_LINE_SIZE, rq->socket_id); + /* Allocate the mbuf rings */ + rq_sop->mbuf_ring = (struct rte_mbuf **)rte_zmalloc_socket("rq->mbuf_ring", + sizeof(struct rte_mbuf *) * nb_sop_desc, + RTE_CACHE_LINE_SIZE, rq_sop->socket_id); + if (rq_sop->mbuf_ring == NULL) + goto err_free_cq; + + if (rq_data->in_use) { + rq_data->mbuf_ring = (struct rte_mbuf **)rte_zmalloc_socket("rq->mbuf_ring", + sizeof(struct rte_mbuf *) * nb_data_desc, + RTE_CACHE_LINE_SIZE, rq_sop->socket_id); + if (rq_data->mbuf_ring == NULL) + goto err_free_sop_mbuf; + } - if (rq->mbuf_ring != NULL) - return 0; + return 0; +err_free_sop_mbuf: + rte_free(rq_sop->mbuf_ring); +err_free_cq: /* cleanup on error */ vnic_cq_free(&enic->cq[queue_idx]); -err_free_rq_exit: - vnic_rq_free(rq); +err_free_rq_data: + if (rq_data->in_use) + vnic_rq_free(rq_data); +err_free_rq_sop: + vnic_rq_free(rq_sop); err_exit: return -ENOMEM; } diff -r -u dpdk-16.04.orig2/drivers/net/enic/enic_rxtx.c dpdk-16.04/drivers/net/enic/enic_rxtx.c --- dpdk-16.04.orig2/drivers/net/enic/enic_rxtx.c 2016-05-13 18:09:07.556940752 -0700 +++ dpdk-16.04/drivers/net/enic/enic_rxtx.c 2016-05-13 18:12:22.225755674 -0700 @@ -242,22 +242,27 @@ enic_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) { - struct vnic_rq *rq = rx_queue; - struct enic *enic = vnic_dev_priv(rq->vdev); - unsigned int rx_id; + struct vnic_rq *sop_rq = rx_queue; + struct vnic_rq *data_rq; + struct vnic_rq *rq; + struct enic *enic = vnic_dev_priv(sop_rq->vdev); + uint16_t cq_idx; + uint16_t rq_idx; + uint16_t rq_num; struct rte_mbuf *nmb, *rxmb; uint16_t nb_rx = 0; - uint16_t nb_hold; struct vnic_cq *cq; volatile struct cq_desc *cqd_ptr; uint8_t color; - uint16_t nb_err = 0; + uint16_t seg_length; + struct rte_mbuf *first_seg = sop_rq->pkt_first_seg; + struct rte_mbuf *last_seg = sop_rq->pkt_last_seg; + + cq = &enic->cq[enic_cq_rq(enic, sop_rq->index)]; + cq_idx = cq->to_clean; /* index of cqd, rqd, mbuf_table */ + cqd_ptr = (struct cq_desc *)(cq->ring.descs) + cq_idx; - cq = &enic->cq[enic_cq_rq(enic, rq->index)]; - rx_id = cq->to_clean; /* index of cqd, rqd, mbuf_table */ - cqd_ptr = (struct cq_desc *)(cq->ring.descs) + rx_id; - - nb_hold = rq->rx_nb_hold; /* mbufs held by software */ + data_rq = &enic->rq[sop_rq->data_queue_idx]; while (nb_rx < nb_pkts) { volatile struct rq_enet_desc *rqd_ptr; @@ -265,6 +270,7 @@ struct cq_desc cqd; uint64_t ol_err_flags; uint8_t packet_error; + uint16_t ciflags; /* Check for pkts available */ color = (cqd_ptr->type_color >> CQ_DESC_COLOR_SHIFT) @@ -272,9 +278,13 @@ if (color == cq->last_color) break; - /* Get the cq descriptor and rq pointer */ + /* Get the cq descriptor and extract rq info from it */ cqd = *cqd_ptr; - rqd_ptr = (struct rq_enet_desc *)(rq->ring.descs) + rx_id; + rq_num = cqd.q_number & CQ_DESC_Q_NUM_MASK; + rq_idx = cqd.completed_index & CQ_DESC_COMP_NDX_MASK; + + rq = &enic->rq[rq_num]; + rqd_ptr = ((struct rq_enet_desc *)rq->ring.descs) + rq_idx; /* allocate a new mbuf */ nmb = rte_rxmbuf_alloc(rq->mp); @@ -287,67 +297,106 @@ packet_error = enic_cq_rx_to_pkt_err_flags(&cqd, &ol_err_flags); /* Get the mbuf to return and replace with one just allocated */ - rxmb = rq->mbuf_ring[rx_id]; - rq->mbuf_ring[rx_id] = nmb; + rxmb = rq->mbuf_ring[rq_idx]; + rq->mbuf_ring[rq_idx] = nmb; /* Increment cqd, rqd, mbuf_table index */ - rx_id++; - if (unlikely(rx_id == rq->ring.desc_count)) { - rx_id = 0; + cq_idx++; + if (unlikely(cq_idx == cq->ring.desc_count)) { + cq_idx = 0; cq->last_color = cq->last_color ? 0 : 1; } /* Prefetch next mbuf & desc while processing current one */ - cqd_ptr = (struct cq_desc *)(cq->ring.descs) + rx_id; + cqd_ptr = (struct cq_desc *)(cq->ring.descs) + cq_idx; rte_enic_prefetch(cqd_ptr); - rte_enic_prefetch(rq->mbuf_ring[rx_id]); - rte_enic_prefetch((struct rq_enet_desc *)(rq->ring.descs) - + rx_id); +// rte_enic_prefetch(rq->mbuf_ring[rx_id]); +// rte_enic_prefetch((struct rq_enet_desc *)(rq->ring.descs) +// + rx_id); + + ciflags = enic_cq_rx_desc_ciflags((struct cq_enet_rq_desc *) &cqd); /* Push descriptor for newly allocated mbuf */ - dma_addr = (dma_addr_t)(nmb->buf_physaddr - + RTE_PKTMBUF_HEADROOM); - rqd_ptr->address = rte_cpu_to_le_64(dma_addr); - rqd_ptr->length_type = cpu_to_le16(nmb->buf_len - - RTE_PKTMBUF_HEADROOM); + + dma_addr = (dma_addr_t)(nmb->buf_physaddr + RTE_PKTMBUF_HEADROOM); + rq_enet_desc_enc(rqd_ptr, dma_addr, + (rq->is_sop ? RQ_ENET_TYPE_ONLY_SOP + : RQ_ENET_TYPE_NOT_SOP), + nmb->buf_len - RTE_PKTMBUF_HEADROOM); /* Fill in the rest of the mbuf */ - rxmb->data_off = RTE_PKTMBUF_HEADROOM; - rxmb->nb_segs = 1; + seg_length = enic_cq_rx_desc_n_bytes(&cqd); + rxmb->packet_type = enic_cq_rx_flags_to_pkt_type(&cqd); + enic_cq_rx_to_pkt_flags(&cqd, rxmb); + if (rq->is_sop) { + first_seg = rxmb; + first_seg->nb_segs = 1; + first_seg->pkt_len = seg_length; + } else { + first_seg->pkt_len = (uint16_t)(first_seg->pkt_len + + seg_length); + first_seg->nb_segs++; + last_seg->next = rxmb; + } + rxmb->next = NULL; rxmb->port = enic->port_id; - if (!packet_error) { - rxmb->pkt_len = enic_cq_rx_desc_n_bytes(&cqd); - rxmb->packet_type = enic_cq_rx_flags_to_pkt_type(&cqd); - enic_cq_rx_to_pkt_flags(&cqd, rxmb); - } else { - rte_pktmbuf_free(rxmb); + rxmb->data_len = seg_length; + + rq->rx_nb_hold++; + + if (!(enic_cq_rx_desc_eop(ciflags))) { + last_seg = rxmb; + continue; + } + + if (unlikely(packet_error)) { + rte_pktmbuf_free(first_seg); rte_atomic64_inc(&enic->soft_stats.rx_packet_errors); - nb_err++; + continue; } - rxmb->data_len = rxmb->pkt_len; + + +// printf("EOP: final packet length is %d\n", first_seg->pkt_len); +// rte_pktmbuf_dump(stdout, first_seg, 64); /* prefetch mbuf data for caller */ - rte_packet_prefetch(RTE_PTR_ADD(rxmb->buf_addr, + rte_packet_prefetch(RTE_PTR_ADD(first_seg->buf_addr, RTE_PKTMBUF_HEADROOM)); /* store the mbuf address into the next entry of the array */ - rx_pkts[nb_rx++] = rxmb; + rx_pkts[nb_rx++] = first_seg; } - nb_hold += nb_rx + nb_err; - cq->to_clean = rx_id; + sop_rq->pkt_first_seg = first_seg; + sop_rq->pkt_last_seg = last_seg; + + cq->to_clean = cq_idx; + + if ((sop_rq->rx_nb_hold + data_rq->rx_nb_hold) > sop_rq->rx_free_thresh) { + if (data_rq->in_use) { + data_rq->posted_index = enic_ring_add(data_rq->ring.desc_count, + data_rq->posted_index, + data_rq->rx_nb_hold); + //printf("Processed %d data descs. Posted index now %d\n", + // data_rq->rx_nb_hold, data_rq->posted_index); + data_rq->rx_nb_hold = 0; + } + sop_rq->posted_index = enic_ring_add(sop_rq->ring.desc_count, + sop_rq->posted_index, + sop_rq->rx_nb_hold); + //printf("Processed %d sop descs. Posted index now %d\n", + // sop_rq->rx_nb_hold, sop_rq->posted_index); + sop_rq->rx_nb_hold = 0; - if (nb_hold > rq->rx_free_thresh) { - rq->posted_index = enic_ring_add(rq->ring.desc_count, - rq->posted_index, nb_hold); - nb_hold = 0; rte_mb(); - iowrite32(rq->posted_index, &rq->ctrl->posted_index); + if (data_rq->in_use) + iowrite32(data_rq->posted_index, &data_rq->ctrl->posted_index); + rte_compiler_barrier(); + iowrite32(sop_rq->posted_index, &sop_rq->ctrl->posted_index); } - rq->rx_nb_hold = nb_hold; return nb_rx; }