| .. | .. |
|---|
| 43 | 43 | |
|---|
| 44 | 44 | /* Minihydra command IDs */ |
|---|
| 45 | 45 | #define CMD_SET_BUSPARAMS_REQ 16 |
|---|
| 46 | +#define CMD_GET_BUSPARAMS_REQ 17 |
|---|
| 47 | +#define CMD_GET_BUSPARAMS_RESP 18 |
|---|
| 46 | 48 | #define CMD_GET_CHIP_STATE_REQ 19 |
|---|
| 47 | 49 | #define CMD_CHIP_STATE_EVENT 20 |
|---|
| 48 | 50 | #define CMD_SET_DRIVERMODE_REQ 21 |
|---|
| .. | .. |
|---|
| 193 | 195 | #define KVASER_USB_HYDRA_BUS_MODE_CANFD_ISO 0x01 |
|---|
| 194 | 196 | #define KVASER_USB_HYDRA_BUS_MODE_NONISO 0x02 |
|---|
| 195 | 197 | struct kvaser_cmd_set_busparams { |
|---|
| 196 | | - __le32 bitrate; |
|---|
| 197 | | - u8 tseg1; |
|---|
| 198 | | - u8 tseg2; |
|---|
| 199 | | - u8 sjw; |
|---|
| 200 | | - u8 nsamples; |
|---|
| 198 | + struct kvaser_usb_busparams busparams_nominal; |
|---|
| 201 | 199 | u8 reserved0[4]; |
|---|
| 202 | | - __le32 bitrate_d; |
|---|
| 203 | | - u8 tseg1_d; |
|---|
| 204 | | - u8 tseg2_d; |
|---|
| 205 | | - u8 sjw_d; |
|---|
| 206 | | - u8 nsamples_d; |
|---|
| 200 | + struct kvaser_usb_busparams busparams_data; |
|---|
| 207 | 201 | u8 canfd_mode; |
|---|
| 208 | 202 | u8 reserved1[7]; |
|---|
| 203 | +} __packed; |
|---|
| 204 | + |
|---|
| 205 | +/* Busparam type */ |
|---|
| 206 | +#define KVASER_USB_HYDRA_BUSPARAM_TYPE_CAN 0x00 |
|---|
| 207 | +#define KVASER_USB_HYDRA_BUSPARAM_TYPE_CANFD 0x01 |
|---|
| 208 | +struct kvaser_cmd_get_busparams_req { |
|---|
| 209 | + u8 type; |
|---|
| 210 | + u8 reserved[27]; |
|---|
| 211 | +} __packed; |
|---|
| 212 | + |
|---|
| 213 | +struct kvaser_cmd_get_busparams_res { |
|---|
| 214 | + struct kvaser_usb_busparams busparams; |
|---|
| 215 | + u8 reserved[20]; |
|---|
| 209 | 216 | } __packed; |
|---|
| 210 | 217 | |
|---|
| 211 | 218 | /* Ctrl modes */ |
|---|
| .. | .. |
|---|
| 278 | 285 | struct kvaser_cmd_error_event error_event; |
|---|
| 279 | 286 | |
|---|
| 280 | 287 | struct kvaser_cmd_set_busparams set_busparams_req; |
|---|
| 288 | + struct kvaser_cmd_get_busparams_req get_busparams_req; |
|---|
| 289 | + struct kvaser_cmd_get_busparams_res get_busparams_res; |
|---|
| 281 | 290 | |
|---|
| 282 | 291 | struct kvaser_cmd_chip_state_event chip_state_event; |
|---|
| 283 | 292 | |
|---|
| .. | .. |
|---|
| 293 | 302 | #define KVASER_USB_HYDRA_CF_FLAG_OVERRUN BIT(1) |
|---|
| 294 | 303 | #define KVASER_USB_HYDRA_CF_FLAG_REMOTE_FRAME BIT(4) |
|---|
| 295 | 304 | #define KVASER_USB_HYDRA_CF_FLAG_EXTENDED_ID BIT(5) |
|---|
| 305 | +#define KVASER_USB_HYDRA_CF_FLAG_TX_ACK BIT(6) |
|---|
| 296 | 306 | /* CAN frame flags. Used in ext_rx_can and ext_tx_can */ |
|---|
| 297 | 307 | #define KVASER_USB_HYDRA_CF_FLAG_OSM_NACK BIT(12) |
|---|
| 298 | 308 | #define KVASER_USB_HYDRA_CF_FLAG_ABL BIT(13) |
|---|
| .. | .. |
|---|
| 359 | 369 | } __packed; |
|---|
| 360 | 370 | } __packed; |
|---|
| 361 | 371 | |
|---|
| 372 | +struct kvaser_usb_net_hydra_priv { |
|---|
| 373 | + int pending_get_busparams_type; |
|---|
| 374 | +}; |
|---|
| 375 | + |
|---|
| 362 | 376 | static const struct can_bittiming_const kvaser_usb_hydra_kcan_bittiming_c = { |
|---|
| 363 | 377 | .name = "kvaser_usb_kcan", |
|---|
| 364 | 378 | .tseg1_min = 1, |
|---|
| .. | .. |
|---|
| 371 | 385 | .brp_inc = 1, |
|---|
| 372 | 386 | }; |
|---|
| 373 | 387 | |
|---|
| 374 | | -static const struct can_bittiming_const kvaser_usb_hydra_flexc_bittiming_c = { |
|---|
| 388 | +const struct can_bittiming_const kvaser_usb_flexc_bittiming_const = { |
|---|
| 375 | 389 | .name = "kvaser_usb_flex", |
|---|
| 376 | 390 | .tseg1_min = 4, |
|---|
| 377 | 391 | .tseg1_max = 16, |
|---|
| .. | .. |
|---|
| 504 | 518 | u8 cmd_no, int channel) |
|---|
| 505 | 519 | { |
|---|
| 506 | 520 | struct kvaser_cmd *cmd; |
|---|
| 521 | + size_t cmd_len; |
|---|
| 507 | 522 | int err; |
|---|
| 508 | 523 | |
|---|
| 509 | 524 | cmd = kcalloc(1, sizeof(struct kvaser_cmd), GFP_KERNEL); |
|---|
| .. | .. |
|---|
| 511 | 526 | return -ENOMEM; |
|---|
| 512 | 527 | |
|---|
| 513 | 528 | cmd->header.cmd_no = cmd_no; |
|---|
| 529 | + cmd_len = kvaser_usb_hydra_cmd_size(cmd); |
|---|
| 514 | 530 | if (channel < 0) { |
|---|
| 515 | 531 | kvaser_usb_hydra_set_cmd_dest_he |
|---|
| 516 | 532 | (cmd, KVASER_USB_HYDRA_HE_ADDRESS_ILLEGAL); |
|---|
| .. | .. |
|---|
| 527 | 543 | kvaser_usb_hydra_set_cmd_transid |
|---|
| 528 | 544 | (cmd, kvaser_usb_hydra_get_next_transid(dev)); |
|---|
| 529 | 545 | |
|---|
| 530 | | - err = kvaser_usb_send_cmd(dev, cmd, kvaser_usb_hydra_cmd_size(cmd)); |
|---|
| 546 | + err = kvaser_usb_send_cmd(dev, cmd, cmd_len); |
|---|
| 531 | 547 | if (err) |
|---|
| 532 | 548 | goto end; |
|---|
| 533 | 549 | |
|---|
| .. | .. |
|---|
| 543 | 559 | { |
|---|
| 544 | 560 | struct kvaser_cmd *cmd; |
|---|
| 545 | 561 | struct kvaser_usb *dev = priv->dev; |
|---|
| 562 | + size_t cmd_len; |
|---|
| 546 | 563 | int err; |
|---|
| 547 | 564 | |
|---|
| 548 | 565 | cmd = kcalloc(1, sizeof(struct kvaser_cmd), GFP_ATOMIC); |
|---|
| .. | .. |
|---|
| 550 | 567 | return -ENOMEM; |
|---|
| 551 | 568 | |
|---|
| 552 | 569 | cmd->header.cmd_no = cmd_no; |
|---|
| 570 | + cmd_len = kvaser_usb_hydra_cmd_size(cmd); |
|---|
| 553 | 571 | |
|---|
| 554 | 572 | kvaser_usb_hydra_set_cmd_dest_he |
|---|
| 555 | 573 | (cmd, dev->card_data.hydra.channel_to_he[priv->channel]); |
|---|
| 556 | 574 | kvaser_usb_hydra_set_cmd_transid |
|---|
| 557 | 575 | (cmd, kvaser_usb_hydra_get_next_transid(dev)); |
|---|
| 558 | 576 | |
|---|
| 559 | | - err = kvaser_usb_send_cmd_async(priv, cmd, |
|---|
| 560 | | - kvaser_usb_hydra_cmd_size(cmd)); |
|---|
| 577 | + err = kvaser_usb_send_cmd_async(priv, cmd, cmd_len); |
|---|
| 561 | 578 | if (err) |
|---|
| 562 | 579 | kfree(cmd); |
|---|
| 563 | 580 | |
|---|
| .. | .. |
|---|
| 701 | 718 | { |
|---|
| 702 | 719 | struct kvaser_usb_dev_card_data *card_data = &dev->card_data; |
|---|
| 703 | 720 | struct kvaser_cmd *cmd; |
|---|
| 721 | + size_t cmd_len; |
|---|
| 704 | 722 | u32 value = 0; |
|---|
| 705 | 723 | u32 mask = 0; |
|---|
| 706 | 724 | u16 cap_cmd_res; |
|---|
| .. | .. |
|---|
| 712 | 730 | return -ENOMEM; |
|---|
| 713 | 731 | |
|---|
| 714 | 732 | cmd->header.cmd_no = CMD_GET_CAPABILITIES_REQ; |
|---|
| 733 | + cmd_len = kvaser_usb_hydra_cmd_size(cmd); |
|---|
| 715 | 734 | cmd->cap_req.cap_cmd = cpu_to_le16(cap_cmd_req); |
|---|
| 716 | 735 | |
|---|
| 717 | 736 | kvaser_usb_hydra_set_cmd_dest_he(cmd, card_data->hydra.sysdbg_he); |
|---|
| 718 | 737 | kvaser_usb_hydra_set_cmd_transid |
|---|
| 719 | 738 | (cmd, kvaser_usb_hydra_get_next_transid(dev)); |
|---|
| 720 | 739 | |
|---|
| 721 | | - err = kvaser_usb_send_cmd(dev, cmd, kvaser_usb_hydra_cmd_size(cmd)); |
|---|
| 740 | + err = kvaser_usb_send_cmd(dev, cmd, cmd_len); |
|---|
| 722 | 741 | if (err) |
|---|
| 723 | 742 | goto end; |
|---|
| 724 | 743 | |
|---|
| .. | .. |
|---|
| 812 | 831 | complete(&priv->flush_comp); |
|---|
| 813 | 832 | } |
|---|
| 814 | 833 | |
|---|
| 834 | +static void kvaser_usb_hydra_get_busparams_reply(const struct kvaser_usb *dev, |
|---|
| 835 | + const struct kvaser_cmd *cmd) |
|---|
| 836 | +{ |
|---|
| 837 | + struct kvaser_usb_net_priv *priv; |
|---|
| 838 | + struct kvaser_usb_net_hydra_priv *hydra; |
|---|
| 839 | + |
|---|
| 840 | + priv = kvaser_usb_hydra_net_priv_from_cmd(dev, cmd); |
|---|
| 841 | + if (!priv) |
|---|
| 842 | + return; |
|---|
| 843 | + |
|---|
| 844 | + hydra = priv->sub_priv; |
|---|
| 845 | + if (!hydra) |
|---|
| 846 | + return; |
|---|
| 847 | + |
|---|
| 848 | + switch (hydra->pending_get_busparams_type) { |
|---|
| 849 | + case KVASER_USB_HYDRA_BUSPARAM_TYPE_CAN: |
|---|
| 850 | + memcpy(&priv->busparams_nominal, &cmd->get_busparams_res.busparams, |
|---|
| 851 | + sizeof(priv->busparams_nominal)); |
|---|
| 852 | + break; |
|---|
| 853 | + case KVASER_USB_HYDRA_BUSPARAM_TYPE_CANFD: |
|---|
| 854 | + memcpy(&priv->busparams_data, &cmd->get_busparams_res.busparams, |
|---|
| 855 | + sizeof(priv->busparams_nominal)); |
|---|
| 856 | + break; |
|---|
| 857 | + default: |
|---|
| 858 | + dev_warn(&dev->intf->dev, "Unknown get_busparams_type %d\n", |
|---|
| 859 | + hydra->pending_get_busparams_type); |
|---|
| 860 | + break; |
|---|
| 861 | + } |
|---|
| 862 | + hydra->pending_get_busparams_type = -1; |
|---|
| 863 | + |
|---|
| 864 | + complete(&priv->get_busparams_comp); |
|---|
| 865 | +} |
|---|
| 866 | + |
|---|
| 815 | 867 | static void |
|---|
| 816 | 868 | kvaser_usb_hydra_bus_status_to_can_state(const struct kvaser_usb_net_priv *priv, |
|---|
| 817 | 869 | u8 bus_status, |
|---|
| .. | .. |
|---|
| 890 | 942 | new_state < CAN_STATE_BUS_OFF) |
|---|
| 891 | 943 | priv->can.can_stats.restarts++; |
|---|
| 892 | 944 | |
|---|
| 893 | | - cf->data[6] = bec->txerr; |
|---|
| 894 | | - cf->data[7] = bec->rxerr; |
|---|
| 945 | + if (new_state != CAN_STATE_BUS_OFF) { |
|---|
| 946 | + cf->data[6] = bec->txerr; |
|---|
| 947 | + cf->data[7] = bec->rxerr; |
|---|
| 948 | + } |
|---|
| 895 | 949 | |
|---|
| 896 | 950 | stats = &netdev->stats; |
|---|
| 897 | 951 | stats->rx_packets++; |
|---|
| .. | .. |
|---|
| 1045 | 1099 | shhwtstamps->hwtstamp = hwtstamp; |
|---|
| 1046 | 1100 | |
|---|
| 1047 | 1101 | cf->can_id |= CAN_ERR_BUSERROR; |
|---|
| 1048 | | - cf->data[6] = bec.txerr; |
|---|
| 1049 | | - cf->data[7] = bec.rxerr; |
|---|
| 1102 | + if (new_state != CAN_STATE_BUS_OFF) { |
|---|
| 1103 | + cf->data[6] = bec.txerr; |
|---|
| 1104 | + cf->data[7] = bec.rxerr; |
|---|
| 1105 | + } |
|---|
| 1050 | 1106 | |
|---|
| 1051 | 1107 | stats->rx_packets++; |
|---|
| 1052 | 1108 | stats->rx_bytes += cf->can_dlc; |
|---|
| .. | .. |
|---|
| 1095 | 1151 | struct kvaser_usb_net_priv *priv; |
|---|
| 1096 | 1152 | unsigned long irq_flags; |
|---|
| 1097 | 1153 | bool one_shot_fail = false; |
|---|
| 1154 | + bool is_err_frame = false; |
|---|
| 1098 | 1155 | u16 transid = kvaser_usb_hydra_get_cmd_transid(cmd); |
|---|
| 1099 | 1156 | |
|---|
| 1100 | 1157 | priv = kvaser_usb_hydra_net_priv_from_cmd(dev, cmd); |
|---|
| .. | .. |
|---|
| 1113 | 1170 | kvaser_usb_hydra_one_shot_fail(priv, cmd_ext); |
|---|
| 1114 | 1171 | one_shot_fail = true; |
|---|
| 1115 | 1172 | } |
|---|
| 1173 | + |
|---|
| 1174 | + is_err_frame = flags & KVASER_USB_HYDRA_CF_FLAG_TX_ACK && |
|---|
| 1175 | + flags & KVASER_USB_HYDRA_CF_FLAG_ERROR_FRAME; |
|---|
| 1116 | 1176 | } |
|---|
| 1117 | 1177 | |
|---|
| 1118 | 1178 | context = &priv->tx_contexts[transid % dev->max_tx_urbs]; |
|---|
| 1119 | | - if (!one_shot_fail) { |
|---|
| 1179 | + if (!one_shot_fail && !is_err_frame) { |
|---|
| 1120 | 1180 | struct net_device_stats *stats = &priv->netdev->stats; |
|---|
| 1121 | 1181 | |
|---|
| 1122 | 1182 | stats->tx_packets++; |
|---|
| .. | .. |
|---|
| 1288 | 1348 | |
|---|
| 1289 | 1349 | case CMD_CHIP_STATE_EVENT: |
|---|
| 1290 | 1350 | kvaser_usb_hydra_state_event(dev, cmd); |
|---|
| 1351 | + break; |
|---|
| 1352 | + |
|---|
| 1353 | + case CMD_GET_BUSPARAMS_RESP: |
|---|
| 1354 | + kvaser_usb_hydra_get_busparams_reply(dev, cmd); |
|---|
| 1291 | 1355 | break; |
|---|
| 1292 | 1356 | |
|---|
| 1293 | 1357 | case CMD_ERROR_EVENT: |
|---|
| .. | .. |
|---|
| 1490 | 1554 | return err; |
|---|
| 1491 | 1555 | } |
|---|
| 1492 | 1556 | |
|---|
| 1493 | | -static int kvaser_usb_hydra_set_bittiming(struct net_device *netdev) |
|---|
| 1557 | +static int kvaser_usb_hydra_get_busparams(struct kvaser_usb_net_priv *priv, |
|---|
| 1558 | + int busparams_type) |
|---|
| 1559 | +{ |
|---|
| 1560 | + struct kvaser_usb *dev = priv->dev; |
|---|
| 1561 | + struct kvaser_usb_net_hydra_priv *hydra = priv->sub_priv; |
|---|
| 1562 | + struct kvaser_cmd *cmd; |
|---|
| 1563 | + size_t cmd_len; |
|---|
| 1564 | + int err; |
|---|
| 1565 | + |
|---|
| 1566 | + if (!hydra) |
|---|
| 1567 | + return -EINVAL; |
|---|
| 1568 | + |
|---|
| 1569 | + cmd = kcalloc(1, sizeof(struct kvaser_cmd), GFP_KERNEL); |
|---|
| 1570 | + if (!cmd) |
|---|
| 1571 | + return -ENOMEM; |
|---|
| 1572 | + |
|---|
| 1573 | + cmd->header.cmd_no = CMD_GET_BUSPARAMS_REQ; |
|---|
| 1574 | + cmd_len = kvaser_usb_hydra_cmd_size(cmd); |
|---|
| 1575 | + kvaser_usb_hydra_set_cmd_dest_he |
|---|
| 1576 | + (cmd, dev->card_data.hydra.channel_to_he[priv->channel]); |
|---|
| 1577 | + kvaser_usb_hydra_set_cmd_transid |
|---|
| 1578 | + (cmd, kvaser_usb_hydra_get_next_transid(dev)); |
|---|
| 1579 | + cmd->get_busparams_req.type = busparams_type; |
|---|
| 1580 | + hydra->pending_get_busparams_type = busparams_type; |
|---|
| 1581 | + |
|---|
| 1582 | + reinit_completion(&priv->get_busparams_comp); |
|---|
| 1583 | + |
|---|
| 1584 | + err = kvaser_usb_send_cmd(dev, cmd, cmd_len); |
|---|
| 1585 | + if (err) |
|---|
| 1586 | + return err; |
|---|
| 1587 | + |
|---|
| 1588 | + if (!wait_for_completion_timeout(&priv->get_busparams_comp, |
|---|
| 1589 | + msecs_to_jiffies(KVASER_USB_TIMEOUT))) |
|---|
| 1590 | + return -ETIMEDOUT; |
|---|
| 1591 | + |
|---|
| 1592 | + return err; |
|---|
| 1593 | +} |
|---|
| 1594 | + |
|---|
| 1595 | +static int kvaser_usb_hydra_get_nominal_busparams(struct kvaser_usb_net_priv *priv) |
|---|
| 1596 | +{ |
|---|
| 1597 | + return kvaser_usb_hydra_get_busparams(priv, KVASER_USB_HYDRA_BUSPARAM_TYPE_CAN); |
|---|
| 1598 | +} |
|---|
| 1599 | + |
|---|
| 1600 | +static int kvaser_usb_hydra_get_data_busparams(struct kvaser_usb_net_priv *priv) |
|---|
| 1601 | +{ |
|---|
| 1602 | + return kvaser_usb_hydra_get_busparams(priv, KVASER_USB_HYDRA_BUSPARAM_TYPE_CANFD); |
|---|
| 1603 | +} |
|---|
| 1604 | + |
|---|
| 1605 | +static int kvaser_usb_hydra_set_bittiming(const struct net_device *netdev, |
|---|
| 1606 | + const struct kvaser_usb_busparams *busparams) |
|---|
| 1494 | 1607 | { |
|---|
| 1495 | 1608 | struct kvaser_cmd *cmd; |
|---|
| 1496 | 1609 | struct kvaser_usb_net_priv *priv = netdev_priv(netdev); |
|---|
| 1497 | | - struct can_bittiming *bt = &priv->can.bittiming; |
|---|
| 1498 | 1610 | struct kvaser_usb *dev = priv->dev; |
|---|
| 1499 | | - int tseg1 = bt->prop_seg + bt->phase_seg1; |
|---|
| 1500 | | - int tseg2 = bt->phase_seg2; |
|---|
| 1501 | | - int sjw = bt->sjw; |
|---|
| 1611 | + size_t cmd_len; |
|---|
| 1502 | 1612 | int err; |
|---|
| 1503 | 1613 | |
|---|
| 1504 | 1614 | cmd = kcalloc(1, sizeof(struct kvaser_cmd), GFP_KERNEL); |
|---|
| .. | .. |
|---|
| 1506 | 1616 | return -ENOMEM; |
|---|
| 1507 | 1617 | |
|---|
| 1508 | 1618 | cmd->header.cmd_no = CMD_SET_BUSPARAMS_REQ; |
|---|
| 1509 | | - cmd->set_busparams_req.bitrate = cpu_to_le32(bt->bitrate); |
|---|
| 1510 | | - cmd->set_busparams_req.sjw = (u8)sjw; |
|---|
| 1511 | | - cmd->set_busparams_req.tseg1 = (u8)tseg1; |
|---|
| 1512 | | - cmd->set_busparams_req.tseg2 = (u8)tseg2; |
|---|
| 1513 | | - cmd->set_busparams_req.nsamples = 1; |
|---|
| 1619 | + cmd_len = kvaser_usb_hydra_cmd_size(cmd); |
|---|
| 1620 | + memcpy(&cmd->set_busparams_req.busparams_nominal, busparams, |
|---|
| 1621 | + sizeof(cmd->set_busparams_req.busparams_nominal)); |
|---|
| 1514 | 1622 | |
|---|
| 1515 | 1623 | kvaser_usb_hydra_set_cmd_dest_he |
|---|
| 1516 | 1624 | (cmd, dev->card_data.hydra.channel_to_he[priv->channel]); |
|---|
| 1517 | 1625 | kvaser_usb_hydra_set_cmd_transid |
|---|
| 1518 | 1626 | (cmd, kvaser_usb_hydra_get_next_transid(dev)); |
|---|
| 1519 | 1627 | |
|---|
| 1520 | | - err = kvaser_usb_send_cmd(dev, cmd, kvaser_usb_hydra_cmd_size(cmd)); |
|---|
| 1628 | + err = kvaser_usb_send_cmd(dev, cmd, cmd_len); |
|---|
| 1521 | 1629 | |
|---|
| 1522 | 1630 | kfree(cmd); |
|---|
| 1523 | 1631 | |
|---|
| 1524 | 1632 | return err; |
|---|
| 1525 | 1633 | } |
|---|
| 1526 | 1634 | |
|---|
| 1527 | | -static int kvaser_usb_hydra_set_data_bittiming(struct net_device *netdev) |
|---|
| 1635 | +static int kvaser_usb_hydra_set_data_bittiming(const struct net_device *netdev, |
|---|
| 1636 | + const struct kvaser_usb_busparams *busparams) |
|---|
| 1528 | 1637 | { |
|---|
| 1529 | 1638 | struct kvaser_cmd *cmd; |
|---|
| 1530 | 1639 | struct kvaser_usb_net_priv *priv = netdev_priv(netdev); |
|---|
| 1531 | | - struct can_bittiming *dbt = &priv->can.data_bittiming; |
|---|
| 1532 | 1640 | struct kvaser_usb *dev = priv->dev; |
|---|
| 1533 | | - int tseg1 = dbt->prop_seg + dbt->phase_seg1; |
|---|
| 1534 | | - int tseg2 = dbt->phase_seg2; |
|---|
| 1535 | | - int sjw = dbt->sjw; |
|---|
| 1641 | + size_t cmd_len; |
|---|
| 1536 | 1642 | int err; |
|---|
| 1537 | 1643 | |
|---|
| 1538 | 1644 | cmd = kcalloc(1, sizeof(struct kvaser_cmd), GFP_KERNEL); |
|---|
| .. | .. |
|---|
| 1540 | 1646 | return -ENOMEM; |
|---|
| 1541 | 1647 | |
|---|
| 1542 | 1648 | cmd->header.cmd_no = CMD_SET_BUSPARAMS_FD_REQ; |
|---|
| 1543 | | - cmd->set_busparams_req.bitrate_d = cpu_to_le32(dbt->bitrate); |
|---|
| 1544 | | - cmd->set_busparams_req.sjw_d = (u8)sjw; |
|---|
| 1545 | | - cmd->set_busparams_req.tseg1_d = (u8)tseg1; |
|---|
| 1546 | | - cmd->set_busparams_req.tseg2_d = (u8)tseg2; |
|---|
| 1547 | | - cmd->set_busparams_req.nsamples_d = 1; |
|---|
| 1649 | + cmd_len = kvaser_usb_hydra_cmd_size(cmd); |
|---|
| 1650 | + memcpy(&cmd->set_busparams_req.busparams_data, busparams, |
|---|
| 1651 | + sizeof(cmd->set_busparams_req.busparams_data)); |
|---|
| 1548 | 1652 | |
|---|
| 1549 | 1653 | if (priv->can.ctrlmode & CAN_CTRLMODE_FD) { |
|---|
| 1550 | 1654 | if (priv->can.ctrlmode & CAN_CTRLMODE_FD_NON_ISO) |
|---|
| .. | .. |
|---|
| 1560 | 1664 | kvaser_usb_hydra_set_cmd_transid |
|---|
| 1561 | 1665 | (cmd, kvaser_usb_hydra_get_next_transid(dev)); |
|---|
| 1562 | 1666 | |
|---|
| 1563 | | - err = kvaser_usb_send_cmd(dev, cmd, kvaser_usb_hydra_cmd_size(cmd)); |
|---|
| 1667 | + err = kvaser_usb_send_cmd(dev, cmd, cmd_len); |
|---|
| 1564 | 1668 | |
|---|
| 1565 | 1669 | kfree(cmd); |
|---|
| 1566 | 1670 | |
|---|
| .. | .. |
|---|
| 1651 | 1755 | return 0; |
|---|
| 1652 | 1756 | } |
|---|
| 1653 | 1757 | |
|---|
| 1758 | +static int kvaser_usb_hydra_init_channel(struct kvaser_usb_net_priv *priv) |
|---|
| 1759 | +{ |
|---|
| 1760 | + struct kvaser_usb_net_hydra_priv *hydra; |
|---|
| 1761 | + |
|---|
| 1762 | + hydra = devm_kzalloc(&priv->dev->intf->dev, sizeof(*hydra), GFP_KERNEL); |
|---|
| 1763 | + if (!hydra) |
|---|
| 1764 | + return -ENOMEM; |
|---|
| 1765 | + |
|---|
| 1766 | + priv->sub_priv = hydra; |
|---|
| 1767 | + |
|---|
| 1768 | + return 0; |
|---|
| 1769 | +} |
|---|
| 1770 | + |
|---|
| 1654 | 1771 | static int kvaser_usb_hydra_get_software_info(struct kvaser_usb *dev) |
|---|
| 1655 | 1772 | { |
|---|
| 1656 | 1773 | struct kvaser_cmd cmd; |
|---|
| .. | .. |
|---|
| 1675 | 1792 | static int kvaser_usb_hydra_get_software_details(struct kvaser_usb *dev) |
|---|
| 1676 | 1793 | { |
|---|
| 1677 | 1794 | struct kvaser_cmd *cmd; |
|---|
| 1795 | + size_t cmd_len; |
|---|
| 1678 | 1796 | int err; |
|---|
| 1679 | 1797 | u32 flags; |
|---|
| 1680 | 1798 | struct kvaser_usb_dev_card_data *card_data = &dev->card_data; |
|---|
| .. | .. |
|---|
| 1684 | 1802 | return -ENOMEM; |
|---|
| 1685 | 1803 | |
|---|
| 1686 | 1804 | cmd->header.cmd_no = CMD_GET_SOFTWARE_DETAILS_REQ; |
|---|
| 1805 | + cmd_len = kvaser_usb_hydra_cmd_size(cmd); |
|---|
| 1687 | 1806 | cmd->sw_detail_req.use_ext_cmd = 1; |
|---|
| 1688 | 1807 | kvaser_usb_hydra_set_cmd_dest_he |
|---|
| 1689 | 1808 | (cmd, KVASER_USB_HYDRA_HE_ADDRESS_ILLEGAL); |
|---|
| .. | .. |
|---|
| 1691 | 1810 | kvaser_usb_hydra_set_cmd_transid |
|---|
| 1692 | 1811 | (cmd, kvaser_usb_hydra_get_next_transid(dev)); |
|---|
| 1693 | 1812 | |
|---|
| 1694 | | - err = kvaser_usb_send_cmd(dev, cmd, kvaser_usb_hydra_cmd_size(cmd)); |
|---|
| 1813 | + err = kvaser_usb_send_cmd(dev, cmd, cmd_len); |
|---|
| 1695 | 1814 | if (err) |
|---|
| 1696 | 1815 | goto end; |
|---|
| 1697 | 1816 | |
|---|
| .. | .. |
|---|
| 1807 | 1926 | { |
|---|
| 1808 | 1927 | struct kvaser_usb *dev = priv->dev; |
|---|
| 1809 | 1928 | struct kvaser_cmd *cmd; |
|---|
| 1929 | + size_t cmd_len; |
|---|
| 1810 | 1930 | int err; |
|---|
| 1811 | 1931 | |
|---|
| 1812 | 1932 | if ((priv->can.ctrlmode & |
|---|
| .. | .. |
|---|
| 1822 | 1942 | return -ENOMEM; |
|---|
| 1823 | 1943 | |
|---|
| 1824 | 1944 | cmd->header.cmd_no = CMD_SET_DRIVERMODE_REQ; |
|---|
| 1945 | + cmd_len = kvaser_usb_hydra_cmd_size(cmd); |
|---|
| 1825 | 1946 | kvaser_usb_hydra_set_cmd_dest_he |
|---|
| 1826 | 1947 | (cmd, dev->card_data.hydra.channel_to_he[priv->channel]); |
|---|
| 1827 | 1948 | kvaser_usb_hydra_set_cmd_transid |
|---|
| .. | .. |
|---|
| 1831 | 1952 | else |
|---|
| 1832 | 1953 | cmd->set_ctrlmode.mode = KVASER_USB_HYDRA_CTRLMODE_NORMAL; |
|---|
| 1833 | 1954 | |
|---|
| 1834 | | - err = kvaser_usb_send_cmd(dev, cmd, kvaser_usb_hydra_cmd_size(cmd)); |
|---|
| 1955 | + err = kvaser_usb_send_cmd(dev, cmd, cmd_len); |
|---|
| 1835 | 1956 | kfree(cmd); |
|---|
| 1836 | 1957 | |
|---|
| 1837 | 1958 | return err; |
|---|
| .. | .. |
|---|
| 1841 | 1962 | { |
|---|
| 1842 | 1963 | int err; |
|---|
| 1843 | 1964 | |
|---|
| 1844 | | - init_completion(&priv->start_comp); |
|---|
| 1965 | + reinit_completion(&priv->start_comp); |
|---|
| 1845 | 1966 | |
|---|
| 1846 | 1967 | err = kvaser_usb_hydra_send_simple_cmd(priv->dev, CMD_START_CHIP_REQ, |
|---|
| 1847 | 1968 | priv->channel); |
|---|
| .. | .. |
|---|
| 1859 | 1980 | { |
|---|
| 1860 | 1981 | int err; |
|---|
| 1861 | 1982 | |
|---|
| 1862 | | - init_completion(&priv->stop_comp); |
|---|
| 1983 | + reinit_completion(&priv->stop_comp); |
|---|
| 1863 | 1984 | |
|---|
| 1864 | 1985 | /* Make sure we do not report invalid BUS_OFF from CMD_CHIP_STATE_EVENT |
|---|
| 1865 | 1986 | * see comment in kvaser_usb_hydra_update_state() |
|---|
| .. | .. |
|---|
| 1882 | 2003 | { |
|---|
| 1883 | 2004 | int err; |
|---|
| 1884 | 2005 | |
|---|
| 1885 | | - init_completion(&priv->flush_comp); |
|---|
| 2006 | + reinit_completion(&priv->flush_comp); |
|---|
| 1886 | 2007 | |
|---|
| 1887 | 2008 | err = kvaser_usb_hydra_send_simple_cmd(priv->dev, CMD_FLUSH_QUEUE, |
|---|
| 1888 | 2009 | priv->channel); |
|---|
| .. | .. |
|---|
| 1993 | 2114 | const struct kvaser_usb_dev_ops kvaser_usb_hydra_dev_ops = { |
|---|
| 1994 | 2115 | .dev_set_mode = kvaser_usb_hydra_set_mode, |
|---|
| 1995 | 2116 | .dev_set_bittiming = kvaser_usb_hydra_set_bittiming, |
|---|
| 2117 | + .dev_get_busparams = kvaser_usb_hydra_get_nominal_busparams, |
|---|
| 1996 | 2118 | .dev_set_data_bittiming = kvaser_usb_hydra_set_data_bittiming, |
|---|
| 2119 | + .dev_get_data_busparams = kvaser_usb_hydra_get_data_busparams, |
|---|
| 1997 | 2120 | .dev_get_berr_counter = kvaser_usb_hydra_get_berr_counter, |
|---|
| 1998 | 2121 | .dev_setup_endpoints = kvaser_usb_hydra_setup_endpoints, |
|---|
| 1999 | 2122 | .dev_init_card = kvaser_usb_hydra_init_card, |
|---|
| 2123 | + .dev_init_channel = kvaser_usb_hydra_init_channel, |
|---|
| 2000 | 2124 | .dev_get_software_info = kvaser_usb_hydra_get_software_info, |
|---|
| 2001 | 2125 | .dev_get_software_details = kvaser_usb_hydra_get_software_details, |
|---|
| 2002 | 2126 | .dev_get_card_info = kvaser_usb_hydra_get_card_info, |
|---|
| .. | .. |
|---|
| 2024 | 2148 | .freq = 24000000, |
|---|
| 2025 | 2149 | }, |
|---|
| 2026 | 2150 | .timestamp_freq = 1, |
|---|
| 2027 | | - .bittiming_const = &kvaser_usb_hydra_flexc_bittiming_c, |
|---|
| 2151 | + .bittiming_const = &kvaser_usb_flexc_bittiming_const, |
|---|
| 2028 | 2152 | }; |
|---|