Signed-off-by: Alexander Kozhinov <ak.alexander.kozhinov@xxxxxxxxx> --- drivers/net/can/usb/gs_usb.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c index bc86e9b329fd..5f10cd9bced5 100644 --- a/drivers/net/can/usb/gs_usb.c +++ b/drivers/net/can/usb/gs_usb.c @@ -43,9 +43,6 @@ #define USB_XYLANTA_SAINT3_VENDOR_ID 0x16d0 #define USB_XYLANTA_SAINT3_PRODUCT_ID 0x0f30 -#define GS_USB_ENDPOINT_IN 1 -#define GS_USB_ENDPOINT_OUT 2 - /* Timestamp 32 bit timer runs at 1 MHz (1 µs tick). Worker accounts * for timer overflow (will be after ~71 minutes) */ @@ -336,6 +333,9 @@ struct gs_usb { unsigned int hf_size_rx; u8 active_channels; + + u8 ep_in; + u8 ep_out; }; /* 'allocate' a tx context. @@ -687,7 +687,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb) resubmit_urb: usb_fill_bulk_urb(urb, parent->udev, - usb_rcvbulkpipe(parent->udev, GS_USB_ENDPOINT_IN), + usb_rcvbulkpipe(parent->udev, parent->ep_in), hf, dev->parent->hf_size_rx, gs_usb_receive_bulk_callback, parent); @@ -819,7 +819,7 @@ static netdev_tx_t gs_can_start_xmit(struct sk_buff *skb, } usb_fill_bulk_urb(urb, dev->udev, - usb_sndbulkpipe(dev->udev, GS_USB_ENDPOINT_OUT), + usb_sndbulkpipe(dev->udev, dev->parent->ep_out), hf, dev->hf_size_tx, gs_usb_xmit_callback, txc); @@ -926,7 +926,7 @@ static int gs_can_open(struct net_device *netdev) usb_fill_bulk_urb(urb, dev->udev, usb_rcvbulkpipe(dev->udev, - GS_USB_ENDPOINT_IN), + dev->parent->ep_in), buf, dev->parent->hf_size_rx, gs_usb_receive_bulk_callback, parent); @@ -1421,6 +1421,26 @@ static int gs_usb_probe(struct usb_interface *intf, struct gs_device_config dconf; unsigned int icount, i; int rc; + struct usb_host_interface *host_iface; + u8 ep_in = 0, ep_out = 0; + + host_iface = intf->cur_altsetting; + + /* check interface endpoint addresses */ + for (i = 0; i < host_iface->desc.bNumEndpoints; i++) { + struct usb_endpoint_descriptor *ep = &host_iface->endpoint[i].desc; + + if (usb_endpoint_is_bulk_in(ep)) { + ep_in = ep->bEndpointAddress; + } else if (usb_endpoint_is_bulk_out(ep)) { + ep_out = ep->bEndpointAddress; + } + } + + if (!ep_in || !ep_out) { + dev_err(&intf->dev, "Required endpoints not found\n"); + return -ENODEV; + } /* send host config */ rc = usb_control_msg_send(udev, 0, @@ -1466,6 +1486,10 @@ static int gs_usb_probe(struct usb_interface *intf, usb_set_intfdata(intf, parent); parent->udev = udev; + /* store the detected endpoints */ + parent->ep_in = ep_in; + parent->ep_out = ep_out; + for (i = 0; i < icount; i++) { unsigned int hf_size_rx = 0; -- 2.43.0