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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
|
/*
* BSD LICENSE
*
* Copyright(c) 2017 Cavium, Inc.. All rights reserved.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Cavium, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "lio_bsd.h"
#include "lio_common.h"
#include "lio_droq.h"
#include "lio_iq.h"
#include "lio_response_manager.h"
#include "lio_device.h"
#include "lio_ctrl.h"
#include "lio_main.h"
#include "lio_network.h"
#include "lio_rxtx.h"
int
lio_xmit(struct lio *lio, struct lio_instr_queue *iq,
struct mbuf **m_headp)
{
struct lio_data_pkt ndata;
union lio_cmd_setup cmdsetup;
struct lio_mbuf_free_info *finfo = NULL;
struct octeon_device *oct = iq->oct_dev;
struct lio_iq_stats *stats;
struct octeon_instr_irh *irh;
struct lio_request_list *tx_buf;
union lio_tx_info *tx_info;
struct mbuf *m_head;
bus_dma_segment_t segs[LIO_MAX_SG];
bus_dmamap_t map;
uint64_t dptr = 0;
uint32_t tag = 0;
int iq_no = 0;
int nsegs;
int status = 0;
iq_no = iq->txpciq.s.q_no;
tag = iq_no;
stats = &oct->instr_queue[iq_no]->stats;
tx_buf = iq->request_list + iq->host_write_index;
/*
* Check for all conditions in which the current packet cannot be
* transmitted.
*/
if (!(atomic_load_acq_int(&lio->ifstate) & LIO_IFSTATE_RUNNING) ||
(!lio->linfo.link.s.link_up)) {
lio_dev_info(oct, "Transmit failed link_status : %d\n",
lio->linfo.link.s.link_up);
status = ENETDOWN;
goto drop_packet;
}
if (lio_iq_is_full(oct, iq_no)) {
/* Defer sending if queue is full */
lio_dev_dbg(oct, "Transmit failed iq:%d full\n", iq_no);
stats->tx_iq_busy++;
return (ENOBUFS);
}
map = tx_buf->map;
status = bus_dmamap_load_mbuf_sg(iq->txtag, map, *m_headp, segs, &nsegs,
BUS_DMA_NOWAIT);
if (status == EFBIG) {
struct mbuf *m;
m = m_defrag(*m_headp, M_NOWAIT);
if (m == NULL) {
stats->mbuf_defrag_failed++;
goto drop_packet;
}
*m_headp = m;
status = bus_dmamap_load_mbuf_sg(iq->txtag, map,
*m_headp, segs, &nsegs,
BUS_DMA_NOWAIT);
}
if (status == ENOMEM) {
goto retry;
} else if (status) {
stats->tx_dmamap_fail++;
lio_dev_dbg(oct, "bus_dmamap_load_mbuf_sg failed with error %d. iq:%d",
status, iq_no);
goto drop_packet;
}
m_head = *m_headp;
/* Info used to unmap and free the buffers. */
finfo = &tx_buf->finfo;
finfo->map = map;
finfo->mb = m_head;
/* Prepare the attributes for the data to be passed to OSI. */
bzero(&ndata, sizeof(struct lio_data_pkt));
ndata.buf = (void *)finfo;
ndata.q_no = iq_no;
ndata.datasize = m_head->m_pkthdr.len;
cmdsetup.cmd_setup64 = 0;
cmdsetup.s.iq_no = iq_no;
if (m_head->m_pkthdr.csum_flags & CSUM_IP)
cmdsetup.s.ip_csum = 1;
if ((m_head->m_pkthdr.csum_flags & (CSUM_IP_TCP | CSUM_IP6_TCP)) ||
(m_head->m_pkthdr.csum_flags & (CSUM_IP_UDP | CSUM_IP6_UDP)))
cmdsetup.s.transport_csum = 1;
if (nsegs == 1) {
cmdsetup.s.u.datasize = segs[0].ds_len;
lio_prepare_pci_cmd(oct, &ndata.cmd, &cmdsetup, tag);
dptr = segs[0].ds_addr;
ndata.cmd.cmd3.dptr = dptr;
ndata.reqtype = LIO_REQTYPE_NORESP_NET;
} else {
struct lio_gather *g;
int i;
mtx_lock(&lio->glist_lock[iq_no]);
g = (struct lio_gather *)
lio_delete_first_node(&lio->ghead[iq_no]);
mtx_unlock(&lio->glist_lock[iq_no]);
if (g == NULL) {
lio_dev_err(oct,
"Transmit scatter gather: glist null!\n");
goto retry;
}
cmdsetup.s.gather = 1;
cmdsetup.s.u.gatherptrs = nsegs;
lio_prepare_pci_cmd(oct, &ndata.cmd, &cmdsetup, tag);
bzero(g->sg, g->sg_size);
i = 0;
while (nsegs--) {
g->sg[(i >> 2)].ptr[(i & 3)] = segs[i].ds_addr;
lio_add_sg_size(&g->sg[(i >> 2)], segs[i].ds_len,
(i & 3));
i++;
}
dptr = g->sg_dma_ptr;
ndata.cmd.cmd3.dptr = dptr;
finfo->g = g;
ndata.reqtype = LIO_REQTYPE_NORESP_NET_SG;
}
irh = (struct octeon_instr_irh *)&ndata.cmd.cmd3.irh;
tx_info = (union lio_tx_info *)&ndata.cmd.cmd3.ossp[0];
if (m_head->m_pkthdr.csum_flags & (CSUM_IP_TSO | CSUM_IP6_TSO)) {
tx_info->s.gso_size = m_head->m_pkthdr.tso_segsz;
tx_info->s.gso_segs = howmany(m_head->m_pkthdr.len,
m_head->m_pkthdr.tso_segsz);
stats->tx_gso++;
}
/* HW insert VLAN tag */
if (m_head->m_flags & M_VLANTAG) {
irh->priority = m_head->m_pkthdr.ether_vtag >> 13;
irh->vlan = m_head->m_pkthdr.ether_vtag & 0xfff;
}
status = lio_send_data_pkt(oct, &ndata);
if (status == LIO_IQ_SEND_FAILED)
goto retry;
if (tx_info->s.gso_segs)
stats->tx_done += tx_info->s.gso_segs;
else
stats->tx_done++;
stats->tx_tot_bytes += ndata.datasize;
return (0);
retry:
return (ENOBUFS);
drop_packet:
stats->tx_dropped++;
lio_dev_err(oct, "IQ%d Transmit dropped: %llu\n", iq_no,
LIO_CAST64(stats->tx_dropped));
m_freem(*m_headp);
*m_headp = NULL;
return (status);
}
int
lio_mq_start_locked(if_t ifp, struct lio_instr_queue *iq)
{
struct lio *lio = if_getsoftc(ifp);
struct mbuf *next;
int err = 0;
if (((if_getdrvflags(ifp) & IFF_DRV_RUNNING) == 0) ||
(!lio->linfo.link.s.link_up))
return (-ENETDOWN);
/* Process the queue */
while ((next = drbr_peek(ifp, iq->br)) != NULL) {
err = lio_xmit(lio, iq, &next);
if (err) {
if (next == NULL)
drbr_advance(ifp, iq->br);
else
drbr_putback(ifp, iq->br, next);
break;
}
drbr_advance(ifp, iq->br);
/* Send a copy of the frame to the BPF listener */
ETHER_BPF_MTAP(ifp, next);
if (((if_getdrvflags(ifp) & IFF_DRV_RUNNING) == 0) ||
(!lio->linfo.link.s.link_up))
break;
}
return (err);
}
int
lio_mq_start(if_t ifp, struct mbuf *m)
{
struct lio *lio = if_getsoftc(ifp);
struct octeon_device *oct = lio->oct_dev;
struct lio_instr_queue *iq;
int err = 0, i;
#ifdef RSS
uint32_t bucket_id;
#endif
if (M_HASHTYPE_GET(m) != M_HASHTYPE_NONE) {
#ifdef RSS
if (rss_hash2bucket(m->m_pkthdr.flowid, M_HASHTYPE_GET(m),
&bucket_id) == 0) {
i = bucket_id % oct->num_iqs;
if (bucket_id > oct->num_iqs)
lio_dev_dbg(oct,
"bucket_id (%d) > num_iqs (%d)\n",
bucket_id, oct->num_iqs);
} else
#endif
i = m->m_pkthdr.flowid % oct->num_iqs;
} else
i = curcpu % oct->num_iqs;
iq = oct->instr_queue[i];
err = drbr_enqueue(ifp, iq->br, m);
if (err)
return (err);
if (mtx_trylock(&iq->enq_lock)) {
lio_mq_start_locked(ifp, iq);
mtx_unlock(&iq->enq_lock);
}
return (err);
}
void
lio_qflush(if_t ifp)
{
struct lio *lio = if_getsoftc(ifp);
struct octeon_device *oct = lio->oct_dev;
struct lio_instr_queue *iq;
struct mbuf *m;
int i;
for (i = 0; i < LIO_MAX_INSTR_QUEUES(oct); i++) {
if (!(oct->io_qmask.iq & BIT_ULL(i)))
continue;
iq = oct->instr_queue[i];
mtx_lock(&iq->enq_lock);
while ((m = buf_ring_dequeue_sc(iq->br)) != NULL)
m_freem(m);
mtx_unlock(&iq->enq_lock);
}
if_qflush(ifp);
}
|