History

can: gs_usb: add ethtool set_phys_id callback to locate physical device

This patch Implements the ethtool set_phys_id callback to ease the locating of specific physical devices. Currently only supported on candleLight interfaces.

Maximilian Schneider committed 10 years ago

Commit 05ca5271 parent 9be95c91 file · +85 −31Browse files

Unified · Split

drivers/net/can/usb/gs_usb.c+85−31
@@ -39,7 +39,9 @@ enum gs_usb_breq { · 38 unmodified lines
3939 GS_USB_BREQ_MODE,
4040 GS_USB_BREQ_BERR,
4141 GS_USB_BREQ_BT_CONST,
42− GS_USB_BREQ_DEVICE_CONFIG
42+ GS_USB_BREQ_DEVICE_CONFIG,
43+ GS_USB_BREQ_TIMESTAMP,
44+ GS_USB_BREQ_IDENTIFY,
4345 };
4446
4547 enum gs_can_mode {
@@ -58,6 +60,11 @@ enum gs_can_state { · 12 unmodified lines
5860 GS_CAN_STATE_SLEEPING
5961 };
6062
63+enum gs_can_identify_mode {
64+ GS_CAN_IDENTIFY_OFF = 0,
65+ GS_CAN_IDENTIFY_ON
66+};
67+
6168 /* data types passed between host and device */
6269 struct gs_host_config {
6370 u32 byte_order;
@@ -101,10 +108,16 @@ struct gs_device_bittiming { · 37 unmodified lines
101108 u32 brp;
102109 } __packed;
103110
111+struct gs_identify_mode {
112+ u32 mode;
113+} __packed;
114+
104115 #define GS_CAN_FEATURE_LISTEN_ONLY BIT(0)
105116 #define GS_CAN_FEATURE_LOOP_BACK BIT(1)
106117 #define GS_CAN_FEATURE_TRIPLE_SAMPLE BIT(2)
107118 #define GS_CAN_FEATURE_ONE_SHOT BIT(3)
119+#define GS_CAN_FEATURE_HW_TIMESTAMP BIT(4)
120+#define GS_CAN_FEATURE_IDENTIFY BIT(5)
108121
109122 struct gs_device_bt_const {
110123 u32 feature;
@@ -724,7 +737,59 @@ static const struct net_device_ops gs_usb_netdev_ops = { · 613 unmodified lines
724737 .ndo_change_mtu = can_change_mtu,
725738 };
726739
727−static struct gs_can *gs_make_candev(unsigned int channel, struct usb_interface *intf)
740+static int gs_usb_set_identify(struct net_device *netdev, bool do_identify)
741+{
742+ struct gs_can *dev = netdev_priv(netdev);
743+ struct gs_identify_mode imode;
744+ int rc;
745+
746+ if (do_identify)
747+ imode.mode = GS_CAN_IDENTIFY_ON;
748+ else
749+ imode.mode = GS_CAN_IDENTIFY_OFF;
750+
751+ rc = usb_control_msg(interface_to_usbdev(dev->iface),
752+ usb_sndctrlpipe(interface_to_usbdev(dev->iface),
753+ 0),
754+ GS_USB_BREQ_IDENTIFY,
755+ USB_DIR_OUT | USB_TYPE_VENDOR |
756+ USB_RECIP_INTERFACE,
757+ dev->channel,
758+ 0,
759+ &imode,
760+ sizeof(imode),
761+ 100);
762+
763+ return (rc > 0) ? 0 : rc;
764+}
765+
766+/* blink LED's for finding the this interface */
767+static int gs_usb_set_phys_id(struct net_device *dev,
768+ enum ethtool_phys_id_state state)
769+{
770+ int rc = 0;
771+
772+ switch (state) {
773+ case ETHTOOL_ID_ACTIVE:
774+ rc = gs_usb_set_identify(dev, GS_CAN_IDENTIFY_ON);
775+ break;
776+ case ETHTOOL_ID_INACTIVE:
777+ rc = gs_usb_set_identify(dev, GS_CAN_IDENTIFY_OFF);
778+ break;
779+ default:
780+ break;
781+ }
782+
783+ return rc;
784+}
785+
786+static const struct ethtool_ops gs_usb_ethtool_ops = {
787+ .set_phys_id = gs_usb_set_phys_id,
788+};
789+
790+static struct gs_can *gs_make_candev(unsigned int channel,
791+ struct usb_interface *intf,
792+ struct gs_device_config *dconf)
728793 {
729794 struct gs_can *dev;
730795 struct net_device *netdev;
@@ -812,10 +877,14 @@ static struct gs_can *gs_make_candev(unsigned int channel, struct usb_interface · 81 unmodified lines
812877 if (bt_const->feature & GS_CAN_FEATURE_ONE_SHOT)
813878 dev->can.ctrlmode_supported |= CAN_CTRLMODE_ONE_SHOT;
814879
815− kfree(bt_const);
816−
817880 SET_NETDEV_DEV(netdev, &intf->dev);
818881
882+ if (dconf->sw_version > 1)
883+ if (bt_const->feature & GS_CAN_FEATURE_IDENTIFY)
884+ netdev->ethtool_ops = &gs_usb_ethtool_ops;
885+
886+ kfree(bt_const);
887+
819888 rc = register_candev(dev->netdev);
820889 if (rc) {
821890 free_candev(dev->netdev);
@@ -833,19 +902,16 @@ static void gs_destroy_candev(struct gs_can *dev) · 11 unmodified lines
833902 free_candev(dev->netdev);
834903 }
835904
836−static int gs_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
905+static int gs_usb_probe(struct usb_interface *intf,
906+ const struct usb_device_id *id)
837907 {
838908 struct gs_usb *dev;
839909 int rc = -ENOMEM;
840910 unsigned int icount, i;
841− struct gs_host_config *hconf;
842− struct gs_device_config *dconf;
843−
844− hconf = kmalloc(sizeof(*hconf), GFP_KERNEL);
845− if (!hconf)
846− return -ENOMEM;
847−
848− hconf->byte_order = 0x0000beef;
911+ struct gs_host_config hconf = {
912+ .byte_order = 0x0000beef,
913+ };
914+ struct gs_device_config dconf;
849915
850916 /* send host config */
851917 rc = usb_control_msg(interface_to_usbdev(intf),
@@ -854,22 +920,16 @@ static int gs_usb_probe(struct usb_interface *intf, const struct usb_device_id * · 2 unmodified lines
854920 USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
855921 1,
856922 intf->altsetting[0].desc.bInterfaceNumber,
857− hconf,
858− sizeof(*hconf),
923+ &hconf,
924+ sizeof(hconf),
859925 1000);
860926
861− kfree(hconf);
862−
863927 if (rc < 0) {
864928 dev_err(&intf->dev, "Couldn't send data format (err=%d)\n",
865929 rc);
866930 return rc;
867931 }
868932
869− dconf = kmalloc(sizeof(*dconf), GFP_KERNEL);
870− if (!dconf)
871− return -ENOMEM;
872−
873933 /* read device config */
874934 rc = usb_control_msg(interface_to_usbdev(intf),
875935 usb_rcvctrlpipe(interface_to_usbdev(intf), 0),
@@ -877,22 +937,16 @@ static int gs_usb_probe(struct usb_interface *intf, const struct usb_device_id * · 1 unmodified line
877937 USB_DIR_IN|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
878938 1,
879939 intf->altsetting[0].desc.bInterfaceNumber,
880− dconf,
881− sizeof(*dconf),
940+ &dconf,
941+ sizeof(dconf),
882942 1000);
883943 if (rc < 0) {
884944 dev_err(&intf->dev, "Couldn't get device config: (err=%d)\n",
885945 rc);
886−
887− kfree(dconf);
888−
889946 return rc;
890947 }
891948
892− icount = dconf->icount+1;
893−
894− kfree(dconf);
895−
949+ icount = dconf.icount + 1;
896950 dev_info(&intf->dev, "Configuring for %d interfaces\n", icount);
897951
898952 if (icount > GS_MAX_INTF) {
@@ -913,7 +967,7 @@ static int gs_usb_probe(struct usb_interface *intf, const struct usb_device_id * · 14 unmodified lines
913967 dev->udev = interface_to_usbdev(intf);
914968
915969 for (i = 0; i < icount; i++) {
916− dev->canch[i] = gs_make_candev(i, intf);
970+ dev->canch[i] = gs_make_candev(i, intf, &dconf);
917971 if (IS_ERR_OR_NULL(dev->canch[i])) {
918972 /* save error code to return later */
919973 rc = PTR_ERR(dev->canch[i]);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t