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
39 GS_USB_BREQ_MODE,39 GS_USB_BREQ_MODE,
40 GS_USB_BREQ_BERR,40 GS_USB_BREQ_BERR,
41 GS_USB_BREQ_BT_CONST,41 GS_USB_BREQ_BT_CONST,
42 GS_USB_BREQ_DEVICE_CONFIG42 GS_USB_BREQ_DEVICE_CONFIG,
43 GS_USB_BREQ_TIMESTAMP,
44 GS_USB_BREQ_IDENTIFY,
43};45};
44 46
45enum gs_can_mode {47enum gs_can_mode {
@@ -58,6 +60,11 @@ enum gs_can_state { · 12 unmodified lines
58 GS_CAN_STATE_SLEEPING60 GS_CAN_STATE_SLEEPING
59};61};
60 62
63enum gs_can_identify_mode {
64 GS_CAN_IDENTIFY_OFF = 0,
65 GS_CAN_IDENTIFY_ON
66};
67
61/* data types passed between host and device */68/* data types passed between host and device */
62struct gs_host_config {69struct gs_host_config {
63 u32 byte_order;70 u32 byte_order;
@@ -101,10 +108,16 @@ struct gs_device_bittiming { · 37 unmodified lines
101 u32 brp;108 u32 brp;
102} __packed;109} __packed;
103 110
111struct gs_identify_mode {
112 u32 mode;
113} __packed;
114
104#define GS_CAN_FEATURE_LISTEN_ONLY BIT(0)115#define GS_CAN_FEATURE_LISTEN_ONLY BIT(0)
105#define GS_CAN_FEATURE_LOOP_BACK BIT(1)116#define GS_CAN_FEATURE_LOOP_BACK BIT(1)
106#define GS_CAN_FEATURE_TRIPLE_SAMPLE BIT(2)117#define GS_CAN_FEATURE_TRIPLE_SAMPLE BIT(2)
107#define GS_CAN_FEATURE_ONE_SHOT BIT(3)118#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)
108 121
109struct gs_device_bt_const {122struct gs_device_bt_const {
110 u32 feature;123 u32 feature;
@@ -724,7 +737,59 @@ static const struct net_device_ops gs_usb_netdev_ops = { · 613 unmodified lines
724 .ndo_change_mtu = can_change_mtu,737 .ndo_change_mtu = can_change_mtu,
725};738};
726 739
727static struct gs_can *gs_make_candev(unsigned int channel, struct usb_interface *intf)740static 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 */
767static 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
786static const struct ethtool_ops gs_usb_ethtool_ops = {
787 .set_phys_id = gs_usb_set_phys_id,
788};
789
790static struct gs_can *gs_make_candev(unsigned int channel,
791 struct usb_interface *intf,
792 struct gs_device_config *dconf)
728{793{
729 struct gs_can *dev;794 struct gs_can *dev;
730 struct net_device *netdev;795 struct net_device *netdev;
@@ -812,10 +877,14 @@ static struct gs_can *gs_make_candev(unsigned int channel, struct usb_interface · 81 unmodified lines
812 if (bt_const->feature & GS_CAN_FEATURE_ONE_SHOT)877 if (bt_const->feature & GS_CAN_FEATURE_ONE_SHOT)
813 dev->can.ctrlmode_supported |= CAN_CTRLMODE_ONE_SHOT;878 dev->can.ctrlmode_supported |= CAN_CTRLMODE_ONE_SHOT;
814 879
815 kfree(bt_const);
816
817 SET_NETDEV_DEV(netdev, &intf->dev);880 SET_NETDEV_DEV(netdev, &intf->dev);
818 881
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
819 rc = register_candev(dev->netdev);888 rc = register_candev(dev->netdev);
820 if (rc) {889 if (rc) {
821 free_candev(dev->netdev);890 free_candev(dev->netdev);
@@ -833,19 +902,16 @@ static void gs_destroy_candev(struct gs_can *dev) · 11 unmodified lines
833 free_candev(dev->netdev);902 free_candev(dev->netdev);
834}903}
835 904
836static int gs_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)905static int gs_usb_probe(struct usb_interface *intf,
906 const struct usb_device_id *id)
837{907{
838 struct gs_usb *dev;908 struct gs_usb *dev;
839 int rc = -ENOMEM;909 int rc = -ENOMEM;
840 unsigned int icount, i;910 unsigned int icount, i;
841 struct gs_host_config *hconf;911 struct gs_host_config hconf = {
842 struct gs_device_config *dconf;912 .byte_order = 0x0000beef,
843 913 };
844 hconf = kmalloc(sizeof(*hconf), GFP_KERNEL);914 struct gs_device_config dconf;
845 if (!hconf)
846 return -ENOMEM;
847
848 hconf->byte_order = 0x0000beef;
849 915
850 /* send host config */916 /* send host config */
851 rc = usb_control_msg(interface_to_usbdev(intf),917 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
854 USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,920 USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
855 1,921 1,
856 intf->altsetting[0].desc.bInterfaceNumber,922 intf->altsetting[0].desc.bInterfaceNumber,
857 hconf,923 &hconf,
858 sizeof(*hconf),924 sizeof(hconf),
859 1000);925 1000);
860 926
861 kfree(hconf);
862
863 if (rc < 0) {927 if (rc < 0) {
864 dev_err(&intf->dev, "Couldn't send data format (err=%d)\n",928 dev_err(&intf->dev, "Couldn't send data format (err=%d)\n",
865 rc);929 rc);
866 return rc;930 return rc;
867 }931 }
868 932
869 dconf = kmalloc(sizeof(*dconf), GFP_KERNEL);
870 if (!dconf)
871 return -ENOMEM;
872
873 /* read device config */933 /* read device config */
874 rc = usb_control_msg(interface_to_usbdev(intf),934 rc = usb_control_msg(interface_to_usbdev(intf),
875 usb_rcvctrlpipe(interface_to_usbdev(intf), 0),935 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
877 USB_DIR_IN|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,937 USB_DIR_IN|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
878 1,938 1,
879 intf->altsetting[0].desc.bInterfaceNumber,939 intf->altsetting[0].desc.bInterfaceNumber,
880 dconf,940 &dconf,
881 sizeof(*dconf),941 sizeof(dconf),
882 1000);942 1000);
883 if (rc < 0) {943 if (rc < 0) {
884 dev_err(&intf->dev, "Couldn't get device config: (err=%d)\n",944 dev_err(&intf->dev, "Couldn't get device config: (err=%d)\n",
885 rc);945 rc);
886
887 kfree(dconf);
888
889 return rc;946 return rc;
890 }947 }
891 948
892 icount = dconf->icount+1;949 icount = dconf.icount + 1;
893
894 kfree(dconf);
895
896 dev_info(&intf->dev, "Configuring for %d interfaces\n", icount);950 dev_info(&intf->dev, "Configuring for %d interfaces\n", icount);
897 951
898 if (icount > GS_MAX_INTF) {952 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
913 dev->udev = interface_to_usbdev(intf);967 dev->udev = interface_to_usbdev(intf);
914 968
915 for (i = 0; i < icount; i++) {969 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);
917 if (IS_ERR_OR_NULL(dev->canch[i])) {971 if (IS_ERR_OR_NULL(dev->canch[i])) {
918 /* save error code to return later */972 /* save error code to return later */
919 rc = PTR_ERR(dev->canch[i]);973 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