, <tech-net@netbsd.org>
From: Vikram <vikram@controlnet.co.in>
List: tech-net
Date: 06/20/2000 12:37:21
Hello NetBSD gurus!!,
I have a memory mapped network card. And I am map the memory and then
access the memory using
bus_space_write_4(sc->pm_memt, sc->pm_sh,..) the pm_memt and pm_sh are
returned by pci_mapreg_map() which I uae for mapping the memory.
Is every thing done properly? I hope so.
Now the problem is after some while the whenever I try to read the
registers they all give content as 0xffffffff . May I know the reason? Pls
Help.
Thanking you,
Vikram
/*
* REFERence drivers if_de.c and tulip.c
* Attach for autoconfig to find. Initialise the lists and return...
*/
void my_pci_attach( struct device *parent,
struct device *self,
void * const aux)
{
/* nothing to do for my, this is where resources that
need to be allocated/initialised before open is called
can be set up */
my_softc * const sc = (my_softc *) self;
struct pci_attach_args * const pa = (struct pci_attach_args *) aux;
const int unit = sc->pm_dev.dv_unit;
pci_intr_handle_t ih;// interrupt handler
const char *intrstr;
// int retval;
// bus_addr_t csrbase;
struct ifnet *ifp;
u_int8_t enaddr[ETHER_ADDR_LEN];
bus_space_tag_t memt;
bus_space_handle_t memh;
int memh_valid,s;
printf("my_:_ Number of mys found = %d\n",unit + 1);
sc->pm_pc = pa->pa_pc;
file://Get the device info
(sc)->pm_pci_busno = parent;
(sc)->pm_pci_devno = pa->pa_device;
file://make sure bus mastering is enabled
pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
PCI_COMMAND_MASTER_ENABLE);
file://interrupt map
if (pci_intr_map(sc->pm_pc, pa->pa_intrtag, pa->pa_intrpin,
pa->pa_intrline, &ih))
{
printf("%s: couldn't map interrupt\n", "my_:_");
return;
}
sc->pm_intr = my_intr;// link the my intrupt hadler with driver data
intrstr = pci_intr_string(sc->pm_pc, ih);
sc->pm_ih = pci_intr_establish(sc->pm_pc, ih, IPL_NET, sc->pm_intr, sc);
if (sc->pm_ih == NULL)
{
printf("%s: couldn't establish interrupt\n", "my_:_");
if (intrstr != NULL)
printf(" at %s", intrstr);
printf("\n");
return;
}
printf("%s: interrupting at %s\n", "my_:_", intrstr);
sc->pm_sdhook = shutdownhook_establish(my_shutdown, sc);
// Copying the names.
bcopy(self->dv_xname, sc->pm_ethercom.ec_if.if_xname, IFNAMSIZ);
sc->pm_ethercom.ec_if.if_softc = sc;
sc->pm_pc = pa->pa_pc;
// Saving the dmatag for the future use
sc->pm_dmat = pa->pa_dmat;
sc->cur_tx = sc->cur_rx = 0;
file://csr_base = 0;// Check if this is needed
// My card has stored memory mapped address at PCI_CBIO
// For Memory mapped access
memh_valid = (pci_mapreg_map(pa, PCI_CBIO,
PCI_MAPREG_TYPE_MEM |
PCI_MAPREG_MEM_TYPE_32BIT,
0, &memt, &memh, NULL, NULL) == 0);
if (memh_valid)
{
sc->pm_memt = memt;
sc->pm_sh = memh;
} else
{
printf("my_:_ unable to map device registers\n");
return;
}
// Make sure bus mastering is enabled.
pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
pci_conf_read(pa->pa_pc, pa->pa_tag,
PCI_COMMAND_STATUS_REG) |
PCI_COMMAND_MASTER_ENABLE);
// Display all the registers
DisplayReg(sc);
if( my_busdma_allocmem(sc) )
goto LoadFail; // BusDma allocation problem!
printf("my_:_ bus_dmamap ing successful\n");
if( my_init_ring(sc) )
goto LoadFail; // Can't init the descriptor memories!
printf("my_:_ initing the descriptor memories\n");
// Give driver reset
my_reset(sc);
printf("my_:_ Driver Reset ***** Done\n");
// Suppose by this time the media is detected and here I am hardcoding
// that until I write the Link checking code
sc->my_media = 7; // 100 Mbps
// Any change after the reset?
// DisplayReg(sc);
/* Announce ourselves. */
printf("%s: %s Ethernet address %s\n", sc->pm_dev.dv_xname,
"my",
ether_sprintf(enaddr));
s = splnet();
/*
* Initialize our media structures. This may probe the MII, if
* present.
*/
// (*sc->pm_mediasw->tmsw_init)(sc);
// For attaching to if_config etc
ifp = &sc->pm_ethercom.ec_if;
strcpy(ifp->if_xname, sc->pm_dev.dv_xname);
ifp->if_softc = sc;
ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_NOTRAILERS|IFF_MULTICAST;
ifp->if_ioctl = my_ifioctl;
ifp->if_start = my_ifstart;
ifp->if_watchdog = my_ifwatchdog;
ifp->if_timer = 1;
/*
* the ifp is initialised
*/
ifp->if_output = ether_output;
#if defined(IFM_ETHER)
ifmedia_init(&sc->my_ifmedia,0,my_ifmedia_change,my_ifmedia_status);
my_ifmedia_add(sc);
#endif
/*
* Attach the interface.
*/
if_attach(ifp);
ether_ifattach(ifp, enaddr);
#if NBPFILTER > 0
bpfattach(&sc->pm_ethercom.ec_if.if_bpf, ifp, DLT_EN10MB,sizeof(struct
ether_header));
#endif
#if defined(__NetBSD__) && NRND > 0
// For kernel entropy collection
rnd_attach_source(&sc->my_rndsource, sc->pm_dev.dv_xname,RND_TYPE_NET, 0);
#endif
splx(s);
/*
* Driver loaded Successfully
*/
printf("my_:_ Driver loading successful\n");
return;
LoadFail:
printf("my_:_ Loading my failed.");
return;
}