> > > +static int z87_probe(struct mcb_device *mdev, > > > + const struct mcb_device_id *id) > > > +{ > > > + const struct board_config *cfg = NULL; > > > + struct net_device *dev = NULL; > > > + struct z87_private *np = NULL; > > > + void *mem_virt_dma = NULL; > > > + dma_addr_t mem_hw_dma; > > > + struct resource *mem; > > > + int res = -ENXIO; > > > + > > > + cfg = z87_get_board_config(mdev); > > > + if (!cfg) > > > + return -EOPNOTSUPP; > > > + > > > + /** > > > + * mdev->inst is defined in a per-board basis, so lets check > > > + * if there are more devices that defined for the board. In that > > > + * case, something is wrong. > > > + */ > > > + if (mdev->inst >= cfg->num_devs) { > > > + return dev_err_probe(&mdev->dev, -EINVAL, > > > + "detected more devices than configured for board: %s", > > > + cfg->board_name); > > > + }
> > > > Does something actually go wrong if there are more?
> > Yes, It could crash as it tries to access to an array index that does not exist. However > I am pretty sure this condition hardly could happens so I just could remove it.
You generally try to write drivers so you can instantiate them an arbitrary number of times. That means not having any global state.
> > Sorry, but no. The PHY driver should export the LEDs via > > /sys/class/leds.
> > Understood. I would like to agree on this approach. > > PHY driver dp83822 already implements the mechanism to handle LEDs > in the correct way using DT nodes. My hardware (FPGA) is a PCI device > that typically runs on x86 so there is DT node for the PCI function, > the MCB devices or the PHYs yet. > > Another solution could be transforming of_phy_led()/of_phy_leds() > functions on phy_device to fwnodes thus my driver just could create > a subnode describing leds. > > Please could you help me with that? which could be the best approach?
There are a few possible solutions. It is possible to use DT with X86. drivers/misc/lan966x_pci.dtso gets loaded as a DT overlay on top of the PCIe node, instantiating various devices the DT way. You can also at runtime create fwnode entries and associate them to the device. I don't know if anybody has done this if LEDs yet, bit it has been used for SFP sockets and phylink. wangxun/txgbe/txgbe_phy.c And lastly, you could consider adding an ACPI binding. ACPI and complex network hardware configurations generally don't go together. PCIe devices tend to hide all there internal details in firmware, rather than have Linux drive the hardware. So there has not been any real need to describe networking hardware in ACPI. But maybe LEDs do have some sort of standard way of being described in ACPI? Andrew