Deleted Added
sdiff udiff text old ( 267919 ) new ( 267920 )
full compact
1/*-
2 * Copyright (c) 2012-2014 Bjoern A. Zeeb
3 * All rights reserved.
4 *
5 * This software was developed by SRI International and the University of
6 * Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-11-C-0249
7 * ("MRC2"), as part of the DARPA MRC research programme.
8 *

--- 23 unchanged lines hidden (view full) ---

32 *
33 * TODO:
34 * - figure out on the HW side why some data is LE and some is BE.
35 * - general set of improvements possible (e.g., reduce times of copying,
36 * do on-the-copy checksum calculations)
37 */
38
39#include <sys/cdefs.h>
40__FBSDID("$FreeBSD: head/sys/dev/netfpga10g/nf10bmac/if_nf10bmac.c 267919 2014-06-26 17:03:08Z bz $");
41
42#include "opt_device_polling.h"
43
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/kernel.h>
47#include <sys/bus.h>
48#include <sys/endian.h>

--- 63 unchanged lines hidden (view full) ---

112#define NF10BMAC_TUSER_CPU3 (1 << 7)
113
114#define NF10BMAC_DATA_LEN_MASK 0x0000ffff
115#define NF10BMAC_DATA_DPORT_MASK 0xff000000
116#define NF10BMAC_DATA_DPORT_SHIFT 24
117#define NF10BMAC_DATA_SPORT_MASK 0x00ff0000
118#define NF10BMAC_DATA_SPORT_SHIFT 16
119#define NF10BMAC_DATA_LAST 0x00008000
120#define NF10BMAC_DATA_STRB 0x0000000f
121
122
123static inline void
124nf10bmac_write(struct resource *res, uint32_t reg, uint32_t val,
125 const char *f __unused, const int l __unused)
126{
127
128 bus_write_4(res, reg, htole32(val));
129}
130
131static inline uint32_t
132nf10bmac_read(struct resource *res, uint32_t reg,
133 const char *f __unused, const int l __unused)
134{
135
136 return (le32toh(bus_read_4(res, reg)));
137}
138
139static inline void
140nf10bmac_write_be(struct resource *res, uint32_t reg, uint32_t val,
141 const char *f __unused, const int l __unused)
142{
143
144 bus_write_4(res, reg, htobe32(val));
145}
146
147
148static inline uint32_t
149nf10bmac_read_be(struct resource *res, uint32_t reg,
150 const char *f __unused, const int l __unused)
151{
152
153 return (be32toh(bus_read_4(res, reg)));
154}
155
156#define NF10BMAC_WRITE_CTRL(sc, reg, val) \
157 nf10bmac_write((sc)->nf10bmac_ctrl_res, (reg), (val), \
158 __func__, __LINE__)
159#define NF10BMAC_WRITE(sc, reg, val) \
160 nf10bmac_write((sc)->nf10bmac_tx_mem_res, (reg), (val), \
161 __func__, __LINE__)

--- 29 unchanged lines hidden (view full) ---

191
192devclass_t nf10bmac_devclass;
193
194
195static int
196nf10bmac_tx_locked(struct nf10bmac_softc *sc, struct mbuf *m)
197{
198 int32_t len, l, ml;
199 uint32_t md, val;
200
201 NF10BMAC_LOCK_ASSERT(sc);
202
203 KASSERT(m != NULL, ("%s: m is null: sc=%p", __func__, sc));
204 KASSERT(m->m_flags & M_PKTHDR, ("%s: not a pkthdr: m=%p", __func__, m));
205 /*
206 * Copy to buffer to minimize our pain as we can only store
207 * double words which, after the first mbuf gets out of alignment

--- 98 unchanged lines hidden (view full) ---

306 NF10BMAC_LOCK(sc);
307 nf10bmac_start_locked(ifp);
308 NF10BMAC_UNLOCK(sc);
309}
310
311static void
312nf10bmac_eat_packet_munch_munch(struct nf10bmac_softc *sc)
313{
314 uint32_t md, val;
315
316 do {
317 md = NF10BMAC_READ_BE(sc, NF10BMAC_RX_META);
318 if ((md & NF10BMAC_DATA_STRB) != 0)
319 val = NF10BMAC_READ_BE(sc, NF10BMAC_RX_DATA);
320 } while ((md & NF10BMAC_DATA_STRB) != 0 &&
321 (md & NF10BMAC_DATA_LAST) == 0);
322}
323
324static int
325nf10bmac_rx_locked(struct nf10bmac_softc *sc)
326{
327 struct ifnet *ifp;
328 struct mbuf *m;
329 uint32_t md, val;
330 int32_t len, l;
331
332 /*
333 * General problem here in case we need to sync ourselves to the
334 * beginning of a packet. Length will only be set for the first
335 * read, and together with strb we can detect the begining (or
336 * skip to tlast).
337 */

--- 78 unchanged lines hidden (view full) ---

416 while ((md & NF10BMAC_DATA_STRB) == 0 && cl-- > 0) {
417 DELAY(10);
418 md = NF10BMAC_READ(sc, NF10BMAC_RX_META);
419 }
420 }
421 /* We should get out of this loop with tlast and tsrb. */
422 if ((md & NF10BMAC_DATA_LAST) == 0 || (md & NF10BMAC_DATA_STRB) == 0) {
423 device_printf(sc->nf10bmac_dev, "Unexpected rx loop end state: "
424 "md=0x%08x len=%d l=%d\n", md, len, l);
425 ifp->if_ierrors++;
426 m_freem(m);
427 return (0);
428 }
429
430 m->m_pkthdr.len = m->m_len = len;
431 m->m_pkthdr.rcvif = ifp;
432 ifp->if_ipackets++;

--- 515 unchanged lines hidden ---