freebsd11_network: Synchronize fbsd_uipc_mbuf with FreeBSD 11.

Includes changes to the mbuf struct to more closely mirror FreeBSD 11.
Tested with the idualwifi7260 driver.
This commit is contained in:
Augustin Cavalier 2018-07-06 10:58:45 -04:00
parent 5af0299e37
commit 4cc829dc65
5 changed files with 1273 additions and 543 deletions

View File

@ -26,8 +26,8 @@ KernelStaticLibrary libfreebsd11_network.a :
fbsd_busdma_x86.c
fbsd_ether.c
fbsd_if_media.c
fbsd_mbuf.c
fbsd_mbuf2.c
fbsd_uipc_mbuf.c
fbsd_uipc_mbuf2.c
fbsd_mii.c
fbsd_mii_bitbang.c
fbsd_mii_physubr.c

View File

@ -168,24 +168,17 @@ struct mbuf {
union {
struct {
struct pkthdr MH_pkthdr;
struct pkthdr m_pkthdr; /* M_PKTHDR set */
union {
struct m_ext MH_ext;
char MH_databuf[0];
} MH_dat;
} MH;
char M_databuf[0];
} M_dat;
struct m_ext m_ext; /* M_EXT set */
char m_pktdat[0];
};
};
char m_dat[0]; /* !M_PKTHDR, !M_EXT */
};
};
#define m_act m_nextpkt
#define m_pkthdr M_dat.MH.MH_pkthdr
#define m_ext M_dat.MH.MH_dat.MH_ext
#define m_pktdat M_dat.MH.MH_dat.MH_databuf
#define m_dat M_dat.M_databuf
void m_catpkt(struct mbuf *m, struct mbuf *n);
void m_adj(struct mbuf*, int);
int m_append(struct mbuf*, int, c_caddr_t);
@ -193,7 +186,7 @@ void m_cat(struct mbuf*, struct mbuf*);
int m_clget(struct mbuf*, int);
void* m_cljget(struct mbuf*, int, int);
struct mbuf* m_collapse(struct mbuf*, int, int);
void m_copyback(struct mbuf*, int, int, caddr_t);
void m_copyback(struct mbuf *m0, int off, int len, c_caddr_t cp);
void m_copydata(const struct mbuf*, int, int, caddr_t);
struct mbuf* m_copypacket(struct mbuf*, int);
struct mbuf * m_copym(struct mbuf *m, int off0, int len, int wait);
@ -201,8 +194,8 @@ struct mbuf* m_defrag(struct mbuf*, int);
struct mbuf* m_devget(char*, int, int, struct ifnet*,
void(*) (char*, caddr_t, u_int));
struct mbuf* m_dup(struct mbuf*, int);
int m_dup_pkthdr(struct mbuf*, struct mbuf*, int);
struct mbuf* m_dup(const struct mbuf *m, int how);
int m_dup_pkthdr(struct mbuf *to, const struct mbuf *from, int how);
void m_demote_pkthdr(struct mbuf *m);
void m_demote(struct mbuf *m0, int all, int flags);
@ -232,7 +225,7 @@ void m_tag_delete_chain(struct mbuf*, struct m_tag*);
void m_tag_free_default(struct m_tag*);
struct m_tag* m_tag_locate(struct mbuf*, u_int32_t, int, struct m_tag*);
struct m_tag* m_tag_copy(struct m_tag*, int);
int m_tag_copy_chain(struct mbuf*, struct mbuf*, int);
int m_tag_copy_chain(struct mbuf *to, const struct mbuf *from, int how);
void m_tag_delete_nonpersistent(struct mbuf*);

View File

@ -58,10 +58,8 @@ int printf(const char *format, ...) __printflike(1, 2);
void wakeup(void *);
#ifndef CTASSERT /* Allow lint to override */
#define CTASSERT(x) _CTASSERT(x, __LINE__)
#define _CTASSERT(x, y) __CTASSERT(x, y)
#define __CTASSERT(x, y) typedef char __assert ## y[(x) ? 1 : -1]
#ifndef CTASSERT /* Allow lint to override */
#define CTASSERT(x) _Static_assert(x, "compile-time assertion failed")
#endif

View File

@ -4,7 +4,7 @@
/*-
* Copyright (C) 1999 WIDE Project.
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@ -16,7 +16,7 @@
* 3. Neither the name of the project 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 PROJECT 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
@ -59,11 +59,16 @@
*
* @(#)uipc_mbuf.c 8.4 (Berkeley) 2/14/95
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
__FBSDID("$FreeBSD: stable/11/sys/kern/uipc_mbuf2.c 312441 2017-01-19 23:42:51Z rpokala $");
/*#define PULLDOWN_DEBUG*/
#ifdef __HAIKU__
#define FBSD_DRIVER
#endif
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
@ -74,8 +79,8 @@ __FBSDID("$FreeBSD$");
#include <security/mac/mac_framework.h>
#define malloc(size, tag, flags) kernel_malloc(size, tag, flags)
#define free(pointer, tag) kernel_free(pointer, tag)
static MALLOC_DEFINE(M_PACKET_TAGS, MBUF_TAG_MEM_NAME,
"packet-attached information");
/* can't call it m_dup(), as freebsd[34] uses m_dup() with different arg */
static struct mbuf *m_dup1(struct mbuf *, int, int, int);
@ -130,6 +135,8 @@ m_pulldown(struct mbuf *m, int off, int len, int *offp)
}
/*
* The following comment is dated but still partially applies:
*
* XXX: This code is flawed because it considers a "writable" mbuf
* data region to require all of the following:
* (i) mbuf _has_ to have M_EXT set; if it is just a regular
@ -140,17 +147,13 @@ m_pulldown(struct mbuf *m, int off, int len, int *offp)
* Ideally, the requirement should only be (iii).
*
* If we're writable, we're sure we're writable, because the ref. count
* cannot increase from 1, as that would require posession of mbuf
* cannot increase from 1, as that would require possession of mbuf
* n by someone else (which is impossible). However, if we're _not_
* writable, we may eventually become writable )if the ref. count drops
* to 1), but we'll fail to notice it unless we re-evaluate
* M_WRITABLE(). For now, we only evaluate once at the beginning and
* live with this.
*/
/*
* XXX: This is dumb. If we're just a regular mbuf with no M_EXT,
* then we're not "writable," according to this code.
*/
writable = 0;
if ((n->m_flags & M_EXT) == 0 ||
(n->m_ext.ext_type == EXT_CLUSTER && M_WRITABLE(n)))
@ -160,7 +163,7 @@ m_pulldown(struct mbuf *m, int off, int len, int *offp)
* the target data is on <n, off>.
* if we got enough data on the mbuf "n", we're done.
*/
if ((off == 0 || offp) && len <= n->m_len - off && writable)
if ((off == 0 || offp) && len <= n->m_len - off)
goto ok;
/*
@ -170,7 +173,7 @@ m_pulldown(struct mbuf *m, int off, int len, int *offp)
* chop the current mbuf into two pieces, set off to 0.
*/
if (len <= n->m_len - off) {
o = m_dup1(n, off, n->m_len - off, M_DONTWAIT);
o = m_dup1(n, off, n->m_len - off, M_NOWAIT);
if (o == NULL) {
m_freem(m);
return NULL; /* ENOBUFS */
@ -230,9 +233,9 @@ m_pulldown(struct mbuf *m, int off, int len, int *offp)
* on both end.
*/
if (len > MLEN)
o = m_getcl(M_DONTWAIT, m->m_type, 0);
o = m_getcl(M_NOWAIT, m->m_type, 0);
else
o = m_get(M_DONTWAIT, m->m_type);
o = m_get(M_NOWAIT, m->m_type);
if (!o) {
m_freem(m);
return NULL; /* ENOBUFS */
@ -313,7 +316,7 @@ m_tag_free_default(struct m_tag *t)
/* Get a packet tag structure along with specified data following. */
struct m_tag *
m_tag_alloc(u_int32_t cookie, int type, int len, int wait)
m_tag_alloc(uint32_t cookie, int type, int len, int wait)
{
struct m_tag *t;
@ -375,7 +378,7 @@ m_tag_delete_nonpersistent(struct mbuf *m)
/* Find a tag, starting from a given position. */
struct m_tag *
m_tag_locate(struct mbuf *m, u_int32_t cookie, int type, struct m_tag *t)
m_tag_locate(struct mbuf *m, uint32_t cookie, int type, struct m_tag *t)
{
struct m_tag *p;
@ -428,7 +431,7 @@ m_tag_copy(struct m_tag *t, int how)
* destination mbuf.
*/
int
m_tag_copy_chain(struct mbuf *to, struct mbuf *from, int how)
m_tag_copy_chain(struct mbuf *to, const struct mbuf *from, int how)
{
struct m_tag *p, *t, *tprev = NULL;