1998-09-03 20:51:50 +00:00
|
|
|
/*-
|
2017-11-27 14:52:40 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2002-03-23 15:49:15 +00:00
|
|
|
* Copyright (c) 1998, 2001 Nicolas Souchu
|
1998-09-03 20:51:50 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
|
|
|
*/
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1998-09-03 20:51:50 +00:00
|
|
|
/*
|
|
|
|
* I2C bus IP driver
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/filio.h>
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
#include <sys/kernel.h>
|
2008-08-04 21:14:24 +00:00
|
|
|
#include <sys/lock.h>
|
1998-09-03 20:51:50 +00:00
|
|
|
#include <sys/module.h>
|
2008-08-04 21:14:24 +00:00
|
|
|
#include <sys/mutex.h>
|
1998-09-03 20:51:50 +00:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
2013-10-26 17:58:36 +00:00
|
|
|
#include <net/if_var.h>
|
1998-09-03 20:51:50 +00:00
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/netisr.h>
|
|
|
|
|
|
|
|
#include <net/route.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/if_ether.h>
|
|
|
|
|
|
|
|
#include <net/bpf.h>
|
|
|
|
|
|
|
|
#include <dev/iicbus/iiconf.h>
|
|
|
|
#include <dev/iicbus/iicbus.h>
|
|
|
|
|
|
|
|
#include "iicbus_if.h"
|
|
|
|
|
2002-03-23 15:49:15 +00:00
|
|
|
#define PCF_MASTER_ADDRESS 0xaa
|
|
|
|
|
2003-12-28 03:56:00 +00:00
|
|
|
#define ICHDRLEN sizeof(u_int32_t)
|
1998-09-03 20:51:50 +00:00
|
|
|
#define ICMTU 1500 /* default mtu */
|
|
|
|
|
|
|
|
struct ic_softc {
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *ic_ifp;
|
2008-08-04 21:14:24 +00:00
|
|
|
device_t ic_dev;
|
1998-09-03 20:51:50 +00:00
|
|
|
|
|
|
|
u_char ic_addr; /* peer I2C address */
|
|
|
|
|
2008-08-04 21:14:24 +00:00
|
|
|
int ic_flags;
|
1998-09-03 20:51:50 +00:00
|
|
|
|
|
|
|
char *ic_obuf;
|
|
|
|
char *ic_ifbuf;
|
|
|
|
char *ic_cp;
|
|
|
|
|
|
|
|
int ic_xfercnt;
|
|
|
|
|
|
|
|
int ic_iferrs;
|
2008-08-04 21:14:24 +00:00
|
|
|
|
|
|
|
struct mtx ic_lock;
|
1998-09-03 20:51:50 +00:00
|
|
|
};
|
|
|
|
|
2008-08-04 21:14:24 +00:00
|
|
|
#define IC_SENDING 0x0001
|
|
|
|
#define IC_OBUF_BUSY 0x0002
|
|
|
|
#define IC_IFBUF_BUSY 0x0004
|
|
|
|
#define IC_BUFFERS_BUSY (IC_OBUF_BUSY | IC_IFBUF_BUSY)
|
|
|
|
#define IC_BUFFER_WAITER 0x0004
|
|
|
|
|
1998-09-03 20:51:50 +00:00
|
|
|
static devclass_t ic_devclass;
|
|
|
|
|
|
|
|
static int icprobe(device_t);
|
|
|
|
static int icattach(device_t);
|
|
|
|
|
|
|
|
static int icioctl(struct ifnet *, u_long, caddr_t);
|
2013-04-26 12:50:32 +00:00
|
|
|
static int icoutput(struct ifnet *, struct mbuf *, const struct sockaddr *,
|
2009-04-16 20:30:28 +00:00
|
|
|
struct route *);
|
1998-09-03 20:51:50 +00:00
|
|
|
|
2009-02-10 22:50:23 +00:00
|
|
|
static int icintr(device_t, int, char *);
|
1998-09-03 20:51:50 +00:00
|
|
|
|
|
|
|
static device_method_t ic_methods[] = {
|
|
|
|
/* device interface */
|
|
|
|
DEVMETHOD(device_probe, icprobe),
|
|
|
|
DEVMETHOD(device_attach, icattach),
|
|
|
|
|
|
|
|
/* iicbus interface */
|
|
|
|
DEVMETHOD(iicbus_intr, icintr),
|
|
|
|
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t ic_driver = {
|
|
|
|
"ic",
|
|
|
|
ic_methods,
|
|
|
|
sizeof(struct ic_softc),
|
|
|
|
};
|
|
|
|
|
2008-08-04 21:14:24 +00:00
|
|
|
static void
|
|
|
|
ic_alloc_buffers(struct ic_softc *sc, int mtu)
|
|
|
|
{
|
|
|
|
char *obuf, *ifbuf;
|
|
|
|
|
|
|
|
obuf = malloc(mtu + ICHDRLEN, M_DEVBUF, M_WAITOK);
|
|
|
|
ifbuf = malloc(mtu + ICHDRLEN, M_DEVBUF, M_WAITOK);
|
|
|
|
|
|
|
|
mtx_lock(&sc->ic_lock);
|
|
|
|
while (sc->ic_flags & IC_BUFFERS_BUSY) {
|
|
|
|
sc->ic_flags |= IC_BUFFER_WAITER;
|
|
|
|
mtx_sleep(sc, &sc->ic_lock, 0, "icalloc", 0);
|
|
|
|
sc->ic_flags &= ~IC_BUFFER_WAITER;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(sc->ic_obuf, M_DEVBUF);
|
|
|
|
free(sc->ic_ifbuf, M_DEVBUF);
|
|
|
|
sc->ic_obuf = obuf;
|
|
|
|
sc->ic_ifbuf = ifbuf;
|
|
|
|
sc->ic_ifp->if_mtu = mtu;
|
|
|
|
mtx_unlock(&sc->ic_lock);
|
|
|
|
}
|
|
|
|
|
1998-09-03 20:51:50 +00:00
|
|
|
/*
|
|
|
|
* icprobe()
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
icprobe(device_t dev)
|
|
|
|
{
|
2009-01-06 17:23:37 +00:00
|
|
|
return (BUS_PROBE_NOWILDCARD);
|
1998-09-03 20:51:50 +00:00
|
|
|
}
|
2008-08-04 21:14:24 +00:00
|
|
|
|
1998-09-03 20:51:50 +00:00
|
|
|
/*
|
|
|
|
* icattach()
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
icattach(device_t dev)
|
|
|
|
{
|
|
|
|
struct ic_softc *sc = (struct ic_softc *)device_get_softc(dev);
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
|
|
|
|
ifp = sc->ic_ifp = if_alloc(IFT_PARA);
|
2006-04-04 19:30:47 +00:00
|
|
|
if (ifp == NULL)
|
2005-06-10 16:49:24 +00:00
|
|
|
return (ENOSPC);
|
1998-09-03 20:51:50 +00:00
|
|
|
|
2008-08-04 21:14:24 +00:00
|
|
|
mtx_init(&sc->ic_lock, device_get_nameunit(dev), MTX_NETWORK_LOCK,
|
|
|
|
MTX_DEF);
|
2002-03-23 15:49:15 +00:00
|
|
|
sc->ic_addr = PCF_MASTER_ADDRESS; /* XXX only PCF masters */
|
2008-08-04 21:14:24 +00:00
|
|
|
sc->ic_dev = dev;
|
1998-09-03 20:51:50 +00:00
|
|
|
|
|
|
|
ifp->if_softc = sc;
|
2003-10-31 18:32:15 +00:00
|
|
|
if_initname(ifp, device_get_name(dev), device_get_unit(dev));
|
2008-08-04 21:14:24 +00:00
|
|
|
ifp->if_flags = IFF_SIMPLEX | IFF_POINTOPOINT | IFF_MULTICAST;
|
1998-09-03 20:51:50 +00:00
|
|
|
ifp->if_ioctl = icioctl;
|
|
|
|
ifp->if_output = icoutput;
|
|
|
|
ifp->if_hdrlen = 0;
|
|
|
|
ifp->if_addrlen = 0;
|
2010-05-03 07:32:50 +00:00
|
|
|
ifp->if_snd.ifq_maxlen = ifqmaxlen;
|
1998-09-03 20:51:50 +00:00
|
|
|
|
2008-08-04 21:14:24 +00:00
|
|
|
ic_alloc_buffers(sc, ICMTU);
|
|
|
|
|
1998-09-03 20:51:50 +00:00
|
|
|
if_attach(ifp);
|
|
|
|
|
|
|
|
bpfattach(ifp, DLT_NULL, ICHDRLEN);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* iciotcl()
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
icioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
|
|
|
|
{
|
2008-08-04 21:14:24 +00:00
|
|
|
struct ic_softc *sc = ifp->if_softc;
|
|
|
|
device_t icdev = sc->ic_dev;
|
2006-04-04 19:30:47 +00:00
|
|
|
device_t parent = device_get_parent(icdev);
|
|
|
|
struct ifaddr *ifa = (struct ifaddr *)data;
|
|
|
|
struct ifreq *ifr = (struct ifreq *)data;
|
|
|
|
int error;
|
1998-09-03 20:51:50 +00:00
|
|
|
|
2006-04-04 19:30:47 +00:00
|
|
|
switch (cmd) {
|
1998-09-03 20:51:50 +00:00
|
|
|
|
2006-04-04 19:30:47 +00:00
|
|
|
case SIOCAIFADDR:
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
if (ifa->ifa_addr->sa_family != AF_INET)
|
|
|
|
return (EAFNOSUPPORT);
|
2008-08-04 21:14:24 +00:00
|
|
|
mtx_lock(&sc->ic_lock);
|
2006-04-04 19:30:47 +00:00
|
|
|
ifp->if_flags |= IFF_UP;
|
2008-08-04 21:14:24 +00:00
|
|
|
goto locked;
|
2006-04-04 19:30:47 +00:00
|
|
|
case SIOCSIFFLAGS:
|
2008-08-04 21:14:24 +00:00
|
|
|
mtx_lock(&sc->ic_lock);
|
|
|
|
locked:
|
2006-04-04 19:30:47 +00:00
|
|
|
if ((!(ifp->if_flags & IFF_UP)) &&
|
|
|
|
(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
|
1998-09-03 20:51:50 +00:00
|
|
|
|
2006-04-04 19:30:47 +00:00
|
|
|
/* XXX disable PCF */
|
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
|
2008-08-04 21:14:24 +00:00
|
|
|
mtx_unlock(&sc->ic_lock);
|
1998-09-03 20:51:50 +00:00
|
|
|
|
2006-04-04 19:30:47 +00:00
|
|
|
/* IFF_UP is not set, try to release the bus anyway */
|
|
|
|
iicbus_release_bus(parent, icdev);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (((ifp->if_flags & IFF_UP)) &&
|
|
|
|
(!(ifp->if_drv_flags & IFF_DRV_RUNNING))) {
|
2008-08-04 21:14:24 +00:00
|
|
|
mtx_unlock(&sc->ic_lock);
|
2006-04-04 19:30:47 +00:00
|
|
|
if ((error = iicbus_request_bus(parent, icdev,
|
|
|
|
IIC_WAIT | IIC_INTR)))
|
|
|
|
return (error);
|
2008-08-04 21:14:24 +00:00
|
|
|
mtx_lock(&sc->ic_lock);
|
2006-04-04 19:30:47 +00:00
|
|
|
iicbus_reset(parent, IIC_FASTEST, 0, NULL);
|
|
|
|
ifp->if_drv_flags |= IFF_DRV_RUNNING;
|
|
|
|
}
|
2008-08-04 21:14:24 +00:00
|
|
|
mtx_unlock(&sc->ic_lock);
|
2006-04-04 19:30:47 +00:00
|
|
|
break;
|
1998-09-03 20:51:50 +00:00
|
|
|
|
2006-04-04 19:30:47 +00:00
|
|
|
case SIOCSIFMTU:
|
2008-08-04 21:14:24 +00:00
|
|
|
ic_alloc_buffers(sc, ifr->ifr_mtu);
|
2006-04-04 19:30:47 +00:00
|
|
|
break;
|
1998-09-03 20:51:50 +00:00
|
|
|
|
2006-04-04 19:30:47 +00:00
|
|
|
case SIOCGIFMTU:
|
2008-08-04 21:14:24 +00:00
|
|
|
mtx_lock(&sc->ic_lock);
|
2006-04-04 19:30:47 +00:00
|
|
|
ifr->ifr_mtu = sc->ic_ifp->if_mtu;
|
2008-08-04 21:14:24 +00:00
|
|
|
mtx_unlock(&sc->ic_lock);
|
2006-04-04 19:30:47 +00:00
|
|
|
break;
|
1998-09-03 20:51:50 +00:00
|
|
|
|
2006-04-04 19:30:47 +00:00
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
2017-02-20 03:43:12 +00:00
|
|
|
if (ifr == NULL)
|
2006-04-04 19:30:47 +00:00
|
|
|
return (EAFNOSUPPORT); /* XXX */
|
|
|
|
switch (ifr->ifr_addr.sa_family) {
|
|
|
|
case AF_INET:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (EAFNOSUPPORT);
|
|
|
|
}
|
|
|
|
break;
|
1998-09-03 20:51:50 +00:00
|
|
|
default:
|
2006-04-04 19:30:47 +00:00
|
|
|
return (EINVAL);
|
1998-09-03 20:51:50 +00:00
|
|
|
}
|
2006-04-04 19:30:47 +00:00
|
|
|
return (0);
|
1998-09-03 20:51:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* icintr()
|
|
|
|
*/
|
2009-02-10 22:50:23 +00:00
|
|
|
static int
|
2006-08-21 17:32:50 +00:00
|
|
|
icintr(device_t dev, int event, char *ptr)
|
1998-09-03 20:51:50 +00:00
|
|
|
{
|
|
|
|
struct ic_softc *sc = (struct ic_softc *)device_get_softc(dev);
|
|
|
|
struct mbuf *top;
|
2008-08-04 21:14:24 +00:00
|
|
|
int len;
|
|
|
|
|
|
|
|
mtx_lock(&sc->ic_lock);
|
1998-09-03 20:51:50 +00:00
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
|
|
|
|
case INTR_GENERAL:
|
|
|
|
case INTR_START:
|
|
|
|
sc->ic_cp = sc->ic_ifbuf;
|
|
|
|
sc->ic_xfercnt = 0;
|
2008-08-04 21:14:24 +00:00
|
|
|
sc->ic_flags |= IC_IFBUF_BUSY;
|
1998-09-03 20:51:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case INTR_STOP:
|
|
|
|
|
2016-05-03 03:41:25 +00:00
|
|
|
/* if any error occurred during transfert,
|
2006-04-04 19:30:47 +00:00
|
|
|
* drop the packet */
|
2008-08-04 21:14:24 +00:00
|
|
|
sc->ic_flags &= ~IC_IFBUF_BUSY;
|
|
|
|
if ((sc->ic_flags & (IC_BUFFERS_BUSY | IC_BUFFER_WAITER)) ==
|
|
|
|
IC_BUFFER_WAITER)
|
|
|
|
wakeup(&sc);
|
2006-04-04 19:30:47 +00:00
|
|
|
if (sc->ic_iferrs)
|
|
|
|
goto err;
|
|
|
|
if ((len = sc->ic_xfercnt) == 0)
|
|
|
|
break; /* ignore */
|
|
|
|
if (len <= ICHDRLEN)
|
|
|
|
goto err;
|
|
|
|
len -= ICHDRLEN;
|
2014-09-19 03:51:26 +00:00
|
|
|
if_inc_counter(sc->ic_ifp, IFCOUNTER_IPACKETS, 1);
|
|
|
|
if_inc_counter(sc->ic_ifp, IFCOUNTER_IBYTES, len);
|
2006-04-04 19:30:47 +00:00
|
|
|
BPF_TAP(sc->ic_ifp, sc->ic_ifbuf, len + ICHDRLEN);
|
|
|
|
top = m_devget(sc->ic_ifbuf + ICHDRLEN, len, 0, sc->ic_ifp, 0);
|
2008-08-04 21:14:24 +00:00
|
|
|
if (top) {
|
Widen NET_EPOCH coverage.
When epoch(9) was introduced to network stack, it was basically
dropped in place of existing locking, which was mutexes and
rwlocks. For the sake of performance mutex covered areas were
as small as possible, so became epoch covered areas.
However, epoch doesn't introduce any contention, it just delays
memory reclaim. So, there is no point to minimise epoch covered
areas in sense of performance. Meanwhile entering/exiting epoch
also has non-zero CPU usage, so doing this less often is a win.
Not the least is also code maintainability. In the new paradigm
we can assume that at any stage of processing a packet, we are
inside network epoch. This makes coding both input and output
path way easier.
On output path we already enter epoch quite early - in the
ip_output(), in the ip6_output().
This patch does the same for the input path. All ISR processing,
network related callouts, other ways of packet injection to the
network stack shall be performed in net_epoch. Any leaf function
that walks network configuration now asserts epoch.
Tricky part is configuration code paths - ioctls, sysctls. They
also call into leaf functions, so some need to be changed.
This patch would introduce more epoch recursions (see EPOCH_TRACE)
than we had before. They will be cleaned up separately, as several
of them aren't trivial. Note, that unlike a lock recursion the
epoch recursion is safe and just wastes a bit of resources.
Reviewed by: gallatin, hselasky, cy, adrian, kristof
Differential Revision: https://reviews.freebsd.org/D19111
2019-10-07 22:40:05 +00:00
|
|
|
struct epoch_tracker et;
|
|
|
|
|
2008-08-04 21:14:24 +00:00
|
|
|
mtx_unlock(&sc->ic_lock);
|
2011-07-03 16:08:38 +00:00
|
|
|
M_SETFIB(top, sc->ic_ifp->if_fib);
|
Widen NET_EPOCH coverage.
When epoch(9) was introduced to network stack, it was basically
dropped in place of existing locking, which was mutexes and
rwlocks. For the sake of performance mutex covered areas were
as small as possible, so became epoch covered areas.
However, epoch doesn't introduce any contention, it just delays
memory reclaim. So, there is no point to minimise epoch covered
areas in sense of performance. Meanwhile entering/exiting epoch
also has non-zero CPU usage, so doing this less often is a win.
Not the least is also code maintainability. In the new paradigm
we can assume that at any stage of processing a packet, we are
inside network epoch. This makes coding both input and output
path way easier.
On output path we already enter epoch quite early - in the
ip_output(), in the ip6_output().
This patch does the same for the input path. All ISR processing,
network related callouts, other ways of packet injection to the
network stack shall be performed in net_epoch. Any leaf function
that walks network configuration now asserts epoch.
Tricky part is configuration code paths - ioctls, sysctls. They
also call into leaf functions, so some need to be changed.
This patch would introduce more epoch recursions (see EPOCH_TRACE)
than we had before. They will be cleaned up separately, as several
of them aren't trivial. Note, that unlike a lock recursion the
epoch recursion is safe and just wastes a bit of resources.
Reviewed by: gallatin, hselasky, cy, adrian, kristof
Differential Revision: https://reviews.freebsd.org/D19111
2019-10-07 22:40:05 +00:00
|
|
|
NET_EPOCH_ENTER(et);
|
2006-04-04 19:30:47 +00:00
|
|
|
netisr_dispatch(NETISR_IP, top);
|
Widen NET_EPOCH coverage.
When epoch(9) was introduced to network stack, it was basically
dropped in place of existing locking, which was mutexes and
rwlocks. For the sake of performance mutex covered areas were
as small as possible, so became epoch covered areas.
However, epoch doesn't introduce any contention, it just delays
memory reclaim. So, there is no point to minimise epoch covered
areas in sense of performance. Meanwhile entering/exiting epoch
also has non-zero CPU usage, so doing this less often is a win.
Not the least is also code maintainability. In the new paradigm
we can assume that at any stage of processing a packet, we are
inside network epoch. This makes coding both input and output
path way easier.
On output path we already enter epoch quite early - in the
ip_output(), in the ip6_output().
This patch does the same for the input path. All ISR processing,
network related callouts, other ways of packet injection to the
network stack shall be performed in net_epoch. Any leaf function
that walks network configuration now asserts epoch.
Tricky part is configuration code paths - ioctls, sysctls. They
also call into leaf functions, so some need to be changed.
This patch would introduce more epoch recursions (see EPOCH_TRACE)
than we had before. They will be cleaned up separately, as several
of them aren't trivial. Note, that unlike a lock recursion the
epoch recursion is safe and just wastes a bit of resources.
Reviewed by: gallatin, hselasky, cy, adrian, kristof
Differential Revision: https://reviews.freebsd.org/D19111
2019-10-07 22:40:05 +00:00
|
|
|
NET_EPOCH_EXIT(et);
|
2008-08-04 21:14:24 +00:00
|
|
|
mtx_lock(&sc->ic_lock);
|
|
|
|
}
|
2006-04-04 19:30:47 +00:00
|
|
|
break;
|
1998-09-03 20:51:50 +00:00
|
|
|
err:
|
2008-08-04 21:14:24 +00:00
|
|
|
if_printf(sc->ic_ifp, "errors (%d)!\n", sc->ic_iferrs);
|
2006-04-04 19:30:47 +00:00
|
|
|
sc->ic_iferrs = 0; /* reset error count */
|
2014-09-19 03:51:26 +00:00
|
|
|
if_inc_counter(sc->ic_ifp, IFCOUNTER_IERRORS, 1);
|
2006-04-04 19:30:47 +00:00
|
|
|
break;
|
1998-09-03 20:51:50 +00:00
|
|
|
|
|
|
|
case INTR_RECEIVE:
|
2008-08-04 21:14:24 +00:00
|
|
|
if (sc->ic_xfercnt >= sc->ic_ifp->if_mtu + ICHDRLEN) {
|
2006-04-04 19:30:47 +00:00
|
|
|
sc->ic_iferrs++;
|
1998-09-03 20:51:50 +00:00
|
|
|
} else {
|
|
|
|
*sc->ic_cp++ = *ptr;
|
2006-04-04 19:30:47 +00:00
|
|
|
sc->ic_xfercnt++;
|
1998-09-03 20:51:50 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INTR_NOACK: /* xfer terminated by master */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INTR_TRANSMIT:
|
|
|
|
*ptr = 0xff; /* XXX */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INTR_ERROR:
|
2006-04-04 19:30:47 +00:00
|
|
|
sc->ic_iferrs++;
|
1998-09-03 20:51:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2001-12-10 08:09:49 +00:00
|
|
|
panic("%s: unknown event (%d)!", __func__, event);
|
1998-09-03 20:51:50 +00:00
|
|
|
}
|
|
|
|
|
2008-08-04 21:14:24 +00:00
|
|
|
mtx_unlock(&sc->ic_lock);
|
2009-02-10 22:50:23 +00:00
|
|
|
return (0);
|
1998-09-03 20:51:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* icoutput()
|
|
|
|
*/
|
|
|
|
static int
|
2013-04-26 12:50:32 +00:00
|
|
|
icoutput(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst,
|
2009-04-16 20:30:28 +00:00
|
|
|
struct route *ro)
|
1998-09-03 20:51:50 +00:00
|
|
|
{
|
2008-08-04 21:14:24 +00:00
|
|
|
struct ic_softc *sc = ifp->if_softc;
|
|
|
|
device_t icdev = sc->ic_dev;
|
1998-09-03 20:51:50 +00:00
|
|
|
device_t parent = device_get_parent(icdev);
|
2008-08-04 21:14:24 +00:00
|
|
|
int len, sent;
|
1998-09-03 20:51:50 +00:00
|
|
|
struct mbuf *mm;
|
|
|
|
u_char *cp;
|
2005-06-26 18:11:11 +00:00
|
|
|
u_int32_t hdr;
|
|
|
|
|
|
|
|
/* BPF writes need to be handled specially. */
|
|
|
|
if (dst->sa_family == AF_UNSPEC)
|
|
|
|
bcopy(dst->sa_data, &hdr, sizeof(hdr));
|
|
|
|
else
|
|
|
|
hdr = dst->sa_family;
|
1998-09-03 20:51:50 +00:00
|
|
|
|
2008-08-04 21:14:24 +00:00
|
|
|
mtx_lock(&sc->ic_lock);
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags |= IFF_DRV_RUNNING;
|
1998-09-03 20:51:50 +00:00
|
|
|
|
|
|
|
/* already sending? */
|
2008-08-04 21:14:24 +00:00
|
|
|
if (sc->ic_flags & IC_SENDING) {
|
2014-09-19 03:51:26 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
|
1998-09-03 20:51:50 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* insert header */
|
|
|
|
bcopy ((char *)&hdr, sc->ic_obuf, ICHDRLEN);
|
|
|
|
|
|
|
|
cp = sc->ic_obuf + ICHDRLEN;
|
|
|
|
len = 0;
|
|
|
|
mm = m;
|
|
|
|
do {
|
2005-06-10 16:49:24 +00:00
|
|
|
if (len + mm->m_len > sc->ic_ifp->if_mtu) {
|
2008-08-04 21:14:24 +00:00
|
|
|
/* packet too large */
|
2014-09-19 03:51:26 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
|
1998-09-03 20:51:50 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
bcopy(mtod(mm,char *), cp, mm->m_len);
|
|
|
|
cp += mm->m_len;
|
|
|
|
len += mm->m_len;
|
|
|
|
|
|
|
|
} while ((mm = mm->m_next));
|
|
|
|
|
2003-12-28 03:56:00 +00:00
|
|
|
BPF_MTAP2(ifp, &hdr, sizeof(hdr), m);
|
1998-09-03 20:51:50 +00:00
|
|
|
|
2008-08-04 21:14:24 +00:00
|
|
|
sc->ic_flags |= (IC_SENDING | IC_OBUF_BUSY);
|
1998-09-03 20:51:50 +00:00
|
|
|
|
|
|
|
m_freem(m);
|
2008-08-04 21:14:24 +00:00
|
|
|
mtx_unlock(&sc->ic_lock);
|
1998-09-03 20:51:50 +00:00
|
|
|
|
|
|
|
/* send the packet */
|
|
|
|
if (iicbus_block_write(parent, sc->ic_addr, sc->ic_obuf,
|
|
|
|
len + ICHDRLEN, &sent))
|
|
|
|
|
2014-09-19 03:51:26 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
|
1998-09-03 20:51:50 +00:00
|
|
|
else {
|
2014-09-19 03:51:26 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
|
|
|
|
if_inc_counter(ifp, IFCOUNTER_OBYTES, len);
|
2008-08-04 21:14:24 +00:00
|
|
|
}
|
1998-09-03 20:51:50 +00:00
|
|
|
|
2008-08-04 21:14:24 +00:00
|
|
|
mtx_lock(&sc->ic_lock);
|
|
|
|
sc->ic_flags &= ~(IC_SENDING | IC_OBUF_BUSY);
|
|
|
|
if ((sc->ic_flags & (IC_BUFFERS_BUSY | IC_BUFFER_WAITER)) ==
|
|
|
|
IC_BUFFER_WAITER)
|
|
|
|
wakeup(&sc);
|
|
|
|
mtx_unlock(&sc->ic_lock);
|
1998-09-03 20:51:50 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
error:
|
|
|
|
m_freem(m);
|
2008-08-04 21:14:24 +00:00
|
|
|
mtx_unlock(&sc->ic_lock);
|
1998-09-03 20:51:50 +00:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
DRIVER_MODULE(ic, iicbus, ic_driver, ic_devclass, 0, 0);
|
2002-03-23 15:49:15 +00:00
|
|
|
MODULE_DEPEND(ic, iicbus, IICBUS_MINVER, IICBUS_PREFVER, IICBUS_MAXVER);
|
|
|
|
MODULE_VERSION(ic, 1);
|