Avoid using any of the ndis_packet/ndis_packet_private fields for

mbuf<->packet housekeeping. Instead, add a couple of extra fields
to the end of ndis_packet. These should be invisible to the Windows
driver module.

This also lets me get rid of a little bit of evil from ndis_ptom()
(frobbing of the ext_buf field instead of relying on the MEXTADD()
macro).
This commit is contained in:
Bill Paul 2003-12-25 06:04:40 +00:00
parent 67206e04f9
commit 72b926ae1a
3 changed files with 24 additions and 23 deletions

View File

@ -328,8 +328,8 @@ ndis_flush_sysctls(arg)
}
void
ndis_return_packet(packet, arg)
void *packet;
ndis_return_packet(buf, arg)
void *buf; /* not used */
void *arg;
{
struct ndis_softc *sc;
@ -337,25 +337,25 @@ ndis_return_packet(packet, arg)
ndis_packet *p;
__stdcall ndis_return_handler returnfunc;
if (arg == NULL || packet == NULL)
if (arg == NULL)
return;
p = packet;
p = arg;
/* Decrement refcount. */
p->np_private.npp_count--;
p->np_refcnt--;
/* Release packet when refcount hits zero, otherwise return. */
if (p->np_private.npp_count)
if (p->np_refcnt)
return;
sc = arg;
sc = p->np_softc;
returnfunc = sc->ndis_chars.nmc_return_packet_func;
adapter = sc->ndis_block.nmb_miniportadapterctx;
if (returnfunc == NULL)
ndis_free_packet((ndis_packet *)packet);
ndis_free_packet(p);
else
returnfunc(adapter, (ndis_packet *)packet);
returnfunc(adapter, p);
return;
}
@ -474,7 +474,7 @@ ndis_ptom(m0, p)
priv = &p->np_private;
buf = priv->npp_head;
priv->npp_count = 0;
p->np_refcnt = 0;
for (buf = priv->npp_head; buf != NULL; buf = buf->nb_next) {
if (buf == priv->npp_head)
@ -489,9 +489,8 @@ ndis_ptom(m0, p)
m->m_len = buf->nb_bytecount;
m->m_data = MDL_VA(buf);
MEXTADD(m, m->m_data, m->m_len, ndis_return_packet,
p->np_rsvd[0], 0, EXT_NDIS);
m->m_ext.ext_buf = (void *)p; /* XXX */
priv->npp_count++;
p, 0, EXT_NDIS);
p->np_refcnt++;
totlen += m->m_len;
if (m->m_flags & MT_HEADER)
*m0 = m;

View File

@ -829,7 +829,6 @@ struct ndis_packet {
} np_macrsvd;
} u;
uint32_t *np_rsvd[2];
uint8_t np_proto_rsvd[1];
/*
* This next part is probably wrong, but we need some place
@ -838,6 +837,13 @@ struct ndis_packet {
ndis_packet_oob np_oob;
ndis_packet_extension np_ext;
ndis_sc_list np_sclist;
/* BSD-specific stuff which should be invisible to drivers. */
uint32_t np_refcnt;
void *np_softc;
void *np_m0;
int np_txidx;
};
typedef struct ndis_packet ndis_packet;

View File

@ -651,7 +651,7 @@ ndis_rxeof(adapter, packets, pktcnt)
for (i = 0; i < pktcnt; i++) {
p = packets[i];
/* Stash the softc here so ptom can use it. */
p->np_rsvd[0] = (uint32_t *)sc;
p->np_softc = sc;
if (ndis_ptom(&m0, p)) {
printf ("ndis%d: ptom failed\n", sc->ndis_unit);
ndis_return_packet(sc, p);
@ -686,13 +686,10 @@ ndis_txeof(adapter, packet, status)
sc = (struct ndis_softc *)block->nmb_ifp;
ifp = block->nmb_ifp;
if (packet->np_rsvd[1] == NULL)
panic("NDIS driver corrupted reserved packet fields");
NDIS_LOCK(sc);
m = (struct mbuf *)packet->np_rsvd[1];
idx = (int)packet->np_rsvd[0];
m = packet->np_m0;
idx = packet->np_txidx;
ifp->if_opackets++;
if (sc->ndis_sc)
bus_dmamap_unload(sc->ndis_ttag, sc->ndis_tmaps[idx]);
@ -900,9 +897,8 @@ ndis_start(ifp)
* so we can free it later.
*/
(sc->ndis_txarray[sc->ndis_txidx])->np_rsvd[0] =
(uint32_t *)sc->ndis_txidx;
(sc->ndis_txarray[sc->ndis_txidx])->np_rsvd[1] = (uint32_t *)m;
(sc->ndis_txarray[sc->ndis_txidx])->np_txidx = sc->ndis_txidx;
(sc->ndis_txarray[sc->ndis_txidx])->np_m0 = m;
/*
* Do scatter/gather processing, if driver requested it.