pccard_attach

Hello,

I am trying to write a driver for a PCMCIA network card, and am having the
following problem. I am trying to use the pccard_xxxxx functions to detect
the pc-card and determine the hardware settings it has been assigned. If I
try this in a stand alone program it works fine, I receive a handle back
from the pccard_attach function and can query the card as needed. If I try
this in the io-net driver though I get a core dump.

Has anyone ever got pccard_attach to work in an io-net driver? Or have any
idea what may be causing this problem? I have included two code samples
below showing it working, and not working (the actual driver code is much
longer then what is shown).

Thanks
Mark Komus
CDS Technologies



Stand alone program that works:
/*

  • stand-alone app
  • compiling with: qcc -Vgcc_ntox86 -l pccard pcc.c -o pcc
  • running with: ./pcc
  • result: # ./pcc
    PC CARD ATTACHED: handle = 3
    */

#include <stdio.h>
#include <stdlib.h>
#include <sys/pccard.h>

int main (void)
{
pccard_t handle;

if ((handle = pccard_attach (0)) == -1)
{
printf (“Unable to attach to PCCARD\n”);
exit (EXIT_FAILURE);
}

printf(“PC CARD ATTACHED: handle = %d\n”, handle);
pccard_detach (handle);
return (EXIT_SUCCESS);
}



IO-Net driver that does not:

/*

  • attaching pc-card to devp-pccard server inside a driver
  • compiling with: qcc -Vgcc_ntox86 -l pccard pcc2.c -shared -o
    devn-pcc.so
  • running with: io-net -dpcc &
  • result: # io-net -dpcc &
    [1] 1384484

pidin |grep io-net

[1] + Memory fault io-net -dpcc (core
dumped)
*/

#include <stdio.h>
#include <stdlib.h>
#include <sys/pccard.h>
#include <sys/neutrino.h>
#include <sys/io-net.h>

int pcc_init(void *dll_hdl,
dispatch_t *dpp,
io_net_self_t *ion,
char *options);

/-----------------------------------------------------------------------
// dll entry structure for the driver
-----------------------------------------------------------------------
/
io_net_dll_entry_t io_net_dll_entry =
{
2,
pcc_init,
NULL
};


/-----------------------------------------------------------------------
// functions that io-net can call in the driver
-----------------------------------------------------------------------
/
io_net_registrant_funcs_t pcc_funcs =
{
8,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};


/-----------------------------------------------------------------------
// driver registration structure
-----------------------------------------------------------------------
/
io_net_registrant_t pcc_entry =
{
_REG_PRODUCER_UP,
“devn-pcc”,
“en”,
NULL,
NULL,
&pcc_funcs,
0
};

/-----------------------------------------------------------------------
// driver initialization
-----------------------------------------------------------------------
/
int pcc_init(void *dll_hdl,
dispatch_t *dpp,
io_net_self_t *ion,
char *options)
{
pccard_t handle;

dpp = dpp;

if ((handle = pccard_attach (0)) == -1)
{
printf (“Unable to attach to PCCARD\n”);
exit (EXIT_FAILURE);
}

printf(“PC CARD ATTACHED: handle = %d\n”, handle);
pccard_detach (handle);
return (EXIT_SUCCESS);
}

Mark Komus <mark@wilinx.com> wrote:
: Hello,

: I am trying to write a driver for a PCMCIA network card, and am having the
: following problem. I am trying to use the pccard_xxxxx functions to detect
: the pc-card and determine the hardware settings it has been assigned. If I
: try this in a stand alone program it works fine, I receive a handle back
: from the pccard_attach function and can query the card as needed. If I try
: this in the io-net driver though I get a core dump.

: Has anyone ever got pccard_attach to work in an io-net driver? Or have any
: idea what may be causing this problem? I have included two code samples
: below showing it working, and not working (the actual driver code is much
: longer then what is shown).

: Thanks
: Mark Komus
: CDS Technologies

: ****************************************************************************
: ********

: Stand alone program that works:
: /*
: - stand-alone app
: - compiling with: qcc -Vgcc_ntox86 -l pccard pcc.c -o pcc
: - running with: ./pcc
: - result: # ./pcc
: PC CARD ATTACHED: handle = 3
: */

: #include <stdio.h>
: #include <stdlib.h>
: #include <sys/pccard.h>

: int main (void)
: {
: pccard_t handle;

: if ((handle = pccard_attach (0)) == -1)
: {
: printf (“Unable to attach to PCCARD\n”);
: exit (EXIT_FAILURE);
: }

: printf(“PC CARD ATTACHED: handle = %d\n”, handle);
: pccard_detach (handle);
: return (EXIT_SUCCESS);
: }

: ****************************************************************************
: ********

: IO-Net driver that does not:

: /*
: - attaching pc-card to devp-pccard server inside a driver
: - compiling with: qcc -Vgcc_ntox86 -l pccard pcc2.c -shared -o
: devn-pcc.so
: - running with: io-net -dpcc &
: - result: # io-net -dpcc &
: [1] 1384484
: # pidin |grep io-net
: [1] + Memory fault io-net -dpcc (core
: dumped)
: */

: #include <stdio.h>
: #include <stdlib.h>
: #include <sys/pccard.h>
: #include <sys/neutrino.h>
: #include <sys/io-net.h>

: int pcc_init(void *dll_hdl,
: dispatch_t *dpp,
: io_net_self_t *ion,
: char *options);

: /-----------------------------------------------------------------------
: // dll entry structure for the driver
: -----------------------------------------------------------------------
/
: io_net_dll_entry_t io_net_dll_entry =
: {
: 2,
: pcc_init,
: NULL
: };


: /-----------------------------------------------------------------------
: // functions that io-net can call in the driver
: -----------------------------------------------------------------------
/


Not sure if this is where you are getting bit, but a _REG_PRODUCER_UP
must supply at least, rx_down() and advertise() functions below. Once
you start sending packets up, you’ll need tx_done() as well. io-net
is probably (or at least will at some time) trying to jump into you
and is dereferencing NULL.

-seanb


: io_net_registrant_funcs_t pcc_funcs =
: {
: 8,
: NULL,
: NULL,
: NULL,
: NULL,
: NULL,
: NULL,
: NULL,
: NULL,
: NULL
: };


: /-----------------------------------------------------------------------
: // driver registration structure
: -----------------------------------------------------------------------
/
: io_net_registrant_t pcc_entry =
: {
: _REG_PRODUCER_UP,
: “devn-pcc”,
: “en”,
: NULL,
: NULL,
: &pcc_funcs,
: 0
: };

Not sure if this is where you are getting bit, but a _REG_PRODUCER_UP
must supply at least, rx_down() and advertise() functions below. Once
you start sending packets up, you’ll need tx_done() as well. io-net
is probably (or at least will at some time) trying to jump into you
and is dereferencing NULL.

In the actual driver code those functions are supplied, I’ve already had
that problem earlier. This is just a sample of the complete code. Thanks
anyways.

Previously, Mark Komus wrote in qdn.public.qnxrtp.os:

Hello,

I am trying to write a driver for a PCMCIA network card, and am having the
following problem. I am trying to use the pccard_xxxxx functions to detect
the pc-card and determine the hardware settings it has been assigned. If I
try this in a stand alone program it works fine, I receive a handle back
from the pccard_attach function and can query the card as needed. If I try
this in the io-net driver though I get a core dump.

Has anyone ever got pccard_attach to work in an io-net driver? Or have any
idea what may be causing this problem? I have included two code samples
below showing it working, and not working (the actual driver code is much
longer then what is shown).

This needs a shared library to be linked with your io-net driver. I have
created one and it should be released with the next rtp update.

Hugh.

Thanks
Mark Komus
CDS Technologies



Stand alone program that works:
/*

  • stand-alone app
  • compiling with: qcc -Vgcc_ntox86 -l pccard pcc.c -o pcc
  • running with: ./pcc
  • result: # ./pcc
    PC CARD ATTACHED: handle = 3
    */

#include <stdio.h
#include <stdlib.h
#include <sys/pccard.h

int main (void)
{
pccard_t handle;

if ((handle = pccard_attach (0)) == -1)
{
printf (“Unable to attach to PCCARD\n”);
exit (EXIT_FAILURE);
}

printf(“PC CARD ATTACHED: handle = %d\n”, handle);
pccard_detach (handle);
return (EXIT_SUCCESS);
}



IO-Net driver that does not:

/*

  • attaching pc-card to devp-pccard server inside a driver
  • compiling with: qcc -Vgcc_ntox86 -l pccard pcc2.c -shared -o
    devn-pcc.so
  • running with: io-net -dpcc &
  • result: # io-net -dpcc &
    [1] 1384484

pidin |grep io-net

[1] + Memory fault io-net -dpcc (core
dumped)
*/

#include <stdio.h
#include <stdlib.h
#include <sys/pccard.h
#include <sys/neutrino.h
#include <sys/io-net.h

int pcc_init(void *dll_hdl,
dispatch_t *dpp,
io_net_self_t *ion,
char *options);

/-----------------------------------------------------------------------
// dll entry structure for the driver
-----------------------------------------------------------------------
/
io_net_dll_entry_t io_net_dll_entry =
{
2,
pcc_init,
NULL
};


/-----------------------------------------------------------------------
// functions that io-net can call in the driver
-----------------------------------------------------------------------
/
io_net_registrant_funcs_t pcc_funcs =
{
8,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};


/-----------------------------------------------------------------------
// driver registration structure
-----------------------------------------------------------------------
/
io_net_registrant_t pcc_entry =
{
_REG_PRODUCER_UP,
“devn-pcc”,
“en”,
NULL,
NULL,
&pcc_funcs,
0
};

/-----------------------------------------------------------------------
// driver initialization
-----------------------------------------------------------------------
/
int pcc_init(void *dll_hdl,
dispatch_t *dpp,
io_net_self_t *ion,
char *options)
{
pccard_t handle;

dpp = dpp;

if ((handle = pccard_attach (0)) == -1)
{
printf (“Unable to attach to PCCARD\n”);
exit (EXIT_FAILURE);
}

printf(“PC CARD ATTACHED: handle = %d\n”, handle);
pccard_detach (handle);
return (EXIT_SUCCESS);
}

\

Hugh Brown (613) 591-0931 ext. 209 (voice)
QNX Software Systems Ltd. (613) 591-3579 (fax)
175 Terence Matthews Cres. email: hsbrown@qnx.com
Kanata, Ontario, Canada.
K2M 1W8