can: populate netdev::dev_id for udev discrimination
authorChristopher R. Baker <cbaker@rec.ri.cmu.edu>
Sat, 8 Mar 2014 16:00:20 +0000 (11:00 -0500)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Mon, 17 Mar 2014 08:20:16 +0000 (09:20 +0100)
My objective is to be able to totally discriminate CAN ports on multi-port
cards via udev so as to rename them to semantically interesting/unique names
for my system (e.g., "ecuCAN" and "auxCAN" instead of "can0" and "can1").

The following patch assigns the dev_id field to match the channel number on all
multi-channel devices. I can only test my two-port Peak PCI card, but it works
as expected: ATTRS{dev_id} now expresses the port number and my udev rules now
unambiguously pick out and rename my individual CAN ports.

Signed-off-by: Christopher R. Baker <cbaker@rec.ri.cmu.edu>
Tested-by: Oliver Hartkopp <socketcan@hartkopp.net> [PEAK PCAN-USB pro and EMS PCMCIA]
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
drivers/net/can/sja1000/ems_pci.c
drivers/net/can/sja1000/ems_pcmcia.c
drivers/net/can/sja1000/kvaser_pci.c
drivers/net/can/sja1000/peak_pci.c
drivers/net/can/sja1000/peak_pcmcia.c
drivers/net/can/sja1000/plx_pci.c
drivers/net/can/softing/softing_main.c
drivers/net/can/usb/esd_usb2.c
drivers/net/can/usb/kvaser_usb.c
drivers/net/can/usb/peak_usb/pcan_usb_core.c

index d790b874ca79ba4cb4d522a8664f24c99ea3ebb8..fd13dbf07d9c0cb3d912c99f326b6e31be965366 100644 (file)
@@ -323,6 +323,7 @@ static int ems_pci_add_card(struct pci_dev *pdev,
                        priv->cdr = EMS_PCI_CDR;
 
                        SET_NETDEV_DEV(dev, &pdev->dev);
+                       dev->dev_id = i;
 
                        if (card->version == 1)
                                /* reset int flag of pita */
index 9e535f2ef52bb03365cc6ccf6f5ac2ababc6e7dc..381de998d2f1655b955bc701add77a30fe44ac21 100644 (file)
@@ -211,6 +211,7 @@ static int ems_pcmcia_add_card(struct pcmcia_device *pdev, unsigned long base)
                priv = netdev_priv(dev);
                priv->priv = card;
                SET_NETDEV_DEV(dev, &pdev->dev);
+               dev->dev_id = i;
 
                priv->irq_flags = IRQF_SHARED;
                dev->irq = pdev->irq;
index c96eb14699d5ad8a00655d71d80c8bd7fcbcf1c9..23b8e1324e25ef9e31a78a8c7591a1c968c01c29 100644 (file)
@@ -270,6 +270,7 @@ static int kvaser_pci_add_chan(struct pci_dev *pdev, int channel,
                 priv->reg_base, board->conf_addr, dev->irq);
 
        SET_NETDEV_DEV(dev, &pdev->dev);
+       dev->dev_id = channel;
 
        /* Register SJA1000 device */
        err = register_sja1000dev(dev);
index 065ca49eb45e72c48c9d1cc5f8fbda0256fdb195..c540e3d12e3d826260dbb590e8045c92fa4efb2b 100644 (file)
@@ -642,6 +642,7 @@ static int peak_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
                icr |= chan->icr_mask;
 
                SET_NETDEV_DEV(dev, &pdev->dev);
+               dev->dev_id = i;
 
                /* Create chain of SJA1000 devices */
                chan->prev_dev = pci_get_drvdata(pdev);
index f7ad754dd2aa1427380b79eabf6c661d6114ba48..dd56133cc4616180bc5841bda60dd576e3ebcd75 100644 (file)
@@ -550,6 +550,7 @@ static int pcan_add_channels(struct pcan_pccard *card)
                priv = netdev_priv(netdev);
                priv->priv = card;
                SET_NETDEV_DEV(netdev, &pdev->dev);
+               netdev->dev_id = i;
 
                priv->irq_flags = IRQF_SHARED;
                netdev->irq = pdev->irq;
index fbb61a0d901fb3c367d2d1dc15a5a524dab43b93..ec39b7cb2287b4764ffbfadffa29ed5286c5c545 100644 (file)
@@ -587,6 +587,7 @@ static int plx_pci_add_card(struct pci_dev *pdev,
                        priv->cdr = ci->cdr;
 
                        SET_NETDEV_DEV(dev, &pdev->dev);
+                       dev->dev_id = i;
 
                        /* Register SJA1000 device */
                        err = register_sja1000dev(dev);
index 3766bd90f3ed9e5d93844199e131a9acc0e6f725..7d8c8f3672dd993119a28f478e5cc43514aa131c 100644 (file)
@@ -833,6 +833,7 @@ static int softing_pdev_probe(struct platform_device *pdev)
                        ret = -ENOMEM;
                        goto netdev_failed;
                }
+               netdev->dev_id = j;
                priv = netdev_priv(card->net[j]);
                priv->index = j;
                ret = softing_netdev_register(netdev);
index 1f8ce91adbd3307646415590327aec77ff250fa7..b7c9e8b11460a3d6bd0e4fe7836f0e07e73eb586 100644 (file)
@@ -1025,6 +1025,7 @@ static int esd_usb2_probe_one_net(struct usb_interface *intf, int index)
        netdev->netdev_ops = &esd_usb2_netdev_ops;
 
        SET_NETDEV_DEV(netdev, &intf->dev);
+       netdev->dev_id = index;
 
        err = register_candev(netdev);
        if (err) {
index ea596b53a5ae7e71d585829c0c60cd9fe59c1824..4ca46edc061d761169a85fc58937dee449a4776f 100644 (file)
@@ -1530,6 +1530,7 @@ static int kvaser_usb_init_one(struct usb_interface *intf,
        netdev->netdev_ops = &kvaser_usb_netdev_ops;
 
        SET_NETDEV_DEV(netdev, &intf->dev);
+       netdev->dev_id = channel;
 
        dev->nets[channel] = priv;
 
index 93e4a55a6c236948ca1d065ea1a540a0b829f175..644e6ab8a489b162ba399a01faa10cc5b09cf3bb 100644 (file)
@@ -770,6 +770,7 @@ static int peak_usb_create_dev(struct peak_usb_adapter *peak_usb_adapter,
        usb_set_intfdata(intf, dev);
 
        SET_NETDEV_DEV(netdev, &intf->dev);
+       netdev->dev_id = ctrl_idx;
 
        err = register_candev(netdev);
        if (err) {