This patch Implements the ethtool set_phys_id callback to ease the locating of specific physical devices. Currently only supported on candleLight interfaces.
Unified · Split
| @@ -39,7 +39,9 @@ enum gs_usb_breq { · 38 unmodified lines | ||
| 39 | 39 | GS_USB_BREQ_MODE, |
| 40 | 40 | GS_USB_BREQ_BERR, |
| 41 | 41 | 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, | |
| 43 | 45 | }; |
| 44 | 46 | |
| 45 | 47 | enum gs_can_mode { |
| @@ -58,6 +60,11 @@ enum gs_can_state { · 12 unmodified lines | ||
| 58 | 60 | GS_CAN_STATE_SLEEPING |
| 59 | 61 | }; |
| 60 | 62 | |
| 63 | +enum gs_can_identify_mode { | |
| 64 | + GS_CAN_IDENTIFY_OFF = 0, | |
| 65 | + GS_CAN_IDENTIFY_ON | |
| 66 | +}; | |
| 67 | + | |
| 61 | 68 | /* data types passed between host and device */ |
| 62 | 69 | struct gs_host_config { |
| 63 | 70 | u32 byte_order; |
| @@ -101,10 +108,16 @@ struct gs_device_bittiming { · 37 unmodified lines | ||
| 101 | 108 | u32 brp; |
| 102 | 109 | } __packed; |
| 103 | 110 | |
| 111 | +struct gs_identify_mode { | |
| 112 | + u32 mode; | |
| 113 | +} __packed; | |
| 114 | + | |
| 104 | 115 | #define GS_CAN_FEATURE_LISTEN_ONLY BIT(0) |
| 105 | 116 | #define GS_CAN_FEATURE_LOOP_BACK BIT(1) |
| 106 | 117 | #define GS_CAN_FEATURE_TRIPLE_SAMPLE BIT(2) |
| 107 | 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 | |
| 109 | 122 | struct gs_device_bt_const { |
| 110 | 123 | u32 feature; |
| @@ -724,7 +737,59 @@ static const struct net_device_ops gs_usb_netdev_ops = { · 613 unmodified lines | ||
| 724 | 737 | .ndo_change_mtu = can_change_mtu, |
| 725 | 738 | }; |
| 726 | 739 | |
| 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) | |
| 728 | 793 | { |
| 729 | 794 | struct gs_can *dev; |
| 730 | 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 | 877 | if (bt_const->feature & GS_CAN_FEATURE_ONE_SHOT) |
| 813 | 878 | dev->can.ctrlmode_supported |= CAN_CTRLMODE_ONE_SHOT; |
| 814 | 879 | |
| 815 | − kfree(bt_const); | |
| 816 | − | |
| 817 | 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 | 888 | rc = register_candev(dev->netdev); |
| 820 | 889 | if (rc) { |
| 821 | 890 | free_candev(dev->netdev); |
| @@ -833,19 +902,16 @@ static void gs_destroy_candev(struct gs_can *dev) · 11 unmodified lines | ||
| 833 | 902 | free_candev(dev->netdev); |
| 834 | 903 | } |
| 835 | 904 | |
| 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) | |
| 837 | 907 | { |
| 838 | 908 | struct gs_usb *dev; |
| 839 | 909 | int rc = -ENOMEM; |
| 840 | 910 | 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; | |
| 849 | 915 | |
| 850 | 916 | /* send host config */ |
| 851 | 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 | 920 | USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE, |
| 855 | 921 | 1, |
| 856 | 922 | intf->altsetting[0].desc.bInterfaceNumber, |
| 857 | − hconf, | |
| 858 | − sizeof(*hconf), | |
| 923 | + &hconf, | |
| 924 | + sizeof(hconf), | |
| 859 | 925 | 1000); |
| 860 | 926 | |
| 861 | − kfree(hconf); | |
| 862 | − | |
| 863 | 927 | if (rc < 0) { |
| 864 | 928 | dev_err(&intf->dev, "Couldn't send data format (err=%d)\n", |
| 865 | 929 | rc); |
| 866 | 930 | return rc; |
| 867 | 931 | } |
| 868 | 932 | |
| 869 | − dconf = kmalloc(sizeof(*dconf), GFP_KERNEL); | |
| 870 | − if (!dconf) | |
| 871 | − return -ENOMEM; | |
| 872 | − | |
| 873 | 933 | /* read device config */ |
| 874 | 934 | rc = usb_control_msg(interface_to_usbdev(intf), |
| 875 | 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 | 937 | USB_DIR_IN|USB_TYPE_VENDOR|USB_RECIP_INTERFACE, |
| 878 | 938 | 1, |
| 879 | 939 | intf->altsetting[0].desc.bInterfaceNumber, |
| 880 | − dconf, | |
| 881 | − sizeof(*dconf), | |
| 940 | + &dconf, | |
| 941 | + sizeof(dconf), | |
| 882 | 942 | 1000); |
| 883 | 943 | if (rc < 0) { |
| 884 | 944 | dev_err(&intf->dev, "Couldn't get device config: (err=%d)\n", |
| 885 | 945 | rc); |
| 886 | − | |
| 887 | − kfree(dconf); | |
| 888 | − | |
| 889 | 946 | return rc; |
| 890 | 947 | } |
| 891 | 948 | |
| 892 | − icount = dconf->icount+1; | |
| 893 | − | |
| 894 | − kfree(dconf); | |
| 895 | − | |
| 949 | + icount = dconf.icount + 1; | |
| 896 | 950 | dev_info(&intf->dev, "Configuring for %d interfaces\n", icount); |
| 897 | 951 | |
| 898 | 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 | 967 | dev->udev = interface_to_usbdev(intf); |
| 914 | 968 | |
| 915 | 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 | 971 | if (IS_ERR_OR_NULL(dev->canch[i])) { |
| 918 | 972 | /* save error code to return later */ |
| 919 | 973 | rc = PTR_ERR(dev->canch[i]); |