1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-11-29 08:08:37 +00:00

Fix compilation with 'option NDISAPI + device ndis' and

without 'device pccard' in the kernel config file.

PR:		171532
Reported by:	Robert Bonomi <bonomi@host128.r-bonomi.com>
MFC after:	1 week
This commit is contained in:
Andriy Voskoboinyk 2019-01-30 11:40:12 +00:00
parent 27c36a12f1
commit a99bdc110b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=343574
3 changed files with 67 additions and 84 deletions

View File

@ -1736,8 +1736,6 @@ extern int ndis_get_supported_oids(void *, ndis_oid **, int *);
extern int ndis_send_packets(void *, ndis_packet **, int);
extern int ndis_send_packet(void *, ndis_packet *);
extern int ndis_convert_res(void *);
extern int ndis_alloc_amem(void *);
extern void ndis_free_amem(void *);
extern void ndis_free_packet(ndis_packet *);
extern void ndis_free_bufs(ndis_buffer *);
extern int ndis_reset_nic(void *);

View File

@ -568,15 +568,6 @@ ndis_attach(device_t dev)
callout_init(&sc->ndis_stat_callout, 1);
mbufq_init(&sc->ndis_rxqueue, INT_MAX); /* XXXGL: sane maximum */
if (sc->ndis_iftype == PCMCIABus) {
error = ndis_alloc_amem(sc);
if (error) {
device_printf(dev, "failed to allocate "
"attribute memory\n");
goto fail;
}
}
/* Create sysctl registry nodes */
ndis_create_sysctls(sc);
@ -1098,9 +1089,6 @@ ndis_detach(device_t dev)
if (ifp != NULL)
if_free(ifp);
if (sc->ndis_iftype == PCMCIABus)
ndis_free_amem(sc);
if (sc->ndis_sc)
ndis_destroy_dma(sc);

View File

@ -74,6 +74,7 @@ MODULE_DEPEND(ndis, pccard, 1, 1, 1);
static int ndis_probe_pccard (device_t);
static int ndis_attach_pccard (device_t);
static int ndis_detach_pccard (device_t);
static struct resource_list *ndis_get_resource_list
(device_t, device_t);
static int ndis_devcompare (interface_type,
@ -91,7 +92,7 @@ static device_method_t ndis_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, ndis_probe_pccard),
DEVMETHOD(device_attach, ndis_attach_pccard),
DEVMETHOD(device_detach, ndis_detach),
DEVMETHOD(device_detach, ndis_detach_pccard),
DEVMETHOD(device_shutdown, ndis_shutdown),
DEVMETHOD(device_suspend, ndis_suspend),
DEVMETHOD(device_resume, ndis_resume),
@ -175,6 +176,50 @@ ndis_probe_pccard(dev)
return(ENXIO);
}
#define NDIS_AM_RID 3
static int
ndis_alloc_amem(struct ndis_softc *sc)
{
int error, rid;
rid = NDIS_AM_RID;
sc->ndis_res_am = bus_alloc_resource_anywhere(sc->ndis_dev,
SYS_RES_MEMORY, &rid, 0x1000, RF_ACTIVE);
if (sc->ndis_res_am == NULL) {
device_printf(sc->ndis_dev,
"failed to allocate attribute memory\n");
return(ENXIO);
}
sc->ndis_rescnt++;
resource_list_add(&sc->ndis_rl, SYS_RES_MEMORY, rid,
rman_get_start(sc->ndis_res_am), rman_get_end(sc->ndis_res_am),
rman_get_size(sc->ndis_res_am));
error = CARD_SET_MEMORY_OFFSET(device_get_parent(sc->ndis_dev),
sc->ndis_dev, rid, 0, NULL);
if (error) {
device_printf(sc->ndis_dev,
"CARD_SET_MEMORY_OFFSET() returned 0x%x\n", error);
return(error);
}
error = CARD_SET_RES_FLAGS(device_get_parent(sc->ndis_dev),
sc->ndis_dev, SYS_RES_MEMORY, rid, PCCARD_A_MEM_ATTR);
if (error) {
device_printf(sc->ndis_dev,
"CARD_SET_RES_FLAGS() returned 0x%x\n", error);
return(error);
}
sc->ndis_am_rid = rid;
return(0);
}
/*
* Attach the interface. Allocate softc structures, do ifmedia
* setup and ethernet/BPF attach.
@ -251,12 +296,33 @@ ndis_attach_pccard(dev)
sc->ndis_devidx = devidx;
error = ndis_alloc_amem(sc);
if (error) {
device_printf(dev, "failed to allocate attribute memory\n");
goto fail;
}
error = ndis_attach(dev);
fail:
return(error);
}
static int
ndis_detach_pccard(device_t dev)
{
struct ndis_softc *sc = device_get_softc(dev);
(void) ndis_detach(dev);
if (sc->ndis_res_am != NULL)
bus_release_resource(sc->ndis_dev, SYS_RES_MEMORY,
sc->ndis_am_rid, sc->ndis_res_am);
resource_list_free(&sc->ndis_rl);
return (0);
}
static struct resource_list *
ndis_get_resource_list(dev, child)
device_t dev;
@ -267,72 +333,3 @@ ndis_get_resource_list(dev, child)
sc = device_get_softc(dev);
return (&sc->ndis_rl);
}
#define NDIS_AM_RID 3
int
ndis_alloc_amem(arg)
void *arg;
{
struct ndis_softc *sc;
int error, rid;
if (arg == NULL)
return(EINVAL);
sc = arg;
rid = NDIS_AM_RID;
sc->ndis_res_am = bus_alloc_resource_anywhere(sc->ndis_dev,
SYS_RES_MEMORY, &rid, 0x1000, RF_ACTIVE);
if (sc->ndis_res_am == NULL) {
device_printf(sc->ndis_dev,
"failed to allocate attribute memory\n");
return(ENXIO);
}
sc->ndis_rescnt++;
resource_list_add(&sc->ndis_rl, SYS_RES_MEMORY, rid,
rman_get_start(sc->ndis_res_am), rman_get_end(sc->ndis_res_am),
rman_get_size(sc->ndis_res_am));
error = CARD_SET_MEMORY_OFFSET(device_get_parent(sc->ndis_dev),
sc->ndis_dev, rid, 0, NULL);
if (error) {
device_printf(sc->ndis_dev,
"CARD_SET_MEMORY_OFFSET() returned 0x%x\n", error);
return(error);
}
error = CARD_SET_RES_FLAGS(device_get_parent(sc->ndis_dev),
sc->ndis_dev, SYS_RES_MEMORY, rid, PCCARD_A_MEM_ATTR);
if (error) {
device_printf(sc->ndis_dev,
"CARD_SET_RES_FLAGS() returned 0x%x\n", error);
return(error);
}
sc->ndis_am_rid = rid;
return(0);
}
void
ndis_free_amem(arg)
void *arg;
{
struct ndis_softc *sc;
if (arg == NULL)
return;
sc = arg;
if (sc->ndis_res_am != NULL)
bus_release_resource(sc->ndis_dev, SYS_RES_MEMORY,
sc->ndis_am_rid, sc->ndis_res_am);
resource_list_free(&sc->ndis_rl);
return;
}