diff options
Diffstat (limited to 'drivers/net/can/usb/kvaser_usb.c')
| -rw-r--r-- | drivers/net/can/usb/kvaser_usb.c | 69 |
1 files changed, 42 insertions, 27 deletions
diff --git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c index e97a08ce0b90..57611fd91229 100644 --- a/drivers/net/can/usb/kvaser_usb.c +++ b/drivers/net/can/usb/kvaser_usb.c | |||
| @@ -25,7 +25,6 @@ | |||
| 25 | #include <linux/can/dev.h> | 25 | #include <linux/can/dev.h> |
| 26 | #include <linux/can/error.h> | 26 | #include <linux/can/error.h> |
| 27 | 27 | ||
| 28 | #define MAX_TX_URBS 16 | ||
| 29 | #define MAX_RX_URBS 4 | 28 | #define MAX_RX_URBS 4 |
| 30 | #define START_TIMEOUT 1000 /* msecs */ | 29 | #define START_TIMEOUT 1000 /* msecs */ |
| 31 | #define STOP_TIMEOUT 1000 /* msecs */ | 30 | #define STOP_TIMEOUT 1000 /* msecs */ |
| @@ -443,6 +442,7 @@ struct kvaser_usb_error_summary { | |||
| 443 | }; | 442 | }; |
| 444 | }; | 443 | }; |
| 445 | 444 | ||
| 445 | /* Context for an outstanding, not yet ACKed, transmission */ | ||
| 446 | struct kvaser_usb_tx_urb_context { | 446 | struct kvaser_usb_tx_urb_context { |
| 447 | struct kvaser_usb_net_priv *priv; | 447 | struct kvaser_usb_net_priv *priv; |
| 448 | u32 echo_index; | 448 | u32 echo_index; |
| @@ -456,8 +456,13 @@ struct kvaser_usb { | |||
| 456 | struct usb_endpoint_descriptor *bulk_in, *bulk_out; | 456 | struct usb_endpoint_descriptor *bulk_in, *bulk_out; |
| 457 | struct usb_anchor rx_submitted; | 457 | struct usb_anchor rx_submitted; |
| 458 | 458 | ||
| 459 | /* @max_tx_urbs: Firmware-reported maximum number of oustanding, | ||
| 460 | * not yet ACKed, transmissions on this device. This value is | ||
| 461 | * also used as a sentinel for marking free tx contexts. | ||
| 462 | */ | ||
| 459 | u32 fw_version; | 463 | u32 fw_version; |
| 460 | unsigned int nchannels; | 464 | unsigned int nchannels; |
| 465 | unsigned int max_tx_urbs; | ||
| 461 | enum kvaser_usb_family family; | 466 | enum kvaser_usb_family family; |
| 462 | 467 | ||
| 463 | bool rxinitdone; | 468 | bool rxinitdone; |
| @@ -467,19 +472,18 @@ struct kvaser_usb { | |||
| 467 | 472 | ||
| 468 | struct kvaser_usb_net_priv { | 473 | struct kvaser_usb_net_priv { |
| 469 | struct can_priv can; | 474 | struct can_priv can; |
| 470 | 475 | struct can_berr_counter bec; | |
| 471 | spinlock_t tx_contexts_lock; | ||
| 472 | int active_tx_contexts; | ||
| 473 | struct kvaser_usb_tx_urb_context tx_contexts[MAX_TX_URBS]; | ||
| 474 | |||
| 475 | struct usb_anchor tx_submitted; | ||
| 476 | struct completion start_comp, stop_comp; | ||
| 477 | 476 | ||
| 478 | struct kvaser_usb *dev; | 477 | struct kvaser_usb *dev; |
| 479 | struct net_device *netdev; | 478 | struct net_device *netdev; |
| 480 | int channel; | 479 | int channel; |
| 481 | 480 | ||
| 482 | struct can_berr_counter bec; | 481 | struct completion start_comp, stop_comp; |
| 482 | struct usb_anchor tx_submitted; | ||
| 483 | |||
| 484 | spinlock_t tx_contexts_lock; | ||
| 485 | int active_tx_contexts; | ||
| 486 | struct kvaser_usb_tx_urb_context tx_contexts[]; | ||
| 483 | }; | 487 | }; |
| 484 | 488 | ||
| 485 | static const struct usb_device_id kvaser_usb_table[] = { | 489 | static const struct usb_device_id kvaser_usb_table[] = { |
| @@ -592,8 +596,8 @@ static int kvaser_usb_wait_msg(const struct kvaser_usb *dev, u8 id, | |||
| 592 | * for further details. | 596 | * for further details. |
| 593 | */ | 597 | */ |
| 594 | if (tmp->len == 0) { | 598 | if (tmp->len == 0) { |
| 595 | pos = round_up(pos, | 599 | pos = round_up(pos, le16_to_cpu(dev->bulk_in-> |
| 596 | dev->bulk_in->wMaxPacketSize); | 600 | wMaxPacketSize)); |
| 597 | continue; | 601 | continue; |
| 598 | } | 602 | } |
| 599 | 603 | ||
| @@ -657,9 +661,13 @@ static int kvaser_usb_get_software_info(struct kvaser_usb *dev) | |||
| 657 | switch (dev->family) { | 661 | switch (dev->family) { |
| 658 | case KVASER_LEAF: | 662 | case KVASER_LEAF: |
| 659 | dev->fw_version = le32_to_cpu(msg.u.leaf.softinfo.fw_version); | 663 | dev->fw_version = le32_to_cpu(msg.u.leaf.softinfo.fw_version); |
| 664 | dev->max_tx_urbs = | ||
| 665 | le16_to_cpu(msg.u.leaf.softinfo.max_outstanding_tx); | ||
| 660 | break; | 666 | break; |
| 661 | case KVASER_USBCAN: | 667 | case KVASER_USBCAN: |
| 662 | dev->fw_version = le32_to_cpu(msg.u.usbcan.softinfo.fw_version); | 668 | dev->fw_version = le32_to_cpu(msg.u.usbcan.softinfo.fw_version); |
| 669 | dev->max_tx_urbs = | ||
| 670 | le16_to_cpu(msg.u.usbcan.softinfo.max_outstanding_tx); | ||
| 663 | break; | 671 | break; |
| 664 | } | 672 | } |
| 665 | 673 | ||
| @@ -715,7 +723,7 @@ static void kvaser_usb_tx_acknowledge(const struct kvaser_usb *dev, | |||
| 715 | 723 | ||
| 716 | stats = &priv->netdev->stats; | 724 | stats = &priv->netdev->stats; |
| 717 | 725 | ||
| 718 | context = &priv->tx_contexts[tid % MAX_TX_URBS]; | 726 | context = &priv->tx_contexts[tid % dev->max_tx_urbs]; |
| 719 | 727 | ||
| 720 | /* Sometimes the state change doesn't come after a bus-off event */ | 728 | /* Sometimes the state change doesn't come after a bus-off event */ |
| 721 | if (priv->can.restart_ms && | 729 | if (priv->can.restart_ms && |
| @@ -744,7 +752,7 @@ static void kvaser_usb_tx_acknowledge(const struct kvaser_usb *dev, | |||
| 744 | spin_lock_irqsave(&priv->tx_contexts_lock, flags); | 752 | spin_lock_irqsave(&priv->tx_contexts_lock, flags); |
| 745 | 753 | ||
| 746 | can_get_echo_skb(priv->netdev, context->echo_index); | 754 | can_get_echo_skb(priv->netdev, context->echo_index); |
| 747 | context->echo_index = MAX_TX_URBS; | 755 | context->echo_index = dev->max_tx_urbs; |
| 748 | --priv->active_tx_contexts; | 756 | --priv->active_tx_contexts; |
| 749 | netif_wake_queue(priv->netdev); | 757 | netif_wake_queue(priv->netdev); |
| 750 | 758 | ||
| @@ -1329,7 +1337,8 @@ static void kvaser_usb_read_bulk_callback(struct urb *urb) | |||
| 1329 | * number of events in case of a heavy rx load on the bus. | 1337 | * number of events in case of a heavy rx load on the bus. |
| 1330 | */ | 1338 | */ |
| 1331 | if (msg->len == 0) { | 1339 | if (msg->len == 0) { |
| 1332 | pos = round_up(pos, dev->bulk_in->wMaxPacketSize); | 1340 | pos = round_up(pos, le16_to_cpu(dev->bulk_in-> |
| 1341 | wMaxPacketSize)); | ||
| 1333 | continue; | 1342 | continue; |
| 1334 | } | 1343 | } |
| 1335 | 1344 | ||
| @@ -1512,11 +1521,13 @@ error: | |||
| 1512 | 1521 | ||
| 1513 | static void kvaser_usb_reset_tx_urb_contexts(struct kvaser_usb_net_priv *priv) | 1522 | static void kvaser_usb_reset_tx_urb_contexts(struct kvaser_usb_net_priv *priv) |
| 1514 | { | 1523 | { |
| 1515 | int i; | 1524 | int i, max_tx_urbs; |
| 1525 | |||
| 1526 | max_tx_urbs = priv->dev->max_tx_urbs; | ||
| 1516 | 1527 | ||
| 1517 | priv->active_tx_contexts = 0; | 1528 | priv->active_tx_contexts = 0; |
| 1518 | for (i = 0; i < MAX_TX_URBS; i++) | 1529 | for (i = 0; i < max_tx_urbs; i++) |
| 1519 | priv->tx_contexts[i].echo_index = MAX_TX_URBS; | 1530 | priv->tx_contexts[i].echo_index = max_tx_urbs; |
| 1520 | } | 1531 | } |
| 1521 | 1532 | ||
| 1522 | /* This method might sleep. Do not call it in the atomic context | 1533 | /* This method might sleep. Do not call it in the atomic context |
| @@ -1702,14 +1713,14 @@ static netdev_tx_t kvaser_usb_start_xmit(struct sk_buff *skb, | |||
| 1702 | *msg_tx_can_flags |= MSG_FLAG_REMOTE_FRAME; | 1713 | *msg_tx_can_flags |= MSG_FLAG_REMOTE_FRAME; |
| 1703 | 1714 | ||
| 1704 | spin_lock_irqsave(&priv->tx_contexts_lock, flags); | 1715 | spin_lock_irqsave(&priv->tx_contexts_lock, flags); |
| 1705 | for (i = 0; i < ARRAY_SIZE(priv->tx_contexts); i++) { | 1716 | for (i = 0; i < dev->max_tx_urbs; i++) { |
| 1706 | if (priv->tx_contexts[i].echo_index == MAX_TX_URBS) { | 1717 | if (priv->tx_contexts[i].echo_index == dev->max_tx_urbs) { |
| 1707 | context = &priv->tx_contexts[i]; | 1718 | context = &priv->tx_contexts[i]; |
| 1708 | 1719 | ||
| 1709 | context->echo_index = i; | 1720 | context->echo_index = i; |
| 1710 | can_put_echo_skb(skb, netdev, context->echo_index); | 1721 | can_put_echo_skb(skb, netdev, context->echo_index); |
| 1711 | ++priv->active_tx_contexts; | 1722 | ++priv->active_tx_contexts; |
| 1712 | if (priv->active_tx_contexts >= MAX_TX_URBS) | 1723 | if (priv->active_tx_contexts >= dev->max_tx_urbs) |
| 1713 | netif_stop_queue(netdev); | 1724 | netif_stop_queue(netdev); |
| 1714 | 1725 | ||
| 1715 | break; | 1726 | break; |
| @@ -1743,7 +1754,7 @@ static netdev_tx_t kvaser_usb_start_xmit(struct sk_buff *skb, | |||
| 1743 | spin_lock_irqsave(&priv->tx_contexts_lock, flags); | 1754 | spin_lock_irqsave(&priv->tx_contexts_lock, flags); |
| 1744 | 1755 | ||
| 1745 | can_free_echo_skb(netdev, context->echo_index); | 1756 | can_free_echo_skb(netdev, context->echo_index); |
| 1746 | context->echo_index = MAX_TX_URBS; | 1757 | context->echo_index = dev->max_tx_urbs; |
| 1747 | --priv->active_tx_contexts; | 1758 | --priv->active_tx_contexts; |
| 1748 | netif_wake_queue(netdev); | 1759 | netif_wake_queue(netdev); |
| 1749 | 1760 | ||
| @@ -1881,7 +1892,9 @@ static int kvaser_usb_init_one(struct usb_interface *intf, | |||
| 1881 | if (err) | 1892 | if (err) |
| 1882 | return err; | 1893 | return err; |
| 1883 | 1894 | ||
| 1884 | netdev = alloc_candev(sizeof(*priv), MAX_TX_URBS); | 1895 | netdev = alloc_candev(sizeof(*priv) + |
| 1896 | dev->max_tx_urbs * sizeof(*priv->tx_contexts), | ||
| 1897 | dev->max_tx_urbs); | ||
| 1885 | if (!netdev) { | 1898 | if (!netdev) { |
| 1886 | dev_err(&intf->dev, "Cannot alloc candev\n"); | 1899 | dev_err(&intf->dev, "Cannot alloc candev\n"); |
| 1887 | return -ENOMEM; | 1900 | return -ENOMEM; |
| @@ -2009,6 +2022,13 @@ static int kvaser_usb_probe(struct usb_interface *intf, | |||
| 2009 | return err; | 2022 | return err; |
| 2010 | } | 2023 | } |
| 2011 | 2024 | ||
| 2025 | dev_dbg(&intf->dev, "Firmware version: %d.%d.%d\n", | ||
| 2026 | ((dev->fw_version >> 24) & 0xff), | ||
| 2027 | ((dev->fw_version >> 16) & 0xff), | ||
| 2028 | (dev->fw_version & 0xffff)); | ||
| 2029 | |||
| 2030 | dev_dbg(&intf->dev, "Max oustanding tx = %d URBs\n", dev->max_tx_urbs); | ||
| 2031 | |||
| 2012 | err = kvaser_usb_get_card_info(dev); | 2032 | err = kvaser_usb_get_card_info(dev); |
| 2013 | if (err) { | 2033 | if (err) { |
| 2014 | dev_err(&intf->dev, | 2034 | dev_err(&intf->dev, |
| @@ -2016,11 +2036,6 @@ static int kvaser_usb_probe(struct usb_interface *intf, | |||
| 2016 | return err; | 2036 | return err; |
| 2017 | } | 2037 | } |
| 2018 | 2038 | ||
| 2019 | dev_dbg(&intf->dev, "Firmware version: %d.%d.%d\n", | ||
| 2020 | ((dev->fw_version >> 24) & 0xff), | ||
| 2021 | ((dev->fw_version >> 16) & 0xff), | ||
| 2022 | (dev->fw_version & 0xffff)); | ||
| 2023 | |||
| 2024 | for (i = 0; i < dev->nchannels; i++) { | 2039 | for (i = 0; i < dev->nchannels; i++) { |
| 2025 | err = kvaser_usb_init_one(intf, id, i); | 2040 | err = kvaser_usb_init_one(intf, id, i); |
| 2026 | if (err) { | 2041 | if (err) { |
