MFC r343574:

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>
This commit is contained in:
Andriy Voskoboinyk 2019-02-06 02:07:37 +00:00
parent b4274b1660
commit 035ec4b4cd
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/stable/10/; revision=343820
3 changed files with 67 additions and 84 deletions

View File

@ -1734,8 +1734,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

@ -559,15 +559,6 @@ ndis_attach(dev)
InitializeListHead(&sc->ndisusb_xferdonelist);
callout_init(&sc->ndis_stat_callout, 1);
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);
@ -1079,9 +1070,6 @@ ndis_detach(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

@ -70,6 +70,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,
@ -87,7 +88,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),
@ -171,6 +172,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(sc->ndis_dev, SYS_RES_MEMORY,
&rid, 0UL, ~0UL, 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.
@ -247,12 +292,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;
@ -263,72 +329,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(sc->ndis_dev, SYS_RES_MEMORY,
&rid, 0UL, ~0UL, 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;
}