Subject: Re: CVS commit: src/sys/dev/pci
To: Gavan Fantom <gavan@NetBSD.org>
From: Jason Thorpe <thorpej@shagadelic.org>
List: tech-kern
Date: 02/16/2006 10:12:48
On Feb 16, 2006, at 9:38 AM, Gavan Fantom wrote:

> How would you determine in this case whether the ethernet device  
> was onboard or on a plug-in card? In the particular case I'm  
> looking at, it's just another PCI device on the same bus, and the  
> only real distinguishing attribute is the lack of a connected EEPROM.

We're talking about a built-in device on a specific model of board,  
right?  If that's the case, then platform-specific code is allowed to  
have knowledge of the physical location of that device, otherwise,  
how does your MD hook know it's supposed to supply the Ethernet  
address?  ...since your original patch did not include an example of  
that [because the MD code is proprietary?], I merely assumed that it  
was doing the appropriate checking ... otherwise, how would it  
distinguish between the on-board Ethernet and a plug-in card that  
simply has had its EEPROM trashed somehow (something that has  
happened to me at least a few times during driver development over  
the years :-)?

> I'd like to do this, but only if there's a reliable way of  
> determining which device to set the properties for.

I'm about to check in in the following change to the "algor" port  
that should provide a good example of how to do this:

#if defined(ALGOR_P4032)
#define BUILTIN_ETHERNET_P 
(pa)                                          \
         ((pa)->pa_bus == 0 && (pa)->pa_device == 5 && (pa)- 
 >pa_function == 0)
#elif defined(ALGOR_P5064)
#define BUILTIN_ETHERNET_P 
(pa)                                          \
         ((pa)->pa_bus == 0 && (pa)->pa_device == 0 && (pa)- 
 >pa_function == 0)
#elif defined(ALGOR_P6032)
#define BUILTIN_ETHERNET_P 
(pa)                                          \
         ((pa)->pa_bus == 0 && (pa)->pa_device == 16 && (pa)- 
 >pa_function == 0)
#else
#define BUILTIN_ETHERNET_P(pa)  0
#endif

void
device_register(struct device *dev, void *aux)
{

         /*
          * We don't ever know the boot device.  But that's because the
          * firmware only loads from the network or the parallel port.
          */

         /*
          * Fetch the MAC address for the built-in Ethernet (we grab it
          * from PMON earlier in the boot process).
          */
         if (dev->dev_parent != NULL &&
             strcmp(dev->dv_parent->dv_cfdata->cf_name, "pci") == 0) {
                 struct pci_attach_args *pa = aux;

                 if (BUILTIN_ETHERNET_P(pa)) {
                         if (prop_set(dev_propdb, dev, "mac-addr",
                                      algor_ethaddr,
                                      sizeof(algor_ethaddr), 0, 0) !=  
0) {
                                 printf("WARNING: unable to set mac- 
addr "
                                     "property for %s\n", dev- 
 >dv_xname);
                         }
#if defined(ALGOR_P4032)
                         /*
                          * XXX This is gross, disgusting, and  
otherwise vile,
                          * XXX but V962 rev. < B2 have broken DMA  
FIFOs.  Give
                          * XXX the on-board Ethernet a different DMA  
window
                          * XXX that has pre-fetching disabled so  
that Ethernet
                          * XXX performance doesn't completely suck.
                          */
                         pa->pa_dmat =  
&p4032_configuration.ac_pci_pf_dmat;
                         pa->pa_dmat64 = NULL;
#endif /* ALGOR_P4032 */
                 }
         }
}


-- thorpej